Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1 | //===--- ASTWriter.cpp - AST File Writer ------------------------*- C++ -*-===// |
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" |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 15 | #include "clang/Serialization/ModuleFileExtension.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 17 | #include "ASTReaderInternals.h" |
| 18 | #include "MultiOnDiskHashTable.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTContext.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclContextInternals.h" |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclFriend.h" |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclLookups.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 25 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 27 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 28 | #include "clang/AST/TypeLocVisitor.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 29 | #include "clang/Basic/DiagnosticOptions.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 30 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 31 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 33 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 34 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | cb177f1 | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 35 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 36 | #include "clang/Basic/Version.h" |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 37 | #include "clang/Basic/VersionTuple.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 38 | #include "clang/Lex/HeaderSearch.h" |
| 39 | #include "clang/Lex/HeaderSearchOptions.h" |
| 40 | #include "clang/Lex/MacroInfo.h" |
| 41 | #include "clang/Lex/PreprocessingRecord.h" |
| 42 | #include "clang/Lex/Preprocessor.h" |
| 43 | #include "clang/Lex/PreprocessorOptions.h" |
| 44 | #include "clang/Sema/IdentifierResolver.h" |
| 45 | #include "clang/Sema/Sema.h" |
| 46 | #include "clang/Serialization/ASTReader.h" |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 47 | #include "clang/Serialization/SerializationDiagnostic.h" |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 48 | #include "llvm/ADT/APFloat.h" |
| 49 | #include "llvm/ADT/APInt.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 50 | #include "llvm/ADT/Hashing.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 51 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 52 | #include "llvm/Bitcode/BitstreamWriter.h" |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 53 | #include "llvm/Support/Compression.h" |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 54 | #include "llvm/Support/EndianStream.h" |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 55 | #include "llvm/Support/FileSystem.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 56 | #include "llvm/Support/MemoryBuffer.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 57 | #include "llvm/Support/OnDiskHashTable.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 58 | #include "llvm/Support/Path.h" |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 59 | #include "llvm/Support/Process.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 60 | #include <algorithm> |
Chris Lattner | 225dd6c | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 61 | #include <cstdio> |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 62 | #include <string.h> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 63 | #include <utility> |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 64 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 65 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 66 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 67 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 68 | template <typename T, typename Allocator> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 69 | static StringRef bytes(const std::vector<T, Allocator> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 70 | if (v.empty()) return StringRef(); |
| 71 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
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 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 74 | |
| 75 | template <typename T> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 76 | static StringRef bytes(const SmallVectorImpl<T> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 77 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 78 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 81 | //===----------------------------------------------------------------------===// |
| 82 | // Type serialization |
| 83 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 84 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 85 | namespace clang { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 86 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 87 | ASTWriter &Writer; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 88 | ASTRecordWriter Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 89 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 90 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 91 | TypeCode Code; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 92 | /// \brief Abbreviation to use for the record, if any. |
| 93 | unsigned AbbrevToUse; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 94 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 95 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 96 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 97 | : Writer(Writer), Record(Writer, Record), Code((TypeCode)0), AbbrevToUse(0) { } |
| 98 | |
| 99 | uint64_t Emit() { |
| 100 | return Record.Emit(Code, AbbrevToUse); |
| 101 | } |
| 102 | |
| 103 | void Visit(QualType T) { |
| 104 | if (T.hasLocalNonFastQualifiers()) { |
| 105 | Qualifiers Qs = T.getLocalQualifiers(); |
| 106 | Record.AddTypeRef(T.getLocalUnqualifiedType()); |
| 107 | Record.push_back(Qs.getAsOpaqueValue()); |
| 108 | Code = TYPE_EXT_QUAL; |
| 109 | AbbrevToUse = Writer.TypeExtQualAbbrev; |
| 110 | } else { |
| 111 | switch (T->getTypeClass()) { |
| 112 | // For all of the concrete, non-dependent types, call the |
| 113 | // appropriate visitor function. |
| 114 | #define TYPE(Class, Base) \ |
| 115 | case Type::Class: Visit##Class##Type(cast<Class##Type>(T)); break; |
| 116 | #define ABSTRACT_TYPE(Class, Base) |
| 117 | #include "clang/AST/TypeNodes.def" |
| 118 | } |
| 119 | } |
| 120 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 121 | |
| 122 | void VisitArrayType(const ArrayType *T); |
| 123 | void VisitFunctionType(const FunctionType *T); |
| 124 | void VisitTagType(const TagType *T); |
| 125 | |
| 126 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 127 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 128 | #include "clang/AST/TypeNodes.def" |
| 129 | }; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 130 | } // end namespace clang |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 131 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 132 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 133 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 136 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 137 | Record.AddTypeRef(T->getElementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 138 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 141 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 142 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 143 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 146 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 147 | Record.AddTypeRef(T->getOriginalType()); |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 148 | Code = TYPE_DECAYED; |
| 149 | } |
| 150 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 151 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 152 | Record.AddTypeRef(T->getOriginalType()); |
| 153 | Record.AddTypeRef(T->getAdjustedType()); |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 154 | Code = TYPE_ADJUSTED; |
| 155 | } |
| 156 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 157 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 158 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 159 | Code = TYPE_BLOCK_POINTER; |
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::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 163 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 164 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 165 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 168 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 169 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 170 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 173 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 174 | Record.AddTypeRef(T->getPointeeType()); |
| 175 | Record.AddTypeRef(QualType(T->getClass(), 0)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 176 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 179 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 180 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 181 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 182 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 185 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 186 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 187 | Record.AddAPInt(T->getSize()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 188 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 191 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 192 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 193 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 196 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 197 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 198 | Record.AddSourceLocation(T->getLBracketLoc()); |
| 199 | Record.AddSourceLocation(T->getRBracketLoc()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 200 | Record.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 201 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 204 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 205 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 206 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 207 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 208 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 211 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 212 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 213 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 216 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 217 | Record.AddTypeRef(T->getReturnType()); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 218 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 219 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 220 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 221 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 222 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 223 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 224 | Record.push_back(C.getProducesResult()); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 225 | |
| 226 | if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult()) |
| 227 | AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 230 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 231 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 232 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 235 | static void addExceptionSpec(const FunctionProtoType *T, |
| 236 | ASTRecordWriter &Record) { |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 237 | Record.push_back(T->getExceptionSpecType()); |
| 238 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 239 | Record.push_back(T->getNumExceptions()); |
| 240 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 241 | Record.AddTypeRef(T->getExceptionType(I)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 242 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 243 | Record.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 244 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 245 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
| 246 | Record.AddDeclRef(T->getExceptionSpecTemplate()); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 247 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 248 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 249 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 253 | VisitFunctionType(T); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 254 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 255 | Record.push_back(T->isVariadic()); |
| 256 | Record.push_back(T->hasTrailingReturn()); |
| 257 | Record.push_back(T->getTypeQuals()); |
| 258 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 259 | addExceptionSpec(T, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 260 | |
| 261 | Record.push_back(T->getNumParams()); |
| 262 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 263 | Record.AddTypeRef(T->getParamType(I)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 264 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 265 | if (T->hasExtParameterInfos()) { |
| 266 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 267 | Record.push_back(T->getExtParameterInfo(I).getOpaqueValue()); |
| 268 | } |
| 269 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 270 | if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 271 | T->getRefQualifier() || T->getExceptionSpecType() != EST_None || |
| 272 | T->hasExtParameterInfos()) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 273 | AbbrevToUse = 0; |
| 274 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 275 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 278 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 279 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 280 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 281 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 282 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 283 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 284 | Record.AddDeclRef(T->getDecl()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 285 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 286 | Record.AddTypeRef(T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 287 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 290 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 291 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 292 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 295 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 296 | Record.AddTypeRef(T->getUnderlyingType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 297 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 300 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 301 | Record.AddTypeRef(T->getUnderlyingType()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 302 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 303 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 306 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 307 | Record.AddTypeRef(T->getBaseType()); |
| 308 | Record.AddTypeRef(T->getUnderlyingType()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 309 | Record.push_back(T->getUTTKind()); |
| 310 | Code = TYPE_UNARY_TRANSFORM; |
| 311 | } |
| 312 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 313 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 314 | Record.AddTypeRef(T->getDeducedType()); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 315 | Record.push_back((unsigned)T->getKeyword()); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 316 | if (T->getDeducedType().isNull()) |
| 317 | Record.push_back(T->isDependentType()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 318 | Code = TYPE_AUTO; |
| 319 | } |
| 320 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 321 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 322 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 323 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 324 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 325 | "Cannot serialize in the middle of a type definition"); |
| 326 | } |
| 327 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 328 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 329 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 330 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 333 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 334 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 335 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 336 | } |
| 337 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 338 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 339 | Record.AddTypeRef(T->getModifiedType()); |
| 340 | Record.AddTypeRef(T->getEquivalentType()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 341 | Record.push_back(T->getAttrKind()); |
| 342 | Code = TYPE_ATTRIBUTED; |
| 343 | } |
| 344 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 345 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 346 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 347 | const SubstTemplateTypeParmType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 348 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 349 | Record.AddTypeRef(T->getReplacementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 350 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 354 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 355 | const SubstTemplateTypeParmPackType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 356 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 357 | Record.AddTemplateArgument(T->getArgumentPack()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 358 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 359 | } |
| 360 | |
| 361 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 362 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 363 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 364 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 365 | Record.AddTemplateName(T->getTemplateName()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 366 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 367 | for (const auto &ArgI : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 368 | Record.AddTemplateArgument(ArgI); |
| 369 | Record.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() |
| 370 | : T->isCanonicalUnqualified() |
| 371 | ? QualType() |
| 372 | : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 373 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 377 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 378 | VisitArrayType(T); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 379 | Record.AddStmt(T->getSizeExpr()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 380 | Record.AddSourceRange(T->getBracketsRange()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 381 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 385 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 386 | const DependentSizedExtVectorType *T) { |
| 387 | // FIXME: Serialize this type (C++ only) |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 388 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 392 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 393 | Record.push_back(T->getDepth()); |
| 394 | Record.push_back(T->getIndex()); |
| 395 | Record.push_back(T->isParameterPack()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 396 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 397 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 401 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 402 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 403 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 404 | Record.AddIdentifierRef(T->getIdentifier()); |
| 405 | Record.AddTypeRef( |
| 406 | T->isCanonicalUnqualified() ? QualType() : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 407 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 411 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 412 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 413 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 414 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 415 | Record.AddIdentifierRef(T->getIdentifier()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 416 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 417 | for (const auto &I : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 418 | Record.AddTemplateArgument(I); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 419 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 422 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 423 | Record.AddTypeRef(T->getPattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 424 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 425 | Record.push_back(*NumExpansions + 1); |
| 426 | else |
| 427 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 428 | Code = TYPE_PACK_EXPANSION; |
| 429 | } |
| 430 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 431 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 432 | Record.AddTypeRef(T->getInnerType()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 433 | Code = TYPE_PAREN; |
| 434 | } |
| 435 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 436 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 437 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 438 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 439 | Record.AddTypeRef(T->getNamedType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 440 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 443 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 444 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
| 445 | Record.AddTypeRef(T->getInjectedSpecializationType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 446 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 449 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 450 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 451 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 454 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 455 | Record.AddTypeRef(T->getBaseType()); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 456 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 457 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 458 | Record.AddTypeRef(TypeArg); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 459 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 460 | for (const auto *I : T->quals()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 461 | Record.AddDeclRef(I); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 462 | Record.push_back(T->isKindOfTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 463 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 466 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 467 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 468 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 469 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 472 | void |
| 473 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 474 | Record.AddTypeRef(T->getValueType()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 475 | Code = TYPE_ATOMIC; |
| 476 | } |
| 477 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 478 | void |
| 479 | ASTTypeWriter::VisitPipeType(const PipeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 480 | Record.AddTypeRef(T->getElementType()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 481 | Code = TYPE_PIPE; |
| 482 | } |
| 483 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 484 | namespace { |
| 485 | |
| 486 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 487 | ASTRecordWriter &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 488 | |
| 489 | public: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 490 | TypeLocWriter(ASTRecordWriter &Record) |
| 491 | : Record(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 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 494 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 495 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 496 | #include "clang/AST/TypeLocNodes.def" |
| 497 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 498 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 499 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 500 | }; |
| 501 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 502 | } // end anonymous namespace |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 503 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 504 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 505 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 506 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 507 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 508 | Record.AddSourceLocation(TL.getBuiltinLoc()); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 509 | if (TL.needsExtraLocalData()) { |
| 510 | Record.push_back(TL.getWrittenTypeSpec()); |
| 511 | Record.push_back(TL.getWrittenSignSpec()); |
| 512 | Record.push_back(TL.getWrittenWidthSpec()); |
| 513 | Record.push_back(TL.hasModeAttr()); |
| 514 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 515 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 516 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 517 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 518 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 519 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 520 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 521 | } |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 522 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 523 | // nothing to do |
| 524 | } |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 525 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 526 | // nothing to do |
| 527 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 528 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 529 | Record.AddSourceLocation(TL.getCaretLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 530 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 531 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 532 | Record.AddSourceLocation(TL.getAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 533 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 534 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 535 | Record.AddSourceLocation(TL.getAmpAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 536 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 537 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 538 | Record.AddSourceLocation(TL.getStarLoc()); |
| 539 | Record.AddTypeSourceInfo(TL.getClassTInfo()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 540 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 541 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 542 | Record.AddSourceLocation(TL.getLBracketLoc()); |
| 543 | Record.AddSourceLocation(TL.getRBracketLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 544 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 545 | if (TL.getSizeExpr()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 546 | Record.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 547 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 548 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 549 | VisitArrayTypeLoc(TL); |
| 550 | } |
| 551 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 552 | VisitArrayTypeLoc(TL); |
| 553 | } |
| 554 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 555 | VisitArrayTypeLoc(TL); |
| 556 | } |
| 557 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 558 | DependentSizedArrayTypeLoc TL) { |
| 559 | VisitArrayTypeLoc(TL); |
| 560 | } |
| 561 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 562 | DependentSizedExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 563 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 564 | } |
| 565 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 566 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 567 | } |
| 568 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 569 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 570 | } |
| 571 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 572 | Record.AddSourceLocation(TL.getLocalRangeBegin()); |
| 573 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 574 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 575 | Record.AddSourceLocation(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 576 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 577 | Record.AddDeclRef(TL.getParam(i)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 578 | } |
| 579 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 580 | VisitFunctionTypeLoc(TL); |
| 581 | } |
| 582 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 583 | VisitFunctionTypeLoc(TL); |
| 584 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 585 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 586 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 587 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 588 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 589 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 590 | } |
| 591 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 592 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 593 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 594 | Record.AddSourceLocation(TL.getRParenLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 595 | } |
| 596 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 597 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 598 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 599 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 600 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 601 | } |
| 602 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 603 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 604 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 605 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 606 | Record.AddSourceLocation(TL.getKWLoc()); |
| 607 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 608 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 609 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 610 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 611 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 612 | Record.AddSourceLocation(TL.getNameLoc()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 613 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 614 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 615 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 616 | } |
| 617 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 618 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 619 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 620 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 621 | Record.AddSourceLocation(TL.getAttrNameLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 622 | if (TL.hasAttrOperand()) { |
| 623 | SourceRange range = TL.getAttrOperandParensRange(); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 624 | Record.AddSourceLocation(range.getBegin()); |
| 625 | Record.AddSourceLocation(range.getEnd()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 626 | } |
| 627 | if (TL.hasAttrExprOperand()) { |
| 628 | Expr *operand = TL.getAttrExprOperand(); |
| 629 | Record.push_back(operand ? 1 : 0); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 630 | if (operand) Record.AddStmt(operand); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 631 | } else if (TL.hasAttrEnumOperand()) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 632 | Record.AddSourceLocation(TL.getAttrEnumOperandLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 633 | } |
| 634 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 635 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 636 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 637 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 638 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 639 | SubstTemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 640 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 641 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 642 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 643 | SubstTemplateTypeParmPackTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 644 | Record.AddSourceLocation(TL.getNameLoc()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 645 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 646 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 647 | TemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 648 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 649 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 650 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 651 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 652 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 653 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 654 | TL.getArgLoc(i).getLocInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 655 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 656 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 657 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 658 | Record.AddSourceLocation(TL.getRParenLoc()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 659 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 660 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 661 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 662 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 663 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 664 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 665 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 666 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 667 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 668 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 669 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 670 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 671 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 672 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 673 | DependentTemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 674 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 675 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 676 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 677 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 678 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 679 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 680 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 681 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 682 | TL.getArgLoc(I).getLocInfo()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 683 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 684 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 685 | Record.AddSourceLocation(TL.getEllipsisLoc()); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 686 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 687 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 688 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 689 | } |
| 690 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 691 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 692 | Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); |
| 693 | Record.AddSourceLocation(TL.getTypeArgsRAngleLoc()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 694 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 695 | Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i)); |
| 696 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 697 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 698 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 699 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 700 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 701 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 702 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 703 | } |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 704 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 705 | Record.AddSourceLocation(TL.getKWLoc()); |
| 706 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 707 | Record.AddSourceLocation(TL.getRParenLoc()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 708 | } |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 709 | void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 710 | Record.AddSourceLocation(TL.getKWLoc()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 711 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 712 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 713 | void ASTWriter::WriteTypeAbbrevs() { |
| 714 | using namespace llvm; |
| 715 | |
| 716 | BitCodeAbbrev *Abv; |
| 717 | |
| 718 | // Abbreviation for TYPE_EXT_QUAL |
| 719 | Abv = new BitCodeAbbrev(); |
| 720 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 721 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 722 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
| 723 | TypeExtQualAbbrev = Stream.EmitAbbrev(Abv); |
| 724 | |
| 725 | // Abbreviation for TYPE_FUNCTION_PROTO |
| 726 | Abv = new BitCodeAbbrev(); |
| 727 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 728 | // FunctionType |
| 729 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 730 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 731 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 732 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 733 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 734 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
| 735 | // FunctionProtoType |
| 736 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 737 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 738 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 739 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 740 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 741 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 742 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 743 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
| 744 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(Abv); |
| 745 | } |
| 746 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 747 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 748 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 749 | //===----------------------------------------------------------------------===// |
| 750 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 751 | static void EmitBlockID(unsigned ID, const char *Name, |
| 752 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 753 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 754 | Record.clear(); |
| 755 | Record.push_back(ID); |
| 756 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 757 | |
| 758 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 759 | if (!Name || Name[0] == 0) |
| 760 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 761 | Record.clear(); |
| 762 | while (*Name) |
| 763 | Record.push_back(*Name++); |
| 764 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 765 | } |
| 766 | |
| 767 | static void EmitRecordID(unsigned ID, const char *Name, |
| 768 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 769 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 770 | Record.clear(); |
| 771 | Record.push_back(ID); |
| 772 | while (*Name) |
| 773 | Record.push_back(*Name++); |
| 774 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 778 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 779 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 780 | RECORD(STMT_STOP); |
| 781 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 782 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 783 | RECORD(STMT_NULL); |
| 784 | RECORD(STMT_COMPOUND); |
| 785 | RECORD(STMT_CASE); |
| 786 | RECORD(STMT_DEFAULT); |
| 787 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 788 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 789 | RECORD(STMT_IF); |
| 790 | RECORD(STMT_SWITCH); |
| 791 | RECORD(STMT_WHILE); |
| 792 | RECORD(STMT_DO); |
| 793 | RECORD(STMT_FOR); |
| 794 | RECORD(STMT_GOTO); |
| 795 | RECORD(STMT_INDIRECT_GOTO); |
| 796 | RECORD(STMT_CONTINUE); |
| 797 | RECORD(STMT_BREAK); |
| 798 | RECORD(STMT_RETURN); |
| 799 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 800 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 801 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 802 | RECORD(EXPR_PREDEFINED); |
| 803 | RECORD(EXPR_DECL_REF); |
| 804 | RECORD(EXPR_INTEGER_LITERAL); |
| 805 | RECORD(EXPR_FLOATING_LITERAL); |
| 806 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 807 | RECORD(EXPR_STRING_LITERAL); |
| 808 | RECORD(EXPR_CHARACTER_LITERAL); |
| 809 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 810 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 811 | RECORD(EXPR_UNARY_OPERATOR); |
| 812 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 813 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 814 | RECORD(EXPR_CALL); |
| 815 | RECORD(EXPR_MEMBER); |
| 816 | RECORD(EXPR_BINARY_OPERATOR); |
| 817 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 818 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 819 | RECORD(EXPR_IMPLICIT_CAST); |
| 820 | RECORD(EXPR_CSTYLE_CAST); |
| 821 | RECORD(EXPR_COMPOUND_LITERAL); |
| 822 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 823 | RECORD(EXPR_INIT_LIST); |
| 824 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 825 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 826 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 827 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 828 | RECORD(EXPR_VA_ARG); |
| 829 | RECORD(EXPR_ADDR_LABEL); |
| 830 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 831 | RECORD(EXPR_CHOOSE); |
| 832 | RECORD(EXPR_GNU_NULL); |
| 833 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 834 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 835 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 836 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 837 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 838 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 839 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 840 | RECORD(EXPR_OBJC_ENCODE); |
| 841 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 842 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 843 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 844 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 845 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 846 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 847 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 848 | RECORD(STMT_OBJC_CATCH); |
| 849 | RECORD(STMT_OBJC_FINALLY); |
| 850 | RECORD(STMT_OBJC_AT_TRY); |
| 851 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 852 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 853 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 854 | RECORD(STMT_CXX_CATCH); |
| 855 | RECORD(STMT_CXX_TRY); |
| 856 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 857 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 858 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 859 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 860 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 861 | RECORD(EXPR_CXX_STATIC_CAST); |
| 862 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 863 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 864 | RECORD(EXPR_CXX_CONST_CAST); |
| 865 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 866 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 867 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 868 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 869 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 870 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 871 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 872 | RECORD(EXPR_CXX_THIS); |
| 873 | RECORD(EXPR_CXX_THROW); |
| 874 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 875 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 876 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 877 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 878 | RECORD(EXPR_CXX_NEW); |
| 879 | RECORD(EXPR_CXX_DELETE); |
| 880 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 881 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 882 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 883 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 884 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 885 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 886 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 887 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 888 | RECORD(EXPR_CXX_NOEXCEPT); |
| 889 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 890 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 891 | RECORD(EXPR_TYPE_TRAIT); |
| 892 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 893 | RECORD(EXPR_PACK_EXPANSION); |
| 894 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 895 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 896 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 897 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 898 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 899 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 900 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 901 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 902 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 903 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 904 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 906 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 907 | RecordData Record; |
| 908 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 910 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 911 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 912 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 913 | // Control Block. |
| 914 | BLOCK(CONTROL_BLOCK); |
| 915 | RECORD(METADATA); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 916 | RECORD(SIGNATURE); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 917 | RECORD(MODULE_NAME); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 918 | RECORD(MODULE_DIRECTORY); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 919 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 920 | RECORD(IMPORTS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 921 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 922 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 923 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 924 | RECORD(INPUT_FILE_OFFSETS); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 925 | |
| 926 | BLOCK(OPTIONS_BLOCK); |
| 927 | RECORD(LANGUAGE_OPTIONS); |
| 928 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 929 | RECORD(DIAGNOSTIC_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 930 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 931 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 932 | RECORD(PREPROCESSOR_OPTIONS); |
| 933 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 934 | BLOCK(INPUT_FILES_BLOCK); |
| 935 | RECORD(INPUT_FILE); |
| 936 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 937 | // AST Top-Level Block. |
| 938 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 939 | RECORD(TYPE_OFFSET); |
| 940 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 941 | RECORD(IDENTIFIER_OFFSET); |
| 942 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 943 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 944 | RECORD(SPECIAL_TYPES); |
| 945 | RECORD(STATISTICS); |
| 946 | RECORD(TENTATIVE_DEFINITIONS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 947 | RECORD(SELECTOR_OFFSETS); |
| 948 | RECORD(METHOD_POOL); |
| 949 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 950 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 951 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 952 | RECORD(EXT_VECTOR_DECLS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 953 | RECORD(UNUSED_FILESCOPED_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 954 | RECORD(PPD_ENTITIES_OFFSETS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 955 | RECORD(VTABLE_USES); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 956 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 957 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 958 | RECORD(SEMA_DECL_REFS); |
| 959 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 960 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 961 | RECORD(UPDATE_VISIBLE); |
| 962 | RECORD(DECL_UPDATE_OFFSETS); |
| 963 | RECORD(DECL_UPDATES); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 964 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 965 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 966 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 967 | RECORD(FP_PRAGMA_OPTIONS); |
| 968 | RECORD(OPENCL_EXTENSIONS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 969 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 970 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 971 | RECORD(MODULE_OFFSET_MAP); |
| 972 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 973 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 974 | RECORD(FILE_SORTED_DECLS); |
| 975 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 976 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 977 | RECORD(MACRO_OFFSET); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 978 | RECORD(INTERESTING_IDENTIFIERS); |
| 979 | RECORD(UNDEFINED_BUT_USED); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 980 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 981 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 982 | RECORD(MSSTRUCT_PRAGMA_OPTIONS); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 983 | RECORD(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 984 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 985 | RECORD(DELETE_EXPRS_TO_ANALYZE); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 986 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 987 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 988 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 989 | RECORD(SM_SLOC_FILE_ENTRY); |
| 990 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 991 | RECORD(SM_SLOC_BUFFER_BLOB); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 992 | RECORD(SM_SLOC_BUFFER_BLOB_COMPRESSED); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 993 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 995 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 996 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 997 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 998 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 999 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 1000 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1001 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1002 | |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1003 | // Submodule Block. |
| 1004 | BLOCK(SUBMODULE_BLOCK); |
| 1005 | RECORD(SUBMODULE_METADATA); |
| 1006 | RECORD(SUBMODULE_DEFINITION); |
| 1007 | RECORD(SUBMODULE_UMBRELLA_HEADER); |
| 1008 | RECORD(SUBMODULE_HEADER); |
| 1009 | RECORD(SUBMODULE_TOPHEADER); |
| 1010 | RECORD(SUBMODULE_UMBRELLA_DIR); |
| 1011 | RECORD(SUBMODULE_IMPORTS); |
| 1012 | RECORD(SUBMODULE_EXPORTS); |
| 1013 | RECORD(SUBMODULE_REQUIRES); |
| 1014 | RECORD(SUBMODULE_EXCLUDED_HEADER); |
| 1015 | RECORD(SUBMODULE_LINK_LIBRARY); |
| 1016 | RECORD(SUBMODULE_CONFIG_MACRO); |
| 1017 | RECORD(SUBMODULE_CONFLICT); |
| 1018 | RECORD(SUBMODULE_PRIVATE_HEADER); |
| 1019 | RECORD(SUBMODULE_TEXTUAL_HEADER); |
| 1020 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); |
| 1021 | |
| 1022 | // Comments Block. |
| 1023 | BLOCK(COMMENTS_BLOCK); |
| 1024 | RECORD(COMMENTS_RAW_COMMENT); |
| 1025 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1026 | // Decls and Types block. |
| 1027 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1028 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1029 | RECORD(TYPE_COMPLEX); |
| 1030 | RECORD(TYPE_POINTER); |
| 1031 | RECORD(TYPE_BLOCK_POINTER); |
| 1032 | RECORD(TYPE_LVALUE_REFERENCE); |
| 1033 | RECORD(TYPE_RVALUE_REFERENCE); |
| 1034 | RECORD(TYPE_MEMBER_POINTER); |
| 1035 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1036 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1037 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1038 | RECORD(TYPE_VECTOR); |
| 1039 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1040 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1041 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1042 | RECORD(TYPE_TYPEDEF); |
| 1043 | RECORD(TYPE_TYPEOF_EXPR); |
| 1044 | RECORD(TYPE_TYPEOF); |
| 1045 | RECORD(TYPE_RECORD); |
| 1046 | RECORD(TYPE_ENUM); |
| 1047 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1048 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1049 | RECORD(TYPE_DECLTYPE); |
| 1050 | RECORD(TYPE_ELABORATED); |
| 1051 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 1052 | RECORD(TYPE_UNRESOLVED_USING); |
| 1053 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 1054 | RECORD(TYPE_OBJC_OBJECT); |
| 1055 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 1056 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 1057 | RECORD(TYPE_DEPENDENT_NAME); |
| 1058 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 1059 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 1060 | RECORD(TYPE_PAREN); |
| 1061 | RECORD(TYPE_PACK_EXPANSION); |
| 1062 | RECORD(TYPE_ATTRIBUTED); |
| 1063 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1064 | RECORD(TYPE_AUTO); |
| 1065 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1066 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1067 | RECORD(TYPE_DECAYED); |
| 1068 | RECORD(TYPE_ADJUSTED); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 1069 | RECORD(LOCAL_REDECLARATIONS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1070 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1071 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1072 | RECORD(DECL_ENUM); |
| 1073 | RECORD(DECL_RECORD); |
| 1074 | RECORD(DECL_ENUM_CONSTANT); |
| 1075 | RECORD(DECL_FUNCTION); |
| 1076 | RECORD(DECL_OBJC_METHOD); |
| 1077 | RECORD(DECL_OBJC_INTERFACE); |
| 1078 | RECORD(DECL_OBJC_PROTOCOL); |
| 1079 | RECORD(DECL_OBJC_IVAR); |
| 1080 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1081 | RECORD(DECL_OBJC_CATEGORY); |
| 1082 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1083 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1084 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1085 | RECORD(DECL_OBJC_PROPERTY); |
| 1086 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1087 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1088 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1089 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1090 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1091 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1092 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1093 | RECORD(DECL_BLOCK); |
| 1094 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1095 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1096 | RECORD(DECL_NAMESPACE); |
| 1097 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1098 | RECORD(DECL_USING); |
| 1099 | RECORD(DECL_USING_SHADOW); |
| 1100 | RECORD(DECL_USING_DIRECTIVE); |
| 1101 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1102 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1103 | RECORD(DECL_LINKAGE_SPEC); |
| 1104 | RECORD(DECL_CXX_RECORD); |
| 1105 | RECORD(DECL_CXX_METHOD); |
| 1106 | RECORD(DECL_CXX_CONSTRUCTOR); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame^] | 1107 | RECORD(DECL_CXX_INHERITED_CONSTRUCTOR); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1108 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1109 | RECORD(DECL_CXX_CONVERSION); |
| 1110 | RECORD(DECL_ACCESS_SPEC); |
| 1111 | RECORD(DECL_FRIEND); |
| 1112 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1113 | RECORD(DECL_CLASS_TEMPLATE); |
| 1114 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1115 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1116 | RECORD(DECL_VAR_TEMPLATE); |
| 1117 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1118 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1119 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1120 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1121 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1122 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1123 | RECORD(DECL_TYPE_ALIAS_TEMPLATE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1124 | RECORD(DECL_STATIC_ASSERT); |
| 1125 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1126 | RECORD(DECL_CXX_CTOR_INITIALIZERS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1127 | RECORD(DECL_INDIRECTFIELD); |
| 1128 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1129 | RECORD(DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK); |
| 1130 | RECORD(DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION); |
| 1131 | RECORD(DECL_IMPORT); |
| 1132 | RECORD(DECL_OMP_THREADPRIVATE); |
| 1133 | RECORD(DECL_EMPTY); |
| 1134 | RECORD(DECL_OBJC_TYPE_PARAM); |
| 1135 | RECORD(DECL_OMP_CAPTUREDEXPR); |
| 1136 | RECORD(DECL_PRAGMA_COMMENT); |
| 1137 | RECORD(DECL_PRAGMA_DETECT_MISMATCH); |
| 1138 | RECORD(DECL_OMP_DECLARE_REDUCTION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1139 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1140 | // Statements and Exprs can occur in the Decls and Types block. |
| 1141 | AddStmtsExprs(Stream, Record); |
| 1142 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1143 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1144 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1145 | RECORD(PPD_MACRO_DEFINITION); |
| 1146 | RECORD(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 1147 | |
| 1148 | // Decls and Types block. |
| 1149 | BLOCK(EXTENSION_BLOCK); |
| 1150 | RECORD(EXTENSION_METADATA); |
| 1151 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1152 | #undef RECORD |
| 1153 | #undef BLOCK |
| 1154 | Stream.ExitBlock(); |
| 1155 | } |
| 1156 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1157 | /// \brief Prepares a path for being written to an AST file by converting it |
| 1158 | /// to an absolute path and removing nested './'s. |
| 1159 | /// |
| 1160 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1161 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1162 | SmallVectorImpl<char> &Path) { |
Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 1163 | bool Changed = FileMgr.makeAbsolutePath(Path); |
Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame] | 1164 | return Changed | llvm::sys::path::remove_dots(Path); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1167 | /// \brief Adjusts the given filename to only write out the portion of the |
| 1168 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1170 | /// \param Filename the file name to adjust. |
| 1171 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1172 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1173 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1174 | /// |
| 1175 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1176 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1178 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1179 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1181 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1182 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1183 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1184 | // Verify that the filename and the system root have the same prefix. |
| 1185 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1186 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1187 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1188 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1189 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1190 | // We hit the end of the filename before we hit the end of the system root. |
| 1191 | if (!Filename[Pos]) |
| 1192 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1193 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1194 | // If there's not a path separator at the end of the base directory nor |
| 1195 | // immediately after it, then this isn't within the base directory. |
| 1196 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1197 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1198 | return Filename; |
| 1199 | } else { |
| 1200 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1201 | // We distinguish relative paths from absolute paths by the |
| 1202 | // absence of '/' at the beginning of relative paths. |
| 1203 | // |
| 1204 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1205 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1206 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1207 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1208 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1209 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1210 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1211 | return Filename + Pos; |
| 1212 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1213 | |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1214 | static ASTFileSignature getSignature() { |
| 1215 | while (1) { |
| 1216 | if (ASTFileSignature S = llvm::sys::Process::GetRandomNumber()) |
| 1217 | return S; |
| 1218 | // Rely on GetRandomNumber to eventually return non-zero... |
| 1219 | } |
| 1220 | } |
| 1221 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1222 | /// \brief Write the control block. |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1223 | uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP, |
| 1224 | ASTContext &Context, |
| 1225 | StringRef isysroot, |
| 1226 | const std::string &OutputFile) { |
| 1227 | ASTFileSignature Signature = 0; |
| 1228 | |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1229 | using namespace llvm; |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1230 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1231 | RecordData Record; |
| 1232 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1233 | // Metadata |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1234 | auto *MetadataAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1235 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1236 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1237 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1238 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1239 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1240 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1241 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1242 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1243 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1244 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1245 | assert((!WritingModule || isysroot.empty()) && |
| 1246 | "writing module as a relocatable PCH?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1247 | { |
| 1248 | RecordData::value_type Record[] = {METADATA, VERSION_MAJOR, VERSION_MINOR, |
| 1249 | CLANG_VERSION_MAJOR, CLANG_VERSION_MINOR, |
| 1250 | !isysroot.empty(), IncludeTimestamps, |
| 1251 | ASTHasCompilerErrors}; |
| 1252 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1253 | getClangFullRepositoryVersion()); |
| 1254 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1255 | if (WritingModule) { |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1256 | // For implicit modules we output a signature that we can use to ensure |
| 1257 | // duplicate module builds don't collide in the cache as their output order |
| 1258 | // is non-deterministic. |
| 1259 | // FIXME: Remove this when output is deterministic. |
| 1260 | if (Context.getLangOpts().ImplicitModules) { |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1261 | Signature = getSignature(); |
| 1262 | RecordData::value_type Record[] = {Signature}; |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1263 | Stream.EmitRecord(SIGNATURE, Record); |
| 1264 | } |
| 1265 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1266 | // Module name |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1267 | auto *Abbrev = new BitCodeAbbrev(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1268 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1269 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1270 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1271 | RecordData::value_type Record[] = {MODULE_NAME}; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1272 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1273 | } |
| 1274 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1275 | if (WritingModule && WritingModule->Directory) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1276 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1277 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1278 | |
| 1279 | // If the home of the module is the current working directory, then we |
| 1280 | // want to pick up the cwd of the build process loading the module, not |
| 1281 | // our cwd, when we load this module. |
| 1282 | if (!PP.getHeaderSearchInfo() |
| 1283 | .getHeaderSearchOpts() |
| 1284 | .ModuleMapFileHomeIsCwd || |
| 1285 | WritingModule->Directory->getName() != StringRef(".")) { |
| 1286 | // Module directory. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1287 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1288 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1289 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
| 1290 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1291 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1292 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1293 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1294 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1295 | |
| 1296 | // Write out all other paths relative to the base directory if possible. |
| 1297 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1298 | } else if (!isysroot.empty()) { |
| 1299 | // Write out paths relative to the sysroot if possible. |
| 1300 | BaseDirectory = isysroot; |
| 1301 | } |
| 1302 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1303 | // Module map file |
| 1304 | if (WritingModule) { |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1305 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1306 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1307 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 1308 | |
| 1309 | // Primary module map file. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1310 | AddPath(Map.getModuleMapFileForUniquing(WritingModule)->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1311 | |
| 1312 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1313 | if (auto *AdditionalModMaps = |
| 1314 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1315 | Record.push_back(AdditionalModMaps->size()); |
| 1316 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1317 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1318 | } else { |
| 1319 | Record.push_back(0); |
| 1320 | } |
| 1321 | |
| 1322 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1325 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1326 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1327 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1328 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1329 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1330 | for (auto *M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1331 | // Skip modules that weren't directly imported. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1332 | if (!M->isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1333 | continue; |
| 1334 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1335 | Record.push_back((unsigned)M->Kind); // FIXME: Stable encoding |
| 1336 | AddSourceLocation(M->ImportLoc, Record); |
| 1337 | Record.push_back(M->File->getSize()); |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1338 | Record.push_back(getTimestampForOutput(M->File)); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1339 | Record.push_back(M->Signature); |
| 1340 | AddPath(M->FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1341 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1342 | Stream.EmitRecord(IMPORTS, Record); |
| 1343 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1344 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1345 | // Write the options block. |
| 1346 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); |
| 1347 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1348 | // Language options. |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1349 | Record.clear(); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1350 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1351 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1352 | Record.push_back(LangOpts.Name); |
| 1353 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1354 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1355 | #include "clang/Basic/LangOptions.def" |
| 1356 | #define SANITIZER(NAME, ID) \ |
| 1357 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1358 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1359 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1360 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1361 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1362 | AddString(Feature, Record); |
| 1363 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1364 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1365 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1366 | |
| 1367 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1368 | |
| 1369 | // Comment options. |
| 1370 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1371 | for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) { |
| 1372 | AddString(I, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1373 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1374 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1375 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1376 | // OpenMP offloading options. |
| 1377 | Record.push_back(LangOpts.OMPTargetTriples.size()); |
| 1378 | for (auto &T : LangOpts.OMPTargetTriples) |
| 1379 | AddString(T.getTriple(), Record); |
| 1380 | |
| 1381 | AddString(LangOpts.OMPHostIRFile, Record); |
| 1382 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1383 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1384 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1385 | // Target options. |
| 1386 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1387 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1388 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1389 | AddString(TargetOpts.Triple, Record); |
| 1390 | AddString(TargetOpts.CPU, Record); |
| 1391 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1392 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1393 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1394 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1395 | } |
| 1396 | Record.push_back(TargetOpts.Features.size()); |
| 1397 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1398 | AddString(TargetOpts.Features[I], Record); |
| 1399 | } |
| 1400 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1401 | |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1402 | // Diagnostic options. |
| 1403 | Record.clear(); |
| 1404 | const DiagnosticOptions &DiagOpts |
| 1405 | = Context.getDiagnostics().getDiagnosticOptions(); |
| 1406 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1407 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1408 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1409 | #include "clang/Basic/DiagnosticOptions.def" |
| 1410 | Record.push_back(DiagOpts.Warnings.size()); |
| 1411 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1412 | AddString(DiagOpts.Warnings[I], Record); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 1413 | Record.push_back(DiagOpts.Remarks.size()); |
| 1414 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1415 | AddString(DiagOpts.Remarks[I], Record); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1416 | // Note: we don't serialize the log or serialization file names, because they |
| 1417 | // are generally transient files and will almost always be overridden. |
| 1418 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1419 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1420 | // File system options. |
| 1421 | Record.clear(); |
Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1422 | const FileSystemOptions &FSOpts = |
| 1423 | Context.getSourceManager().getFileManager().getFileSystemOpts(); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1424 | AddString(FSOpts.WorkingDir, Record); |
| 1425 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1426 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1427 | // Header search options. |
| 1428 | Record.clear(); |
| 1429 | const HeaderSearchOptions &HSOpts |
| 1430 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1431 | AddString(HSOpts.Sysroot, Record); |
| 1432 | |
| 1433 | // Include entries. |
| 1434 | Record.push_back(HSOpts.UserEntries.size()); |
| 1435 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1436 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1437 | AddString(Entry.Path, Record); |
| 1438 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1439 | Record.push_back(Entry.IsFramework); |
| 1440 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | // System header prefixes. |
| 1444 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1445 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1446 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1447 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1448 | } |
| 1449 | |
| 1450 | AddString(HSOpts.ResourceDir, Record); |
| 1451 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1452 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1453 | Record.push_back(HSOpts.DisableModuleHash); |
| 1454 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1455 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1456 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1457 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1458 | // Write out the specific module cache path that contains the module files. |
| 1459 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1460 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1461 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1462 | // Preprocessor options. |
| 1463 | Record.clear(); |
| 1464 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1465 | |
| 1466 | // Macro definitions. |
| 1467 | Record.push_back(PPOpts.Macros.size()); |
| 1468 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1469 | AddString(PPOpts.Macros[I].first, Record); |
| 1470 | Record.push_back(PPOpts.Macros[I].second); |
| 1471 | } |
| 1472 | |
| 1473 | // Includes |
| 1474 | Record.push_back(PPOpts.Includes.size()); |
| 1475 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1476 | AddString(PPOpts.Includes[I], Record); |
| 1477 | |
| 1478 | // Macro includes |
| 1479 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1480 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1481 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1482 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1483 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1484 | // Detailed record is important since it is used for the module cache hash. |
| 1485 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1486 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1487 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1488 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1489 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1490 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1491 | // Leave the options block. |
| 1492 | Stream.ExitBlock(); |
| 1493 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1494 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1495 | SourceManager &SM = Context.getSourceManager(); |
| 1496 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1497 | auto *FileAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1498 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1499 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1500 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1501 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1502 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1503 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1504 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1505 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1506 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1507 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1508 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1509 | Record.clear(); |
| 1510 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1511 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1512 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1513 | // Original PCH directory |
| 1514 | if (!OutputFile.empty() && OutputFile != "-") { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1515 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1516 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1517 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1518 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1519 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1520 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1521 | |
Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1522 | SM.getFileManager().makeAbsolutePath(OutputPath); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1523 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1524 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1525 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1526 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1527 | } |
| 1528 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1529 | WriteInputFiles(Context.SourceMgr, |
| 1530 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1531 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1532 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1533 | return Signature; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1536 | namespace { |
| 1537 | /// \brief An input file. |
| 1538 | struct InputFileEntry { |
| 1539 | const FileEntry *File; |
| 1540 | bool IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1541 | bool IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1542 | bool BufferOverridden; |
| 1543 | }; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1544 | } // end anonymous namespace |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1545 | |
| 1546 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1547 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1548 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1549 | using namespace llvm; |
| 1550 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1551 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1552 | // Create input-file abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1553 | auto *IFAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1554 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1555 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1556 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1557 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1558 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1559 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1560 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1561 | unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); |
| 1562 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1563 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1564 | // 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] | 1565 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1566 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1567 | // Get this source location entry. |
| 1568 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1569 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1570 | |
| 1571 | // We only care about file entries that were not overridden. |
| 1572 | if (!SLoc->isFile()) |
| 1573 | continue; |
| 1574 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1575 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1576 | continue; |
| 1577 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1578 | InputFileEntry Entry; |
| 1579 | Entry.File = Cache->OrigEntry; |
| 1580 | Entry.IsSystemFile = Cache->IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1581 | Entry.IsTransient = Cache->IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1582 | Entry.BufferOverridden = Cache->BufferOverridden; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1583 | if (Cache->IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1584 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1585 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1586 | SortedFiles.push_front(Entry); |
| 1587 | } |
| 1588 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1589 | unsigned UserFilesNum = 0; |
| 1590 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1591 | std::vector<uint64_t> InputFileOffsets; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1592 | for (const auto &Entry : SortedFiles) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1593 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1594 | if (InputFileID != 0) |
| 1595 | continue; // already recorded this file. |
| 1596 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1597 | // Record this entry's offset. |
| 1598 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1599 | |
| 1600 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1601 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1602 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1603 | ++UserFilesNum; |
| 1604 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1605 | // Emit size/modification time for this file. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1606 | // And whether this file was overridden. |
| 1607 | RecordData::value_type Record[] = { |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1608 | INPUT_FILE, |
| 1609 | InputFileOffsets.size(), |
| 1610 | (uint64_t)Entry.File->getSize(), |
| 1611 | (uint64_t)getTimestampForOutput(Entry.File), |
| 1612 | Entry.BufferOverridden, |
| 1613 | Entry.IsTransient}; |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1614 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1615 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1616 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1617 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1618 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1619 | |
| 1620 | // Create input file offsets abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1621 | auto *OffsetsAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1622 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1623 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1624 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1625 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1626 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
| 1627 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(OffsetsAbbrev); |
| 1628 | |
| 1629 | // Write input file offsets. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1630 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, |
| 1631 | InputFileOffsets.size(), UserFilesNum}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1632 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1635 | //===----------------------------------------------------------------------===// |
| 1636 | // Source Manager Serialization |
| 1637 | //===----------------------------------------------------------------------===// |
| 1638 | |
| 1639 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1640 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1641 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1642 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1643 | |
| 1644 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1645 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1646 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1647 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1648 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1649 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1650 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1651 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1652 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1653 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1654 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1655 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1659 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1660 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1661 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1662 | |
| 1663 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1664 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1665 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1666 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1667 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1668 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1669 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1670 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1674 | /// buffer's blob. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1675 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, |
| 1676 | bool Compressed) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1677 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1678 | |
| 1679 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1680 | Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED |
| 1681 | : SM_SLOC_BUFFER_BLOB)); |
| 1682 | if (Compressed) |
| 1683 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1684 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1685 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1688 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1689 | /// expansion. |
| 1690 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1691 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1692 | |
| 1693 | auto *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1694 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1695 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1696 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1697 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1698 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1699 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1700 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1703 | namespace { |
| 1704 | // Trait used for the on-disk hash table of header search information. |
| 1705 | class HeaderFileInfoTrait { |
| 1706 | ASTWriter &Writer; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1707 | const HeaderSearch &HS; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1708 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1709 | // Keep track of the framework names we've used during serialization. |
| 1710 | SmallVector<char, 128> FrameworkStringData; |
| 1711 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1712 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1713 | public: |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1714 | HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) |
| 1715 | : Writer(Writer), HS(HS) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1716 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1717 | struct key_type { |
| 1718 | const FileEntry *FE; |
| 1719 | const char *Filename; |
| 1720 | }; |
| 1721 | typedef const key_type &key_type_ref; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1722 | |
| 1723 | typedef HeaderFileInfo data_type; |
| 1724 | typedef const data_type &data_type_ref; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 1725 | typedef unsigned hash_value_type; |
| 1726 | typedef unsigned offset_type; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1727 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1728 | hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1729 | // The hash is based only on size/time of the file, so that the reader can |
| 1730 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1731 | // change the form of the name. However, complete path is still the key. |
| 1732 | return llvm::hash_combine(key.FE->getSize(), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1733 | Writer.getTimestampForOutput(key.FE)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | std::pair<unsigned,unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1737 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1738 | using namespace llvm::support; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1739 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1740 | unsigned KeyLen = strlen(key.Filename) + 1 + 8 + 8; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1741 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1742 | unsigned DataLen = 1 + 2 + 4 + 4; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1743 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) |
| 1744 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) |
| 1745 | DataLen += 4; |
| 1746 | LE.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1747 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1750 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1751 | using namespace llvm::support; |
| 1752 | endian::Writer<little> LE(Out); |
| 1753 | LE.write<uint64_t>(key.FE->getSize()); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1754 | KeyLen -= 8; |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1755 | LE.write<uint64_t>(Writer.getTimestampForOutput(key.FE)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1756 | KeyLen -= 8; |
| 1757 | Out.write(key.Filename, KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1760 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1761 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1762 | using namespace llvm::support; |
| 1763 | endian::Writer<little> LE(Out); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1764 | uint64_t Start = Out.tell(); (void)Start; |
| 1765 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1766 | unsigned char Flags = (Data.isImport << 4) |
| 1767 | | (Data.isPragmaOnce << 3) |
| 1768 | | (Data.DirInfo << 1) |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1769 | | Data.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1770 | LE.write<uint8_t>(Flags); |
| 1771 | LE.write<uint16_t>(Data.NumIncludes); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1772 | |
| 1773 | if (!Data.ControllingMacro) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1774 | LE.write<uint32_t>(Data.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1775 | else |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1776 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1777 | |
| 1778 | unsigned Offset = 0; |
| 1779 | if (!Data.Framework.empty()) { |
| 1780 | // If this header refers into a framework, save the framework name. |
| 1781 | llvm::StringMap<unsigned>::iterator Pos |
| 1782 | = FrameworkNameOffset.find(Data.Framework); |
| 1783 | if (Pos == FrameworkNameOffset.end()) { |
| 1784 | Offset = FrameworkStringData.size() + 1; |
| 1785 | FrameworkStringData.append(Data.Framework.begin(), |
| 1786 | Data.Framework.end()); |
| 1787 | FrameworkStringData.push_back(0); |
| 1788 | |
| 1789 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1790 | } else |
| 1791 | Offset = Pos->second; |
| 1792 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1793 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1794 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1795 | // FIXME: If the header is excluded, we should write out some |
| 1796 | // record of that fact. |
| 1797 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) { |
| 1798 | if (uint32_t ModID = |
| 1799 | Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) { |
| 1800 | uint32_t Value = (ModID << 2) | (unsigned)ModInfo.getRole(); |
| 1801 | assert((Value >> 2) == ModID && "overflow in header module info"); |
| 1802 | LE.write<uint32_t>(Value); |
| 1803 | } |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1806 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1807 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1808 | |
| 1809 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1810 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1811 | }; |
| 1812 | } // end anonymous namespace |
| 1813 | |
| 1814 | /// \brief Write the header search block for the list of files that |
| 1815 | /// |
| 1816 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1817 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1818 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1819 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1820 | |
| 1821 | if (FilesByUID.size() > HS.header_file_size()) |
| 1822 | FilesByUID.resize(HS.header_file_size()); |
| 1823 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1824 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 1825 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1826 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1827 | unsigned NumHeaderSearchEntries = 0; |
| 1828 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1829 | const FileEntry *File = FilesByUID[UID]; |
| 1830 | if (!File) |
| 1831 | continue; |
| 1832 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1833 | // Get the file info. This will load info from the external source if |
| 1834 | // necessary. Skip emitting this file if we have no information on it |
| 1835 | // as a header file (in which case HFI will be null) or if it hasn't |
| 1836 | // changed since it was loaded. Also skip it if it's for a modular header |
| 1837 | // from a different module; in that case, we rely on the module(s) |
| 1838 | // containing the header to provide this information. |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1839 | const HeaderFileInfo *HFI = |
| 1840 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); |
| 1841 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 1842 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1843 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1844 | // Massage the file path into an appropriate form. |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1845 | const char *Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1846 | SmallString<128> FilenameTmp(Filename); |
| 1847 | if (PreparePathForOutput(FilenameTmp)) { |
| 1848 | // If we performed any translation on the file name at all, we need to |
| 1849 | // save this string, since the generator will refer to it later. |
| 1850 | Filename = strdup(FilenameTmp.c_str()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1851 | SavedStrings.push_back(Filename); |
| 1852 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1853 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1854 | HeaderFileInfoTrait::key_type key = { File, Filename }; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1855 | Generator.insert(key, *HFI, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1856 | ++NumHeaderSearchEntries; |
| 1857 | } |
| 1858 | |
| 1859 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1860 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1861 | uint32_t BucketOffset; |
| 1862 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1863 | using namespace llvm::support; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1864 | llvm::raw_svector_ostream Out(TableData); |
| 1865 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1866 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1867 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1868 | } |
| 1869 | |
| 1870 | // Create a blob abbreviation |
| 1871 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1872 | |
| 1873 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1874 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1875 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1876 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1877 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1878 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1879 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1880 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1881 | // Write the header search table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1882 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, |
| 1883 | NumHeaderSearchEntries, TableData.size()}; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1884 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 1885 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1886 | |
| 1887 | // Free all of the strings we had to duplicate. |
| 1888 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1889 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1892 | /// \brief Writes the block containing the serialized form of the |
| 1893 | /// source manager. |
| 1894 | /// |
| 1895 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1896 | /// blob), indexed based on the file name, so that we only create |
| 1897 | /// entries for files that we actually need. In the common case (no |
| 1898 | /// errors), we probably won't have to create file entries for any of |
| 1899 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1900 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1901 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1902 | RecordData Record; |
| 1903 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1904 | // Enter the source manager block. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1905 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1906 | |
| 1907 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1908 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1909 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1910 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false); |
| 1911 | unsigned SLocBufferBlobCompressedAbbrv = |
| 1912 | CreateSLocBufferBlobAbbrev(Stream, true); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1913 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1914 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1915 | // Write out the source location entry table. We skip the first |
| 1916 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1917 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1918 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1919 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1920 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1921 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1922 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1923 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1924 | FileID FID = FileID::get(I); |
| 1925 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1926 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1927 | // Record the offset of this source-location entry. |
| 1928 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1929 | |
| 1930 | // Figure out which record code to use. |
| 1931 | unsigned Code; |
| 1932 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1933 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1934 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1935 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1936 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1937 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1938 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1939 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1940 | Record.clear(); |
| 1941 | Record.push_back(Code); |
| 1942 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1943 | // Starting offset of this entry within this module, so skip the dummy. |
| 1944 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1945 | if (SLoc->isFile()) { |
| 1946 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 1947 | AddSourceLocation(File.getIncludeLoc(), Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1948 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1949 | Record.push_back(File.hasLineDirectives()); |
| 1950 | |
| 1951 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1952 | bool EmitBlob = false; |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1953 | if (Content->OrigEntry) { |
| 1954 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1955 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1956 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1957 | // The source location entry is a file. Emit input file ID. |
| 1958 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 1959 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1960 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1961 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1962 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1963 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1964 | if (FDI != FileDeclIDs.end()) { |
| 1965 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1966 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1967 | } else { |
| 1968 | Record.push_back(0); |
| 1969 | Record.push_back(0); |
| 1970 | } |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1971 | |
| 1972 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
| 1973 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1974 | if (Content->BufferOverridden || Content->IsTransient) |
| 1975 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1976 | } else { |
| 1977 | // The source location entry is a buffer. The blob associated |
| 1978 | // with this entry contains the contents of the buffer. |
| 1979 | |
| 1980 | // We add one to the size so that we capture the trailing NULL |
| 1981 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1982 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1983 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1984 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1985 | const char *Name = Buffer->getBufferIdentifier(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1986 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1987 | StringRef(Name, strlen(Name) + 1)); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1988 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1989 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1990 | if (strcmp(Name, "<built-in>") == 0) { |
| 1991 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1992 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1993 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1994 | |
| 1995 | if (EmitBlob) { |
| 1996 | // Include the implicit terminating null character in the on-disk buffer |
| 1997 | // if we're writing it uncompressed. |
| 1998 | const llvm::MemoryBuffer *Buffer = |
| 1999 | Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 2000 | StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1); |
| 2001 | |
| 2002 | // Compress the buffer if possible. We expect that almost all PCM |
| 2003 | // consumers will not want its contents. |
| 2004 | SmallString<0> CompressedBuffer; |
| 2005 | if (llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer) == |
| 2006 | llvm::zlib::StatusOK) { |
| 2007 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, |
| 2008 | Blob.size() - 1}; |
| 2009 | Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, |
| 2010 | CompressedBuffer); |
| 2011 | } else { |
| 2012 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB}; |
| 2013 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob); |
| 2014 | } |
| 2015 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2016 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2017 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 2018 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2019 | AddSourceLocation(Expansion.getSpellingLoc(), Record); |
| 2020 | AddSourceLocation(Expansion.getExpansionLocStart(), Record); |
| 2021 | AddSourceLocation(Expansion.isMacroArgExpansion() |
| 2022 | ? SourceLocation() |
| 2023 | : Expansion.getExpansionLocEnd(), |
| 2024 | Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2025 | |
| 2026 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2027 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2028 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2029 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2030 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2031 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2035 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2036 | |
| 2037 | if (SLocEntryOffsets.empty()) |
| 2038 | return; |
| 2039 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2040 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2041 | // table is used for lazily loading source-location information. |
| 2042 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2043 | |
| 2044 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2045 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2046 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2047 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2048 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 2049 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2050 | { |
| 2051 | RecordData::value_type Record[] = { |
| 2052 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), |
| 2053 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */}; |
| 2054 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
| 2055 | bytes(SLocEntryOffsets)); |
| 2056 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2057 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2058 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2059 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2060 | |
| 2061 | // Write the line table. It depends on remapping working, so it must come |
| 2062 | // after the source location offsets. |
| 2063 | if (SourceMgr.hasLineTable()) { |
| 2064 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 2065 | |
| 2066 | Record.clear(); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2067 | |
| 2068 | // Emit the needed file names. |
| 2069 | llvm::DenseMap<int, int> FilenameMap; |
| 2070 | for (const auto &L : LineTable) { |
| 2071 | if (L.first.ID < 0) |
| 2072 | continue; |
| 2073 | for (auto &LE : L.second) { |
| 2074 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, |
| 2075 | FilenameMap.size())).second) |
| 2076 | AddPath(LineTable.getFilename(LE.FilenameID), Record); |
| 2077 | } |
| 2078 | } |
| 2079 | Record.push_back(0); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2080 | |
| 2081 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2082 | for (const auto &L : LineTable) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2083 | // Only emit entries for local files. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2084 | if (L.first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2085 | continue; |
| 2086 | |
| 2087 | // Emit the file ID |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2088 | Record.push_back(L.first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2089 | |
| 2090 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2091 | Record.push_back(L.second.size()); |
| 2092 | for (const auto &LE : L.second) { |
| 2093 | Record.push_back(LE.FileOffset); |
| 2094 | Record.push_back(LE.LineNo); |
| 2095 | Record.push_back(FilenameMap[LE.FilenameID]); |
| 2096 | Record.push_back((unsigned)LE.FileKind); |
| 2097 | Record.push_back(LE.IncludeOffset); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2098 | } |
| 2099 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2100 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2101 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 2102 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2105 | //===----------------------------------------------------------------------===// |
| 2106 | // Preprocessor Serialization |
| 2107 | //===----------------------------------------------------------------------===// |
| 2108 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2109 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 2110 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2111 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 2112 | if (MI->isBuiltinMacro()) |
| 2113 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2114 | |
| 2115 | if (IsModule) { |
| 2116 | SourceLocation Loc = MD->getLocation(); |
| 2117 | if (Loc.isInvalid()) |
| 2118 | return true; |
| 2119 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 2120 | return true; |
| 2121 | } |
| 2122 | |
| 2123 | return false; |
| 2124 | } |
| 2125 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2126 | /// \brief Writes the block containing the serialized form of the |
| 2127 | /// preprocessor. |
| 2128 | /// |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2129 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2130 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2131 | if (PPRec) |
| 2132 | WritePreprocessorDetail(*PPRec); |
| 2133 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2134 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2135 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2136 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2137 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2138 | if (PP.getCounterValue() != 0) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2139 | RecordData::value_type Record[] = {PP.getCounterValue()}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2140 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2144 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2145 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2146 | // If the AST file contains __DATE__ or __TIME__ emit a warning about this. |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2147 | // FIXME: Include a location for the use, and say which one was used. |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2148 | if (PP.SawDateOrTime()) |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2149 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2150 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2151 | // 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] | 2152 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2153 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2154 | // Construct the list of identifiers with macro directives that need to be |
| 2155 | // serialized. |
| 2156 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2157 | for (auto &Id : PP.getIdentifierTable()) |
| 2158 | if (Id.second->hadMacroDefinition() && |
| 2159 | (!Id.second->isFromAST() || |
| 2160 | Id.second->hasChangedSinceDeserialization())) |
| 2161 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2162 | // Sort the set of macro definitions that need to be serialized by the |
| 2163 | // name of the macro, to provide a stable ordering. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2164 | std::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(), |
| 2165 | llvm::less_ptr<IdentifierInfo>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2166 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2167 | // Emit the macro directives as a list and associate the offset with the |
| 2168 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2169 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2170 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2171 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2172 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2173 | // Emit the macro directives in reverse source order. |
| 2174 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2175 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2176 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2177 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2178 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2179 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2180 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2181 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2182 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2183 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2184 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2185 | Record.push_back(VisMD->isPublic()); |
| 2186 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2187 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2188 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2189 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2190 | bool EmittedModuleMacros = false; |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2191 | // We write out exported module macros for PCH as well. |
| 2192 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2193 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2194 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2195 | while (!Worklist.empty()) { |
| 2196 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2197 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2198 | // Emit a record indicating this submodule exports this macro. |
| 2199 | ModuleMacroRecord.push_back( |
| 2200 | getSubmoduleID(Macro->getOwningModule())); |
| 2201 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
| 2202 | for (auto *M : Macro->overrides()) |
| 2203 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2204 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2205 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2206 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2207 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2208 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2209 | for (auto *M : Macro->overrides()) |
| 2210 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2211 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2212 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2213 | EmittedModuleMacros = true; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2214 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2215 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2216 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2217 | continue; |
| 2218 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2219 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2220 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2221 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2222 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2223 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2224 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 2225 | /// the local macro ID |
| 2226 | /// |
| 2227 | /// For each identifier that is associated with a macro, this map |
| 2228 | /// provides the offset into the bitstream where that macro is |
| 2229 | /// defined. |
| 2230 | std::vector<uint32_t> MacroOffsets; |
| 2231 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2232 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2233 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2234 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2235 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2236 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2237 | if (ID < FirstMacroID) { |
| 2238 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2239 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2240 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2241 | |
| 2242 | // Record the local offset of this macro. |
| 2243 | unsigned Index = ID - FirstMacroID; |
| 2244 | if (Index == MacroOffsets.size()) |
| 2245 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2246 | else { |
| 2247 | if (Index > MacroOffsets.size()) |
| 2248 | MacroOffsets.resize(Index + 1); |
| 2249 | |
| 2250 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2251 | } |
| 2252 | |
| 2253 | AddIdentifierRef(Name, Record); |
| 2254 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
| 2255 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2256 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2257 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2258 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2259 | unsigned Code; |
| 2260 | if (MI->isObjectLike()) { |
| 2261 | Code = PP_MACRO_OBJECT_LIKE; |
| 2262 | } else { |
| 2263 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2264 | |
| 2265 | Record.push_back(MI->isC99Varargs()); |
| 2266 | Record.push_back(MI->isGNUVarargs()); |
| 2267 | Record.push_back(MI->hasCommaPasting()); |
| 2268 | Record.push_back(MI->getNumArgs()); |
Daniel Marjamaki | e4770da | 2015-05-29 09:15:24 +0000 | [diff] [blame] | 2269 | for (const IdentifierInfo *Arg : MI->args()) |
| 2270 | AddIdentifierRef(Arg, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | // If we have a detailed preprocessing record, record the macro definition |
| 2274 | // ID that corresponds to this macro. |
| 2275 | if (PPRec) |
| 2276 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2277 | |
| 2278 | Stream.EmitRecord(Code, Record); |
| 2279 | Record.clear(); |
| 2280 | |
| 2281 | // Emit the tokens array. |
| 2282 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2283 | // Note that we know that the preprocessor does not have any annotation |
| 2284 | // tokens in it because they are created by the parser, and thus can't |
| 2285 | // be in a macro definition. |
| 2286 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2287 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2288 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2289 | Record.clear(); |
| 2290 | } |
| 2291 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2292 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2293 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2294 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2295 | |
| 2296 | // Write the offsets table for macro IDs. |
| 2297 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2298 | |
Richard Smith | 13090a2 | 2015-04-10 02:02:24 +0000 | [diff] [blame] | 2299 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2300 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2301 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2302 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2303 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2304 | |
| 2305 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2306 | { |
| 2307 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), |
| 2308 | FirstMacroID - NUM_PREDEF_MACRO_IDS}; |
| 2309 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); |
| 2310 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2314 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2315 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2316 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2317 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2318 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2319 | // Enter the preprocessor block. |
| 2320 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2321 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2322 | // If the preprocessor has a preprocessing record, emit it. |
| 2323 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2324 | using namespace llvm; |
| 2325 | |
| 2326 | // Set up the abbreviation for |
| 2327 | unsigned InclusionAbbrev = 0; |
| 2328 | { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2329 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2330 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2331 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2332 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2333 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2334 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2335 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2336 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2337 | } |
| 2338 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2339 | unsigned FirstPreprocessorEntityID |
| 2340 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 2341 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2342 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2343 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2344 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2345 | EEnd = PPRec.local_end(); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2346 | E != EEnd; |
| 2347 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2348 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2349 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2350 | PreprocessedEntityOffsets.push_back( |
| 2351 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2352 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2353 | if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2354 | // Record this macro definition's ID. |
| 2355 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2356 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2357 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2358 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2359 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2360 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2361 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2362 | if (auto *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2363 | Record.push_back(ME->isBuiltinMacro()); |
| 2364 | if (ME->isBuiltinMacro()) |
| 2365 | AddIdentifierRef(ME->getName(), Record); |
| 2366 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2367 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2368 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2369 | continue; |
| 2370 | } |
| 2371 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2372 | if (auto *ID = dyn_cast<InclusionDirective>(*E)) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2373 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2374 | Record.push_back(ID->getFileName().size()); |
| 2375 | Record.push_back(ID->wasInQuotes()); |
| 2376 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2377 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2378 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2379 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2380 | // Check that the FileEntry is not null because it was not resolved and |
| 2381 | // we create a PCH even with compiler errors. |
| 2382 | if (ID->getFile()) |
| 2383 | Buffer += ID->getFile()->getName(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2384 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2385 | continue; |
| 2386 | } |
| 2387 | |
| 2388 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2389 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2390 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2391 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2392 | // Write the offsets table for the preprocessing record. |
| 2393 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2394 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2395 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2396 | // Write the offsets table for identifier IDs. |
| 2397 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2398 | |
| 2399 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2400 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2401 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2402 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2403 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2404 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2405 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, |
| 2406 | FirstPreprocessorEntityID - |
| 2407 | NUM_PREDEF_PP_ENTITY_IDS}; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2408 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2409 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2410 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2413 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2414 | if (!Mod) |
| 2415 | return 0; |
| 2416 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2417 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2418 | if (Known != SubmoduleIDs.end()) |
| 2419 | return Known->second; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2420 | |
| 2421 | if (Mod->getTopLevelModule() != WritingModule) |
| 2422 | return 0; |
| 2423 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2424 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2425 | } |
| 2426 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2427 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2428 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2429 | // did not result in us loading a module file for that submodule. For |
| 2430 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2431 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); |
| 2432 | assert((ID || !Mod) && |
| 2433 | "asked for module ID for non-local, non-imported module"); |
| 2434 | return ID; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2435 | } |
| 2436 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2437 | /// \brief Compute the number of modules within the given tree (including the |
| 2438 | /// given module). |
| 2439 | static unsigned getNumberOfModules(Module *Mod) { |
| 2440 | unsigned ChildModules = 0; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2441 | for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2442 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2443 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2444 | |
| 2445 | return ChildModules + 1; |
| 2446 | } |
| 2447 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2448 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2449 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2450 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2451 | |
| 2452 | // Write the abbreviations needed for the submodules block. |
| 2453 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2454 | |
| 2455 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2456 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2457 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2458 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2459 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2460 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2461 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2462 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2463 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2464 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2465 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2466 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2467 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2468 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2469 | |
| 2470 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2471 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2472 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2473 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2474 | |
| 2475 | Abbrev = new BitCodeAbbrev(); |
| 2476 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2477 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2478 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2479 | |
| 2480 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2481 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2482 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2483 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2484 | |
| 2485 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2486 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2487 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2488 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2489 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2490 | Abbrev = new BitCodeAbbrev(); |
| 2491 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2492 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2493 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2494 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2495 | |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2496 | Abbrev = new BitCodeAbbrev(); |
| 2497 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2498 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2499 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2500 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2501 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2502 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2503 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2504 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2505 | |
| 2506 | Abbrev = new BitCodeAbbrev(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2507 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2508 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2509 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2510 | |
| 2511 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2512 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2513 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2514 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2515 | |
| 2516 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2517 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2518 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2519 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2520 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2521 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2522 | Abbrev = new BitCodeAbbrev(); |
| 2523 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2524 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
| 2525 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2526 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2527 | Abbrev = new BitCodeAbbrev(); |
| 2528 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2529 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2530 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
| 2531 | unsigned ConflictAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2532 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2533 | // Write the submodule metadata block. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2534 | RecordData::value_type Record[] = {getNumberOfModules(WritingModule), |
| 2535 | FirstSubmoduleID - |
| 2536 | NUM_PREDEF_SUBMODULE_IDS}; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2537 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2538 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2539 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2540 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2541 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2542 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2543 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2544 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2545 | unsigned ID = getSubmoduleID(Mod); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2546 | |
| 2547 | uint64_t ParentID = 0; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2548 | if (Mod->Parent) { |
| 2549 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2550 | ParentID = SubmoduleIDs[Mod->Parent]; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2551 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2552 | |
| 2553 | // Emit the definition of the block. |
| 2554 | { |
| 2555 | RecordData::value_type Record[] = { |
| 2556 | SUBMODULE_DEFINITION, ID, ParentID, Mod->IsFramework, Mod->IsExplicit, |
| 2557 | Mod->IsSystem, Mod->IsExternC, Mod->InferSubmodules, |
| 2558 | Mod->InferExplicitSubmodules, Mod->InferExportWildcard, |
| 2559 | Mod->ConfigMacrosExhaustive}; |
| 2560 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2561 | } |
| 2562 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2563 | // Emit the requirements. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2564 | for (const auto &R : Mod->Requirements) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2565 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2566 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2569 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2570 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2571 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2572 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2573 | UmbrellaHeader.NameAsWritten); |
| 2574 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2575 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; |
| 2576 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2577 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2578 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2579 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2580 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2581 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2582 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2583 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2584 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2585 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2586 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 2587 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 2588 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2589 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2590 | Module::HK_PrivateTextual}, |
| 2591 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2592 | }; |
| 2593 | for (auto &HL : HeaderLists) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2594 | RecordData::value_type Record[] = {HL.RecordKind}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2595 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 2596 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 2597 | } |
| 2598 | |
| 2599 | // Emit the top headers. |
| 2600 | { |
| 2601 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2602 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2603 | for (auto *H : TopHeaders) |
| 2604 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2605 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2606 | |
| 2607 | // Emit the imports. |
| 2608 | if (!Mod->Imports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2609 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2610 | for (auto *I : Mod->Imports) |
| 2611 | Record.push_back(getSubmoduleID(I)); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2612 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2613 | } |
| 2614 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2615 | // Emit the exports. |
| 2616 | if (!Mod->Exports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2617 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2618 | for (const auto &E : Mod->Exports) { |
| 2619 | // FIXME: This may fail; we don't require that all exported modules |
| 2620 | // are local or imported. |
| 2621 | Record.push_back(getSubmoduleID(E.getPointer())); |
| 2622 | Record.push_back(E.getInt()); |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2623 | } |
| 2624 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2625 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2626 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2627 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 2628 | // Might be unnecessary as use declarations are only used to build the |
| 2629 | // module itself. |
| 2630 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2631 | // Emit the link libraries. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2632 | for (const auto &LL : Mod->LinkLibraries) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2633 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, |
| 2634 | LL.IsFramework}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2635 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2638 | // Emit the conflicts. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2639 | for (const auto &C : Mod->Conflicts) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2640 | // FIXME: This may fail; we don't require that all conflicting modules |
| 2641 | // are local or imported. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2642 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, |
| 2643 | getSubmoduleID(C.Other)}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2644 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2645 | } |
| 2646 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2647 | // Emit the configuration macros. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2648 | for (const auto &CM : Mod->ConfigMacros) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2649 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2650 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2653 | // Queue up the submodules of this module. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2654 | for (auto *M : Mod->submodules()) |
| 2655 | Q.push(M); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2659 | |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2660 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 2661 | getNumberOfModules(WritingModule)) && |
| 2662 | "Wrong # of submodules; found a reference to a non-local, " |
| 2663 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2666 | serialization::SubmoduleID |
| 2667 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2668 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2669 | return 0; // No submodule |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2670 | |
| 2671 | // Find the module that owns this location. |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2672 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2673 | Module *OwningMod |
| 2674 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2675 | if (!OwningMod) |
| 2676 | return 0; |
| 2677 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2678 | // Check whether this submodule is part of our own module. |
| 2679 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2680 | return 0; |
| 2681 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2682 | return getSubmoduleID(OwningMod); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2683 | } |
| 2684 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 2685 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 2686 | bool isModule) { |
| 2687 | // Make sure set diagnostic pragmas don't affect the translation unit that |
| 2688 | // imports the module. |
| 2689 | // FIXME: Make diagnostic pragma sections work properly with modules. |
| 2690 | if (isModule) |
| 2691 | return; |
| 2692 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2693 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2694 | DiagStateIDMap; |
| 2695 | unsigned CurrID = 0; |
| 2696 | DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2697 | RecordData Record; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2698 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2699 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2700 | I != E; ++I) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2701 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2702 | if (point.Loc.isInvalid()) |
| 2703 | continue; |
| 2704 | |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2705 | AddSourceLocation(point.Loc, Record); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2706 | unsigned &DiagStateID = DiagStateIDMap[point.State]; |
| 2707 | Record.push_back(DiagStateID); |
| 2708 | |
| 2709 | if (DiagStateID == 0) { |
| 2710 | DiagStateID = ++CurrID; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2711 | for (const auto &I : *(point.State)) { |
| 2712 | if (I.second.isPragma()) { |
| 2713 | Record.push_back(I.first); |
| 2714 | Record.push_back((unsigned)I.second.getSeverity()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2715 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2716 | } |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2717 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2718 | // location. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2719 | } |
| 2720 | } |
| 2721 | |
Argyrios Kyrtzidis | b0ca9eb | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2722 | if (!Record.empty()) |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2723 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2724 | } |
| 2725 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2726 | //===----------------------------------------------------------------------===// |
| 2727 | // Type Serialization |
| 2728 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2729 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2730 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2731 | void ASTWriter::WriteType(QualType T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2732 | TypeIdx &IdxRef = TypeIdxs[T]; |
| 2733 | if (IdxRef.getIndex() == 0) // we haven't seen this type before. |
| 2734 | IdxRef = TypeIdx(NextTypeID++); |
| 2735 | TypeIdx Idx = IdxRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2736 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2737 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2738 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2739 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2740 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2741 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2742 | ASTTypeWriter W(*this, Record); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2743 | W.Visit(T); |
| 2744 | uint64_t Offset = W.Emit(); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2745 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2746 | // Record the offset for this type. |
| 2747 | unsigned Index = Idx.getIndex() - FirstTypeID; |
| 2748 | if (TypeOffsets.size() == Index) |
| 2749 | TypeOffsets.push_back(Offset); |
| 2750 | else if (TypeOffsets.size() < Index) { |
| 2751 | TypeOffsets.resize(Index + 1); |
| 2752 | TypeOffsets[Index] = Offset; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2753 | } else { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2754 | llvm_unreachable("Types emitted in wrong order"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2755 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2756 | } |
| 2757 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2758 | //===----------------------------------------------------------------------===// |
| 2759 | // Declaration Serialization |
| 2760 | //===----------------------------------------------------------------------===// |
| 2761 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2762 | /// \brief Write the block containing all of the declaration IDs |
| 2763 | /// lexically declared within the given DeclContext. |
| 2764 | /// |
| 2765 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2766 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2767 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2768 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2769 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2770 | return 0; |
| 2771 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2772 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2773 | SmallVector<uint32_t, 128> KindDeclPairs; |
| 2774 | for (const auto *D : DC->decls()) { |
| 2775 | KindDeclPairs.push_back(D->getKind()); |
| 2776 | KindDeclPairs.push_back(GetDeclRef(D)); |
| 2777 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2778 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2779 | ++NumLexicalDeclContexts; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2780 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2781 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, |
| 2782 | bytes(KindDeclPairs)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2783 | return Offset; |
| 2784 | } |
| 2785 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2786 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2787 | using namespace llvm; |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2788 | |
| 2789 | // Write the type offsets array |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2790 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2791 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2792 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2793 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2794 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2795 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2796 | { |
| 2797 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), |
| 2798 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; |
| 2799 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
| 2800 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2801 | |
| 2802 | // Write the declaration offsets array |
| 2803 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2804 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2805 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2806 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2807 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2808 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2809 | { |
| 2810 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), |
| 2811 | FirstDeclID - NUM_PREDEF_DECL_IDS}; |
| 2812 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
| 2813 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2814 | } |
| 2815 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2816 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2817 | using namespace llvm; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2818 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2819 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 2820 | FileDeclIDs.begin(), FileDeclIDs.end()); |
| 2821 | std::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), |
| 2822 | llvm::less_first()); |
| 2823 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2824 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2825 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 2826 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 2827 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 2828 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 2829 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 2830 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2833 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2834 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2835 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2836 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2837 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2838 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, |
| 2839 | FileGroupedDeclIDs.size()}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2840 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2843 | void ASTWriter::WriteComments() { |
| 2844 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2845 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2846 | RecordData Record; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2847 | for (const auto *I : RawComments) { |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2848 | Record.clear(); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2849 | AddSourceRange(I->getSourceRange(), Record); |
| 2850 | Record.push_back(I->getKind()); |
| 2851 | Record.push_back(I->isTrailingComment()); |
| 2852 | Record.push_back(I->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2853 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2854 | } |
| 2855 | Stream.ExitBlock(); |
| 2856 | } |
| 2857 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2858 | //===----------------------------------------------------------------------===// |
| 2859 | // Global Method Pool and Selector Serialization |
| 2860 | //===----------------------------------------------------------------------===// |
| 2861 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2862 | namespace { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2863 | // 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] | 2864 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2865 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2866 | |
| 2867 | public: |
| 2868 | typedef Selector key_type; |
| 2869 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2870 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2871 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2872 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2873 | ObjCMethodList Instance, Factory; |
| 2874 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2875 | typedef const data_type& data_type_ref; |
| 2876 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2877 | typedef unsigned hash_value_type; |
| 2878 | typedef unsigned offset_type; |
| 2879 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2880 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2881 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2882 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2883 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2884 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2885 | |
| 2886 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2887 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2888 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2889 | using namespace llvm::support; |
| 2890 | endian::Writer<little> LE(Out); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2891 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2892 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2893 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2894 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2895 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2896 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2897 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2898 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2899 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2900 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2901 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2902 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2903 | return std::make_pair(KeyLen, DataLen); |
| 2904 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2905 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2906 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2907 | using namespace llvm::support; |
| 2908 | endian::Writer<little> LE(Out); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2909 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2910 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2911 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2912 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2913 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2914 | if (N == 0) |
| 2915 | N = 1; |
| 2916 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2917 | LE.write<uint32_t>( |
| 2918 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2919 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2920 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2921 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2922 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2923 | using namespace llvm::support; |
| 2924 | endian::Writer<little> LE(Out); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2925 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2926 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2927 | unsigned NumInstanceMethods = 0; |
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()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2931 | ++NumInstanceMethods; |
| 2932 | |
| 2933 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2934 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2935 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2936 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2937 | ++NumFactoryMethods; |
| 2938 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2939 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 2940 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2941 | unsigned InstanceHasMoreThanOneDeclBit = |
| 2942 | Methods.Instance.hasMoreThanOneDecl(); |
| 2943 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 2944 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 2945 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2946 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 2947 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2948 | unsigned FactoryHasMoreThanOneDeclBit = |
| 2949 | Methods.Factory.hasMoreThanOneDecl(); |
| 2950 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 2951 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 2952 | FactoryBits; |
| 2953 | LE.write<uint16_t>(FullInstanceBits); |
| 2954 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2955 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2956 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2957 | if (Method->getMethod()) |
| 2958 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2959 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2960 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2961 | if (Method->getMethod()) |
| 2962 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2963 | |
| 2964 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2965 | } |
| 2966 | }; |
| 2967 | } // end anonymous namespace |
| 2968 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2969 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2970 | /// |
| 2971 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2972 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2973 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2974 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2975 | using namespace llvm; |
| 2976 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2977 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2978 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2979 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2980 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2981 | // 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] | 2982 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 2983 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2984 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2985 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2986 | // Create the on-disk hash table representation. We walk through every |
| 2987 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2988 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 2989 | for (auto &SelectorAndID : SelectorIDs) { |
| 2990 | Selector S = SelectorAndID.first; |
| 2991 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2992 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2993 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 2994 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2995 | ObjCMethodList(), |
| 2996 | ObjCMethodList() |
| 2997 | }; |
| 2998 | if (F != SemaRef.MethodPool.end()) { |
| 2999 | Data.Instance = F->second.first; |
| 3000 | Data.Factory = F->second.second; |
| 3001 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3002 | // 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] | 3003 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3004 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3005 | // Selector already exists. Did it change? |
| 3006 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3007 | for (ObjCMethodList *M = &Data.Instance; |
| 3008 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 3009 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3010 | changed = true; |
| 3011 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3012 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3013 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3014 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3015 | changed = true; |
| 3016 | } |
| 3017 | if (!changed) |
| 3018 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3019 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3020 | // A new method pool entry. |
| 3021 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3022 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3023 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3024 | } |
| 3025 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3026 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3027 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3028 | uint32_t BucketOffset; |
| 3029 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3030 | using namespace llvm::support; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3031 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3032 | llvm::raw_svector_ostream Out(MethodPool); |
| 3033 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3034 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3035 | BucketOffset = Generator.Emit(Out, Trait); |
| 3036 | } |
| 3037 | |
| 3038 | // Create a blob abbreviation |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3039 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3040 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3041 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3042 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3043 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3044 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3045 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3046 | // Write the method pool |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3047 | { |
| 3048 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, |
| 3049 | NumTableEntries}; |
| 3050 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
| 3051 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3052 | |
| 3053 | // Create a blob abbreviation for the selector table offsets. |
| 3054 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3055 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3056 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3057 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3058 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3059 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3060 | |
| 3061 | // Write the selector offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3062 | { |
| 3063 | RecordData::value_type Record[] = { |
| 3064 | SELECTOR_OFFSETS, SelectorOffsets.size(), |
| 3065 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; |
| 3066 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 3067 | bytes(SelectorOffsets)); |
| 3068 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3069 | } |
| 3070 | } |
| 3071 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3072 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3073 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3074 | using namespace llvm; |
| 3075 | if (SemaRef.ReferencedSelectors.empty()) |
| 3076 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3077 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3078 | RecordData Record; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3079 | ASTRecordWriter Writer(*this, Record); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3080 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3081 | // 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] | 3082 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3083 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3084 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3085 | Selector Sel = SelectorAndLocation.first; |
| 3086 | SourceLocation Loc = SelectorAndLocation.second; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3087 | Writer.AddSelectorRef(Sel); |
| 3088 | Writer.AddSourceLocation(Loc); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3089 | } |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3090 | Writer.Emit(REFERENCED_SELECTOR_POOL); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3093 | //===----------------------------------------------------------------------===// |
| 3094 | // Identifier Table Serialization |
| 3095 | //===----------------------------------------------------------------------===// |
| 3096 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3097 | /// Determine the declaration that should be put into the name lookup table to |
| 3098 | /// represent the given declaration in this module. This is usually D itself, |
| 3099 | /// but if D was imported and merged into a local declaration, we want the most |
| 3100 | /// recent local declaration instead. The chosen declaration will be the most |
| 3101 | /// recent declaration in any module that imports this one. |
| 3102 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3103 | NamedDecl *D) { |
| 3104 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3105 | return D; |
| 3106 | |
| 3107 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3108 | // For Redeclarable decls, a prior declaration might be local. |
| 3109 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3110 | // If we find a local decl, we're done. |
| 3111 | if (!Redecl->isFromASTFile()) { |
| 3112 | // Exception: in very rare cases (for injected-class-names), not all |
| 3113 | // redeclarations are in the same semantic context. Skip ones in a |
| 3114 | // different context. They don't go in this lookup table at all. |
| 3115 | if (!Redecl->getDeclContext()->getRedeclContext()->Equals( |
| 3116 | D->getDeclContext()->getRedeclContext())) |
| 3117 | continue; |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3118 | return cast<NamedDecl>(Redecl); |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3121 | // 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] | 3122 | // local one. |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3123 | if (Redecl->getOwningModuleID() == 0) |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3124 | break; |
| 3125 | } |
| 3126 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3127 | // For Mergeable decls, the first decl might be local. |
| 3128 | if (!First->isFromASTFile()) |
| 3129 | return cast<NamedDecl>(First); |
| 3130 | } |
| 3131 | |
| 3132 | // All declarations are imported. Our most recent declaration will also be |
| 3133 | // the most recent one in anyone who imports us. |
| 3134 | return D; |
| 3135 | } |
| 3136 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3137 | namespace { |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3138 | class ASTIdentifierTableTrait { |
| 3139 | ASTWriter &Writer; |
| 3140 | Preprocessor &PP; |
| 3141 | IdentifierResolver &IdResolver; |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3142 | bool IsModule; |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3143 | bool NeedDecls; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3144 | ASTWriter::RecordData *InterestingIdentifierOffsets; |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3145 | |
| 3146 | /// \brief Determines whether this is an "interesting" identifier that needs a |
| 3147 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3148 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3149 | /// to check that. |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3150 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3151 | if (MacroOffset || |
| 3152 | II->isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3153 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3154 | II->hasRevertedTokenIDToIdentifier() || |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3155 | (NeedDecls && II->getFETokenInfo<void>())) |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3156 | return true; |
| 3157 | |
| 3158 | return false; |
| 3159 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3160 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3161 | public: |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3162 | typedef IdentifierInfo* key_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3163 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3164 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3165 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3166 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3167 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3168 | typedef unsigned hash_value_type; |
| 3169 | typedef unsigned offset_type; |
| 3170 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3171 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3172 | IdentifierResolver &IdResolver, bool IsModule, |
| 3173 | ASTWriter::RecordData *InterestingIdentifierOffsets) |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3174 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3175 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), |
| 3176 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3177 | |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3178 | bool needDecls() const { return NeedDecls; } |
| 3179 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3180 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 3181 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3182 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3183 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3184 | bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 3185 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3186 | return isInterestingIdentifier(II, MacroOffset); |
| 3187 | } |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3188 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { |
| 3189 | return isInterestingIdentifier(II, 0); |
| 3190 | } |
| 3191 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3192 | std::pair<unsigned,unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3193 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3194 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3195 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3196 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3197 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3198 | DataLen += 2; // 2 bytes for builtin ID |
| 3199 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3200 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3201 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3202 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3203 | if (NeedDecls) { |
| 3204 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3205 | DEnd = IdResolver.end(); |
| 3206 | D != DEnd; ++D) |
| 3207 | DataLen += 4; |
| 3208 | } |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3209 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3210 | using namespace llvm::support; |
| 3211 | endian::Writer<little> LE(Out); |
| 3212 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3213 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3214 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3215 | // We emit the key length after the data length so that every |
| 3216 | // string is preceded by a 16-bit length. This matches the PTH |
| 3217 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3218 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3219 | return std::make_pair(KeyLen, DataLen); |
| 3220 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3221 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3222 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3223 | unsigned KeyLen) { |
| 3224 | // Record the location of the key data. This is used when generating |
| 3225 | // the mapping from persistent IDs to strings. |
| 3226 | Writer.SetIdentifierOffset(II, Out.tell()); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3227 | |
| 3228 | // Emit the offset of the key/data length information to the interesting |
| 3229 | // identifiers table if necessary. |
| 3230 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) |
| 3231 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); |
| 3232 | |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3233 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3234 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3235 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3236 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3237 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3238 | using namespace llvm::support; |
| 3239 | endian::Writer<little> LE(Out); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3240 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3241 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3242 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3243 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3244 | return; |
| 3245 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3246 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3247 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3248 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3249 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3250 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3251 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3252 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3253 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3254 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3255 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3256 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3257 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3258 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3259 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3260 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3261 | if (HadMacroDefinition) |
| 3262 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3263 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3264 | if (NeedDecls) { |
| 3265 | // Emit the declaration IDs in reverse order, because the |
| 3266 | // IdentifierResolver provides the declarations as they would be |
| 3267 | // visible (e.g., the function "stat" would come before the struct |
| 3268 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3269 | // (so we need to see the struct "stat" before the function "stat"). |
| 3270 | // Only emit declarations that aren't from a chained PCH, though. |
| 3271 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), |
| 3272 | IdResolver.end()); |
| 3273 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3274 | DEnd = Decls.rend(); |
| 3275 | D != DEnd; ++D) |
| 3276 | LE.write<uint32_t>( |
| 3277 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
| 3278 | } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3279 | } |
| 3280 | }; |
| 3281 | } // end anonymous namespace |
| 3282 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3283 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3284 | /// |
| 3285 | /// The identifier table consists of a blob containing string data |
| 3286 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3287 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3288 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 3289 | IdentifierResolver &IdResolver, |
| 3290 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3291 | using namespace llvm; |
| 3292 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3293 | RecordData InterestingIdents; |
| 3294 | |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3295 | // Create and write out the blob that contains the identifier |
| 3296 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3297 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3298 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3299 | ASTIdentifierTableTrait Trait( |
| 3300 | *this, PP, IdResolver, IsModule, |
| 3301 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3302 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3303 | // Look for any identifiers that were named while processing the |
| 3304 | // headers, but are otherwise not needed. We add these to the hash |
| 3305 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3306 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3307 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3308 | SmallVector<const IdentifierInfo *, 128> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3309 | for (const auto &ID : PP.getIdentifierTable()) |
| 3310 | IIs.push_back(ID.second); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3311 | // Sort the identifiers lexicographically before getting them references so |
| 3312 | // that their order is stable. |
| 3313 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 3314 | for (const IdentifierInfo *II : IIs) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3315 | if (Trait.isInterestingNonMacroIdentifier(II)) |
| 3316 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3317 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3318 | // Create the on-disk hash table representation. We only store offsets |
| 3319 | // for identifiers that appear here for the first time. |
| 3320 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3321 | for (auto IdentIDPair : IdentifierIDs) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3322 | auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3323 | IdentID ID = IdentIDPair.second; |
| 3324 | assert(II && "NULL identifier in identifier table"); |
Vassil Vassilev | 262f41e | 2016-03-30 20:16:03 +0000 | [diff] [blame] | 3325 | // Write out identifiers if either the ID is local or the identifier has |
| 3326 | // changed since it was loaded. |
| 3327 | if (ID >= FirstIdentID || !Chain || !II->isFromAST() |
| 3328 | || II->hasChangedSinceDeserialization() || |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3329 | (Trait.needDecls() && |
| 3330 | II->hasFETokenInfoChangedSinceDeserialization())) |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3331 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3332 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3333 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3334 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3335 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3336 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3337 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3338 | using namespace llvm::support; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3339 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3340 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3341 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3342 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | // Create a blob abbreviation |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3346 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3347 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3348 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3349 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3350 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3351 | |
| 3352 | // Write the identifier table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3353 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3354 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | // Write the offsets table for identifier IDs. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3358 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3359 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3360 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3361 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3362 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3363 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3364 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3365 | #ifndef NDEBUG |
| 3366 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3367 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3368 | #endif |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3369 | |
| 3370 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, |
| 3371 | IdentifierOffsets.size(), |
| 3372 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3373 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3374 | bytes(IdentifierOffsets)); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3375 | |
| 3376 | // In C++, write the list of interesting identifiers (those that are |
| 3377 | // defined as macros, poisoned, or similar unusual things). |
| 3378 | if (!InterestingIdents.empty()) |
| 3379 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3382 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3383 | // DeclContext's Name Lookup Table Serialization |
| 3384 | //===----------------------------------------------------------------------===// |
| 3385 | |
| 3386 | namespace { |
| 3387 | // Trait used for the on-disk hash table used in the method pool. |
| 3388 | class ASTDeclContextNameLookupTrait { |
| 3389 | ASTWriter &Writer; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3390 | llvm::SmallVector<DeclID, 64> DeclIDs; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3391 | |
| 3392 | public: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3393 | typedef DeclarationNameKey key_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3394 | typedef key_type key_type_ref; |
| 3395 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3396 | /// A start and end index into DeclIDs, representing a sequence of decls. |
| 3397 | typedef std::pair<unsigned, unsigned> data_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3398 | typedef const data_type& data_type_ref; |
| 3399 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3400 | typedef unsigned hash_value_type; |
| 3401 | typedef unsigned offset_type; |
| 3402 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3403 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 3404 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3405 | template<typename Coll> |
| 3406 | data_type getData(const Coll &Decls) { |
| 3407 | unsigned Start = DeclIDs.size(); |
| 3408 | for (NamedDecl *D : Decls) { |
| 3409 | DeclIDs.push_back( |
| 3410 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); |
| 3411 | } |
| 3412 | return std::make_pair(Start, DeclIDs.size()); |
| 3413 | } |
| 3414 | |
| 3415 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { |
| 3416 | unsigned Start = DeclIDs.size(); |
| 3417 | for (auto ID : FromReader) |
| 3418 | DeclIDs.push_back(ID); |
| 3419 | return std::make_pair(Start, DeclIDs.size()); |
| 3420 | } |
| 3421 | |
| 3422 | static bool EqualKey(key_type_ref a, key_type_ref b) { |
| 3423 | return a == b; |
| 3424 | } |
| 3425 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3426 | hash_value_type ComputeHash(DeclarationNameKey Name) { |
| 3427 | return Name.getHash(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3430 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { |
| 3431 | assert(Writer.hasChain() && |
| 3432 | "have reference to loaded module file but no chain?"); |
| 3433 | |
| 3434 | using namespace llvm::support; |
| 3435 | endian::Writer<little>(Out) |
| 3436 | .write<uint32_t>(Writer.getChain()->getModuleFileID(F)); |
| 3437 | } |
| 3438 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3439 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, |
| 3440 | DeclarationNameKey Name, |
| 3441 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3442 | using namespace llvm::support; |
| 3443 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3444 | unsigned KeyLen = 1; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3445 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3446 | case DeclarationName::Identifier: |
| 3447 | case DeclarationName::ObjCZeroArgSelector: |
| 3448 | case DeclarationName::ObjCOneArgSelector: |
| 3449 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3450 | case DeclarationName::CXXLiteralOperatorName: |
| 3451 | KeyLen += 4; |
| 3452 | break; |
| 3453 | case DeclarationName::CXXOperatorName: |
| 3454 | KeyLen += 1; |
| 3455 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3456 | case DeclarationName::CXXConstructorName: |
| 3457 | case DeclarationName::CXXDestructorName: |
| 3458 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3459 | case DeclarationName::CXXUsingDirective: |
| 3460 | break; |
| 3461 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3462 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3463 | |
Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3464 | // 4 bytes for each DeclID. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3465 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); |
| 3466 | assert(uint16_t(DataLen) == DataLen && |
| 3467 | "too many decls for serialized lookup result"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3468 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3469 | |
| 3470 | return std::make_pair(KeyLen, DataLen); |
| 3471 | } |
| 3472 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3473 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3474 | using namespace llvm::support; |
| 3475 | endian::Writer<little> LE(Out); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3476 | LE.write<uint8_t>(Name.getKind()); |
| 3477 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3478 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3479 | case DeclarationName::CXXLiteralOperatorName: |
| 3480 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3481 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3482 | case DeclarationName::ObjCZeroArgSelector: |
| 3483 | case DeclarationName::ObjCOneArgSelector: |
| 3484 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3485 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3486 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3487 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3488 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3489 | "Invalid operator?"); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3490 | LE.write<uint8_t>(Name.getOperatorKind()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3491 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3492 | case DeclarationName::CXXConstructorName: |
| 3493 | case DeclarationName::CXXDestructorName: |
| 3494 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3495 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3496 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3497 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3498 | |
| 3499 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3500 | } |
| 3501 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3502 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, |
| 3503 | unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3504 | using namespace llvm::support; |
| 3505 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3506 | uint64_t Start = Out.tell(); (void)Start; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3507 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) |
| 3508 | LE.write<uint32_t>(DeclIDs[I]); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3509 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3510 | } |
| 3511 | }; |
| 3512 | } // end anonymous namespace |
| 3513 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3514 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 3515 | DeclContext *DC) { |
| 3516 | return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage; |
| 3517 | } |
| 3518 | |
| 3519 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 3520 | DeclContext *DC) { |
| 3521 | for (auto *D : Result.getLookupResult()) |
| 3522 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 3523 | return false; |
| 3524 | |
| 3525 | return true; |
| 3526 | } |
| 3527 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3528 | void |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3529 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3530 | llvm::SmallVectorImpl<char> &LookupTable) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3531 | assert(!ConstDC->HasLazyLocalLexicalLookups && |
| 3532 | !ConstDC->HasLazyExternalLexicalLookups && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3533 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3534 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3535 | // FIXME: We need to build the lookups table, which is logically const. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3536 | auto *DC = const_cast<DeclContext*>(ConstDC); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3537 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 3538 | |
| 3539 | // Create the on-disk hash table representation. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3540 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, |
| 3541 | ASTDeclContextNameLookupTrait> Generator; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3542 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3543 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3544 | // The first step is to collect the declaration names which we need to |
| 3545 | // serialize into the name lookup table, and to collect them in a stable |
| 3546 | // order. |
| 3547 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3548 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3549 | // We also build up small sets of the constructor and conversion function |
| 3550 | // names which are visible. |
| 3551 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3552 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3553 | for (auto &Lookup : *DC->buildLookup()) { |
| 3554 | auto &Name = Lookup.first; |
| 3555 | auto &Result = Lookup.second; |
| 3556 | |
Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 3557 | // If there are no local declarations in our lookup result, we |
| 3558 | // don't need to write an entry for the name at all. If we can't |
| 3559 | // write out a lookup set without performing more deserialization, |
| 3560 | // just skip this entry. |
| 3561 | if (isLookupResultExternal(Result, DC) && |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3562 | isLookupResultEntirelyExternal(Result, DC)) |
| 3563 | continue; |
| 3564 | |
| 3565 | // We also skip empty results. If any of the results could be external and |
| 3566 | // the currently available results are empty, then all of the results are |
| 3567 | // external and we skip it above. So the only way we get here with an empty |
| 3568 | // results is when no results could have been external *and* we have |
| 3569 | // external results. |
| 3570 | // |
| 3571 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 3572 | // lookups into a decl context as an optimization, today we *have* to skip |
| 3573 | // them because there are names with empty lookup results in decl contexts |
| 3574 | // which we can't emit in any stable ordering: we lookup constructors and |
| 3575 | // conversion functions in the enclosing namespace scope creating empty |
| 3576 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 3577 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 3578 | // here by omitting lookups with empty results. |
| 3579 | if (Lookup.second.getLookupResult().empty()) |
| 3580 | continue; |
| 3581 | |
| 3582 | switch (Lookup.first.getNameKind()) { |
| 3583 | default: |
| 3584 | Names.push_back(Lookup.first); |
| 3585 | break; |
| 3586 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3587 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3588 | assert(isa<CXXRecordDecl>(DC) && |
| 3589 | "Cannot have a constructor name outside of a class!"); |
| 3590 | ConstructorNameSet.insert(Name); |
| 3591 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3592 | |
| 3593 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3594 | assert(isa<CXXRecordDecl>(DC) && |
| 3595 | "Cannot have a conversion function name outside of a class!"); |
| 3596 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 3597 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3598 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3599 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3600 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3601 | // Sort the names into a stable order. |
| 3602 | std::sort(Names.begin(), Names.end()); |
| 3603 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3604 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3605 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3606 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3607 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3608 | // First we try the easy case by forming the current context's constructor |
| 3609 | // name and adding that name first. This is a very useful optimization to |
| 3610 | // avoid walking the lexical declarations in many cases, and it also |
| 3611 | // handles the only case where a constructor name can come from some other |
| 3612 | // lexical context -- when that name is an implicit constructor merged from |
| 3613 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 3614 | // conversion function which doesn't occur in all the lexical contexts |
| 3615 | // would be an ODR violation. |
| 3616 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 3617 | Context->getCanonicalType(Context->getRecordType(D))); |
| 3618 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 3619 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3620 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3621 | // If we still have constructors or conversion functions, we walk all the |
| 3622 | // names in the decl and add the constructors and conversion functions |
| 3623 | // which are visible in the order they lexically occur within the context. |
| 3624 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 3625 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 3626 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 3627 | auto Name = ChildND->getDeclName(); |
| 3628 | switch (Name.getNameKind()) { |
| 3629 | default: |
| 3630 | continue; |
| 3631 | |
| 3632 | case DeclarationName::CXXConstructorName: |
| 3633 | if (ConstructorNameSet.erase(Name)) |
| 3634 | Names.push_back(Name); |
| 3635 | break; |
| 3636 | |
| 3637 | case DeclarationName::CXXConversionFunctionName: |
| 3638 | if (ConversionNameSet.erase(Name)) |
| 3639 | Names.push_back(Name); |
| 3640 | break; |
| 3641 | } |
| 3642 | |
| 3643 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 3644 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3645 | } |
| 3646 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3647 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 3648 | "constructors by walking all the " |
| 3649 | "lexical members of the context."); |
| 3650 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 3651 | "conversion functions by walking all " |
| 3652 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3653 | } |
| 3654 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3655 | // Next we need to do a lookup with each name into this decl context to fully |
| 3656 | // populate any results from external sources. We don't actually use the |
| 3657 | // results of these lookups because we only want to use the results after all |
| 3658 | // results have been loaded and the pointers into them will be stable. |
| 3659 | for (auto &Name : Names) |
| 3660 | DC->lookup(Name); |
| 3661 | |
| 3662 | // Now we need to insert the results for each name into the hash table. For |
| 3663 | // constructor names and conversion function names, we actually need to merge |
| 3664 | // all of the results for them into one list of results each and insert |
| 3665 | // those. |
| 3666 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 3667 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 3668 | |
| 3669 | // Now loop over the names, either inserting them or appending for the two |
| 3670 | // special cases. |
| 3671 | for (auto &Name : Names) { |
| 3672 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 3673 | |
| 3674 | switch (Name.getNameKind()) { |
| 3675 | default: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3676 | Generator.insert(Name, Trait.getData(Result), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3677 | break; |
| 3678 | |
| 3679 | case DeclarationName::CXXConstructorName: |
| 3680 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 3681 | break; |
| 3682 | |
| 3683 | case DeclarationName::CXXConversionFunctionName: |
| 3684 | ConversionDecls.append(Result.begin(), Result.end()); |
| 3685 | break; |
| 3686 | } |
| 3687 | } |
| 3688 | |
| 3689 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 3690 | // the first declaration's name here because the name itself isn't part of |
| 3691 | // the key, only the kind of name is used. |
| 3692 | if (!ConstructorDecls.empty()) |
| 3693 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3694 | Trait.getData(ConstructorDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3695 | if (!ConversionDecls.empty()) |
| 3696 | Generator.insert(ConversionDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3697 | Trait.getData(ConversionDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3698 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3699 | // Create the on-disk hash table. Also emit the existing imported and |
| 3700 | // merged table if there is one. |
| 3701 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; |
| 3702 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3703 | } |
| 3704 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3705 | /// \brief Write the block containing all of the declaration IDs |
| 3706 | /// visible from the given DeclContext. |
| 3707 | /// |
| 3708 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3709 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3710 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 3711 | DeclContext *DC) { |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3712 | // If we imported a key declaration of this namespace, write the visible |
| 3713 | // lookup results as an update record for it rather than including them |
| 3714 | // on this declaration. We will only look at key declarations on reload. |
| 3715 | if (isa<NamespaceDecl>(DC) && Chain && |
| 3716 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { |
| 3717 | // Only do this once, for the first local declaration of the namespace. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3718 | for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3719 | Prev = Prev->getPreviousDecl()) |
| 3720 | if (!Prev->isFromASTFile()) |
| 3721 | return 0; |
| 3722 | |
| 3723 | // Note that we need to emit an update record for the primary context. |
| 3724 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); |
| 3725 | |
| 3726 | // Make sure all visible decls are written. They will be recorded later. We |
| 3727 | // do this using a side data structure so we can sort the names into |
| 3728 | // a deterministic order. |
| 3729 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); |
| 3730 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> |
| 3731 | LookupResults; |
| 3732 | if (Map) { |
| 3733 | LookupResults.reserve(Map->size()); |
| 3734 | for (auto &Entry : *Map) |
| 3735 | LookupResults.push_back( |
| 3736 | std::make_pair(Entry.first, Entry.second.getLookupResult())); |
| 3737 | } |
| 3738 | |
| 3739 | std::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); |
| 3740 | for (auto &NameAndResult : LookupResults) { |
| 3741 | DeclarationName Name = NameAndResult.first; |
| 3742 | DeclContext::lookup_result Result = NameAndResult.second; |
| 3743 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || |
| 3744 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 3745 | // We have to work around a name lookup bug here where negative lookup |
| 3746 | // results for these names get cached in namespace lookup tables (these |
| 3747 | // names should never be looked up in a namespace). |
| 3748 | assert(Result.empty() && "Cannot have a constructor or conversion " |
| 3749 | "function name in a namespace!"); |
| 3750 | continue; |
| 3751 | } |
| 3752 | |
| 3753 | for (NamedDecl *ND : Result) |
| 3754 | if (!ND->isFromASTFile()) |
| 3755 | GetDeclRef(ND); |
| 3756 | } |
| 3757 | |
| 3758 | return 0; |
| 3759 | } |
| 3760 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3761 | if (DC->getPrimaryContext() != DC) |
| 3762 | return 0; |
| 3763 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3764 | // Skip contexts which don't support name lookup. |
| 3765 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3766 | return 0; |
| 3767 | |
| 3768 | // If not in C++, we perform name lookup for the translation unit via the |
| 3769 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3770 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3771 | return 0; |
| 3772 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3773 | // Serialize the contents of the mapping used for lookup. Note that, |
| 3774 | // although we have two very different code paths, the serialized |
| 3775 | // representation is the same for both cases: a declaration name, |
| 3776 | // followed by a size, followed by references to the visible |
| 3777 | // declarations that have that name. |
| 3778 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3779 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3780 | if (!Map || Map->empty()) |
| 3781 | return 0; |
| 3782 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3783 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3784 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3785 | GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3786 | |
| 3787 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3788 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3789 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3790 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3791 | ++NumVisibleDeclContexts; |
| 3792 | return Offset; |
| 3793 | } |
| 3794 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3795 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3796 | /// |
| 3797 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3798 | /// 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] | 3799 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3800 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3801 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3802 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3803 | if (!Map || Map->empty()) |
| 3804 | return; |
| 3805 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3806 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3807 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3808 | GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3809 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3810 | // If we're updating a namespace, select a key declaration as the key for the |
| 3811 | // update record; those are the only ones that will be checked on reload. |
| 3812 | if (isa<NamespaceDecl>(DC)) |
| 3813 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); |
| 3814 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3815 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3816 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3817 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3818 | } |
| 3819 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3820 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3821 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3822 | RecordData::value_type Record[] = {Opts.fp_contract}; |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3823 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3824 | } |
| 3825 | |
| 3826 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3827 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3828 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3829 | return; |
| 3830 | |
| 3831 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3832 | RecordData Record; |
| 3833 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3834 | #include "clang/Basic/OpenCLExtensions.def" |
| 3835 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3836 | } |
| 3837 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3838 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3839 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3840 | RecordData Categories; |
| 3841 | |
| 3842 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3843 | unsigned Size = 0; |
| 3844 | unsigned StartIndex = Categories.size(); |
| 3845 | |
| 3846 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3847 | |
| 3848 | // Allocate space for the size. |
| 3849 | Categories.push_back(0); |
| 3850 | |
| 3851 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3852 | for (ObjCInterfaceDecl::known_categories_iterator |
| 3853 | Cat = Class->known_categories_begin(), |
| 3854 | CatEnd = Class->known_categories_end(); |
| 3855 | Cat != CatEnd; ++Cat, ++Size) { |
| 3856 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 3857 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | // Update the size. |
| 3861 | Categories[StartIndex] = Size; |
| 3862 | |
| 3863 | // Record this interface -> category map. |
| 3864 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3865 | CategoriesMap.push_back(CatInfo); |
| 3866 | } |
| 3867 | |
| 3868 | // Sort the categories map by the definition ID, since the reader will be |
| 3869 | // performing binary searches on this information. |
| 3870 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3871 | |
| 3872 | // Emit the categories map. |
| 3873 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3874 | |
| 3875 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3876 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3877 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3878 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3879 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3880 | |
| 3881 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; |
| 3882 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3883 | reinterpret_cast<char *>(CategoriesMap.data()), |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3884 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3885 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3886 | // Emit the category lists. |
| 3887 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3888 | } |
| 3889 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3890 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 3891 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 3892 | |
| 3893 | if (LPTMap.empty()) |
| 3894 | return; |
| 3895 | |
| 3896 | RecordData Record; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 3897 | for (auto LPTMapEntry : LPTMap) { |
| 3898 | const FunctionDecl *FD = LPTMapEntry.first; |
| 3899 | LateParsedTemplate *LPT = LPTMapEntry.second; |
| 3900 | AddDeclRef(FD, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3901 | AddDeclRef(LPT->D, Record); |
| 3902 | Record.push_back(LPT->Toks.size()); |
| 3903 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3904 | for (const auto &Tok : LPT->Toks) { |
| 3905 | AddToken(Tok, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 3909 | } |
| 3910 | |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3911 | /// \brief Write the state of 'pragma clang optimize' at the end of the module. |
| 3912 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 3913 | RecordData Record; |
| 3914 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 3915 | AddSourceLocation(PragmaLoc, Record); |
| 3916 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 3917 | } |
| 3918 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 3919 | /// \brief Write the state of 'pragma ms_struct' at the end of the module. |
| 3920 | void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) { |
| 3921 | RecordData Record; |
| 3922 | Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF); |
| 3923 | Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record); |
| 3924 | } |
| 3925 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 3926 | /// \brief Write the state of 'pragma pointers_to_members' at the end of the |
| 3927 | //module. |
| 3928 | void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) { |
| 3929 | RecordData Record; |
| 3930 | Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod); |
| 3931 | AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record); |
| 3932 | Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record); |
| 3933 | } |
| 3934 | |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 3935 | void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, |
| 3936 | ModuleFileExtensionWriter &Writer) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3937 | // Enter the extension block. |
| 3938 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); |
| 3939 | |
| 3940 | // Emit the metadata record abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3941 | auto *Abv = new llvm::BitCodeAbbrev(); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3942 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); |
| 3943 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3944 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3945 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3946 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3947 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3948 | unsigned Abbrev = Stream.EmitAbbrev(Abv); |
| 3949 | |
| 3950 | // Emit the metadata record. |
| 3951 | RecordData Record; |
| 3952 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); |
| 3953 | Record.push_back(EXTENSION_METADATA); |
| 3954 | Record.push_back(Metadata.MajorVersion); |
| 3955 | Record.push_back(Metadata.MinorVersion); |
| 3956 | Record.push_back(Metadata.BlockName.size()); |
| 3957 | Record.push_back(Metadata.UserInfo.size()); |
| 3958 | SmallString<64> Buffer; |
| 3959 | Buffer += Metadata.BlockName; |
| 3960 | Buffer += Metadata.UserInfo; |
| 3961 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); |
| 3962 | |
| 3963 | // Emit the contents of the extension block. |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 3964 | Writer.writeExtensionContents(SemaRef, Stream); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3965 | |
| 3966 | // Exit the extension block. |
| 3967 | Stream.ExitBlock(); |
| 3968 | } |
| 3969 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3970 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3971 | // General Serialization Routines |
| 3972 | //===----------------------------------------------------------------------===// |
| 3973 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 3974 | /// \brief Emit the list of attributes to the specified record. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3975 | void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) { |
| 3976 | auto &Record = *this; |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3977 | Record.push_back(Attrs.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3978 | for (const auto *A : Attrs) { |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3979 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3980 | Record.AddSourceRange(A->getRange()); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3981 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3982 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3984 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3985 | } |
| 3986 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 3987 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 3988 | AddSourceLocation(Tok.getLocation(), Record); |
| 3989 | Record.push_back(Tok.getLength()); |
| 3990 | |
| 3991 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 3992 | // if it is needed. |
| 3993 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 3994 | // FIXME: Should translate token kind to a stable encoding. |
| 3995 | Record.push_back(Tok.getKind()); |
| 3996 | // FIXME: Should translate token flags to a stable encoding. |
| 3997 | Record.push_back(Tok.getFlags()); |
| 3998 | } |
| 3999 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4000 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4001 | Record.push_back(Str.size()); |
| 4002 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 4003 | } |
| 4004 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4005 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4006 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4007 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4008 | bool Changed = |
| 4009 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4010 | |
| 4011 | // Remove a prefix to make the path relative, if relevant. |
| 4012 | const char *PathBegin = Path.data(); |
| 4013 | const char *PathPtr = |
| 4014 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 4015 | if (PathPtr != PathBegin) { |
| 4016 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 4017 | Changed = true; |
| 4018 | } |
| 4019 | |
| 4020 | return Changed; |
| 4021 | } |
| 4022 | |
| 4023 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 4024 | SmallString<128> FilePath(Path); |
| 4025 | PreparePathForOutput(FilePath); |
| 4026 | AddString(FilePath, Record); |
| 4027 | } |
| 4028 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4029 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4030 | StringRef Path) { |
| 4031 | SmallString<128> FilePath(Path); |
| 4032 | PreparePathForOutput(FilePath); |
| 4033 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 4034 | } |
| 4035 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4036 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 4037 | RecordDataImpl &Record) { |
| 4038 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4039 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4040 | Record.push_back(*Minor + 1); |
| 4041 | else |
| 4042 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4043 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4044 | Record.push_back(*Subminor + 1); |
| 4045 | else |
| 4046 | Record.push_back(0); |
| 4047 | } |
| 4048 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4049 | /// \brief Note that the identifier II occurs at the given offset |
| 4050 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4051 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4052 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4053 | // 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] | 4054 | // up earlier in the chain and thus don't need an offset. |
| 4055 | if (ID >= FirstIdentID) |
| 4056 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4057 | } |
| 4058 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4059 | /// \brief Note that the selector Sel occurs at the given offset |
| 4060 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4061 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4062 | unsigned ID = SelectorIDs[Sel]; |
| 4063 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4064 | // Don't record offsets for selectors that are also available in a different |
| 4065 | // file. |
| 4066 | if (ID < FirstSelectorID) |
| 4067 | return; |
| 4068 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4069 | } |
| 4070 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4071 | ASTWriter::ASTWriter( |
| 4072 | llvm::BitstreamWriter &Stream, |
| 4073 | ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions, |
| 4074 | bool IncludeTimestamps) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4075 | : Stream(Stream), Context(nullptr), PP(nullptr), Chain(nullptr), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4076 | WritingModule(nullptr), IncludeTimestamps(IncludeTimestamps), |
| 4077 | WritingAST(false), DoneWritingDeclsAndTypes(false), |
| 4078 | ASTHasCompilerErrors(false), FirstDeclID(NUM_PREDEF_DECL_IDS), |
| 4079 | NextDeclID(FirstDeclID), FirstTypeID(NUM_PREDEF_TYPE_IDS), |
| 4080 | NextTypeID(FirstTypeID), FirstIdentID(NUM_PREDEF_IDENT_IDS), |
| 4081 | NextIdentID(FirstIdentID), FirstMacroID(NUM_PREDEF_MACRO_IDS), |
| 4082 | NextMacroID(FirstMacroID), FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4083 | NextSubmoduleID(FirstSubmoduleID), |
| 4084 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4085 | NumStatements(0), NumMacros(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4086 | NumLexicalDeclContexts(0), NumVisibleDeclContexts(0), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4087 | TypeExtQualAbbrev(0), TypeFunctionProtoAbbrev(0), DeclParmVarAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4088 | DeclContextLexicalAbbrev(0), DeclContextVisibleLookupAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4089 | UpdateVisibleAbbrev(0), DeclRecordAbbrev(0), DeclTypedefAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4090 | DeclVarAbbrev(0), DeclFieldAbbrev(0), DeclEnumAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4091 | DeclObjCIvarAbbrev(0), DeclCXXMethodAbbrev(0), DeclRefExprAbbrev(0), |
| 4092 | CharacterLiteralAbbrev(0), IntegerLiteralAbbrev(0), |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4093 | ExprImplicitCastAbbrev(0) { |
| 4094 | for (const auto &Ext : Extensions) { |
| 4095 | if (auto Writer = Ext->createExtensionWriter(*this)) |
| 4096 | ModuleFileExtensionWriters.push_back(std::move(Writer)); |
| 4097 | } |
| 4098 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4099 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4100 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 4101 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4102 | } |
| 4103 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4104 | const LangOptions &ASTWriter::getLangOpts() const { |
| 4105 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 4106 | return Context->getLangOpts(); |
| 4107 | } |
| 4108 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4109 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { |
| 4110 | return IncludeTimestamps ? E->getModificationTime() : 0; |
| 4111 | } |
| 4112 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4113 | uint64_t ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile, |
| 4114 | Module *WritingModule, StringRef isysroot, |
| 4115 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4116 | WritingAST = true; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4117 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4118 | ASTHasCompilerErrors = hasErrors; |
| 4119 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4120 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4121 | Stream.Emit((unsigned)'C', 8); |
| 4122 | Stream.Emit((unsigned)'P', 8); |
| 4123 | Stream.Emit((unsigned)'C', 8); |
| 4124 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4125 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4126 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4127 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4128 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4129 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4130 | this->WritingModule = WritingModule; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4131 | ASTFileSignature Signature = |
| 4132 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4133 | Context = nullptr; |
| 4134 | PP = nullptr; |
| 4135 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4136 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4137 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4138 | WritingAST = false; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4139 | return Signature; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4140 | } |
| 4141 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4142 | template<typename Vector> |
| 4143 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4144 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4145 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4146 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4147 | Writer.AddDeclRef(*I, Record); |
| 4148 | } |
| 4149 | } |
| 4150 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4151 | uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, |
| 4152 | const std::string &OutputFile, |
| 4153 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4154 | using namespace llvm; |
| 4155 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4156 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4157 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4158 | // Make sure that the AST reader knows to finalize itself. |
| 4159 | if (Chain) |
| 4160 | Chain->finalizeForWriting(); |
| 4161 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4162 | ASTContext &Context = SemaRef.Context; |
| 4163 | Preprocessor &PP = SemaRef.PP; |
| 4164 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4165 | // Set up predefined declaration IDs. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4166 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { |
| 4167 | if (D) { |
| 4168 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); |
| 4169 | DeclIDs[D] = ID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4170 | } |
| 4171 | }; |
| 4172 | RegisterPredefDecl(Context.getTranslationUnitDecl(), |
| 4173 | PREDEF_DECL_TRANSLATION_UNIT_ID); |
| 4174 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); |
| 4175 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); |
| 4176 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); |
| 4177 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, |
| 4178 | PREDEF_DECL_OBJC_PROTOCOL_ID); |
| 4179 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); |
| 4180 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); |
| 4181 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, |
| 4182 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); |
| 4183 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4184 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4185 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, |
| 4186 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4187 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4188 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, |
| 4189 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 4190 | RegisterPredefDecl(Context.CFConstantStringTypeDecl, |
| 4191 | PREDEF_DECL_CF_CONSTANT_STRING_ID); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 4192 | RegisterPredefDecl(Context.CFConstantStringTagDecl, |
| 4193 | PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4194 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4195 | // 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] | 4196 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4197 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4198 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4199 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4200 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4201 | // Build a record containing all of the file scoped decls in this file. |
| 4202 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4203 | if (!isModule) |
| 4204 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4205 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4206 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4207 | // Build a record containing all of the delegating constructors we still need |
| 4208 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4209 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4210 | if (!isModule) |
| 4211 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4212 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4213 | // Write the set of weak, undeclared identifiers. We always write the |
| 4214 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4215 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4216 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4217 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4218 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4219 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4220 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4221 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4222 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4223 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4224 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4225 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4226 | // Build a record containing all of the ext_vector declarations. |
| 4227 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4228 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4229 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4230 | // Build a record containing all of the VTable uses information. |
| 4231 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4232 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4233 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4234 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4235 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4236 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4237 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4240 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4241 | RecordData UnusedLocalTypedefNameCandidates; |
| 4242 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4243 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4244 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4245 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4246 | RecordData PendingInstantiations; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4247 | for (const auto &I : SemaRef.PendingInstantiations) { |
| 4248 | AddDeclRef(I.first, PendingInstantiations); |
| 4249 | AddSourceLocation(I.second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4250 | } |
| 4251 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4252 | "There are local ones at end of translation unit!"); |
| 4253 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4254 | // Build a record containing some declaration references. |
| 4255 | RecordData SemaDeclRefs; |
| 4256 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 4257 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4258 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 4259 | } |
| 4260 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4261 | RecordData CUDASpecialDeclRefs; |
| 4262 | if (Context.getcudaConfigureCallDecl()) { |
| 4263 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4264 | } |
| 4265 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4266 | // Build a record containing all of the known namespaces. |
| 4267 | RecordData KnownNamespaces; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4268 | for (const auto &I : SemaRef.KnownNamespaces) { |
| 4269 | if (!I.second) |
| 4270 | AddDeclRef(I.first, KnownNamespaces); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4271 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4272 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4273 | // Build a record of all used, undefined objects that require definitions. |
| 4274 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4275 | |
| 4276 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4277 | SemaRef.getUndefinedButUsed(Undefined); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4278 | for (const auto &I : Undefined) { |
| 4279 | AddDeclRef(I.first, UndefinedButUsed); |
| 4280 | AddSourceLocation(I.second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4281 | } |
| 4282 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4283 | // Build a record containing all delete-expressions that we would like to |
| 4284 | // analyze later in AST. |
| 4285 | RecordData DeleteExprsToAnalyze; |
| 4286 | |
| 4287 | for (const auto &DeleteExprsInfo : |
| 4288 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4289 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4290 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4291 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4292 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4293 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4294 | } |
| 4295 | } |
| 4296 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4297 | // Write the control block |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4298 | uint64_t Signature = WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4299 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4300 | // Write the remaining AST contents. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4301 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4302 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4303 | // This is so that older clang versions, before the introduction |
| 4304 | // of the control block, can read and reject the newer PCH format. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4305 | { |
| 4306 | RecordData Record = {VERSION_MAJOR}; |
| 4307 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4308 | } |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4309 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4310 | // Create a lexical update block containing all of the declarations in the |
| 4311 | // translation unit that do not come from other AST files. |
| 4312 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4313 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; |
| 4314 | for (const auto *D : TU->noload_decls()) { |
| 4315 | if (!D->isFromASTFile()) { |
| 4316 | NewGlobalKindDeclPairs.push_back(D->getKind()); |
| 4317 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); |
| 4318 | } |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4319 | } |
| 4320 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4321 | auto *Abv = new llvm::BitCodeAbbrev(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4322 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4323 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4324 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4325 | { |
| 4326 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; |
| 4327 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 4328 | bytes(NewGlobalKindDeclPairs)); |
| 4329 | } |
| 4330 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4331 | // And a visible updates block for the translation unit. |
| 4332 | Abv = new llvm::BitCodeAbbrev(); |
| 4333 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4334 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4335 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4336 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 4337 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4338 | |
| 4339 | // If we have any extern "C" names, write out a visible update for them. |
| 4340 | if (Context.ExternCContext) |
| 4341 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4342 | |
| 4343 | // If the translation unit has an anonymous namespace, and we don't already |
| 4344 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4345 | // 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] | 4346 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4347 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4348 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4349 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4350 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4351 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4352 | // Add update records for all mangling numbers and static local numbers. |
| 4353 | // These aren't really update records, but this is a convenient way of |
| 4354 | // tagging this rare extra data onto the declarations. |
| 4355 | for (const auto &Number : Context.MangleNumbers) |
| 4356 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4357 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4358 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4359 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4360 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4361 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4362 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4363 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4364 | // Make sure visible decls, added to DeclContexts previously loaded from |
| 4365 | // an AST file, are registered for serialization. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4366 | for (const auto *I : UpdatingVisibleDecls) { |
| 4367 | GetDeclRef(I); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4370 | // Make sure all decls associated with an identifier are registered for |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4371 | // serialization, if we're storing decls with identifiers. |
| 4372 | if (!WritingModule || !getLangOpts().CPlusPlus) { |
| 4373 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4374 | for (const auto &ID : PP.getIdentifierTable()) { |
| 4375 | const IdentifierInfo *II = ID.second; |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4376 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 4377 | IIs.push_back(II); |
| 4378 | } |
| 4379 | // Sort the identifiers to visit based on their name. |
| 4380 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 4381 | for (const IdentifierInfo *II : IIs) { |
| 4382 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4383 | DEnd = SemaRef.IdResolver.end(); |
| 4384 | D != DEnd; ++D) { |
| 4385 | GetDeclRef(*D); |
| 4386 | } |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4387 | } |
| 4388 | } |
| 4389 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 4390 | // For method pool in the module, if it contains an entry for a selector, |
| 4391 | // the entry should be complete, containing everything introduced by that |
| 4392 | // module and all modules it imports. It's possible that the entry is out of |
| 4393 | // date, so we need to pull in the new content here. |
| 4394 | |
| 4395 | // It's possible that updateOutOfDateSelector can update SelectorIDs. To be |
| 4396 | // safe, we copy all selectors out. |
| 4397 | llvm::SmallVector<Selector, 256> AllSelectors; |
| 4398 | for (auto &SelectorAndID : SelectorIDs) |
| 4399 | AllSelectors.push_back(SelectorAndID.first); |
| 4400 | for (auto &Selector : AllSelectors) |
| 4401 | SemaRef.updateOutOfDateSelector(Selector); |
| 4402 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4403 | // Form the record of special types. |
| 4404 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4405 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4406 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 4407 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 4408 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 4409 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 4410 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4411 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4412 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4413 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4414 | if (Chain) { |
| 4415 | // Write the mapping information describing our module dependencies and how |
| 4416 | // each of those modules were mapped into our own offset/ID space, so that |
| 4417 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4418 | // The map consists solely of a blob with the following format: |
| 4419 | // *(module-name-len:i16 module-name:len*i8 |
| 4420 | // source-location-offset:i32 |
| 4421 | // identifier-id:i32 |
| 4422 | // preprocessed-entity-id:i32 |
| 4423 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4424 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4425 | // selector-id:i32 |
| 4426 | // declaration-id:i32 |
| 4427 | // c++-base-specifiers-id:i32 |
| 4428 | // type-id:i32) |
| 4429 | // |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4430 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4431 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4432 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 4433 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4434 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4435 | { |
| 4436 | llvm::raw_svector_ostream Out(Buffer); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4437 | for (ModuleFile *M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4438 | using namespace llvm::support; |
| 4439 | endian::Writer<little> LE(Out); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4440 | StringRef FileName = M->FileName; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4441 | LE.write<uint16_t>(FileName.size()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4442 | Out.write(FileName.data(), FileName.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4443 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4444 | // Note: if a base ID was uint max, it would not be possible to load |
| 4445 | // another module after it or have more than one entity inside it. |
| 4446 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 4447 | |
| 4448 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 4449 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 4450 | if (ShouldWrite) |
| 4451 | LE.write<uint32_t>(BaseID); |
| 4452 | else |
| 4453 | LE.write<uint32_t>(None); |
| 4454 | }; |
| 4455 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4456 | // These values should be unique within a chain, since they will be read |
| 4457 | // as keys into ContinuousRangeMaps. |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4458 | writeBaseIDOrNone(M->SLocEntryBaseOffset, M->LocalNumSLocEntries); |
| 4459 | writeBaseIDOrNone(M->BaseIdentifierID, M->LocalNumIdentifiers); |
| 4460 | writeBaseIDOrNone(M->BaseMacroID, M->LocalNumMacros); |
| 4461 | writeBaseIDOrNone(M->BasePreprocessedEntityID, |
| 4462 | M->NumPreprocessedEntities); |
| 4463 | writeBaseIDOrNone(M->BaseSubmoduleID, M->LocalNumSubmodules); |
| 4464 | writeBaseIDOrNone(M->BaseSelectorID, M->LocalNumSelectors); |
| 4465 | writeBaseIDOrNone(M->BaseDeclID, M->LocalNumDecls); |
| 4466 | writeBaseIDOrNone(M->BaseTypeIndex, M->LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4467 | } |
| 4468 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4469 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4470 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4471 | Buffer.data(), Buffer.size()); |
| 4472 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4473 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4474 | RecordData DeclUpdatesOffsetsRecord; |
| 4475 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4476 | // Keep writing types, declarations, and declaration update records |
| 4477 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4478 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 4479 | WriteTypeAbbrevs(); |
| 4480 | WriteDeclAbbrevs(); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4481 | do { |
| 4482 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 4483 | while (!DeclTypesToEmit.empty()) { |
| 4484 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 4485 | DeclTypesToEmit.pop(); |
| 4486 | if (DOT.isType()) |
| 4487 | WriteType(DOT.getType()); |
| 4488 | else |
| 4489 | WriteDecl(Context, DOT.getDecl()); |
| 4490 | } |
| 4491 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4492 | Stream.ExitBlock(); |
| 4493 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4494 | DoneWritingDeclsAndTypes = true; |
| 4495 | |
| 4496 | // These things can only be done once we've written out decls and types. |
| 4497 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4498 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 4499 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4500 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4501 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4502 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4503 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4504 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4505 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4506 | WriteReferencedSelectorsPool(SemaRef); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 4507 | WriteLateParsedTemplates(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4508 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4509 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 4510 | WriteOpenCLExtensions(SemaRef); |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 4511 | WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4512 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4513 | // If we're emitting a module, write out the submodule information. |
| 4514 | if (WritingModule) |
| 4515 | WriteSubmodules(WritingModule); |
| 4516 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4517 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 4518 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4519 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 4520 | if (!EagerlyDeserializedDecls.empty()) |
| 4521 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4522 | |
| 4523 | // Write the record containing tentative definitions. |
| 4524 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4525 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4526 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4527 | // Write the record containing unused file scoped decls. |
| 4528 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4529 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4530 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4531 | // Write the record containing weak undeclared identifiers. |
| 4532 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4533 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4534 | WeakUndeclaredIdentifiers); |
| 4535 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4536 | // Write the record containing ext_vector type names. |
| 4537 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4538 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4539 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4540 | // Write the record containing VTable uses information. |
| 4541 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4542 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4543 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4544 | // Write the record containing potentially unused local typedefs. |
| 4545 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 4546 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 4547 | UnusedLocalTypedefNameCandidates); |
| 4548 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4549 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4550 | if (!PendingInstantiations.empty()) |
| 4551 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4552 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4553 | // Write the record containing declaration references of Sema. |
| 4554 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4555 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4556 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4557 | // Write the record containing CUDA-specific declaration references. |
| 4558 | if (!CUDASpecialDeclRefs.empty()) |
| 4559 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4560 | |
| 4561 | // Write the delegating constructors. |
| 4562 | if (!DelegatingCtorDecls.empty()) |
| 4563 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4565 | // Write the known namespaces. |
| 4566 | if (!KnownNamespaces.empty()) |
| 4567 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4568 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4569 | // Write the undefined internal functions and variables, and inline functions. |
| 4570 | if (!UndefinedButUsed.empty()) |
| 4571 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4572 | |
| 4573 | if (!DeleteExprsToAnalyze.empty()) |
| 4574 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 4575 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4576 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4577 | for (auto *DC : UpdatedDeclContexts) |
| 4578 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4579 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4580 | if (!WritingModule) { |
| 4581 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4582 | struct ModuleInfo { |
| 4583 | uint64_t ID; |
| 4584 | Module *M; |
| 4585 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 4586 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4587 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 4588 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4589 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4590 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 4591 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4592 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4593 | |
| 4594 | if (!Imports.empty()) { |
| 4595 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4596 | return A.ID < B.ID; |
| 4597 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4598 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4599 | return A.ID == B.ID; |
| 4600 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4601 | |
| 4602 | // Sort and deduplicate module IDs. |
| 4603 | std::sort(Imports.begin(), Imports.end(), Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4604 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4605 | Imports.end()); |
| 4606 | |
| 4607 | RecordData ImportedModules; |
| 4608 | for (const auto &Import : Imports) { |
| 4609 | ImportedModules.push_back(Import.ID); |
| 4610 | // FIXME: If the module has macros imported then later has declarations |
| 4611 | // imported, this location won't be the right one as a location for the |
| 4612 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 4613 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4614 | } |
| 4615 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4616 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 4617 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4618 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4619 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4620 | WriteObjCCategories(); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4621 | if(!WritingModule) { |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4622 | WriteOptimizePragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4623 | WriteMSStructPragmaOptions(SemaRef); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4624 | WriteMSPointersToMembersPragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4625 | } |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4626 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4627 | // Some simple statistics |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4628 | RecordData::value_type Record[] = { |
| 4629 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4630 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4631 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4632 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4633 | // Write the module file extension blocks. |
| 4634 | for (const auto &ExtWriter : ModuleFileExtensionWriters) |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4635 | WriteModuleFileExtension(SemaRef, *ExtWriter); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4636 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4637 | return Signature; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4638 | } |
| 4639 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4640 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4641 | if (DeclUpdates.empty()) |
| 4642 | return; |
| 4643 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4644 | DeclUpdateMap LocalUpdates; |
| 4645 | LocalUpdates.swap(DeclUpdates); |
| 4646 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4647 | for (auto &DeclUpdate : LocalUpdates) { |
| 4648 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 4649 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4650 | bool HasUpdatedBody = false; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4651 | RecordData RecordData; |
| 4652 | ASTRecordWriter Record(*this, RecordData); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4653 | for (auto &Update : DeclUpdate.second) { |
| 4654 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 4655 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4656 | // An updated body is emitted last, so that the reader doesn't need |
| 4657 | // to skip over the lazy body to reach statements for other records. |
| 4658 | if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION) |
| 4659 | HasUpdatedBody = true; |
| 4660 | else |
| 4661 | Record.push_back(Kind); |
| 4662 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4663 | switch (Kind) { |
| 4664 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 4665 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 4666 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4667 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4668 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 4669 | break; |
| 4670 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4671 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4672 | break; |
| 4673 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4674 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4675 | Record.AddSourceLocation(Update.getLoc()); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4676 | break; |
| 4677 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4678 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4679 | Record.AddStmt(const_cast<Expr *>( |
| 4680 | cast<ParmVarDecl>(Update.getDecl())->getDefaultArg())); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4681 | break; |
| 4682 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4683 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4684 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 4685 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4686 | Record.AddCXXDefinitionData(RD); |
Richard Smith | 72e50fe | 2016-04-14 00:50:18 +0000 | [diff] [blame] | 4687 | Record.AddOffset(WriteDeclContextLexicalBlock( |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4688 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 4689 | |
| 4690 | // This state is sometimes updated by template instantiation, when we |
| 4691 | // switch from the specialization referring to the template declaration |
| 4692 | // to it referring to the template definition. |
| 4693 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 4694 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4695 | Record.AddSourceLocation(MSInfo->getPointOfInstantiation()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4696 | } else { |
| 4697 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 4698 | Record.push_back(Spec->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4699 | Record.AddSourceLocation(Spec->getPointOfInstantiation()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4700 | |
| 4701 | // The instantiation might have been resolved to a partial |
| 4702 | // specialization. If so, record which one. |
| 4703 | auto From = Spec->getInstantiatedFrom(); |
| 4704 | if (auto PartialSpec = |
| 4705 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 4706 | Record.push_back(true); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4707 | Record.AddDeclRef(PartialSpec); |
| 4708 | Record.AddTemplateArgumentList( |
| 4709 | &Spec->getTemplateInstantiationArgs()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4710 | } else { |
| 4711 | Record.push_back(false); |
| 4712 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4713 | } |
| 4714 | Record.push_back(RD->getTagKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4715 | Record.AddSourceLocation(RD->getLocation()); |
| 4716 | Record.AddSourceLocation(RD->getLocStart()); |
| 4717 | Record.AddSourceLocation(RD->getRBraceLoc()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4718 | |
| 4719 | // Instantiation may change attributes; write them all out afresh. |
| 4720 | Record.push_back(D->hasAttrs()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4721 | if (D->hasAttrs()) |
| 4722 | Record.AddAttributes(D->getAttrs()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4723 | |
| 4724 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 4725 | break; |
| 4726 | } |
| 4727 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4728 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4729 | Record.AddDeclRef(Update.getDecl()); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4730 | break; |
| 4731 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4732 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 4733 | addExceptionSpec( |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4734 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 4735 | Record); |
| 4736 | break; |
| 4737 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4738 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 4739 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 4740 | break; |
| 4741 | |
| 4742 | case UPD_DECL_MARKED_USED: |
| 4743 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4744 | |
| 4745 | case UPD_MANGLING_NUMBER: |
| 4746 | case UPD_STATIC_LOCAL_NUMBER: |
| 4747 | Record.push_back(Update.getNumber()); |
| 4748 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4749 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4750 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4751 | Record.AddSourceRange( |
| 4752 | D->getAttr<OMPThreadPrivateDeclAttr>()->getRange()); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4753 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4754 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 4755 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: |
| 4756 | Record.AddSourceRange( |
| 4757 | D->getAttr<OMPDeclareTargetDeclAttr>()->getRange()); |
| 4758 | break; |
| 4759 | |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4760 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 4761 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4762 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4763 | |
| 4764 | case UPD_ADDED_ATTR_TO_RECORD: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4765 | Record.AddAttributes(llvm::makeArrayRef(Update.getAttr())); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4766 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4767 | } |
| 4768 | } |
| 4769 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4770 | if (HasUpdatedBody) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4771 | const auto *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4772 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4773 | Record.push_back(Def->isInlined()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4774 | Record.AddSourceLocation(Def->getInnerLocStart()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4775 | Record.AddFunctionDefinition(Def); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4776 | } |
| 4777 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4778 | OffsetsRecord.push_back(GetDeclRef(D)); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4779 | OffsetsRecord.push_back(Record.Emit(DECL_UPDATES)); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4780 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4781 | } |
| 4782 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4783 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 4784 | uint32_t Raw = Loc.getRawEncoding(); |
| 4785 | Record.push_back((Raw << 1) | (Raw >> 31)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4786 | } |
| 4787 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4788 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4789 | AddSourceLocation(Range.getBegin(), Record); |
| 4790 | AddSourceLocation(Range.getEnd(), Record); |
| 4791 | } |
| 4792 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4793 | void ASTRecordWriter::AddAPInt(const llvm::APInt &Value) { |
| 4794 | Record->push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4795 | const uint64_t *Words = Value.getRawData(); |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4796 | Record->append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4797 | } |
| 4798 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4799 | void ASTRecordWriter::AddAPSInt(const llvm::APSInt &Value) { |
| 4800 | Record->push_back(Value.isUnsigned()); |
| 4801 | AddAPInt(Value); |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4802 | } |
| 4803 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4804 | void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) { |
| 4805 | AddAPInt(Value.bitcastToAPInt()); |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4808 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4809 | Record.push_back(getIdentifierRef(II)); |
| 4810 | } |
| 4811 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4812 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4813 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4814 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4815 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4816 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4817 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4818 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4819 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4820 | } |
| 4821 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4822 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4823 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 4824 | // have been redefined by the header (in which case they are not |
| 4825 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4826 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4827 | return 0; |
| 4828 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4829 | MacroID &ID = MacroIDs[MI]; |
| 4830 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4831 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4832 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 4833 | MacroInfosToEmit.push_back(Info); |
| 4834 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4835 | return ID; |
| 4836 | } |
| 4837 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4838 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4839 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4840 | return 0; |
| 4841 | |
| 4842 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 4843 | return MacroIDs[MI]; |
| 4844 | } |
| 4845 | |
| 4846 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 4847 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4848 | } |
| 4849 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 4850 | void ASTRecordWriter::AddSelectorRef(const Selector SelRef) { |
| 4851 | Record->push_back(Writer->getSelectorRef(SelRef)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4852 | } |
| 4853 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4854 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4855 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4856 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4857 | } |
| 4858 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4859 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4860 | if (SID == 0 && Chain) { |
| 4861 | // This might trigger a ReadSelector callback, which will set the ID for |
| 4862 | // this selector. |
| 4863 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4864 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4865 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4866 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4867 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4868 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4869 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4870 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 4873 | void ASTRecordWriter::AddCXXTemporary(const CXXTemporary *Temp) { |
| 4874 | AddDeclRef(Temp->getDestructor()); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4875 | } |
| 4876 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4877 | void ASTRecordWriter::AddTemplateArgumentLocInfo( |
| 4878 | TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4879 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4880 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4881 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4882 | break; |
| 4883 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4884 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4885 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4886 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4887 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 4888 | AddSourceLocation(Arg.getTemplateNameLoc()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4889 | break; |
| 4890 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4891 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 4892 | AddSourceLocation(Arg.getTemplateNameLoc()); |
| 4893 | AddSourceLocation(Arg.getTemplateEllipsisLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4894 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4895 | case TemplateArgument::Null: |
| 4896 | case TemplateArgument::Integral: |
| 4897 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4898 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4899 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4900 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4901 | break; |
| 4902 | } |
| 4903 | } |
| 4904 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4905 | void ASTRecordWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg) { |
| 4906 | AddTemplateArgument(Arg.getArgument()); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4907 | |
| 4908 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 4909 | bool InfoHasSameExpr |
| 4910 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4911 | Record->push_back(InfoHasSameExpr); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4912 | if (InfoHasSameExpr) |
| 4913 | return; // Avoid storing the same expr twice. |
| 4914 | } |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4915 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo()); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4918 | void ASTRecordWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4919 | if (!TInfo) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4920 | AddTypeRef(QualType()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4921 | return; |
| 4922 | } |
| 4923 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4924 | AddTypeLoc(TInfo->getTypeLoc()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4927 | void ASTRecordWriter::AddTypeLoc(TypeLoc TL) { |
| 4928 | AddTypeRef(TL.getType()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4929 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4930 | TypeLocWriter TLW(*this); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4931 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4932 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4933 | } |
| 4934 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4935 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 4936 | Record.push_back(GetOrCreateTypeID(T)); |
| 4937 | } |
| 4938 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4939 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4940 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4941 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 4942 | if (T.isNull()) |
| 4943 | return TypeIdx(); |
| 4944 | assert(!T.getLocalFastQualifiers()); |
| 4945 | |
| 4946 | TypeIdx &Idx = TypeIdxs[T]; |
| 4947 | if (Idx.getIndex() == 0) { |
| 4948 | if (DoneWritingDeclsAndTypes) { |
| 4949 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 4950 | return TypeIdx(); |
| 4951 | } |
| 4952 | |
| 4953 | // We haven't seen this type before. Assign it a new ID and put it |
| 4954 | // into the queue of types to emit. |
| 4955 | Idx = TypeIdx(NextTypeID++); |
| 4956 | DeclTypesToEmit.push(T); |
| 4957 | } |
| 4958 | return Idx; |
| 4959 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 4960 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4961 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4962 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4963 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4964 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 4965 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4966 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4967 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4968 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4969 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 4970 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 4971 | return I->second; |
| 4972 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4973 | } |
| 4974 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4975 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4976 | Record.push_back(GetDeclRef(D)); |
| 4977 | } |
| 4978 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4979 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4980 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4981 | |
| 4982 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4983 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4984 | } |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4985 | |
| 4986 | // If D comes from an AST file, its declaration ID is already known and |
| 4987 | // fixed. |
| 4988 | if (D->isFromASTFile()) |
| 4989 | return D->getGlobalID(); |
| 4990 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4991 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4992 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4993 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4994 | if (DoneWritingDeclsAndTypes) { |
| 4995 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 4996 | return 0; |
| 4997 | } |
| 4998 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4999 | // We haven't seen this declaration before. Give it a new ID and |
| 5000 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5001 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5002 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5005 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5006 | } |
| 5007 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5008 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5009 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5010 | return 0; |
| 5011 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5012 | // If D comes from an AST file, its declaration ID is already known and |
| 5013 | // fixed. |
| 5014 | if (D->isFromASTFile()) |
| 5015 | return D->getGlobalID(); |
| 5016 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5017 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 5018 | return DeclIDs[D]; |
| 5019 | } |
| 5020 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5021 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5022 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5023 | assert(D); |
| 5024 | |
| 5025 | SourceLocation Loc = D->getLocation(); |
| 5026 | if (Loc.isInvalid()) |
| 5027 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5028 | |
| 5029 | // We only keep track of the file-level declarations of each file. |
| 5030 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 5031 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5032 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 5033 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5034 | if (isa<ParmVarDecl>(D)) |
| 5035 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5036 | |
| 5037 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5038 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5039 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5040 | FileID FID; |
| 5041 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5042 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5043 | if (FID.isInvalid()) |
| 5044 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5045 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5046 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5047 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5048 | if (!Info) |
| 5049 | Info = new DeclIDInFileInfo(); |
| 5050 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5051 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5052 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 5053 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5054 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5055 | Decls.push_back(LocDecl); |
| 5056 | return; |
| 5057 | } |
| 5058 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5059 | LocDeclIDsTy::iterator I = |
| 5060 | std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5061 | |
| 5062 | Decls.insert(I, LocDecl); |
| 5063 | } |
| 5064 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5065 | void ASTRecordWriter::AddDeclarationName(DeclarationName Name) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 5066 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5067 | Record->push_back(Name.getNameKind()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5068 | switch (Name.getNameKind()) { |
| 5069 | case DeclarationName::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5070 | AddIdentifierRef(Name.getAsIdentifierInfo()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5071 | break; |
| 5072 | |
| 5073 | case DeclarationName::ObjCZeroArgSelector: |
| 5074 | case DeclarationName::ObjCOneArgSelector: |
| 5075 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5076 | AddSelectorRef(Name.getObjCSelector()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5077 | break; |
| 5078 | |
| 5079 | case DeclarationName::CXXConstructorName: |
| 5080 | case DeclarationName::CXXDestructorName: |
| 5081 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5082 | AddTypeRef(Name.getCXXNameType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5083 | break; |
| 5084 | |
| 5085 | case DeclarationName::CXXOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5086 | Record->push_back(Name.getCXXOverloadedOperator()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5087 | break; |
| 5088 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5089 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5090 | AddIdentifierRef(Name.getCXXLiteralIdentifier()); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5091 | break; |
| 5092 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5093 | case DeclarationName::CXXUsingDirective: |
| 5094 | // No extra data to emit |
| 5095 | break; |
| 5096 | } |
| 5097 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5098 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5099 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5100 | assert(needsAnonymousDeclarationNumber(D) && |
| 5101 | "expected an anonymous declaration"); |
| 5102 | |
| 5103 | // Number the anonymous declarations within this context, if we've not |
| 5104 | // already done so. |
| 5105 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5106 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5107 | auto *DC = D->getLexicalDeclContext(); |
| 5108 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5109 | AnonymousDeclarationNumbers[ND] = Number; |
| 5110 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5111 | |
| 5112 | It = AnonymousDeclarationNumbers.find(D); |
| 5113 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5114 | "declaration not found within its lexical context"); |
| 5115 | } |
| 5116 | |
| 5117 | return It->second; |
| 5118 | } |
| 5119 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5120 | void ASTRecordWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
| 5121 | DeclarationName Name) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5122 | switch (Name.getNameKind()) { |
| 5123 | case DeclarationName::CXXConstructorName: |
| 5124 | case DeclarationName::CXXDestructorName: |
| 5125 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5126 | AddTypeSourceInfo(DNLoc.NamedType.TInfo); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5127 | break; |
| 5128 | |
| 5129 | case DeclarationName::CXXOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5130 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5131 | DNLoc.CXXOperatorName.BeginOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5132 | AddSourceLocation( |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5133 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5134 | break; |
| 5135 | |
| 5136 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5137 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5138 | DNLoc.CXXLiteralOperatorName.OpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5139 | break; |
| 5140 | |
| 5141 | case DeclarationName::Identifier: |
| 5142 | case DeclarationName::ObjCZeroArgSelector: |
| 5143 | case DeclarationName::ObjCOneArgSelector: |
| 5144 | case DeclarationName::ObjCMultiArgSelector: |
| 5145 | case DeclarationName::CXXUsingDirective: |
| 5146 | break; |
| 5147 | } |
| 5148 | } |
| 5149 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5150 | void ASTRecordWriter::AddDeclarationNameInfo( |
| 5151 | const DeclarationNameInfo &NameInfo) { |
| 5152 | AddDeclarationName(NameInfo.getName()); |
| 5153 | AddSourceLocation(NameInfo.getLoc()); |
| 5154 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName()); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5155 | } |
| 5156 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5157 | void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { |
| 5158 | AddNestedNameSpecifierLoc(Info.QualifierLoc); |
| 5159 | Record->push_back(Info.NumTemplParamLists); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5160 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5161 | AddTemplateParameterList(Info.TemplParamLists[i]); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5162 | } |
| 5163 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5164 | void ASTRecordWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5165 | // 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] | 5166 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5167 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5168 | |
| 5169 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5170 | while (NNS) { |
| 5171 | NestedNames.push_back(NNS); |
| 5172 | NNS = NNS->getPrefix(); |
| 5173 | } |
| 5174 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5175 | Record->push_back(NestedNames.size()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5176 | while(!NestedNames.empty()) { |
| 5177 | NNS = NestedNames.pop_back_val(); |
| 5178 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5179 | Record->push_back(Kind); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5180 | switch (Kind) { |
| 5181 | case NestedNameSpecifier::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5182 | AddIdentifierRef(NNS->getAsIdentifier()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5183 | break; |
| 5184 | |
| 5185 | case NestedNameSpecifier::Namespace: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5186 | AddDeclRef(NNS->getAsNamespace()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5187 | break; |
| 5188 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5189 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5190 | AddDeclRef(NNS->getAsNamespaceAlias()); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5191 | break; |
| 5192 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5193 | case NestedNameSpecifier::TypeSpec: |
| 5194 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5195 | AddTypeRef(QualType(NNS->getAsType(), 0)); |
| 5196 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5197 | break; |
| 5198 | |
| 5199 | case NestedNameSpecifier::Global: |
| 5200 | // Don't need to write an associated value. |
| 5201 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5202 | |
| 5203 | case NestedNameSpecifier::Super: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5204 | AddDeclRef(NNS->getAsRecordDecl()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5205 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5206 | } |
| 5207 | } |
| 5208 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5209 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5210 | void ASTRecordWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5211 | // 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] | 5212 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5213 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5214 | |
| 5215 | // Push each of the nested-name-specifiers's onto a stack for |
| 5216 | // serialization in reverse order. |
| 5217 | while (NNS) { |
| 5218 | NestedNames.push_back(NNS); |
| 5219 | NNS = NNS.getPrefix(); |
| 5220 | } |
| 5221 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5222 | Record->push_back(NestedNames.size()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5223 | while(!NestedNames.empty()) { |
| 5224 | NNS = NestedNames.pop_back_val(); |
| 5225 | NestedNameSpecifier::SpecifierKind Kind |
| 5226 | = NNS.getNestedNameSpecifier()->getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5227 | Record->push_back(Kind); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5228 | switch (Kind) { |
| 5229 | case NestedNameSpecifier::Identifier: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5230 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier()); |
| 5231 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5232 | break; |
| 5233 | |
| 5234 | case NestedNameSpecifier::Namespace: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5235 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace()); |
| 5236 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5237 | break; |
| 5238 | |
| 5239 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5240 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias()); |
| 5241 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5242 | break; |
| 5243 | |
| 5244 | case NestedNameSpecifier::TypeSpec: |
| 5245 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5246 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5247 | AddTypeLoc(NNS.getTypeLoc()); |
| 5248 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5249 | break; |
| 5250 | |
| 5251 | case NestedNameSpecifier::Global: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5252 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5253 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5254 | |
| 5255 | case NestedNameSpecifier::Super: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5256 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl()); |
| 5257 | AddSourceRange(NNS.getLocalSourceRange()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5258 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5259 | } |
| 5260 | } |
| 5261 | } |
| 5262 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5263 | void ASTRecordWriter::AddTemplateName(TemplateName Name) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5264 | TemplateName::NameKind Kind = Name.getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5265 | Record->push_back(Kind); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5266 | switch (Kind) { |
| 5267 | case TemplateName::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5268 | AddDeclRef(Name.getAsTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5269 | break; |
| 5270 | |
| 5271 | case TemplateName::OverloadedTemplate: { |
| 5272 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5273 | Record->push_back(OvT->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5274 | for (const auto &I : *OvT) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5275 | AddDeclRef(I); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5276 | break; |
| 5277 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5278 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5279 | case TemplateName::QualifiedTemplate: { |
| 5280 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5281 | AddNestedNameSpecifier(QualT->getQualifier()); |
| 5282 | Record->push_back(QualT->hasTemplateKeyword()); |
| 5283 | AddDeclRef(QualT->getTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5284 | break; |
| 5285 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5286 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5287 | case TemplateName::DependentTemplate: { |
| 5288 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5289 | AddNestedNameSpecifier(DepT->getQualifier()); |
| 5290 | Record->push_back(DepT->isIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5291 | if (DepT->isIdentifier()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5292 | AddIdentifierRef(DepT->getIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5293 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5294 | Record->push_back(DepT->getOperator()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5295 | break; |
| 5296 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5297 | |
| 5298 | case TemplateName::SubstTemplateTemplateParm: { |
| 5299 | SubstTemplateTemplateParmStorage *subst |
| 5300 | = Name.getAsSubstTemplateTemplateParm(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5301 | AddDeclRef(subst->getParameter()); |
| 5302 | AddTemplateName(subst->getReplacement()); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5303 | break; |
| 5304 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5305 | |
| 5306 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5307 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5308 | = Name.getAsSubstTemplateTemplateParmPack(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5309 | AddDeclRef(SubstPack->getParameterPack()); |
| 5310 | AddTemplateArgument(SubstPack->getArgumentPack()); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5311 | break; |
| 5312 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5313 | } |
| 5314 | } |
| 5315 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5316 | void ASTRecordWriter::AddTemplateArgument(const TemplateArgument &Arg) { |
| 5317 | Record->push_back(Arg.getKind()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5318 | switch (Arg.getKind()) { |
| 5319 | case TemplateArgument::Null: |
| 5320 | break; |
| 5321 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5322 | AddTypeRef(Arg.getAsType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5323 | break; |
| 5324 | case TemplateArgument::Declaration: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5325 | AddDeclRef(Arg.getAsDecl()); |
| 5326 | AddTypeRef(Arg.getParamTypeForDecl()); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5327 | break; |
| 5328 | case TemplateArgument::NullPtr: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5329 | AddTypeRef(Arg.getNullPtrType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5330 | break; |
| 5331 | case TemplateArgument::Integral: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5332 | AddAPSInt(Arg.getAsIntegral()); |
| 5333 | AddTypeRef(Arg.getIntegralType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5334 | break; |
| 5335 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5336 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5337 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5338 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5339 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5340 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5341 | Record->push_back(*NumExpansions + 1); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5342 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5343 | Record->push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5344 | break; |
| 5345 | case TemplateArgument::Expression: |
| 5346 | AddStmt(Arg.getAsExpr()); |
| 5347 | break; |
| 5348 | case TemplateArgument::Pack: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5349 | Record->push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 5350 | for (const auto &P : Arg.pack_elements()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5351 | AddTemplateArgument(P); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5352 | break; |
| 5353 | } |
| 5354 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5355 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5356 | void ASTRecordWriter::AddTemplateParameterList( |
| 5357 | const TemplateParameterList *TemplateParams) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5358 | assert(TemplateParams && "No TemplateParams!"); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5359 | AddSourceLocation(TemplateParams->getTemplateLoc()); |
| 5360 | AddSourceLocation(TemplateParams->getLAngleLoc()); |
| 5361 | AddSourceLocation(TemplateParams->getRAngleLoc()); |
| 5362 | Record->push_back(TemplateParams->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5363 | for (const auto &P : *TemplateParams) |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5364 | AddDeclRef(P); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | /// \brief Emit a template argument list. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5368 | void ASTRecordWriter::AddTemplateArgumentList( |
| 5369 | const TemplateArgumentList *TemplateArgs) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5370 | assert(TemplateArgs && "No TemplateArgs!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5371 | Record->push_back(TemplateArgs->size()); |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5372 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5373 | AddTemplateArgument(TemplateArgs->get(i)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5374 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5375 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5376 | void ASTRecordWriter::AddASTTemplateArgumentListInfo( |
| 5377 | const ASTTemplateArgumentListInfo *ASTTemplArgList) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5378 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5379 | AddSourceLocation(ASTTemplArgList->LAngleLoc); |
| 5380 | AddSourceLocation(ASTTemplArgList->RAngleLoc); |
| 5381 | Record->push_back(ASTTemplArgList->NumTemplateArgs); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5382 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
| 5383 | for (int i=0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5384 | AddTemplateArgumentLoc(TemplArgs[i]); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5385 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5386 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5387 | void ASTRecordWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set) { |
| 5388 | Record->push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5389 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5390 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5391 | AddDeclRef(I.getDecl()); |
| 5392 | Record->push_back(I.getAccess()); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5393 | } |
| 5394 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5395 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5396 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5397 | void ASTRecordWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base) { |
| 5398 | Record->push_back(Base.isVirtual()); |
| 5399 | Record->push_back(Base.isBaseOfClass()); |
| 5400 | Record->push_back(Base.getAccessSpecifierAsWritten()); |
| 5401 | Record->push_back(Base.getInheritConstructors()); |
| 5402 | AddTypeSourceInfo(Base.getTypeSourceInfo()); |
| 5403 | AddSourceRange(Base.getSourceRange()); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5404 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5405 | : SourceLocation()); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5406 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5407 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5408 | static uint64_t EmitCXXBaseSpecifiers(ASTWriter &W, |
| 5409 | ArrayRef<CXXBaseSpecifier> Bases) { |
| 5410 | ASTWriter::RecordData Record; |
| 5411 | ASTRecordWriter Writer(W, Record); |
| 5412 | Writer.push_back(Bases.size()); |
Dmitry Polukhin | 790b540 | 2016-04-06 10:01:46 +0000 | [diff] [blame] | 5413 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5414 | for (auto &Base : Bases) |
| 5415 | Writer.AddCXXBaseSpecifier(Base); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5416 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5417 | return Writer.Emit(serialization::DECL_CXX_BASE_SPECIFIERS); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5418 | } |
| 5419 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5420 | // FIXME: Move this out of the main ASTRecordWriter interface. |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5421 | void ASTRecordWriter::AddCXXBaseSpecifiers(ArrayRef<CXXBaseSpecifier> Bases) { |
| 5422 | AddOffset(EmitCXXBaseSpecifiers(*Writer, Bases)); |
| 5423 | } |
| 5424 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5425 | static uint64_t |
| 5426 | EmitCXXCtorInitializers(ASTWriter &W, |
| 5427 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 5428 | ASTWriter::RecordData Record; |
| 5429 | ASTRecordWriter Writer(W, Record); |
| 5430 | Writer.push_back(CtorInits.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5431 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5432 | for (auto *Init : CtorInits) { |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5433 | if (Init->isBaseInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5434 | Writer.push_back(CTOR_INITIALIZER_BASE); |
| 5435 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
| 5436 | Writer.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5437 | } else if (Init->isDelegatingInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5438 | Writer.push_back(CTOR_INITIALIZER_DELEGATING); |
| 5439 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5440 | } else if (Init->isMemberInitializer()){ |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5441 | Writer.push_back(CTOR_INITIALIZER_MEMBER); |
| 5442 | Writer.AddDeclRef(Init->getMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5443 | } else { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5444 | Writer.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 5445 | Writer.AddDeclRef(Init->getIndirectMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5446 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5447 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5448 | Writer.AddSourceLocation(Init->getMemberLocation()); |
| 5449 | Writer.AddStmt(Init->getInit()); |
| 5450 | Writer.AddSourceLocation(Init->getLParenLoc()); |
| 5451 | Writer.AddSourceLocation(Init->getRParenLoc()); |
| 5452 | Writer.push_back(Init->isWritten()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5453 | if (Init->isWritten()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5454 | Writer.push_back(Init->getSourceOrder()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5455 | } else { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5456 | Writer.push_back(Init->getNumArrayIndices()); |
| 5457 | for (auto *VD : Init->getArrayIndices()) |
| 5458 | Writer.AddDeclRef(VD); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5459 | } |
| 5460 | } |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5461 | |
| 5462 | return Writer.Emit(serialization::DECL_CXX_CTOR_INITIALIZERS); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5463 | } |
| 5464 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5465 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5466 | void ASTRecordWriter::AddCXXCtorInitializers( |
| 5467 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 5468 | AddOffset(EmitCXXCtorInitializers(*Writer, CtorInits)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5469 | } |
| 5470 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5471 | void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5472 | auto &Data = D->data(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5473 | Record->push_back(Data.IsLambda); |
| 5474 | Record->push_back(Data.UserDeclaredConstructor); |
| 5475 | Record->push_back(Data.UserDeclaredSpecialMembers); |
| 5476 | Record->push_back(Data.Aggregate); |
| 5477 | Record->push_back(Data.PlainOldData); |
| 5478 | Record->push_back(Data.Empty); |
| 5479 | Record->push_back(Data.Polymorphic); |
| 5480 | Record->push_back(Data.Abstract); |
| 5481 | Record->push_back(Data.IsStandardLayout); |
| 5482 | Record->push_back(Data.HasNoNonEmptyBases); |
| 5483 | Record->push_back(Data.HasPrivateFields); |
| 5484 | Record->push_back(Data.HasProtectedFields); |
| 5485 | Record->push_back(Data.HasPublicFields); |
| 5486 | Record->push_back(Data.HasMutableFields); |
| 5487 | Record->push_back(Data.HasVariantMembers); |
| 5488 | Record->push_back(Data.HasOnlyCMembers); |
| 5489 | Record->push_back(Data.HasInClassInitializer); |
| 5490 | Record->push_back(Data.HasUninitializedReferenceMember); |
| 5491 | Record->push_back(Data.HasUninitializedFields); |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 5492 | Record->push_back(Data.HasInheritedConstructor); |
| 5493 | Record->push_back(Data.HasInheritedAssignment); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5494 | Record->push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 5495 | Record->push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 5496 | Record->push_back(Data.NeedOverloadResolutionForDestructor); |
| 5497 | Record->push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 5498 | Record->push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 5499 | Record->push_back(Data.DefaultedDestructorIsDeleted); |
| 5500 | Record->push_back(Data.HasTrivialSpecialMembers); |
| 5501 | Record->push_back(Data.DeclaredNonTrivialSpecialMembers); |
| 5502 | Record->push_back(Data.HasIrrelevantDestructor); |
| 5503 | Record->push_back(Data.HasConstexprNonCopyMoveConstructor); |
| 5504 | Record->push_back(Data.HasDefaultedDefaultConstructor); |
| 5505 | Record->push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
| 5506 | Record->push_back(Data.HasConstexprDefaultConstructor); |
| 5507 | Record->push_back(Data.HasNonLiteralTypeFieldsOrBases); |
| 5508 | Record->push_back(Data.ComputedVisibleConversions); |
| 5509 | Record->push_back(Data.UserProvidedDefaultConstructor); |
| 5510 | Record->push_back(Data.DeclaredSpecialMembers); |
| 5511 | Record->push_back(Data.ImplicitCopyConstructorHasConstParam); |
| 5512 | Record->push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 5513 | Record->push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 5514 | Record->push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5515 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5516 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5517 | Record->push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5518 | if (Data.NumBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5519 | AddCXXBaseSpecifiers(Data.bases()); |
| 5520 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5521 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5522 | Record->push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5523 | if (Data.NumVBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5524 | AddCXXBaseSpecifiers(Data.vbases()); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5525 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5526 | AddUnresolvedSet(Data.Conversions.get(*Writer->Context)); |
| 5527 | AddUnresolvedSet(Data.VisibleConversions.get(*Writer->Context)); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5528 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5529 | AddDeclRef(D->getFirstFriend()); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5530 | |
| 5531 | // Add lambda-specific data. |
| 5532 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5533 | auto &Lambda = D->getLambdaData(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5534 | Record->push_back(Lambda.Dependent); |
| 5535 | Record->push_back(Lambda.IsGenericLambda); |
| 5536 | Record->push_back(Lambda.CaptureDefault); |
| 5537 | Record->push_back(Lambda.NumCaptures); |
| 5538 | Record->push_back(Lambda.NumExplicitCaptures); |
| 5539 | Record->push_back(Lambda.ManglingNumber); |
| 5540 | AddDeclRef(Lambda.ContextDecl); |
| 5541 | AddTypeSourceInfo(Lambda.MethodTyInfo); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5542 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 5543 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5544 | AddSourceLocation(Capture.getLocation()); |
| 5545 | Record->push_back(Capture.isImplicit()); |
| 5546 | Record->push_back(Capture.getCaptureKind()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5547 | switch (Capture.getCaptureKind()) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 5548 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5549 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 5550 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5551 | break; |
| 5552 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 5553 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5554 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5555 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5556 | AddDeclRef(Var); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5557 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5558 | : SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5559 | break; |
| 5560 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5561 | } |
| 5562 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5563 | } |
| 5564 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5565 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5566 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5567 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5568 | assert(FirstDeclID == NextDeclID && |
| 5569 | FirstTypeID == NextTypeID && |
| 5570 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5571 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5572 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5573 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5574 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5575 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5576 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5577 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 5578 | // Note, this will get called multiple times, once one the reader starts up |
| 5579 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5580 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 5581 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 5582 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5583 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5584 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5585 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5586 | NextDeclID = FirstDeclID; |
| 5587 | NextTypeID = FirstTypeID; |
| 5588 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5589 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5590 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5591 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5592 | } |
| 5593 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5594 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5595 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5596 | IdentID &StoredID = IdentifierIDs[II]; |
| 5597 | if (ID > StoredID) |
| 5598 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5601 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5602 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5603 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5604 | if (ID > StoredID) |
| 5605 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5608 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5609 | // Always take the highest-numbered type index. This copes with an interesting |
| 5610 | // 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] | 5611 | // 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] | 5612 | // keep the higher-numbered entry so that we can properly write it out to |
| 5613 | // the AST file. |
| 5614 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 5615 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 5616 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5617 | } |
| 5618 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5619 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5620 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5621 | SelectorID &StoredID = SelectorIDs[S]; |
| 5622 | if (ID > StoredID) |
| 5623 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5624 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5625 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5626 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5627 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5628 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5629 | MacroDefinitions[MD] = ID; |
| 5630 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5631 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 5632 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 5633 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 5634 | SubmoduleIDs[Mod] = ID; |
| 5635 | } |
| 5636 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5637 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5638 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5639 | assert(!WritingAST && "Already writing the AST!"); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5640 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5641 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5642 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5643 | // A forward reference was mutated into a definition. Rewrite it. |
| 5644 | // FIXME: This happens during template instantiation, should we |
| 5645 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5646 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 5647 | "completed a tag from another module but not by instantiation?"); |
| 5648 | DeclUpdates[RD].push_back( |
| 5649 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5650 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5651 | } |
| 5652 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5653 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5654 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { |
| 5655 | if (D->isFromASTFile()) |
| 5656 | return true; |
| 5657 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5658 | // The predefined __va_list_tag struct is imported if we imported any decls. |
| 5659 | // FIXME: This is a gross hack. |
| 5660 | return D == D->getASTContext().getVaListTagDecl(); |
| 5661 | } |
| 5662 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5663 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Vassil Vassilev | 71eafde | 2016-04-06 20:56:03 +0000 | [diff] [blame] | 5664 | assert(DC->isLookupContext() && |
| 5665 | "Should not add lookup results to non-lookup contexts!"); |
| 5666 | |
Vassil Vassilev | 632eac3 | 2016-03-16 11:17:04 +0000 | [diff] [blame] | 5667 | // TU is handled elsewhere. |
| 5668 | if (isa<TranslationUnitDecl>(DC)) |
| 5669 | return; |
| 5670 | |
| 5671 | // Namespaces are handled elsewhere, except for template instantiations of |
| 5672 | // FunctionTemplateDecls in namespaces. We are interested in cases where the |
| 5673 | // local instantiations are added to an imported context. Only happens when |
| 5674 | // adding ADL lookup candidates, for example templated friends. |
| 5675 | if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && |
| 5676 | !isa<FunctionTemplateDecl>(D)) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5677 | return; |
| 5678 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5679 | // We're only interested in cases where a local declaration is added to an |
| 5680 | // imported context. |
| 5681 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) |
| 5682 | return; |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5683 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 5684 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5685 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5686 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5687 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { |
| 5688 | // We're adding a visible declaration to a predefined decl context. Ensure |
| 5689 | // that we write out all of its lookup results so we don't get a nasty |
| 5690 | // surprise when we try to emit its lookup table. |
| 5691 | for (auto *Child : DC->decls()) |
| 5692 | UpdatingVisibleDecls.push_back(Child); |
| 5693 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5694 | UpdatingVisibleDecls.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5695 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5696 | |
| 5697 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
| 5698 | assert(D->isImplicit()); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5699 | |
| 5700 | // We're only interested in cases where a local declaration is added to an |
| 5701 | // imported context. |
| 5702 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) |
| 5703 | return; |
| 5704 | |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5705 | if (!isa<CXXMethodDecl>(D)) |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5706 | return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5707 | |
| 5708 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5709 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5710 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5711 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5712 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5713 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5714 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5715 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 5716 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5717 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5718 | // If we don't already know the exception specification for this redecl |
| 5719 | // chain, add an update record for it. |
| 5720 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 5721 | ->getType() |
| 5722 | ->castAs<FunctionProtoType>() |
| 5723 | ->getExceptionSpecType())) |
| 5724 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 5725 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5726 | } |
| 5727 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5728 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
| 5729 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5730 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5731 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5732 | DeclUpdates[D].push_back( |
| 5733 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 5734 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5735 | } |
| 5736 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5737 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
| 5738 | const FunctionDecl *Delete) { |
| 5739 | assert(!WritingAST && "Already writing the AST!"); |
| 5740 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5741 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5742 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5743 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 5744 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5745 | } |
| 5746 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5747 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5748 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5749 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5750 | return; // Declaration not imported from PCH. |
| 5751 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5752 | // Implicit function decl from a PCH was defined. |
| 5753 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5754 | } |
| 5755 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5756 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
| 5757 | assert(!WritingAST && "Already writing the AST!"); |
| 5758 | if (!D->isFromASTFile()) |
| 5759 | return; |
| 5760 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5761 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5764 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5765 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5766 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5767 | return; |
| 5768 | |
| 5769 | // Since the actual instantiation is delayed, this really means that we need |
| 5770 | // to update the instantiation location. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5771 | DeclUpdates[D].push_back( |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5772 | DeclUpdate(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER, |
| 5773 | D->getMemberSpecializationInfo()->getPointOfInstantiation())); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5774 | } |
| 5775 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5776 | void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { |
| 5777 | assert(!WritingAST && "Already writing the AST!"); |
| 5778 | if (!D->isFromASTFile()) |
| 5779 | return; |
| 5780 | |
| 5781 | DeclUpdates[D].push_back( |
| 5782 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D)); |
| 5783 | } |
| 5784 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5785 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 5786 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5787 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5788 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5789 | return; // Declaration not imported from PCH. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5790 | |
| 5791 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 5792 | ObjCClassesWithCategories.insert( |
| 5793 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5794 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 5795 | |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5796 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
| 5797 | assert(!WritingAST && "Already writing the AST!"); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 5798 | |
| 5799 | // If there is *any* declaration of the entity that's not from an AST file, |
| 5800 | // we can skip writing the update record. We make sure that isUsed() triggers |
| 5801 | // completion of the redeclaration chain of the entity. |
| 5802 | for (auto Prev = D->getMostRecentDecl(); Prev; Prev = Prev->getPreviousDecl()) |
| 5803 | if (IsLocalDecl(Prev)) |
| 5804 | return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5805 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5806 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5807 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5808 | |
| 5809 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
| 5810 | assert(!WritingAST && "Already writing the AST!"); |
| 5811 | if (!D->isFromASTFile()) |
| 5812 | return; |
| 5813 | |
| 5814 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 5815 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5816 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 5817 | void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, |
| 5818 | const Attr *Attr) { |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5819 | assert(!WritingAST && "Already writing the AST!"); |
| 5820 | if (!D->isFromASTFile()) |
| 5821 | return; |
| 5822 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 5823 | DeclUpdates[D].push_back( |
| 5824 | DeclUpdate(UPD_DECL_MARKED_OPENMP_DECLARETARGET, Attr)); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5825 | } |
| 5826 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5827 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5828 | assert(!WritingAST && "Already writing the AST!"); |
| 5829 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5830 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5831 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5832 | |
| 5833 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 5834 | const RecordDecl *Record) { |
| 5835 | assert(!WritingAST && "Already writing the AST!"); |
| 5836 | if (!Record->isFromASTFile()) |
| 5837 | return; |
| 5838 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 5839 | } |