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" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 16 | #include "ASTReaderInternals.h" |
| 17 | #include "MultiOnDiskHashTable.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTUnresolvedSet.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 20 | #include "clang/AST/Decl.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclCXX.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclContextInternals.h" |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclFriend.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" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 27 | #include "clang/AST/LambdaCapture.h" |
| 28 | #include "clang/AST/NestedNameSpecifier.h" |
| 29 | #include "clang/AST/RawCommentList.h" |
| 30 | #include "clang/AST/TemplateName.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 31 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 32 | #include "clang/AST/TypeLocVisitor.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 33 | #include "clang/Basic/DiagnosticOptions.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 34 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 35 | #include "clang/Basic/FileSystemOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 36 | #include "clang/Basic/LLVM.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 37 | #include "clang/Basic/LangOptions.h" |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 38 | #include "clang/Basic/MemoryBufferCache.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 39 | #include "clang/Basic/Module.h" |
| 40 | #include "clang/Basic/ObjCRuntime.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 41 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 42 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 43 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | cb177f1 | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 44 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 45 | #include "clang/Basic/Version.h" |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 46 | #include "clang/Basic/VersionTuple.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 47 | #include "clang/Lex/HeaderSearch.h" |
| 48 | #include "clang/Lex/HeaderSearchOptions.h" |
| 49 | #include "clang/Lex/MacroInfo.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 50 | #include "clang/Lex/ModuleMap.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 51 | #include "clang/Lex/PreprocessingRecord.h" |
| 52 | #include "clang/Lex/Preprocessor.h" |
| 53 | #include "clang/Lex/PreprocessorOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 54 | #include "clang/Lex/Token.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 55 | #include "clang/Sema/IdentifierResolver.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 56 | #include "clang/Sema/ObjCMethodList.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 57 | #include "clang/Sema/Sema.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 58 | #include "clang/Sema/Weak.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 59 | #include "clang/Serialization/ASTReader.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 60 | #include "clang/Serialization/Module.h" |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 61 | #include "clang/Serialization/ModuleFileExtension.h" |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 62 | #include "clang/Serialization/SerializationDiagnostic.h" |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 63 | #include "llvm/ADT/APFloat.h" |
| 64 | #include "llvm/ADT/APInt.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 65 | #include "llvm/ADT/Hashing.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 66 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 67 | #include "llvm/ADT/Optional.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 68 | #include "llvm/ADT/STLExtras.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 69 | #include "llvm/ADT/SmallSet.h" |
| 70 | #include "llvm/ADT/SmallString.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 71 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 72 | #include "llvm/Bitcode/BitCodes.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 73 | #include "llvm/Bitcode/BitstreamWriter.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 74 | #include "llvm/Support/Casting.h" |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 75 | #include "llvm/Support/Compression.h" |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 76 | #include "llvm/Support/EndianStream.h" |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 77 | #include "llvm/Support/Error.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 78 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 79 | #include "llvm/Support/MemoryBuffer.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 80 | #include "llvm/Support/OnDiskHashTable.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 81 | #include "llvm/Support/Path.h" |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 82 | #include "llvm/Support/Process.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 83 | #include "llvm/Support/SHA1.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 84 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 85 | #include <algorithm> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 86 | #include <cassert> |
| 87 | #include <cstdint> |
| 88 | #include <cstdlib> |
| 89 | #include <cstring> |
| 90 | #include <deque> |
| 91 | #include <limits> |
| 92 | #include <new> |
| 93 | #include <tuple> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 94 | #include <utility> |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 95 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 96 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 97 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 98 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 99 | template <typename T, typename Allocator> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 100 | static StringRef bytes(const std::vector<T, Allocator> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 101 | if (v.empty()) return StringRef(); |
| 102 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 103 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 104 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 105 | |
| 106 | template <typename T> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 107 | static StringRef bytes(const SmallVectorImpl<T> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 108 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 109 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 112 | //===----------------------------------------------------------------------===// |
| 113 | // Type serialization |
| 114 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 115 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 116 | namespace clang { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 117 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 118 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 119 | ASTWriter &Writer; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 120 | ASTRecordWriter Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 122 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 123 | TypeCode Code; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 124 | /// \brief Abbreviation to use for the record, if any. |
| 125 | unsigned AbbrevToUse; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 126 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 127 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 128 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 129 | : Writer(Writer), Record(Writer, Record), Code((TypeCode)0), AbbrevToUse(0) { } |
| 130 | |
| 131 | uint64_t Emit() { |
| 132 | return Record.Emit(Code, AbbrevToUse); |
| 133 | } |
| 134 | |
| 135 | void Visit(QualType T) { |
| 136 | if (T.hasLocalNonFastQualifiers()) { |
| 137 | Qualifiers Qs = T.getLocalQualifiers(); |
| 138 | Record.AddTypeRef(T.getLocalUnqualifiedType()); |
| 139 | Record.push_back(Qs.getAsOpaqueValue()); |
| 140 | Code = TYPE_EXT_QUAL; |
| 141 | AbbrevToUse = Writer.TypeExtQualAbbrev; |
| 142 | } else { |
| 143 | switch (T->getTypeClass()) { |
| 144 | // For all of the concrete, non-dependent types, call the |
| 145 | // appropriate visitor function. |
| 146 | #define TYPE(Class, Base) \ |
| 147 | case Type::Class: Visit##Class##Type(cast<Class##Type>(T)); break; |
| 148 | #define ABSTRACT_TYPE(Class, Base) |
| 149 | #include "clang/AST/TypeNodes.def" |
| 150 | } |
| 151 | } |
| 152 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 153 | |
| 154 | void VisitArrayType(const ArrayType *T); |
| 155 | void VisitFunctionType(const FunctionType *T); |
| 156 | void VisitTagType(const TagType *T); |
| 157 | |
| 158 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 159 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 160 | #include "clang/AST/TypeNodes.def" |
| 161 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 162 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 163 | } // end namespace clang |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 164 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 165 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 166 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 169 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 170 | Record.AddTypeRef(T->getElementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 171 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 174 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 175 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 176 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 179 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 180 | Record.AddTypeRef(T->getOriginalType()); |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 181 | Code = TYPE_DECAYED; |
| 182 | } |
| 183 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 184 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 185 | Record.AddTypeRef(T->getOriginalType()); |
| 186 | Record.AddTypeRef(T->getAdjustedType()); |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 187 | Code = TYPE_ADJUSTED; |
| 188 | } |
| 189 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 190 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 191 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 192 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 195 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 196 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 197 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 198 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 201 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 202 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 203 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 206 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 207 | Record.AddTypeRef(T->getPointeeType()); |
| 208 | Record.AddTypeRef(QualType(T->getClass(), 0)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 209 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 212 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 213 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 214 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 215 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 218 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 219 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 220 | Record.AddAPInt(T->getSize()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 221 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 224 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 225 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 226 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 229 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 230 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 231 | Record.AddSourceLocation(T->getLBracketLoc()); |
| 232 | Record.AddSourceLocation(T->getRBracketLoc()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 233 | Record.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 234 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 237 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 238 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 239 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 240 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 241 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 244 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 245 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 246 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 249 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 250 | Record.AddTypeRef(T->getReturnType()); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 251 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 252 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 253 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 254 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 255 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 256 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 257 | Record.push_back(C.getProducesResult()); |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 258 | Record.push_back(C.getNoCallerSavedRegs()); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 259 | |
| 260 | if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult()) |
| 261 | AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 264 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 265 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 266 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 269 | static void addExceptionSpec(const FunctionProtoType *T, |
| 270 | ASTRecordWriter &Record) { |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 271 | Record.push_back(T->getExceptionSpecType()); |
| 272 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 273 | Record.push_back(T->getNumExceptions()); |
| 274 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 275 | Record.AddTypeRef(T->getExceptionType(I)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 276 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 277 | Record.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 278 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 279 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
| 280 | Record.AddDeclRef(T->getExceptionSpecTemplate()); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 281 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 282 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 283 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 287 | VisitFunctionType(T); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 288 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 289 | Record.push_back(T->isVariadic()); |
| 290 | Record.push_back(T->hasTrailingReturn()); |
| 291 | Record.push_back(T->getTypeQuals()); |
| 292 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 293 | addExceptionSpec(T, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 294 | |
| 295 | Record.push_back(T->getNumParams()); |
| 296 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 297 | Record.AddTypeRef(T->getParamType(I)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 298 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 299 | if (T->hasExtParameterInfos()) { |
| 300 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 301 | Record.push_back(T->getExtParameterInfo(I).getOpaqueValue()); |
| 302 | } |
| 303 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 304 | if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 305 | T->getRefQualifier() || T->getExceptionSpecType() != EST_None || |
| 306 | T->hasExtParameterInfos()) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 307 | AbbrevToUse = 0; |
| 308 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 309 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 312 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 313 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 314 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 315 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 316 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 317 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 318 | Record.AddDeclRef(T->getDecl()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 319 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 320 | Record.AddTypeRef(T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 321 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 324 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 325 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 326 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 329 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 330 | Record.AddTypeRef(T->getUnderlyingType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 331 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 334 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 335 | Record.AddTypeRef(T->getUnderlyingType()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 336 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 337 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 340 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 341 | Record.AddTypeRef(T->getBaseType()); |
| 342 | Record.AddTypeRef(T->getUnderlyingType()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 343 | Record.push_back(T->getUTTKind()); |
| 344 | Code = TYPE_UNARY_TRANSFORM; |
| 345 | } |
| 346 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 347 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 348 | Record.AddTypeRef(T->getDeducedType()); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 349 | Record.push_back((unsigned)T->getKeyword()); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 350 | if (T->getDeducedType().isNull()) |
| 351 | Record.push_back(T->isDependentType()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 352 | Code = TYPE_AUTO; |
| 353 | } |
| 354 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 355 | void ASTTypeWriter::VisitDeducedTemplateSpecializationType( |
| 356 | const DeducedTemplateSpecializationType *T) { |
| 357 | Record.AddTemplateName(T->getTemplateName()); |
| 358 | Record.AddTypeRef(T->getDeducedType()); |
| 359 | if (T->getDeducedType().isNull()) |
| 360 | Record.push_back(T->isDependentType()); |
| 361 | Code = TYPE_DEDUCED_TEMPLATE_SPECIALIZATION; |
| 362 | } |
| 363 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 364 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 365 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 366 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 368 | "Cannot serialize in the middle of a type definition"); |
| 369 | } |
| 370 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 371 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 372 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 373 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 376 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 377 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 378 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 379 | } |
| 380 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 381 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 382 | Record.AddTypeRef(T->getModifiedType()); |
| 383 | Record.AddTypeRef(T->getEquivalentType()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 384 | Record.push_back(T->getAttrKind()); |
| 385 | Code = TYPE_ATTRIBUTED; |
| 386 | } |
| 387 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 389 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 390 | const SubstTemplateTypeParmType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 391 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 392 | Record.AddTypeRef(T->getReplacementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 393 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 397 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 398 | const SubstTemplateTypeParmPackType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 399 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 400 | Record.AddTemplateArgument(T->getArgumentPack()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 401 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 402 | } |
| 403 | |
| 404 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 405 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 406 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 407 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 408 | Record.AddTemplateName(T->getTemplateName()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 409 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 410 | for (const auto &ArgI : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 411 | Record.AddTemplateArgument(ArgI); |
| 412 | Record.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() |
| 413 | : T->isCanonicalUnqualified() |
| 414 | ? QualType() |
| 415 | : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 416 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 420 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 421 | VisitArrayType(T); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 422 | Record.AddStmt(T->getSizeExpr()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 423 | Record.AddSourceRange(T->getBracketsRange()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 424 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 428 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 429 | const DependentSizedExtVectorType *T) { |
Alex Lorenz | 00aee43 | 2017-03-22 10:04:48 +0000 | [diff] [blame] | 430 | Record.AddTypeRef(T->getElementType()); |
| 431 | Record.AddStmt(T->getSizeExpr()); |
| 432 | Record.AddSourceLocation(T->getAttributeLoc()); |
| 433 | Code = TYPE_DEPENDENT_SIZED_EXT_VECTOR; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 437 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 438 | Record.push_back(T->getDepth()); |
| 439 | Record.push_back(T->getIndex()); |
| 440 | Record.push_back(T->isParameterPack()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 441 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 442 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 446 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 447 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 448 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 449 | Record.AddIdentifierRef(T->getIdentifier()); |
| 450 | Record.AddTypeRef( |
| 451 | T->isCanonicalUnqualified() ? QualType() : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 452 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 456 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 457 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 458 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 459 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 460 | Record.AddIdentifierRef(T->getIdentifier()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 461 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 462 | for (const auto &I : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 463 | Record.AddTemplateArgument(I); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 464 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 467 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 468 | Record.AddTypeRef(T->getPattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 469 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 470 | Record.push_back(*NumExpansions + 1); |
| 471 | else |
| 472 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 473 | Code = TYPE_PACK_EXPANSION; |
| 474 | } |
| 475 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 476 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 477 | Record.AddTypeRef(T->getInnerType()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 478 | Code = TYPE_PAREN; |
| 479 | } |
| 480 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 481 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 482 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 483 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 484 | Record.AddTypeRef(T->getNamedType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 485 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 488 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 489 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
| 490 | Record.AddTypeRef(T->getInjectedSpecializationType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 491 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 494 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 495 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 496 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 499 | void ASTTypeWriter::VisitObjCTypeParamType(const ObjCTypeParamType *T) { |
| 500 | Record.AddDeclRef(T->getDecl()); |
| 501 | Record.push_back(T->getNumProtocols()); |
| 502 | for (const auto *I : T->quals()) |
| 503 | Record.AddDeclRef(I); |
| 504 | Code = TYPE_OBJC_TYPE_PARAM; |
| 505 | } |
| 506 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 507 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 508 | Record.AddTypeRef(T->getBaseType()); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 509 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 510 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 511 | Record.AddTypeRef(TypeArg); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 512 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 513 | for (const auto *I : T->quals()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 514 | Record.AddDeclRef(I); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 515 | Record.push_back(T->isKindOfTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 516 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 519 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 520 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 521 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 522 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 525 | void |
| 526 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 527 | Record.AddTypeRef(T->getValueType()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 528 | Code = TYPE_ATOMIC; |
| 529 | } |
| 530 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 531 | void |
| 532 | ASTTypeWriter::VisitPipeType(const PipeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 533 | Record.AddTypeRef(T->getElementType()); |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 534 | Record.push_back(T->isReadOnly()); |
| 535 | Code = TYPE_PIPE; |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 536 | } |
| 537 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 538 | namespace { |
| 539 | |
| 540 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 541 | ASTRecordWriter &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 542 | |
| 543 | public: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 544 | TypeLocWriter(ASTRecordWriter &Record) |
| 545 | : Record(Record) { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 546 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 547 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 548 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 549 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 550 | #include "clang/AST/TypeLocNodes.def" |
| 551 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 552 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 553 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 554 | }; |
| 555 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 556 | } // end anonymous namespace |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 557 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 558 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 559 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 560 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 561 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 562 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 563 | Record.AddSourceLocation(TL.getBuiltinLoc()); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 564 | if (TL.needsExtraLocalData()) { |
| 565 | Record.push_back(TL.getWrittenTypeSpec()); |
| 566 | Record.push_back(TL.getWrittenSignSpec()); |
| 567 | Record.push_back(TL.getWrittenWidthSpec()); |
| 568 | Record.push_back(TL.hasModeAttr()); |
| 569 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 570 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 571 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 572 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 573 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 574 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 575 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 576 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 577 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 578 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 579 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 580 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 581 | // nothing to do |
| 582 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 583 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 584 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 585 | // nothing to do |
| 586 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 587 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 588 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 589 | Record.AddSourceLocation(TL.getCaretLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 590 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 591 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 592 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 593 | Record.AddSourceLocation(TL.getAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 594 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 595 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 596 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 597 | Record.AddSourceLocation(TL.getAmpAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 598 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 599 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 600 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 601 | Record.AddSourceLocation(TL.getStarLoc()); |
| 602 | Record.AddTypeSourceInfo(TL.getClassTInfo()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 603 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 604 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 605 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 606 | Record.AddSourceLocation(TL.getLBracketLoc()); |
| 607 | Record.AddSourceLocation(TL.getRBracketLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 608 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 609 | if (TL.getSizeExpr()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 610 | Record.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 611 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 612 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 613 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 614 | VisitArrayTypeLoc(TL); |
| 615 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 616 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 617 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 618 | VisitArrayTypeLoc(TL); |
| 619 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 620 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 621 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 622 | VisitArrayTypeLoc(TL); |
| 623 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 624 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 625 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 626 | DependentSizedArrayTypeLoc TL) { |
| 627 | VisitArrayTypeLoc(TL); |
| 628 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 629 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 630 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 631 | DependentSizedExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 632 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 633 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 634 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 635 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc 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 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 638 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 639 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 640 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 641 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 642 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 643 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 644 | Record.AddSourceLocation(TL.getLocalRangeBegin()); |
| 645 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 646 | Record.AddSourceLocation(TL.getRParenLoc()); |
Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 647 | Record.AddSourceRange(TL.getExceptionSpecRange()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 648 | Record.AddSourceLocation(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 649 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 650 | Record.AddDeclRef(TL.getParam(i)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 651 | } |
| 652 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 653 | VisitFunctionTypeLoc(TL); |
| 654 | } |
| 655 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 656 | VisitFunctionTypeLoc(TL); |
| 657 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 658 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 659 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 660 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 661 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 662 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 663 | } |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 664 | void TypeLocWriter::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 665 | if (TL.getNumProtocols()) { |
| 666 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 667 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
| 668 | } |
| 669 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 670 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
| 671 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 672 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 673 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 674 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 675 | Record.AddSourceLocation(TL.getRParenLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 676 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 677 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 678 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 679 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 680 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 681 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 682 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 683 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 684 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 685 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 686 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 687 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 688 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 689 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 690 | Record.AddSourceLocation(TL.getKWLoc()); |
| 691 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 692 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 693 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 694 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 695 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 696 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 697 | Record.AddSourceLocation(TL.getNameLoc()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 698 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 699 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 700 | void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc( |
| 701 | DeducedTemplateSpecializationTypeLoc TL) { |
| 702 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 703 | } |
| 704 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 705 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 706 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 707 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 708 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 709 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 710 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 711 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 712 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 713 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 714 | Record.AddSourceLocation(TL.getAttrNameLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 715 | if (TL.hasAttrOperand()) { |
| 716 | SourceRange range = TL.getAttrOperandParensRange(); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 717 | Record.AddSourceLocation(range.getBegin()); |
| 718 | Record.AddSourceLocation(range.getEnd()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 719 | } |
| 720 | if (TL.hasAttrExprOperand()) { |
| 721 | Expr *operand = TL.getAttrExprOperand(); |
| 722 | Record.push_back(operand ? 1 : 0); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 723 | if (operand) Record.AddStmt(operand); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 724 | } else if (TL.hasAttrEnumOperand()) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 725 | Record.AddSourceLocation(TL.getAttrEnumOperandLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 726 | } |
| 727 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 728 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 729 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 730 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 731 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 732 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 733 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 734 | SubstTemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 735 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 736 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 737 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 738 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 739 | SubstTemplateTypeParmPackTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 740 | Record.AddSourceLocation(TL.getNameLoc()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 741 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 742 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 743 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 744 | TemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 745 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 746 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 747 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 748 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 749 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 750 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 751 | TL.getArgLoc(i).getLocInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 752 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 753 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 754 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 755 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 756 | Record.AddSourceLocation(TL.getRParenLoc()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 757 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 758 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 759 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 760 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 761 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 762 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 763 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 764 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 765 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 766 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 767 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 768 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 769 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 770 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 771 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 772 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 773 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 774 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 775 | DependentTemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 776 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 777 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 778 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 779 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 780 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 781 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 782 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 783 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 784 | TL.getArgLoc(I).getLocInfo()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 785 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 786 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 787 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 788 | Record.AddSourceLocation(TL.getEllipsisLoc()); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 789 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 790 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 791 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 792 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 793 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 794 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 795 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 796 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 797 | Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); |
| 798 | Record.AddSourceLocation(TL.getTypeArgsRAngleLoc()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 799 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 800 | Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i)); |
| 801 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 802 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 803 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 804 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 805 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 806 | |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 807 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 808 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 809 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 810 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 811 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 812 | Record.AddSourceLocation(TL.getKWLoc()); |
| 813 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 814 | Record.AddSourceLocation(TL.getRParenLoc()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 815 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 816 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 817 | void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 818 | Record.AddSourceLocation(TL.getKWLoc()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 819 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 820 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 821 | void ASTWriter::WriteTypeAbbrevs() { |
| 822 | using namespace llvm; |
| 823 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 824 | std::shared_ptr<BitCodeAbbrev> Abv; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 825 | |
| 826 | // Abbreviation for TYPE_EXT_QUAL |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 827 | Abv = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 828 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 829 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 830 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 831 | TypeExtQualAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 832 | |
| 833 | // Abbreviation for TYPE_FUNCTION_PROTO |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 834 | Abv = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 835 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 836 | // FunctionType |
| 837 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 838 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 839 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 840 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 841 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 842 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 843 | Abv->Add(BitCodeAbbrevOp(0)); // NoCallerSavedRegs |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 844 | // FunctionProtoType |
| 845 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 846 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 847 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 848 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 849 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 850 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 851 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 852 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 853 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 856 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 857 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 858 | //===----------------------------------------------------------------------===// |
| 859 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 860 | static void EmitBlockID(unsigned ID, const char *Name, |
| 861 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 862 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 863 | Record.clear(); |
| 864 | Record.push_back(ID); |
| 865 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 866 | |
| 867 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 868 | if (!Name || Name[0] == 0) |
| 869 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 870 | Record.clear(); |
| 871 | while (*Name) |
| 872 | Record.push_back(*Name++); |
| 873 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 874 | } |
| 875 | |
| 876 | static void EmitRecordID(unsigned ID, const char *Name, |
| 877 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 878 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 879 | Record.clear(); |
| 880 | Record.push_back(ID); |
| 881 | while (*Name) |
| 882 | Record.push_back(*Name++); |
| 883 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 887 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 888 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 889 | RECORD(STMT_STOP); |
| 890 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 891 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 892 | RECORD(STMT_NULL); |
| 893 | RECORD(STMT_COMPOUND); |
| 894 | RECORD(STMT_CASE); |
| 895 | RECORD(STMT_DEFAULT); |
| 896 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 897 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 898 | RECORD(STMT_IF); |
| 899 | RECORD(STMT_SWITCH); |
| 900 | RECORD(STMT_WHILE); |
| 901 | RECORD(STMT_DO); |
| 902 | RECORD(STMT_FOR); |
| 903 | RECORD(STMT_GOTO); |
| 904 | RECORD(STMT_INDIRECT_GOTO); |
| 905 | RECORD(STMT_CONTINUE); |
| 906 | RECORD(STMT_BREAK); |
| 907 | RECORD(STMT_RETURN); |
| 908 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 909 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 910 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 911 | RECORD(EXPR_PREDEFINED); |
| 912 | RECORD(EXPR_DECL_REF); |
| 913 | RECORD(EXPR_INTEGER_LITERAL); |
| 914 | RECORD(EXPR_FLOATING_LITERAL); |
| 915 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 916 | RECORD(EXPR_STRING_LITERAL); |
| 917 | RECORD(EXPR_CHARACTER_LITERAL); |
| 918 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 919 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 920 | RECORD(EXPR_UNARY_OPERATOR); |
| 921 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 922 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 923 | RECORD(EXPR_CALL); |
| 924 | RECORD(EXPR_MEMBER); |
| 925 | RECORD(EXPR_BINARY_OPERATOR); |
| 926 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 927 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 928 | RECORD(EXPR_IMPLICIT_CAST); |
| 929 | RECORD(EXPR_CSTYLE_CAST); |
| 930 | RECORD(EXPR_COMPOUND_LITERAL); |
| 931 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 932 | RECORD(EXPR_INIT_LIST); |
| 933 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 934 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 935 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 936 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 937 | RECORD(EXPR_VA_ARG); |
| 938 | RECORD(EXPR_ADDR_LABEL); |
| 939 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 940 | RECORD(EXPR_CHOOSE); |
| 941 | RECORD(EXPR_GNU_NULL); |
| 942 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 943 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 944 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 945 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 946 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 947 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 948 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 949 | RECORD(EXPR_OBJC_ENCODE); |
| 950 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 951 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 952 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 953 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 954 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 955 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 956 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 957 | RECORD(STMT_OBJC_CATCH); |
| 958 | RECORD(STMT_OBJC_FINALLY); |
| 959 | RECORD(STMT_OBJC_AT_TRY); |
| 960 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 961 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 962 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 963 | RECORD(STMT_CXX_CATCH); |
| 964 | RECORD(STMT_CXX_TRY); |
| 965 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 966 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 967 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 968 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 969 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 970 | RECORD(EXPR_CXX_STATIC_CAST); |
| 971 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 972 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 973 | RECORD(EXPR_CXX_CONST_CAST); |
| 974 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 975 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 976 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 977 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 978 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 979 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 980 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 981 | RECORD(EXPR_CXX_THIS); |
| 982 | RECORD(EXPR_CXX_THROW); |
| 983 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 984 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 985 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 986 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 987 | RECORD(EXPR_CXX_NEW); |
| 988 | RECORD(EXPR_CXX_DELETE); |
| 989 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 990 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 991 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 992 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 993 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 994 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 995 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 996 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 997 | RECORD(EXPR_CXX_NOEXCEPT); |
| 998 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 999 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 1000 | RECORD(EXPR_TYPE_TRAIT); |
| 1001 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1002 | RECORD(EXPR_PACK_EXPANSION); |
| 1003 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1004 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1005 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1006 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 1007 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1008 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1009 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 1010 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 1011 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 1012 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1013 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1014 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1015 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1016 | RecordData Record; |
Peter Collingbourne | d3a6c70 | 2016-11-01 01:18:57 +0000 | [diff] [blame] | 1017 | Stream.EnterBlockInfoBlock(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1018 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1019 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 1020 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1021 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1022 | // Control Block. |
| 1023 | BLOCK(CONTROL_BLOCK); |
| 1024 | RECORD(METADATA); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1025 | RECORD(MODULE_NAME); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1026 | RECORD(MODULE_DIRECTORY); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1027 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1028 | RECORD(IMPORTS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1029 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1030 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1031 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1032 | RECORD(INPUT_FILE_OFFSETS); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1033 | |
| 1034 | BLOCK(OPTIONS_BLOCK); |
| 1035 | RECORD(LANGUAGE_OPTIONS); |
| 1036 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1037 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1038 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1039 | RECORD(PREPROCESSOR_OPTIONS); |
| 1040 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 1041 | BLOCK(INPUT_FILES_BLOCK); |
| 1042 | RECORD(INPUT_FILE); |
| 1043 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1044 | // AST Top-Level Block. |
| 1045 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1046 | RECORD(TYPE_OFFSET); |
| 1047 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1048 | RECORD(IDENTIFIER_OFFSET); |
| 1049 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 1050 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 1051 | RECORD(MODULAR_CODEGEN_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1052 | RECORD(SPECIAL_TYPES); |
| 1053 | RECORD(STATISTICS); |
| 1054 | RECORD(TENTATIVE_DEFINITIONS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1055 | RECORD(SELECTOR_OFFSETS); |
| 1056 | RECORD(METHOD_POOL); |
| 1057 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1058 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 1059 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1060 | RECORD(EXT_VECTOR_DECLS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1061 | RECORD(UNUSED_FILESCOPED_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1062 | RECORD(PPD_ENTITIES_OFFSETS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1063 | RECORD(VTABLE_USES); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 1064 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1065 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1066 | RECORD(SEMA_DECL_REFS); |
| 1067 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 1068 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1069 | RECORD(UPDATE_VISIBLE); |
| 1070 | RECORD(DECL_UPDATE_OFFSETS); |
| 1071 | RECORD(DECL_UPDATES); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1072 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1073 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1074 | RECORD(FP_PRAGMA_OPTIONS); |
| 1075 | RECORD(OPENCL_EXTENSIONS); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 1076 | RECORD(OPENCL_EXTENSION_TYPES); |
| 1077 | RECORD(OPENCL_EXTENSION_DECLS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1078 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 1079 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 1080 | RECORD(MODULE_OFFSET_MAP); |
| 1081 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1082 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 1083 | RECORD(FILE_SORTED_DECLS); |
| 1084 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1085 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1086 | RECORD(MACRO_OFFSET); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1087 | RECORD(INTERESTING_IDENTIFIERS); |
| 1088 | RECORD(UNDEFINED_BUT_USED); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1089 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 1090 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 1091 | RECORD(MSSTRUCT_PRAGMA_OPTIONS); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 1092 | RECORD(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1093 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1094 | RECORD(DELETE_EXPRS_TO_ANALYZE); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 1095 | RECORD(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH); |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 1096 | RECORD(PP_CONDITIONAL_STACK); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 1097 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1098 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1099 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1100 | RECORD(SM_SLOC_FILE_ENTRY); |
| 1101 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 1102 | RECORD(SM_SLOC_BUFFER_BLOB); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1103 | RECORD(SM_SLOC_BUFFER_BLOB_COMPRESSED); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1104 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1106 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1107 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1108 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1109 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1110 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 1111 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1112 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1113 | |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1114 | // Submodule Block. |
| 1115 | BLOCK(SUBMODULE_BLOCK); |
| 1116 | RECORD(SUBMODULE_METADATA); |
| 1117 | RECORD(SUBMODULE_DEFINITION); |
| 1118 | RECORD(SUBMODULE_UMBRELLA_HEADER); |
| 1119 | RECORD(SUBMODULE_HEADER); |
| 1120 | RECORD(SUBMODULE_TOPHEADER); |
| 1121 | RECORD(SUBMODULE_UMBRELLA_DIR); |
| 1122 | RECORD(SUBMODULE_IMPORTS); |
| 1123 | RECORD(SUBMODULE_EXPORTS); |
| 1124 | RECORD(SUBMODULE_REQUIRES); |
| 1125 | RECORD(SUBMODULE_EXCLUDED_HEADER); |
| 1126 | RECORD(SUBMODULE_LINK_LIBRARY); |
| 1127 | RECORD(SUBMODULE_CONFIG_MACRO); |
| 1128 | RECORD(SUBMODULE_CONFLICT); |
| 1129 | RECORD(SUBMODULE_PRIVATE_HEADER); |
| 1130 | RECORD(SUBMODULE_TEXTUAL_HEADER); |
| 1131 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 1132 | RECORD(SUBMODULE_INITIALIZERS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1133 | |
| 1134 | // Comments Block. |
| 1135 | BLOCK(COMMENTS_BLOCK); |
| 1136 | RECORD(COMMENTS_RAW_COMMENT); |
| 1137 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1138 | // Decls and Types block. |
| 1139 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1140 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1141 | RECORD(TYPE_COMPLEX); |
| 1142 | RECORD(TYPE_POINTER); |
| 1143 | RECORD(TYPE_BLOCK_POINTER); |
| 1144 | RECORD(TYPE_LVALUE_REFERENCE); |
| 1145 | RECORD(TYPE_RVALUE_REFERENCE); |
| 1146 | RECORD(TYPE_MEMBER_POINTER); |
| 1147 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1148 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1149 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1150 | RECORD(TYPE_VECTOR); |
| 1151 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1152 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1153 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1154 | RECORD(TYPE_TYPEDEF); |
| 1155 | RECORD(TYPE_TYPEOF_EXPR); |
| 1156 | RECORD(TYPE_TYPEOF); |
| 1157 | RECORD(TYPE_RECORD); |
| 1158 | RECORD(TYPE_ENUM); |
| 1159 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1160 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1161 | RECORD(TYPE_DECLTYPE); |
| 1162 | RECORD(TYPE_ELABORATED); |
| 1163 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 1164 | RECORD(TYPE_UNRESOLVED_USING); |
| 1165 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 1166 | RECORD(TYPE_OBJC_OBJECT); |
| 1167 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 1168 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 1169 | RECORD(TYPE_DEPENDENT_NAME); |
| 1170 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 1171 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 1172 | RECORD(TYPE_PAREN); |
| 1173 | RECORD(TYPE_PACK_EXPANSION); |
| 1174 | RECORD(TYPE_ATTRIBUTED); |
| 1175 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1176 | RECORD(TYPE_AUTO); |
| 1177 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1178 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1179 | RECORD(TYPE_DECAYED); |
| 1180 | RECORD(TYPE_ADJUSTED); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 1181 | RECORD(TYPE_OBJC_TYPE_PARAM); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 1182 | RECORD(LOCAL_REDECLARATIONS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1183 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1184 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1185 | RECORD(DECL_ENUM); |
| 1186 | RECORD(DECL_RECORD); |
| 1187 | RECORD(DECL_ENUM_CONSTANT); |
| 1188 | RECORD(DECL_FUNCTION); |
| 1189 | RECORD(DECL_OBJC_METHOD); |
| 1190 | RECORD(DECL_OBJC_INTERFACE); |
| 1191 | RECORD(DECL_OBJC_PROTOCOL); |
| 1192 | RECORD(DECL_OBJC_IVAR); |
| 1193 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1194 | RECORD(DECL_OBJC_CATEGORY); |
| 1195 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1196 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1197 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1198 | RECORD(DECL_OBJC_PROPERTY); |
| 1199 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1200 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1201 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1202 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1203 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1204 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1205 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1206 | RECORD(DECL_BLOCK); |
| 1207 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1208 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1209 | RECORD(DECL_NAMESPACE); |
| 1210 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1211 | RECORD(DECL_USING); |
| 1212 | RECORD(DECL_USING_SHADOW); |
| 1213 | RECORD(DECL_USING_DIRECTIVE); |
| 1214 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1215 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1216 | RECORD(DECL_LINKAGE_SPEC); |
| 1217 | RECORD(DECL_CXX_RECORD); |
| 1218 | RECORD(DECL_CXX_METHOD); |
| 1219 | RECORD(DECL_CXX_CONSTRUCTOR); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1220 | RECORD(DECL_CXX_INHERITED_CONSTRUCTOR); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1221 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1222 | RECORD(DECL_CXX_CONVERSION); |
| 1223 | RECORD(DECL_ACCESS_SPEC); |
| 1224 | RECORD(DECL_FRIEND); |
| 1225 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1226 | RECORD(DECL_CLASS_TEMPLATE); |
| 1227 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1228 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1229 | RECORD(DECL_VAR_TEMPLATE); |
| 1230 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1231 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1232 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1233 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1234 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1235 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1236 | RECORD(DECL_TYPE_ALIAS_TEMPLATE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1237 | RECORD(DECL_STATIC_ASSERT); |
| 1238 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1239 | RECORD(DECL_CXX_CTOR_INITIALIZERS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1240 | RECORD(DECL_INDIRECTFIELD); |
| 1241 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1242 | RECORD(DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK); |
| 1243 | RECORD(DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION); |
| 1244 | RECORD(DECL_IMPORT); |
| 1245 | RECORD(DECL_OMP_THREADPRIVATE); |
| 1246 | RECORD(DECL_EMPTY); |
| 1247 | RECORD(DECL_OBJC_TYPE_PARAM); |
| 1248 | RECORD(DECL_OMP_CAPTUREDEXPR); |
| 1249 | RECORD(DECL_PRAGMA_COMMENT); |
| 1250 | RECORD(DECL_PRAGMA_DETECT_MISMATCH); |
| 1251 | RECORD(DECL_OMP_DECLARE_REDUCTION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1252 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1253 | // Statements and Exprs can occur in the Decls and Types block. |
| 1254 | AddStmtsExprs(Stream, Record); |
| 1255 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1256 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1257 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1258 | RECORD(PPD_MACRO_DEFINITION); |
| 1259 | RECORD(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 1260 | |
| 1261 | // Decls and Types block. |
| 1262 | BLOCK(EXTENSION_BLOCK); |
| 1263 | RECORD(EXTENSION_METADATA); |
| 1264 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1265 | BLOCK(UNHASHED_CONTROL_BLOCK); |
| 1266 | RECORD(SIGNATURE); |
| 1267 | RECORD(DIAGNOSTIC_OPTIONS); |
| 1268 | RECORD(DIAG_PRAGMA_MAPPINGS); |
| 1269 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1270 | #undef RECORD |
| 1271 | #undef BLOCK |
| 1272 | Stream.ExitBlock(); |
| 1273 | } |
| 1274 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1275 | /// \brief Prepares a path for being written to an AST file by converting it |
| 1276 | /// to an absolute path and removing nested './'s. |
| 1277 | /// |
| 1278 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1279 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1280 | SmallVectorImpl<char> &Path) { |
Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 1281 | bool Changed = FileMgr.makeAbsolutePath(Path); |
Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame] | 1282 | return Changed | llvm::sys::path::remove_dots(Path); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1285 | /// \brief Adjusts the given filename to only write out the portion of the |
| 1286 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1287 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1288 | /// \param Filename the file name to adjust. |
| 1289 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1290 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1291 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1292 | /// |
| 1293 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1294 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1296 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1297 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1298 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1299 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1300 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1301 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1302 | // Verify that the filename and the system root have the same prefix. |
| 1303 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1304 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1305 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1306 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1307 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1308 | // We hit the end of the filename before we hit the end of the system root. |
| 1309 | if (!Filename[Pos]) |
| 1310 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1311 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1312 | // If there's not a path separator at the end of the base directory nor |
| 1313 | // immediately after it, then this isn't within the base directory. |
| 1314 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1315 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1316 | return Filename; |
| 1317 | } else { |
| 1318 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1319 | // We distinguish relative paths from absolute paths by the |
| 1320 | // absence of '/' at the beginning of relative paths. |
| 1321 | // |
| 1322 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1323 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1324 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1325 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1326 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1327 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1329 | return Filename + Pos; |
| 1330 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1331 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1332 | ASTFileSignature ASTWriter::createSignature(StringRef Bytes) { |
| 1333 | // Calculate the hash till start of UNHASHED_CONTROL_BLOCK. |
| 1334 | llvm::SHA1 Hasher; |
| 1335 | Hasher.update(ArrayRef<uint8_t>(Bytes.bytes_begin(), Bytes.size())); |
| 1336 | auto Hash = Hasher.result(); |
| 1337 | |
| 1338 | // Convert to an array [5*i32]. |
| 1339 | ASTFileSignature Signature; |
| 1340 | auto LShift = [&](unsigned char Val, unsigned Shift) { |
| 1341 | return (uint32_t)Val << Shift; |
| 1342 | }; |
| 1343 | for (int I = 0; I != 5; ++I) |
| 1344 | Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) | |
| 1345 | LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0); |
| 1346 | |
| 1347 | return Signature; |
| 1348 | } |
| 1349 | |
| 1350 | ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP, |
| 1351 | ASTContext &Context) { |
| 1352 | // Flush first to prepare the PCM hash (signature). |
| 1353 | Stream.FlushToWord(); |
| 1354 | auto StartOfUnhashedControl = Stream.GetCurrentBitNo() >> 3; |
| 1355 | |
| 1356 | // Enter the block and prepare to write records. |
| 1357 | RecordData Record; |
| 1358 | Stream.EnterSubblock(UNHASHED_CONTROL_BLOCK_ID, 5); |
| 1359 | |
| 1360 | // For implicit modules, write the hash of the PCM as its signature. |
| 1361 | ASTFileSignature Signature; |
| 1362 | if (WritingModule && |
| 1363 | PP.getHeaderSearchInfo().getHeaderSearchOpts().ModulesHashContent) { |
| 1364 | Signature = createSignature(StringRef(Buffer.begin(), StartOfUnhashedControl)); |
| 1365 | Record.append(Signature.begin(), Signature.end()); |
| 1366 | Stream.EmitRecord(SIGNATURE, Record); |
| 1367 | Record.clear(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1368 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1369 | |
| 1370 | // Diagnostic options. |
| 1371 | const auto &Diags = Context.getDiagnostics(); |
| 1372 | const DiagnosticOptions &DiagOpts = Diags.getDiagnosticOptions(); |
| 1373 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1374 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1375 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1376 | #include "clang/Basic/DiagnosticOptions.def" |
| 1377 | Record.push_back(DiagOpts.Warnings.size()); |
| 1378 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1379 | AddString(DiagOpts.Warnings[I], Record); |
| 1380 | Record.push_back(DiagOpts.Remarks.size()); |
| 1381 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1382 | AddString(DiagOpts.Remarks[I], Record); |
| 1383 | // Note: we don't serialize the log or serialization file names, because they |
| 1384 | // are generally transient files and will almost always be overridden. |
| 1385 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1386 | |
| 1387 | // Write out the diagnostic/pragma mappings. |
| 1388 | WritePragmaDiagnosticMappings(Diags, /* IsModule = */ WritingModule); |
| 1389 | |
| 1390 | // Leave the options block. |
| 1391 | Stream.ExitBlock(); |
| 1392 | return Signature; |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1395 | /// \brief Write the control block. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1396 | void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, |
| 1397 | StringRef isysroot, |
| 1398 | const std::string &OutputFile) { |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1399 | using namespace llvm; |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1400 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1401 | RecordData Record; |
| 1402 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1403 | // Metadata |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1404 | auto MetadataAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1405 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1406 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1407 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1408 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1409 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1410 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1411 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1412 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1413 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1414 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(std::move(MetadataAbbrev)); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1415 | assert((!WritingModule || isysroot.empty()) && |
| 1416 | "writing module as a relocatable PCH?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1417 | { |
| 1418 | RecordData::value_type Record[] = {METADATA, VERSION_MAJOR, VERSION_MINOR, |
| 1419 | CLANG_VERSION_MAJOR, CLANG_VERSION_MINOR, |
| 1420 | !isysroot.empty(), IncludeTimestamps, |
| 1421 | ASTHasCompilerErrors}; |
| 1422 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1423 | getClangFullRepositoryVersion()); |
| 1424 | } |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1425 | |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 1426 | if (WritingModule) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1427 | // Module name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1428 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1429 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1430 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1431 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1432 | RecordData::value_type Record[] = {MODULE_NAME}; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1433 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1434 | } |
| 1435 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1436 | if (WritingModule && WritingModule->Directory) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1437 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1438 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1439 | |
| 1440 | // If the home of the module is the current working directory, then we |
| 1441 | // want to pick up the cwd of the build process loading the module, not |
| 1442 | // our cwd, when we load this module. |
| 1443 | if (!PP.getHeaderSearchInfo() |
| 1444 | .getHeaderSearchOpts() |
| 1445 | .ModuleMapFileHomeIsCwd || |
| 1446 | WritingModule->Directory->getName() != StringRef(".")) { |
| 1447 | // Module directory. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1448 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1449 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1450 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1451 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1452 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1453 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1454 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1455 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1456 | |
| 1457 | // Write out all other paths relative to the base directory if possible. |
| 1458 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1459 | } else if (!isysroot.empty()) { |
| 1460 | // Write out paths relative to the sysroot if possible. |
| 1461 | BaseDirectory = isysroot; |
| 1462 | } |
| 1463 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1464 | // Module map file |
| 1465 | if (WritingModule) { |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1466 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1467 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1468 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 1469 | AddPath(WritingModule->PresumedModuleMapFile.empty() |
| 1470 | ? Map.getModuleMapFileForUniquing(WritingModule)->getName() |
| 1471 | : StringRef(WritingModule->PresumedModuleMapFile), |
| 1472 | Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1473 | |
| 1474 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1475 | if (auto *AdditionalModMaps = |
| 1476 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1477 | Record.push_back(AdditionalModMaps->size()); |
| 1478 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1479 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1480 | } else { |
| 1481 | Record.push_back(0); |
| 1482 | } |
| 1483 | |
| 1484 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1487 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1488 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1489 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1490 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1491 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1492 | for (ModuleFile &M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1493 | // Skip modules that weren't directly imported. |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1494 | if (!M.isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1495 | continue; |
| 1496 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1497 | Record.push_back((unsigned)M.Kind); // FIXME: Stable encoding |
| 1498 | AddSourceLocation(M.ImportLoc, Record); |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1499 | |
| 1500 | // If we have calculated signature, there is no need to store |
| 1501 | // the size or timestamp. |
| 1502 | Record.push_back(M.Signature ? 0 : M.File->getSize()); |
| 1503 | Record.push_back(M.Signature ? 0 : getTimestampForOutput(M.File)); |
| 1504 | |
| 1505 | for (auto I : M.Signature) |
| 1506 | Record.push_back(I); |
| 1507 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1508 | AddPath(M.FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1509 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1510 | Stream.EmitRecord(IMPORTS, Record); |
| 1511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1512 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1513 | // Write the options block. |
| 1514 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); |
| 1515 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1516 | // Language options. |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1517 | Record.clear(); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1518 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1519 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1520 | Record.push_back(LangOpts.Name); |
| 1521 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1522 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1523 | #include "clang/Basic/LangOptions.def" |
| 1524 | #define SANITIZER(NAME, ID) \ |
| 1525 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1526 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1527 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1528 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1529 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1530 | AddString(Feature, Record); |
| 1531 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1532 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1533 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1534 | |
| 1535 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1536 | |
| 1537 | // Comment options. |
| 1538 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1539 | for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) { |
| 1540 | AddString(I, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1541 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1542 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1543 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1544 | // OpenMP offloading options. |
| 1545 | Record.push_back(LangOpts.OMPTargetTriples.size()); |
| 1546 | for (auto &T : LangOpts.OMPTargetTriples) |
| 1547 | AddString(T.getTriple(), Record); |
| 1548 | |
| 1549 | AddString(LangOpts.OMPHostIRFile, Record); |
| 1550 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1551 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1552 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1553 | // Target options. |
| 1554 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1555 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1556 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1557 | AddString(TargetOpts.Triple, Record); |
| 1558 | AddString(TargetOpts.CPU, Record); |
| 1559 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1560 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1561 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1562 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1563 | } |
| 1564 | Record.push_back(TargetOpts.Features.size()); |
| 1565 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1566 | AddString(TargetOpts.Features[I], Record); |
| 1567 | } |
| 1568 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1569 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1570 | // File system options. |
| 1571 | Record.clear(); |
Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1572 | const FileSystemOptions &FSOpts = |
| 1573 | Context.getSourceManager().getFileManager().getFileSystemOpts(); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1574 | AddString(FSOpts.WorkingDir, Record); |
| 1575 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1576 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1577 | // Header search options. |
| 1578 | Record.clear(); |
| 1579 | const HeaderSearchOptions &HSOpts |
| 1580 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1581 | AddString(HSOpts.Sysroot, Record); |
| 1582 | |
| 1583 | // Include entries. |
| 1584 | Record.push_back(HSOpts.UserEntries.size()); |
| 1585 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1586 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1587 | AddString(Entry.Path, Record); |
| 1588 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1589 | Record.push_back(Entry.IsFramework); |
| 1590 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | // System header prefixes. |
| 1594 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1595 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1596 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1597 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1598 | } |
| 1599 | |
| 1600 | AddString(HSOpts.ResourceDir, Record); |
| 1601 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1602 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1603 | Record.push_back(HSOpts.DisableModuleHash); |
Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 1604 | Record.push_back(HSOpts.ImplicitModuleMaps); |
| 1605 | Record.push_back(HSOpts.ModuleMapFileHomeIsCwd); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1606 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1607 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1608 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1609 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1610 | // Write out the specific module cache path that contains the module files. |
| 1611 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1612 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1613 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1614 | // Preprocessor options. |
| 1615 | Record.clear(); |
| 1616 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1617 | |
| 1618 | // Macro definitions. |
| 1619 | Record.push_back(PPOpts.Macros.size()); |
| 1620 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1621 | AddString(PPOpts.Macros[I].first, Record); |
| 1622 | Record.push_back(PPOpts.Macros[I].second); |
| 1623 | } |
| 1624 | |
| 1625 | // Includes |
| 1626 | Record.push_back(PPOpts.Includes.size()); |
| 1627 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1628 | AddString(PPOpts.Includes[I], Record); |
| 1629 | |
| 1630 | // Macro includes |
| 1631 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1632 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1633 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1634 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1635 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1636 | // Detailed record is important since it is used for the module cache hash. |
| 1637 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1638 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1639 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1640 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1641 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1642 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1643 | // Leave the options block. |
| 1644 | Stream.ExitBlock(); |
| 1645 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1646 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1647 | SourceManager &SM = Context.getSourceManager(); |
| 1648 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1649 | auto FileAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1650 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1651 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1652 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1653 | unsigned FileAbbrevCode = Stream.EmitAbbrev(std::move(FileAbbrev)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1654 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1655 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1656 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1657 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1658 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1659 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1660 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1661 | Record.clear(); |
| 1662 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1663 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1664 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1665 | // Original PCH directory |
| 1666 | if (!OutputFile.empty() && OutputFile != "-") { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1667 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1668 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1669 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1670 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1671 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1672 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1673 | |
Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1674 | SM.getFileManager().makeAbsolutePath(OutputPath); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1675 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1676 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1677 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1678 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1679 | } |
| 1680 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1681 | WriteInputFiles(Context.SourceMgr, |
| 1682 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1683 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1684 | Stream.ExitBlock(); |
| 1685 | } |
| 1686 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1687 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1688 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1689 | /// \brief An input file. |
| 1690 | struct InputFileEntry { |
| 1691 | const FileEntry *File; |
| 1692 | bool IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1693 | bool IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1694 | bool BufferOverridden; |
| 1695 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1696 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1697 | } // end anonymous namespace |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1698 | |
| 1699 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1700 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1701 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1702 | using namespace llvm; |
| 1703 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1704 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1705 | // Create input-file abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1706 | auto IFAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1707 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1708 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1709 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1710 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1711 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1712 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1713 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1714 | unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev)); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1715 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1716 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1717 | // 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] | 1718 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1719 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1720 | // Get this source location entry. |
| 1721 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1722 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1723 | |
| 1724 | // We only care about file entries that were not overridden. |
| 1725 | if (!SLoc->isFile()) |
| 1726 | continue; |
| 1727 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1728 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1729 | continue; |
| 1730 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1731 | InputFileEntry Entry; |
| 1732 | Entry.File = Cache->OrigEntry; |
| 1733 | Entry.IsSystemFile = Cache->IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1734 | Entry.IsTransient = Cache->IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1735 | Entry.BufferOverridden = Cache->BufferOverridden; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1736 | if (Cache->IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1737 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1738 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1739 | SortedFiles.push_front(Entry); |
| 1740 | } |
| 1741 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1742 | unsigned UserFilesNum = 0; |
| 1743 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1744 | std::vector<uint64_t> InputFileOffsets; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1745 | for (const auto &Entry : SortedFiles) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1746 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1747 | if (InputFileID != 0) |
| 1748 | continue; // already recorded this file. |
| 1749 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1750 | // Record this entry's offset. |
| 1751 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1752 | |
| 1753 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1754 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1755 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1756 | ++UserFilesNum; |
| 1757 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1758 | // Emit size/modification time for this file. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1759 | // And whether this file was overridden. |
| 1760 | RecordData::value_type Record[] = { |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1761 | INPUT_FILE, |
| 1762 | InputFileOffsets.size(), |
| 1763 | (uint64_t)Entry.File->getSize(), |
| 1764 | (uint64_t)getTimestampForOutput(Entry.File), |
| 1765 | Entry.BufferOverridden, |
| 1766 | Entry.IsTransient}; |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1767 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1768 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1769 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1770 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1771 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1772 | |
| 1773 | // Create input file offsets abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1774 | auto OffsetsAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1775 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1776 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1777 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1778 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1779 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1780 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(std::move(OffsetsAbbrev)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1781 | |
| 1782 | // Write input file offsets. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1783 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, |
| 1784 | InputFileOffsets.size(), UserFilesNum}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1785 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1788 | //===----------------------------------------------------------------------===// |
| 1789 | // Source Manager Serialization |
| 1790 | //===----------------------------------------------------------------------===// |
| 1791 | |
| 1792 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1793 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1794 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1795 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1796 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1797 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1798 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1799 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1800 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1801 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1802 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1803 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1804 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1805 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1806 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1807 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1808 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1812 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1813 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1814 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1815 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1816 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1817 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1818 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1819 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1820 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1821 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1822 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1823 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1827 | /// buffer's blob. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1828 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, |
| 1829 | bool Compressed) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1830 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1831 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1832 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1833 | Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED |
| 1834 | : SM_SLOC_BUFFER_BLOB)); |
| 1835 | if (Compressed) |
| 1836 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1837 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1838 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1841 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1842 | /// expansion. |
| 1843 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1844 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1845 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1846 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1847 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1848 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1849 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1850 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1851 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1852 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1853 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1856 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1857 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1858 | // Trait used for the on-disk hash table of header search information. |
| 1859 | class HeaderFileInfoTrait { |
| 1860 | ASTWriter &Writer; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1861 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1862 | // Keep track of the framework names we've used during serialization. |
| 1863 | SmallVector<char, 128> FrameworkStringData; |
| 1864 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1865 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1866 | public: |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1867 | HeaderFileInfoTrait(ASTWriter &Writer) : Writer(Writer) {} |
| 1868 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1869 | struct key_type { |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1870 | StringRef Filename; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1871 | off_t Size; |
| 1872 | time_t ModTime; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1873 | }; |
| 1874 | typedef const key_type &key_type_ref; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1875 | |
| 1876 | using UnresolvedModule = |
| 1877 | llvm::PointerIntPair<Module *, 2, ModuleMap::ModuleHeaderRole>; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1878 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1879 | struct data_type { |
| 1880 | const HeaderFileInfo &HFI; |
| 1881 | ArrayRef<ModuleMap::KnownHeader> KnownHeaders; |
| 1882 | UnresolvedModule Unresolved; |
| 1883 | }; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1884 | typedef const data_type &data_type_ref; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1885 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 1886 | typedef unsigned hash_value_type; |
| 1887 | typedef unsigned offset_type; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1888 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1889 | hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1890 | // The hash is based only on size/time of the file, so that the reader can |
| 1891 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1892 | // change the form of the name. However, complete path is still the key. |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1893 | return llvm::hash_combine(key.Size, key.ModTime); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | std::pair<unsigned,unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1897 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1898 | using namespace llvm::support; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1899 | endian::Writer<little> LE(Out); |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1900 | unsigned KeyLen = key.Filename.size() + 1 + 8 + 8; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1901 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1902 | unsigned DataLen = 1 + 2 + 4 + 4; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1903 | for (auto ModInfo : Data.KnownHeaders) |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1904 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) |
| 1905 | DataLen += 4; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1906 | if (Data.Unresolved.getPointer()) |
| 1907 | DataLen += 4; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1908 | LE.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1909 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1910 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1911 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1912 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1913 | using namespace llvm::support; |
| 1914 | endian::Writer<little> LE(Out); |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1915 | LE.write<uint64_t>(key.Size); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1916 | KeyLen -= 8; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1917 | LE.write<uint64_t>(key.ModTime); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1918 | KeyLen -= 8; |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1919 | Out.write(key.Filename.data(), KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1920 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1921 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1922 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1923 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1924 | using namespace llvm::support; |
| 1925 | endian::Writer<little> LE(Out); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1926 | uint64_t Start = Out.tell(); (void)Start; |
| 1927 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1928 | unsigned char Flags = (Data.HFI.isImport << 4) |
| 1929 | | (Data.HFI.isPragmaOnce << 3) |
| 1930 | | (Data.HFI.DirInfo << 1) |
| 1931 | | Data.HFI.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1932 | LE.write<uint8_t>(Flags); |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1933 | LE.write<uint16_t>(Data.HFI.NumIncludes); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1934 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1935 | if (!Data.HFI.ControllingMacro) |
| 1936 | LE.write<uint32_t>(Data.HFI.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1937 | else |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1938 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.HFI.ControllingMacro)); |
| 1939 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1940 | unsigned Offset = 0; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1941 | if (!Data.HFI.Framework.empty()) { |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1942 | // If this header refers into a framework, save the framework name. |
| 1943 | llvm::StringMap<unsigned>::iterator Pos |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1944 | = FrameworkNameOffset.find(Data.HFI.Framework); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1945 | if (Pos == FrameworkNameOffset.end()) { |
| 1946 | Offset = FrameworkStringData.size() + 1; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1947 | FrameworkStringData.append(Data.HFI.Framework.begin(), |
| 1948 | Data.HFI.Framework.end()); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1949 | FrameworkStringData.push_back(0); |
| 1950 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1951 | FrameworkNameOffset[Data.HFI.Framework] = Offset; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1952 | } else |
| 1953 | Offset = Pos->second; |
| 1954 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1955 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1956 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1957 | auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) { |
| 1958 | if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) { |
| 1959 | uint32_t Value = (ModID << 2) | (unsigned)Role; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1960 | assert((Value >> 2) == ModID && "overflow in header module info"); |
| 1961 | LE.write<uint32_t>(Value); |
| 1962 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1963 | }; |
| 1964 | |
| 1965 | // FIXME: If the header is excluded, we should write out some |
| 1966 | // record of that fact. |
| 1967 | for (auto ModInfo : Data.KnownHeaders) |
| 1968 | EmitModule(ModInfo.getModule(), ModInfo.getRole()); |
| 1969 | if (Data.Unresolved.getPointer()) |
| 1970 | EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt()); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1971 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1972 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1973 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1974 | |
| 1975 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1976 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1977 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1978 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1979 | } // end anonymous namespace |
| 1980 | |
| 1981 | /// \brief Write the header search block for the list of files that |
| 1982 | /// |
| 1983 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1984 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1985 | HeaderFileInfoTrait GeneratorTrait(*this); |
| 1986 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
| 1987 | SmallVector<const char *, 4> SavedStrings; |
| 1988 | unsigned NumHeaderSearchEntries = 0; |
| 1989 | |
| 1990 | // Find all unresolved headers for the current module. We generally will |
| 1991 | // have resolved them before we get here, but not necessarily: we might be |
| 1992 | // compiling a preprocessed module, where there is no requirement for the |
| 1993 | // original files to exist any more. |
Benjamin Kramer | ee021d5 | 2017-06-02 17:30:24 +0000 | [diff] [blame] | 1994 | const HeaderFileInfo Empty; // So we can take a reference. |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1995 | if (WritingModule) { |
| 1996 | llvm::SmallVector<Module *, 16> Worklist(1, WritingModule); |
| 1997 | while (!Worklist.empty()) { |
| 1998 | Module *M = Worklist.pop_back_val(); |
| 1999 | if (!M->isAvailable()) |
| 2000 | continue; |
| 2001 | |
| 2002 | // Map to disk files where possible, to pick up any missing stat |
| 2003 | // information. This also means we don't need to check the unresolved |
| 2004 | // headers list when emitting resolved headers in the first loop below. |
| 2005 | // FIXME: It'd be preferable to avoid doing this if we were given |
| 2006 | // sufficient stat information in the module map. |
| 2007 | HS.getModuleMap().resolveHeaderDirectives(M); |
| 2008 | |
| 2009 | // If the file didn't exist, we can still create a module if we were given |
| 2010 | // enough information in the module map. |
| 2011 | for (auto U : M->MissingHeaders) { |
| 2012 | // Check that we were given enough information to build a module |
| 2013 | // without this file existing on disk. |
| 2014 | if (!U.Size || (!U.ModTime && IncludeTimestamps)) { |
| 2015 | PP->Diag(U.FileNameLoc, diag::err_module_no_size_mtime_for_header) |
| 2016 | << WritingModule->getFullModuleName() << U.Size.hasValue() |
| 2017 | << U.FileName; |
| 2018 | continue; |
| 2019 | } |
| 2020 | |
| 2021 | // Form the effective relative pathname for the file. |
| 2022 | SmallString<128> Filename(M->Directory->getName()); |
| 2023 | llvm::sys::path::append(Filename, U.FileName); |
| 2024 | PreparePathForOutput(Filename); |
| 2025 | |
| 2026 | StringRef FilenameDup = strdup(Filename.c_str()); |
| 2027 | SavedStrings.push_back(FilenameDup.data()); |
| 2028 | |
| 2029 | HeaderFileInfoTrait::key_type Key = { |
| 2030 | FilenameDup, *U.Size, IncludeTimestamps ? *U.ModTime : 0 |
| 2031 | }; |
| 2032 | HeaderFileInfoTrait::data_type Data = { |
Benjamin Kramer | ee021d5 | 2017-06-02 17:30:24 +0000 | [diff] [blame] | 2033 | Empty, {}, {M, ModuleMap::headerKindToRole(U.Kind)} |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2034 | }; |
| 2035 | // FIXME: Deal with cases where there are multiple unresolved header |
| 2036 | // directives in different submodules for the same header. |
| 2037 | Generator.insert(Key, Data, GeneratorTrait); |
| 2038 | ++NumHeaderSearchEntries; |
| 2039 | } |
| 2040 | |
| 2041 | Worklist.append(M->submodule_begin(), M->submodule_end()); |
| 2042 | } |
| 2043 | } |
| 2044 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2045 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2046 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 2047 | |
| 2048 | if (FilesByUID.size() > HS.header_file_size()) |
| 2049 | FilesByUID.resize(HS.header_file_size()); |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2050 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2051 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 2052 | const FileEntry *File = FilesByUID[UID]; |
| 2053 | if (!File) |
| 2054 | continue; |
| 2055 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2056 | // Get the file info. This will load info from the external source if |
| 2057 | // necessary. Skip emitting this file if we have no information on it |
| 2058 | // as a header file (in which case HFI will be null) or if it hasn't |
| 2059 | // changed since it was loaded. Also skip it if it's for a modular header |
| 2060 | // from a different module; in that case, we rely on the module(s) |
| 2061 | // containing the header to provide this information. |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 2062 | const HeaderFileInfo *HFI = |
| 2063 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); |
| 2064 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 2065 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2066 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2067 | // Massage the file path into an appropriate form. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 2068 | StringRef Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2069 | SmallString<128> FilenameTmp(Filename); |
| 2070 | if (PreparePathForOutput(FilenameTmp)) { |
| 2071 | // If we performed any translation on the file name at all, we need to |
| 2072 | // save this string, since the generator will refer to it later. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 2073 | Filename = StringRef(strdup(FilenameTmp.c_str())); |
| 2074 | SavedStrings.push_back(Filename.data()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2075 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2076 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2077 | HeaderFileInfoTrait::key_type Key = { |
| 2078 | Filename, File->getSize(), getTimestampForOutput(File) |
| 2079 | }; |
| 2080 | HeaderFileInfoTrait::data_type Data = { |
| 2081 | *HFI, HS.getModuleMap().findAllModulesForHeader(File), {} |
| 2082 | }; |
| 2083 | Generator.insert(Key, Data, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2084 | ++NumHeaderSearchEntries; |
| 2085 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2086 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2087 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2088 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2089 | uint32_t BucketOffset; |
| 2090 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2091 | using namespace llvm::support; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2092 | llvm::raw_svector_ostream Out(TableData); |
| 2093 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2094 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2095 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 2096 | } |
| 2097 | |
| 2098 | // Create a blob abbreviation |
| 2099 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2100 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2101 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2102 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 2103 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 2104 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2105 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2106 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2107 | unsigned TableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2108 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2109 | // Write the header search table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2110 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, |
| 2111 | NumHeaderSearchEntries, TableData.size()}; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2112 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 2113 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2114 | |
| 2115 | // Free all of the strings we had to duplicate. |
| 2116 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 2117 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 2120 | static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob, |
| 2121 | unsigned SLocBufferBlobCompressedAbbrv, |
| 2122 | unsigned SLocBufferBlobAbbrv) { |
| 2123 | typedef ASTWriter::RecordData::value_type RecordDataType; |
| 2124 | |
| 2125 | // Compress the buffer if possible. We expect that almost all PCM |
| 2126 | // consumers will not want its contents. |
| 2127 | SmallString<0> CompressedBuffer; |
| 2128 | if (llvm::zlib::isAvailable()) { |
| 2129 | llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer); |
| 2130 | if (!E) { |
| 2131 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, |
| 2132 | Blob.size() - 1}; |
| 2133 | Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, |
| 2134 | CompressedBuffer); |
| 2135 | return; |
| 2136 | } |
| 2137 | llvm::consumeError(std::move(E)); |
| 2138 | } |
| 2139 | |
| 2140 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB}; |
| 2141 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob); |
| 2142 | } |
| 2143 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2144 | /// \brief Writes the block containing the serialized form of the |
| 2145 | /// source manager. |
| 2146 | /// |
| 2147 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 2148 | /// blob), indexed based on the file name, so that we only create |
| 2149 | /// entries for files that we actually need. In the common case (no |
| 2150 | /// errors), we probably won't have to create file entries for any of |
| 2151 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2152 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2153 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2154 | RecordData Record; |
| 2155 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2156 | // Enter the source manager block. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2157 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2158 | |
| 2159 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 2160 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 2161 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2162 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false); |
| 2163 | unsigned SLocBufferBlobCompressedAbbrv = |
| 2164 | CreateSLocBufferBlobAbbrev(Stream, true); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2165 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2166 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2167 | // Write out the source location entry table. We skip the first |
| 2168 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 2169 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2170 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2171 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 2172 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2173 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2174 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2175 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2176 | FileID FID = FileID::get(I); |
| 2177 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2178 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2179 | // Record the offset of this source-location entry. |
| 2180 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2181 | |
| 2182 | // Figure out which record code to use. |
| 2183 | unsigned Code; |
| 2184 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2185 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 2186 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2187 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2188 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2189 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2190 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2191 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2192 | Record.clear(); |
| 2193 | Record.push_back(Code); |
| 2194 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2195 | // Starting offset of this entry within this module, so skip the dummy. |
| 2196 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2197 | if (SLoc->isFile()) { |
| 2198 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2199 | AddSourceLocation(File.getIncludeLoc(), Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2200 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 2201 | Record.push_back(File.hasLineDirectives()); |
| 2202 | |
| 2203 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2204 | bool EmitBlob = false; |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2205 | if (Content->OrigEntry) { |
| 2206 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2207 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2208 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2209 | // The source location entry is a file. Emit input file ID. |
| 2210 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 2211 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 2213 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2214 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2215 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2216 | if (FDI != FileDeclIDs.end()) { |
| 2217 | Record.push_back(FDI->second->FirstDeclIndex); |
| 2218 | Record.push_back(FDI->second->DeclIDs.size()); |
| 2219 | } else { |
| 2220 | Record.push_back(0); |
| 2221 | Record.push_back(0); |
| 2222 | } |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2223 | |
| 2224 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
| 2225 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2226 | if (Content->BufferOverridden || Content->IsTransient) |
| 2227 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2228 | } else { |
| 2229 | // The source location entry is a buffer. The blob associated |
| 2230 | // with this entry contains the contents of the buffer. |
| 2231 | |
| 2232 | // We add one to the size so that we capture the trailing NULL |
| 2233 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 2234 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 2235 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 2236 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2237 | StringRef Name = Buffer->getBufferIdentifier(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2238 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2239 | StringRef(Name.data(), Name.size() + 1)); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2240 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2241 | |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2242 | if (Name == "<built-in>") |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2243 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2244 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2245 | |
| 2246 | if (EmitBlob) { |
| 2247 | // Include the implicit terminating null character in the on-disk buffer |
| 2248 | // if we're writing it uncompressed. |
| 2249 | const llvm::MemoryBuffer *Buffer = |
| 2250 | Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 2251 | StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1); |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 2252 | emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv, |
| 2253 | SLocBufferBlobAbbrv); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2254 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2255 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2256 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 2257 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2258 | AddSourceLocation(Expansion.getSpellingLoc(), Record); |
| 2259 | AddSourceLocation(Expansion.getExpansionLocStart(), Record); |
| 2260 | AddSourceLocation(Expansion.isMacroArgExpansion() |
| 2261 | ? SourceLocation() |
| 2262 | : Expansion.getExpansionLocEnd(), |
| 2263 | Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2264 | |
| 2265 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2266 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2267 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2268 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2269 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2270 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2271 | } |
| 2272 | } |
| 2273 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2274 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2275 | |
| 2276 | if (SLocEntryOffsets.empty()) |
| 2277 | return; |
| 2278 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2279 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2280 | // table is used for lazily loading source-location information. |
| 2281 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2282 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2283 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2284 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2285 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2286 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2287 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2288 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2289 | { |
| 2290 | RecordData::value_type Record[] = { |
| 2291 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), |
| 2292 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */}; |
| 2293 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
| 2294 | bytes(SLocEntryOffsets)); |
| 2295 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2296 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2297 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2298 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2299 | |
| 2300 | // Write the line table. It depends on remapping working, so it must come |
| 2301 | // after the source location offsets. |
| 2302 | if (SourceMgr.hasLineTable()) { |
| 2303 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 2304 | |
| 2305 | Record.clear(); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2306 | |
| 2307 | // Emit the needed file names. |
| 2308 | llvm::DenseMap<int, int> FilenameMap; |
| 2309 | for (const auto &L : LineTable) { |
| 2310 | if (L.first.ID < 0) |
| 2311 | continue; |
| 2312 | for (auto &LE : L.second) { |
| 2313 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, |
| 2314 | FilenameMap.size())).second) |
| 2315 | AddPath(LineTable.getFilename(LE.FilenameID), Record); |
| 2316 | } |
| 2317 | } |
| 2318 | Record.push_back(0); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2319 | |
| 2320 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2321 | for (const auto &L : LineTable) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2322 | // Only emit entries for local files. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2323 | if (L.first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2324 | continue; |
| 2325 | |
| 2326 | // Emit the file ID |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2327 | Record.push_back(L.first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2328 | |
| 2329 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2330 | Record.push_back(L.second.size()); |
| 2331 | for (const auto &LE : L.second) { |
| 2332 | Record.push_back(LE.FileOffset); |
| 2333 | Record.push_back(LE.LineNo); |
| 2334 | Record.push_back(FilenameMap[LE.FilenameID]); |
| 2335 | Record.push_back((unsigned)LE.FileKind); |
| 2336 | Record.push_back(LE.IncludeOffset); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2337 | } |
| 2338 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2339 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2340 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 2341 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2344 | //===----------------------------------------------------------------------===// |
| 2345 | // Preprocessor Serialization |
| 2346 | //===----------------------------------------------------------------------===// |
| 2347 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2348 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 2349 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2350 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 2351 | if (MI->isBuiltinMacro()) |
| 2352 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2353 | |
| 2354 | if (IsModule) { |
| 2355 | SourceLocation Loc = MD->getLocation(); |
| 2356 | if (Loc.isInvalid()) |
| 2357 | return true; |
| 2358 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 2359 | return true; |
| 2360 | } |
| 2361 | |
| 2362 | return false; |
| 2363 | } |
| 2364 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2365 | /// \brief Writes the block containing the serialized form of the |
| 2366 | /// preprocessor. |
| 2367 | /// |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2368 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2369 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2370 | if (PPRec) |
| 2371 | WritePreprocessorDetail(*PPRec); |
| 2372 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2373 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2374 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2375 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2376 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2377 | if (PP.getCounterValue() != 0) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2378 | RecordData::value_type Record[] = {PP.getCounterValue()}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2379 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 2382 | if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) { |
| 2383 | assert(!IsModule); |
| 2384 | for (const auto &Cond : PP.getPreambleConditionalStack()) { |
| 2385 | AddSourceLocation(Cond.IfLoc, Record); |
| 2386 | Record.push_back(Cond.WasSkipping); |
| 2387 | Record.push_back(Cond.FoundNonSkip); |
| 2388 | Record.push_back(Cond.FoundElse); |
| 2389 | } |
| 2390 | Stream.EmitRecord(PP_CONDITIONAL_STACK, Record); |
| 2391 | Record.clear(); |
| 2392 | } |
| 2393 | |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2394 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2395 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2396 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2397 | // 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] | 2398 | // 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] | 2399 | if (PP.SawDateOrTime()) |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2400 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2401 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2402 | // 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] | 2403 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2404 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2405 | // Construct the list of identifiers with macro directives that need to be |
| 2406 | // serialized. |
| 2407 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2408 | for (auto &Id : PP.getIdentifierTable()) |
| 2409 | if (Id.second->hadMacroDefinition() && |
| 2410 | (!Id.second->isFromAST() || |
| 2411 | Id.second->hasChangedSinceDeserialization())) |
| 2412 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2413 | // Sort the set of macro definitions that need to be serialized by the |
| 2414 | // name of the macro, to provide a stable ordering. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2415 | std::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(), |
| 2416 | llvm::less_ptr<IdentifierInfo>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2417 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2418 | // Emit the macro directives as a list and associate the offset with the |
| 2419 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2420 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2421 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2422 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2423 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2424 | // Emit the macro directives in reverse source order. |
| 2425 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2426 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2427 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2428 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2429 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2430 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2431 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2432 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2433 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2434 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2435 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2436 | Record.push_back(VisMD->isPublic()); |
| 2437 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2438 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2439 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2440 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2441 | bool EmittedModuleMacros = false; |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2442 | // We write out exported module macros for PCH as well. |
| 2443 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2444 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2445 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2446 | while (!Worklist.empty()) { |
| 2447 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2448 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2449 | // Emit a record indicating this submodule exports this macro. |
| 2450 | ModuleMacroRecord.push_back( |
| 2451 | getSubmoduleID(Macro->getOwningModule())); |
| 2452 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
| 2453 | for (auto *M : Macro->overrides()) |
| 2454 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2455 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2456 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2457 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2458 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2459 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2460 | for (auto *M : Macro->overrides()) |
| 2461 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2462 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2463 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2464 | EmittedModuleMacros = true; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2465 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2466 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2467 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2468 | continue; |
| 2469 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2470 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2471 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2472 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2473 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2474 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2475 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 2476 | /// the local macro ID |
| 2477 | /// |
| 2478 | /// For each identifier that is associated with a macro, this map |
| 2479 | /// provides the offset into the bitstream where that macro is |
| 2480 | /// defined. |
| 2481 | std::vector<uint32_t> MacroOffsets; |
| 2482 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2483 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2484 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2485 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2486 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2487 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2488 | if (ID < FirstMacroID) { |
| 2489 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2490 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2491 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2492 | |
| 2493 | // Record the local offset of this macro. |
| 2494 | unsigned Index = ID - FirstMacroID; |
| 2495 | if (Index == MacroOffsets.size()) |
| 2496 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2497 | else { |
| 2498 | if (Index > MacroOffsets.size()) |
| 2499 | MacroOffsets.resize(Index + 1); |
| 2500 | |
| 2501 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2502 | } |
| 2503 | |
| 2504 | AddIdentifierRef(Name, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2505 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2506 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2507 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2508 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2509 | unsigned Code; |
| 2510 | if (MI->isObjectLike()) { |
| 2511 | Code = PP_MACRO_OBJECT_LIKE; |
| 2512 | } else { |
| 2513 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2514 | |
| 2515 | Record.push_back(MI->isC99Varargs()); |
| 2516 | Record.push_back(MI->isGNUVarargs()); |
| 2517 | Record.push_back(MI->hasCommaPasting()); |
| 2518 | Record.push_back(MI->getNumArgs()); |
Daniel Marjamaki | e4770da | 2015-05-29 09:15:24 +0000 | [diff] [blame] | 2519 | for (const IdentifierInfo *Arg : MI->args()) |
| 2520 | AddIdentifierRef(Arg, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | // If we have a detailed preprocessing record, record the macro definition |
| 2524 | // ID that corresponds to this macro. |
| 2525 | if (PPRec) |
| 2526 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2527 | |
| 2528 | Stream.EmitRecord(Code, Record); |
| 2529 | Record.clear(); |
| 2530 | |
| 2531 | // Emit the tokens array. |
| 2532 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2533 | // Note that we know that the preprocessor does not have any annotation |
| 2534 | // tokens in it because they are created by the parser, and thus can't |
| 2535 | // be in a macro definition. |
| 2536 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2537 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2538 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2539 | Record.clear(); |
| 2540 | } |
| 2541 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2542 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2543 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2544 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2545 | |
| 2546 | // Write the offsets table for macro IDs. |
| 2547 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2548 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2549 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2550 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2551 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2552 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2553 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2554 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2555 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2556 | { |
| 2557 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), |
| 2558 | FirstMacroID - NUM_PREDEF_MACRO_IDS}; |
| 2559 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); |
| 2560 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2564 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2565 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2566 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2567 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2568 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2569 | // Enter the preprocessor block. |
| 2570 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2571 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2572 | // If the preprocessor has a preprocessing record, emit it. |
| 2573 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2574 | using namespace llvm; |
| 2575 | |
| 2576 | // Set up the abbreviation for |
| 2577 | unsigned InclusionAbbrev = 0; |
| 2578 | { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2579 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2580 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2581 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2582 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2583 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2584 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2585 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2586 | InclusionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2589 | unsigned FirstPreprocessorEntityID |
| 2590 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 2591 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2592 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2593 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2594 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2595 | EEnd = PPRec.local_end(); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2596 | E != EEnd; |
| 2597 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2598 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2599 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2600 | PreprocessedEntityOffsets.push_back( |
| 2601 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2602 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2603 | if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2604 | // Record this macro definition's ID. |
| 2605 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2606 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2607 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2608 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2609 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2610 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2611 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2612 | if (auto *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2613 | Record.push_back(ME->isBuiltinMacro()); |
| 2614 | if (ME->isBuiltinMacro()) |
| 2615 | AddIdentifierRef(ME->getName(), Record); |
| 2616 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2617 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2618 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2619 | continue; |
| 2620 | } |
| 2621 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2622 | if (auto *ID = dyn_cast<InclusionDirective>(*E)) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2623 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2624 | Record.push_back(ID->getFileName().size()); |
| 2625 | Record.push_back(ID->wasInQuotes()); |
| 2626 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2627 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2628 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2629 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2630 | // Check that the FileEntry is not null because it was not resolved and |
| 2631 | // we create a PCH even with compiler errors. |
| 2632 | if (ID->getFile()) |
| 2633 | Buffer += ID->getFile()->getName(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2634 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2635 | continue; |
| 2636 | } |
| 2637 | |
| 2638 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2639 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2640 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2641 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2642 | // Write the offsets table for the preprocessing record. |
| 2643 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2644 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2645 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2646 | // Write the offsets table for identifier IDs. |
| 2647 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2648 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2649 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2650 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2651 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2652 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2653 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2654 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2655 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, |
| 2656 | FirstPreprocessorEntityID - |
| 2657 | NUM_PREDEF_PP_ENTITY_IDS}; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2658 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2659 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2660 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2661 | } |
| 2662 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2663 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2664 | if (!Mod) |
| 2665 | return 0; |
| 2666 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2667 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2668 | if (Known != SubmoduleIDs.end()) |
| 2669 | return Known->second; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2670 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2671 | auto *Top = Mod->getTopLevelModule(); |
| 2672 | if (Top != WritingModule && |
Bruno Cardoso Lopes | 17da34d | 2017-02-07 21:54:57 +0000 | [diff] [blame] | 2673 | (getLangOpts().CompilingPCH || |
| 2674 | !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule)))) |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2675 | return 0; |
| 2676 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2677 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2678 | } |
| 2679 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2680 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2681 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2682 | // did not result in us loading a module file for that submodule. For |
| 2683 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2684 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); |
| 2685 | assert((ID || !Mod) && |
| 2686 | "asked for module ID for non-local, non-imported module"); |
| 2687 | return ID; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2690 | /// \brief Compute the number of modules within the given tree (including the |
| 2691 | /// given module). |
| 2692 | static unsigned getNumberOfModules(Module *Mod) { |
| 2693 | unsigned ChildModules = 0; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2694 | for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2695 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2696 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2697 | |
| 2698 | return ChildModules + 1; |
| 2699 | } |
| 2700 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2701 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2702 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2703 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2704 | |
| 2705 | // Write the abbreviations needed for the submodules block. |
| 2706 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2707 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2708 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2709 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2710 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2711 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2712 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2713 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2714 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2715 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2716 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2717 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2718 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2719 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2720 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2721 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2722 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2723 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2724 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2725 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2726 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2727 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2728 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2729 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2730 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2731 | unsigned HeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2732 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2733 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2734 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2735 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2736 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2737 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2738 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2739 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2740 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2741 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2742 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2743 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2744 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2745 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2746 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2747 | unsigned RequiresAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2748 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2749 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2750 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2751 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2752 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2753 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2754 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2755 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2756 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2757 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2758 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2759 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2760 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2761 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2762 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2763 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2764 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2765 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2766 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2767 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2768 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2769 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2770 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2771 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2772 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2773 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2774 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2775 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2776 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2777 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2778 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2779 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2780 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2781 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2782 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2783 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2784 | unsigned ConflictAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2785 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2786 | // Write the submodule metadata block. |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 2787 | RecordData::value_type Record[] = { |
| 2788 | getNumberOfModules(WritingModule), |
| 2789 | FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS, |
Richard Smith | e6c8c6d | 2017-04-25 00:40:40 +0000 | [diff] [blame] | 2790 | (unsigned)WritingModule->Kind}; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2791 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2792 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2793 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2794 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2795 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2796 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2797 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2798 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2799 | unsigned ID = getSubmoduleID(Mod); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2800 | |
| 2801 | uint64_t ParentID = 0; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2802 | if (Mod->Parent) { |
| 2803 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2804 | ParentID = SubmoduleIDs[Mod->Parent]; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2805 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2806 | |
| 2807 | // Emit the definition of the block. |
| 2808 | { |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2809 | RecordData::value_type Record[] = {SUBMODULE_DEFINITION, |
| 2810 | ID, |
| 2811 | ParentID, |
| 2812 | Mod->IsFramework, |
| 2813 | Mod->IsExplicit, |
| 2814 | Mod->IsSystem, |
| 2815 | Mod->IsExternC, |
| 2816 | Mod->InferSubmodules, |
| 2817 | Mod->InferExplicitSubmodules, |
| 2818 | Mod->InferExportWildcard, |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 2819 | Mod->ConfigMacrosExhaustive}; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2820 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2821 | } |
| 2822 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2823 | // Emit the requirements. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2824 | for (const auto &R : Mod->Requirements) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2825 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2826 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2829 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2830 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2831 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2832 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2833 | UmbrellaHeader.NameAsWritten); |
| 2834 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2835 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; |
| 2836 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2837 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2838 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2839 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2840 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2841 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2842 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2843 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2844 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2845 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2846 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 2847 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 2848 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2849 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2850 | Module::HK_PrivateTextual}, |
| 2851 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2852 | }; |
| 2853 | for (auto &HL : HeaderLists) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2854 | RecordData::value_type Record[] = {HL.RecordKind}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2855 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 2856 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 2857 | } |
| 2858 | |
| 2859 | // Emit the top headers. |
| 2860 | { |
| 2861 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2862 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2863 | for (auto *H : TopHeaders) |
| 2864 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2865 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2866 | |
| 2867 | // Emit the imports. |
| 2868 | if (!Mod->Imports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2869 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2870 | for (auto *I : Mod->Imports) |
| 2871 | Record.push_back(getSubmoduleID(I)); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2872 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2873 | } |
| 2874 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2875 | // Emit the exports. |
| 2876 | if (!Mod->Exports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2877 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2878 | for (const auto &E : Mod->Exports) { |
| 2879 | // FIXME: This may fail; we don't require that all exported modules |
| 2880 | // are local or imported. |
| 2881 | Record.push_back(getSubmoduleID(E.getPointer())); |
| 2882 | Record.push_back(E.getInt()); |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2883 | } |
| 2884 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2885 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2886 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2887 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 2888 | // Might be unnecessary as use declarations are only used to build the |
| 2889 | // module itself. |
| 2890 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2891 | // Emit the link libraries. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2892 | for (const auto &LL : Mod->LinkLibraries) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2893 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, |
| 2894 | LL.IsFramework}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2895 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2896 | } |
| 2897 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2898 | // Emit the conflicts. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2899 | for (const auto &C : Mod->Conflicts) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2900 | // FIXME: This may fail; we don't require that all conflicting modules |
| 2901 | // are local or imported. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2902 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, |
| 2903 | getSubmoduleID(C.Other)}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2904 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2905 | } |
| 2906 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2907 | // Emit the configuration macros. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2908 | for (const auto &CM : Mod->ConfigMacros) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2909 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2910 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2913 | // Emit the initializers, if any. |
| 2914 | RecordData Inits; |
| 2915 | for (Decl *D : Context->getModuleInitializers(Mod)) |
| 2916 | Inits.push_back(GetDeclRef(D)); |
| 2917 | if (!Inits.empty()) |
| 2918 | Stream.EmitRecord(SUBMODULE_INITIALIZERS, Inits); |
| 2919 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2920 | // Queue up the submodules of this module. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2921 | for (auto *M : Mod->submodules()) |
| 2922 | Q.push(M); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2926 | |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2927 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 2928 | getNumberOfModules(WritingModule)) && |
| 2929 | "Wrong # of submodules; found a reference to a non-local, " |
| 2930 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2931 | } |
| 2932 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 2933 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 2934 | bool isModule) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2935 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2936 | DiagStateIDMap; |
| 2937 | unsigned CurrID = 0; |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2938 | RecordData Record; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2939 | |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 2940 | auto EncodeDiagStateFlags = |
| 2941 | [](const DiagnosticsEngine::DiagState *DS) -> unsigned { |
| 2942 | unsigned Result = (unsigned)DS->ExtBehavior; |
| 2943 | for (unsigned Val : |
Daniel Jasper | ba9aefc | 2017-05-03 07:48:27 +0000 | [diff] [blame] | 2944 | {(unsigned)DS->IgnoreAllWarnings, (unsigned)DS->EnableAllWarnings, |
| 2945 | (unsigned)DS->WarningsAsErrors, (unsigned)DS->ErrorsAsFatal, |
| 2946 | (unsigned)DS->SuppressSystemWarnings}) |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 2947 | Result = (Result << 1) | Val; |
| 2948 | return Result; |
| 2949 | }; |
| 2950 | |
| 2951 | unsigned Flags = EncodeDiagStateFlags(Diag.DiagStatesByLoc.FirstDiagState); |
| 2952 | Record.push_back(Flags); |
| 2953 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2954 | auto AddDiagState = [&](const DiagnosticsEngine::DiagState *State, |
| 2955 | bool IncludeNonPragmaStates) { |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 2956 | // Ensure that the diagnostic state wasn't modified since it was created. |
| 2957 | // We will not correctly round-trip this information otherwise. |
| 2958 | assert(Flags == EncodeDiagStateFlags(State) && |
| 2959 | "diag state flags vary in single AST file"); |
| 2960 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2961 | unsigned &DiagStateID = DiagStateIDMap[State]; |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2962 | Record.push_back(DiagStateID); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2963 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2964 | if (DiagStateID == 0) { |
| 2965 | DiagStateID = ++CurrID; |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 2966 | |
| 2967 | // Add a placeholder for the number of mappings. |
| 2968 | auto SizeIdx = Record.size(); |
| 2969 | Record.emplace_back(); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2970 | for (const auto &I : *State) { |
| 2971 | if (I.second.isPragma() || IncludeNonPragmaStates) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2972 | Record.push_back(I.first); |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 2973 | Record.push_back(I.second.serialize()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2974 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2975 | } |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 2976 | // Update the placeholder. |
| 2977 | Record[SizeIdx] = (Record.size() - SizeIdx) / 2; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2978 | } |
| 2979 | }; |
| 2980 | |
| 2981 | AddDiagState(Diag.DiagStatesByLoc.FirstDiagState, isModule); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2982 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 2983 | // Reserve a spot for the number of locations with state transitions. |
| 2984 | auto NumLocationsIdx = Record.size(); |
| 2985 | Record.emplace_back(); |
| 2986 | |
| 2987 | // Emit the state transitions. |
| 2988 | unsigned NumLocations = 0; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2989 | for (auto &FileIDAndFile : Diag.DiagStatesByLoc.Files) { |
| 2990 | if (!FileIDAndFile.first.isValid() || |
| 2991 | !FileIDAndFile.second.HasLocalTransitions) |
| 2992 | continue; |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 2993 | ++NumLocations; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2994 | AddSourceLocation(Diag.SourceMgr->getLocForStartOfFile(FileIDAndFile.first), |
| 2995 | Record); |
| 2996 | Record.push_back(FileIDAndFile.second.StateTransitions.size()); |
| 2997 | for (auto &StatePoint : FileIDAndFile.second.StateTransitions) { |
| 2998 | Record.push_back(StatePoint.Offset); |
| 2999 | AddDiagState(StatePoint.State, false); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3000 | } |
| 3001 | } |
| 3002 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3003 | // Backpatch the number of locations. |
| 3004 | Record[NumLocationsIdx] = NumLocations; |
| 3005 | |
| 3006 | // Emit CurDiagStateLoc. Do it last in order to match source order. |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 3007 | // |
| 3008 | // This also protects against a hypothetical corner case with simulating |
| 3009 | // -Werror settings for implicit modules in the ASTReader, where reading |
| 3010 | // CurDiagState out of context could change whether warning pragmas are |
| 3011 | // treated as errors. |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3012 | AddSourceLocation(Diag.DiagStatesByLoc.CurDiagStateLoc, Record); |
| 3013 | AddDiagState(Diag.DiagStatesByLoc.CurDiagState, false); |
| 3014 | |
Duncan P. N. Exon Smith | f2435b9 | 2017-04-12 02:31:17 +0000 | [diff] [blame] | 3015 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3018 | //===----------------------------------------------------------------------===// |
| 3019 | // Type Serialization |
| 3020 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 3021 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3022 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3023 | void ASTWriter::WriteType(QualType T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3024 | TypeIdx &IdxRef = TypeIdxs[T]; |
| 3025 | if (IdxRef.getIndex() == 0) // we haven't seen this type before. |
| 3026 | IdxRef = TypeIdx(NextTypeID++); |
| 3027 | TypeIdx Idx = IdxRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3028 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3029 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 3030 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3031 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3032 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3033 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3034 | ASTTypeWriter W(*this, Record); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3035 | W.Visit(T); |
| 3036 | uint64_t Offset = W.Emit(); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3037 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3038 | // Record the offset for this type. |
| 3039 | unsigned Index = Idx.getIndex() - FirstTypeID; |
| 3040 | if (TypeOffsets.size() == Index) |
| 3041 | TypeOffsets.push_back(Offset); |
| 3042 | else if (TypeOffsets.size() < Index) { |
| 3043 | TypeOffsets.resize(Index + 1); |
| 3044 | TypeOffsets[Index] = Offset; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3045 | } else { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3046 | llvm_unreachable("Types emitted in wrong order"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3047 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3050 | //===----------------------------------------------------------------------===// |
| 3051 | // Declaration Serialization |
| 3052 | //===----------------------------------------------------------------------===// |
| 3053 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3054 | /// \brief Write the block containing all of the declaration IDs |
| 3055 | /// lexically declared within the given DeclContext. |
| 3056 | /// |
| 3057 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 3058 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3059 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3060 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 3061 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3062 | return 0; |
| 3063 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3064 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 3065 | SmallVector<uint32_t, 128> KindDeclPairs; |
| 3066 | for (const auto *D : DC->decls()) { |
| 3067 | KindDeclPairs.push_back(D->getKind()); |
| 3068 | KindDeclPairs.push_back(GetDeclRef(D)); |
| 3069 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3070 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3071 | ++NumLexicalDeclContexts; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3072 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 3073 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, |
| 3074 | bytes(KindDeclPairs)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3075 | return Offset; |
| 3076 | } |
| 3077 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3078 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3079 | using namespace llvm; |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3080 | |
| 3081 | // Write the type offsets array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3082 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3083 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3084 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3085 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3086 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3087 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3088 | { |
| 3089 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), |
| 3090 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; |
| 3091 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
| 3092 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3093 | |
| 3094 | // Write the declaration offsets array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3095 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3096 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3097 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3098 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3099 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3100 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3101 | { |
| 3102 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), |
| 3103 | FirstDeclID - NUM_PREDEF_DECL_IDS}; |
| 3104 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
| 3105 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3106 | } |
| 3107 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3108 | void ASTWriter::WriteFileDeclIDsMap() { |
| 3109 | using namespace llvm; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3110 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 3111 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 3112 | FileDeclIDs.begin(), FileDeclIDs.end()); |
| 3113 | std::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), |
| 3114 | llvm::less_first()); |
| 3115 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3116 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 3117 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 3118 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 3119 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 3120 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 3121 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 3122 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3125 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3126 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 3127 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3128 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3129 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3130 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, |
| 3131 | FileGroupedDeclIDs.size()}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3132 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3133 | } |
| 3134 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3135 | void ASTWriter::WriteComments() { |
| 3136 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 3137 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3138 | RecordData Record; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3139 | for (const auto *I : RawComments) { |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3140 | Record.clear(); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3141 | AddSourceRange(I->getSourceRange(), Record); |
| 3142 | Record.push_back(I->getKind()); |
| 3143 | Record.push_back(I->isTrailingComment()); |
| 3144 | Record.push_back(I->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3145 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 3146 | } |
| 3147 | Stream.ExitBlock(); |
| 3148 | } |
| 3149 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3150 | //===----------------------------------------------------------------------===// |
| 3151 | // Global Method Pool and Selector Serialization |
| 3152 | //===----------------------------------------------------------------------===// |
| 3153 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3154 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3155 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3156 | // 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] | 3157 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3158 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3159 | |
| 3160 | public: |
| 3161 | typedef Selector key_type; |
| 3162 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3163 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3164 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3165 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3166 | ObjCMethodList Instance, Factory; |
| 3167 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3168 | typedef const data_type& data_type_ref; |
| 3169 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3170 | typedef unsigned hash_value_type; |
| 3171 | typedef unsigned offset_type; |
| 3172 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3173 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3175 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 3176 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3177 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3178 | |
| 3179 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3180 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3181 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3182 | using namespace llvm::support; |
| 3183 | endian::Writer<little> LE(Out); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3184 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3185 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3186 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 3187 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3188 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3189 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3190 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3191 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3192 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3193 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3194 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3195 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3196 | return std::make_pair(KeyLen, DataLen); |
| 3197 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3198 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3199 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3200 | using namespace llvm::support; |
| 3201 | endian::Writer<little> LE(Out); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3202 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3203 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 3204 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3205 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3206 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3207 | if (N == 0) |
| 3208 | N = 1; |
| 3209 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3210 | LE.write<uint32_t>( |
| 3211 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3212 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3213 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3214 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3215 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3216 | using namespace llvm::support; |
| 3217 | endian::Writer<little> LE(Out); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3218 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3219 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3220 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3221 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3222 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3223 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3224 | ++NumInstanceMethods; |
| 3225 | |
| 3226 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3227 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3228 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3229 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3230 | ++NumFactoryMethods; |
| 3231 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3232 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 3233 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3234 | unsigned InstanceHasMoreThanOneDeclBit = |
| 3235 | Methods.Instance.hasMoreThanOneDecl(); |
| 3236 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 3237 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 3238 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3239 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 3240 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3241 | unsigned FactoryHasMoreThanOneDeclBit = |
| 3242 | Methods.Factory.hasMoreThanOneDecl(); |
| 3243 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 3244 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 3245 | FactoryBits; |
| 3246 | LE.write<uint16_t>(FullInstanceBits); |
| 3247 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3248 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3249 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3250 | if (Method->getMethod()) |
| 3251 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3252 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3253 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3254 | if (Method->getMethod()) |
| 3255 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3256 | |
| 3257 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3258 | } |
| 3259 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3260 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3261 | } // end anonymous namespace |
| 3262 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3263 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3264 | /// |
| 3265 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3266 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 3267 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3268 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3269 | using namespace llvm; |
| 3270 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3271 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3272 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3273 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3274 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3275 | // 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] | 3276 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3277 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3278 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3279 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3280 | // Create the on-disk hash table representation. We walk through every |
| 3281 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3282 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3283 | for (auto &SelectorAndID : SelectorIDs) { |
| 3284 | Selector S = SelectorAndID.first; |
| 3285 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3286 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3287 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3288 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3289 | ObjCMethodList(), |
| 3290 | ObjCMethodList() |
| 3291 | }; |
| 3292 | if (F != SemaRef.MethodPool.end()) { |
| 3293 | Data.Instance = F->second.first; |
| 3294 | Data.Factory = F->second.second; |
| 3295 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3296 | // 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] | 3297 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3298 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3299 | // Selector already exists. Did it change? |
| 3300 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3301 | for (ObjCMethodList *M = &Data.Instance; |
| 3302 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 3303 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3304 | changed = true; |
| 3305 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3306 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3307 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3308 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3309 | changed = true; |
| 3310 | } |
| 3311 | if (!changed) |
| 3312 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3313 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3314 | // A new method pool entry. |
| 3315 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3316 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3317 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3320 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3321 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3322 | uint32_t BucketOffset; |
| 3323 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3324 | using namespace llvm::support; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3325 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3326 | llvm::raw_svector_ostream Out(MethodPool); |
| 3327 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3328 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3329 | BucketOffset = Generator.Emit(Out, Trait); |
| 3330 | } |
| 3331 | |
| 3332 | // Create a blob abbreviation |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3333 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3334 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3335 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3336 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3337 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3338 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3339 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3340 | // Write the method pool |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3341 | { |
| 3342 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, |
| 3343 | NumTableEntries}; |
| 3344 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
| 3345 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3346 | |
| 3347 | // Create a blob abbreviation for the selector table offsets. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3348 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3349 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3350 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3351 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3352 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3353 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3354 | |
| 3355 | // Write the selector offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3356 | { |
| 3357 | RecordData::value_type Record[] = { |
| 3358 | SELECTOR_OFFSETS, SelectorOffsets.size(), |
| 3359 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; |
| 3360 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 3361 | bytes(SelectorOffsets)); |
| 3362 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3363 | } |
| 3364 | } |
| 3365 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3366 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3367 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3368 | using namespace llvm; |
| 3369 | if (SemaRef.ReferencedSelectors.empty()) |
| 3370 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3371 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3372 | RecordData Record; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3373 | ASTRecordWriter Writer(*this, Record); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3374 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3375 | // 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] | 3376 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3377 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3378 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3379 | Selector Sel = SelectorAndLocation.first; |
| 3380 | SourceLocation Loc = SelectorAndLocation.second; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3381 | Writer.AddSelectorRef(Sel); |
| 3382 | Writer.AddSourceLocation(Loc); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3383 | } |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3384 | Writer.Emit(REFERENCED_SELECTOR_POOL); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3385 | } |
| 3386 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3387 | //===----------------------------------------------------------------------===// |
| 3388 | // Identifier Table Serialization |
| 3389 | //===----------------------------------------------------------------------===// |
| 3390 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3391 | /// Determine the declaration that should be put into the name lookup table to |
| 3392 | /// represent the given declaration in this module. This is usually D itself, |
| 3393 | /// but if D was imported and merged into a local declaration, we want the most |
| 3394 | /// recent local declaration instead. The chosen declaration will be the most |
| 3395 | /// recent declaration in any module that imports this one. |
| 3396 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3397 | NamedDecl *D) { |
| 3398 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3399 | return D; |
| 3400 | |
| 3401 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3402 | // For Redeclarable decls, a prior declaration might be local. |
| 3403 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3404 | // If we find a local decl, we're done. |
| 3405 | if (!Redecl->isFromASTFile()) { |
| 3406 | // Exception: in very rare cases (for injected-class-names), not all |
| 3407 | // redeclarations are in the same semantic context. Skip ones in a |
| 3408 | // different context. They don't go in this lookup table at all. |
| 3409 | if (!Redecl->getDeclContext()->getRedeclContext()->Equals( |
| 3410 | D->getDeclContext()->getRedeclContext())) |
| 3411 | continue; |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3412 | return cast<NamedDecl>(Redecl); |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3415 | // 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] | 3416 | // local one. |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3417 | if (Redecl->getOwningModuleID() == 0) |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3418 | break; |
| 3419 | } |
| 3420 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3421 | // For Mergeable decls, the first decl might be local. |
| 3422 | if (!First->isFromASTFile()) |
| 3423 | return cast<NamedDecl>(First); |
| 3424 | } |
| 3425 | |
| 3426 | // All declarations are imported. Our most recent declaration will also be |
| 3427 | // the most recent one in anyone who imports us. |
| 3428 | return D; |
| 3429 | } |
| 3430 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3431 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3432 | |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3433 | class ASTIdentifierTableTrait { |
| 3434 | ASTWriter &Writer; |
| 3435 | Preprocessor &PP; |
| 3436 | IdentifierResolver &IdResolver; |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3437 | bool IsModule; |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3438 | bool NeedDecls; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3439 | ASTWriter::RecordData *InterestingIdentifierOffsets; |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3440 | |
| 3441 | /// \brief Determines whether this is an "interesting" identifier that needs a |
| 3442 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3443 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3444 | /// to check that. |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3445 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3446 | if (MacroOffset || |
| 3447 | II->isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3448 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3449 | II->hasRevertedTokenIDToIdentifier() || |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3450 | (NeedDecls && II->getFETokenInfo<void>())) |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3451 | return true; |
| 3452 | |
| 3453 | return false; |
| 3454 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3455 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3456 | public: |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3457 | typedef IdentifierInfo* key_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3458 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3459 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3460 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3461 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3463 | typedef unsigned hash_value_type; |
| 3464 | typedef unsigned offset_type; |
| 3465 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3466 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3467 | IdentifierResolver &IdResolver, bool IsModule, |
| 3468 | ASTWriter::RecordData *InterestingIdentifierOffsets) |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3469 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3470 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), |
| 3471 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3472 | |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3473 | bool needDecls() const { return NeedDecls; } |
| 3474 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3475 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 3476 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3477 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3478 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3479 | bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 3480 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3481 | return isInterestingIdentifier(II, MacroOffset); |
| 3482 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3483 | |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3484 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { |
| 3485 | return isInterestingIdentifier(II, 0); |
| 3486 | } |
| 3487 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3488 | std::pair<unsigned,unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3489 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3490 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3491 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3492 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3493 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3494 | DataLen += 2; // 2 bytes for builtin ID |
| 3495 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3496 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3497 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3498 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3499 | if (NeedDecls) { |
| 3500 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3501 | DEnd = IdResolver.end(); |
| 3502 | D != DEnd; ++D) |
| 3503 | DataLen += 4; |
| 3504 | } |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3505 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3506 | using namespace llvm::support; |
| 3507 | endian::Writer<little> LE(Out); |
| 3508 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3509 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3510 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3511 | // We emit the key length after the data length so that every |
| 3512 | // string is preceded by a 16-bit length. This matches the PTH |
| 3513 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3514 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3515 | return std::make_pair(KeyLen, DataLen); |
| 3516 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3517 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3518 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3519 | unsigned KeyLen) { |
| 3520 | // Record the location of the key data. This is used when generating |
| 3521 | // the mapping from persistent IDs to strings. |
| 3522 | Writer.SetIdentifierOffset(II, Out.tell()); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3523 | |
| 3524 | // Emit the offset of the key/data length information to the interesting |
| 3525 | // identifiers table if necessary. |
| 3526 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) |
| 3527 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); |
| 3528 | |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3529 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3530 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3532 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3533 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3534 | using namespace llvm::support; |
| 3535 | endian::Writer<little> LE(Out); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3536 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3537 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3538 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3539 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3540 | return; |
| 3541 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3542 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3543 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3544 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3545 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3546 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3547 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3548 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3549 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3550 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3551 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3552 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3553 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3554 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3555 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3556 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3557 | if (HadMacroDefinition) |
| 3558 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3559 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3560 | if (NeedDecls) { |
| 3561 | // Emit the declaration IDs in reverse order, because the |
| 3562 | // IdentifierResolver provides the declarations as they would be |
| 3563 | // visible (e.g., the function "stat" would come before the struct |
| 3564 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3565 | // (so we need to see the struct "stat" before the function "stat"). |
| 3566 | // Only emit declarations that aren't from a chained PCH, though. |
| 3567 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), |
| 3568 | IdResolver.end()); |
| 3569 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3570 | DEnd = Decls.rend(); |
| 3571 | D != DEnd; ++D) |
| 3572 | LE.write<uint32_t>( |
| 3573 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
| 3574 | } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3575 | } |
| 3576 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3577 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3578 | } // end anonymous namespace |
| 3579 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3580 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3581 | /// |
| 3582 | /// The identifier table consists of a blob containing string data |
| 3583 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3584 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3585 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 3586 | IdentifierResolver &IdResolver, |
| 3587 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3588 | using namespace llvm; |
| 3589 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3590 | RecordData InterestingIdents; |
| 3591 | |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3592 | // Create and write out the blob that contains the identifier |
| 3593 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3594 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3595 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3596 | ASTIdentifierTableTrait Trait( |
| 3597 | *this, PP, IdResolver, IsModule, |
| 3598 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3600 | // Look for any identifiers that were named while processing the |
| 3601 | // headers, but are otherwise not needed. We add these to the hash |
| 3602 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3603 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3604 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3605 | SmallVector<const IdentifierInfo *, 128> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3606 | for (const auto &ID : PP.getIdentifierTable()) |
| 3607 | IIs.push_back(ID.second); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3608 | // Sort the identifiers lexicographically before getting them references so |
| 3609 | // that their order is stable. |
| 3610 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 3611 | for (const IdentifierInfo *II : IIs) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3612 | if (Trait.isInterestingNonMacroIdentifier(II)) |
| 3613 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3614 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3615 | // Create the on-disk hash table representation. We only store offsets |
| 3616 | // for identifiers that appear here for the first time. |
| 3617 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3618 | for (auto IdentIDPair : IdentifierIDs) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3619 | auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3620 | IdentID ID = IdentIDPair.second; |
| 3621 | assert(II && "NULL identifier in identifier table"); |
Vassil Vassilev | 262f41e | 2016-03-30 20:16:03 +0000 | [diff] [blame] | 3622 | // Write out identifiers if either the ID is local or the identifier has |
| 3623 | // changed since it was loaded. |
| 3624 | if (ID >= FirstIdentID || !Chain || !II->isFromAST() |
| 3625 | || II->hasChangedSinceDeserialization() || |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3626 | (Trait.needDecls() && |
| 3627 | II->hasFETokenInfoChangedSinceDeserialization())) |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3628 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3629 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3630 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3631 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3632 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3633 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3634 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3635 | using namespace llvm::support; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3636 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3637 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3638 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3639 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | // Create a blob abbreviation |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3643 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3644 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3645 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3646 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3647 | unsigned IDTableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3648 | |
| 3649 | // Write the identifier table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3650 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3651 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | // Write the offsets table for identifier IDs. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3655 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3656 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3657 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3658 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3659 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3660 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3661 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3662 | #ifndef NDEBUG |
| 3663 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3664 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3665 | #endif |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3666 | |
| 3667 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, |
| 3668 | IdentifierOffsets.size(), |
| 3669 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3670 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3671 | bytes(IdentifierOffsets)); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3672 | |
| 3673 | // In C++, write the list of interesting identifiers (those that are |
| 3674 | // defined as macros, poisoned, or similar unusual things). |
| 3675 | if (!InterestingIdents.empty()) |
| 3676 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3677 | } |
| 3678 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3679 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3680 | // DeclContext's Name Lookup Table Serialization |
| 3681 | //===----------------------------------------------------------------------===// |
| 3682 | |
| 3683 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3684 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3685 | // Trait used for the on-disk hash table used in the method pool. |
| 3686 | class ASTDeclContextNameLookupTrait { |
| 3687 | ASTWriter &Writer; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3688 | llvm::SmallVector<DeclID, 64> DeclIDs; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3689 | |
| 3690 | public: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3691 | typedef DeclarationNameKey key_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3692 | typedef key_type key_type_ref; |
| 3693 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3694 | /// A start and end index into DeclIDs, representing a sequence of decls. |
| 3695 | typedef std::pair<unsigned, unsigned> data_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3696 | typedef const data_type& data_type_ref; |
| 3697 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3698 | typedef unsigned hash_value_type; |
| 3699 | typedef unsigned offset_type; |
| 3700 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3701 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 3702 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3703 | template<typename Coll> |
| 3704 | data_type getData(const Coll &Decls) { |
| 3705 | unsigned Start = DeclIDs.size(); |
| 3706 | for (NamedDecl *D : Decls) { |
| 3707 | DeclIDs.push_back( |
| 3708 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); |
| 3709 | } |
| 3710 | return std::make_pair(Start, DeclIDs.size()); |
| 3711 | } |
| 3712 | |
| 3713 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { |
| 3714 | unsigned Start = DeclIDs.size(); |
| 3715 | for (auto ID : FromReader) |
| 3716 | DeclIDs.push_back(ID); |
| 3717 | return std::make_pair(Start, DeclIDs.size()); |
| 3718 | } |
| 3719 | |
| 3720 | static bool EqualKey(key_type_ref a, key_type_ref b) { |
| 3721 | return a == b; |
| 3722 | } |
| 3723 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3724 | hash_value_type ComputeHash(DeclarationNameKey Name) { |
| 3725 | return Name.getHash(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3728 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { |
| 3729 | assert(Writer.hasChain() && |
| 3730 | "have reference to loaded module file but no chain?"); |
| 3731 | |
| 3732 | using namespace llvm::support; |
| 3733 | endian::Writer<little>(Out) |
| 3734 | .write<uint32_t>(Writer.getChain()->getModuleFileID(F)); |
| 3735 | } |
| 3736 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3737 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, |
| 3738 | DeclarationNameKey Name, |
| 3739 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3740 | using namespace llvm::support; |
| 3741 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3742 | unsigned KeyLen = 1; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3743 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3744 | case DeclarationName::Identifier: |
| 3745 | case DeclarationName::ObjCZeroArgSelector: |
| 3746 | case DeclarationName::ObjCOneArgSelector: |
| 3747 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3748 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3749 | case DeclarationName::CXXDeductionGuideName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3750 | KeyLen += 4; |
| 3751 | break; |
| 3752 | case DeclarationName::CXXOperatorName: |
| 3753 | KeyLen += 1; |
| 3754 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3755 | case DeclarationName::CXXConstructorName: |
| 3756 | case DeclarationName::CXXDestructorName: |
| 3757 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3758 | case DeclarationName::CXXUsingDirective: |
| 3759 | break; |
| 3760 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3761 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3762 | |
Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3763 | // 4 bytes for each DeclID. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3764 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); |
| 3765 | assert(uint16_t(DataLen) == DataLen && |
| 3766 | "too many decls for serialized lookup result"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3767 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3768 | |
| 3769 | return std::make_pair(KeyLen, DataLen); |
| 3770 | } |
| 3771 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3772 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3773 | using namespace llvm::support; |
| 3774 | endian::Writer<little> LE(Out); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3775 | LE.write<uint8_t>(Name.getKind()); |
| 3776 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3777 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3778 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3779 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3780 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3781 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3782 | case DeclarationName::ObjCZeroArgSelector: |
| 3783 | case DeclarationName::ObjCOneArgSelector: |
| 3784 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3785 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3786 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3787 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3788 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3789 | "Invalid operator?"); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3790 | LE.write<uint8_t>(Name.getOperatorKind()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3791 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3792 | case DeclarationName::CXXConstructorName: |
| 3793 | case DeclarationName::CXXDestructorName: |
| 3794 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3795 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3796 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3797 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3798 | |
| 3799 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3802 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, |
| 3803 | unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3804 | using namespace llvm::support; |
| 3805 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3806 | uint64_t Start = Out.tell(); (void)Start; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3807 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) |
| 3808 | LE.write<uint32_t>(DeclIDs[I]); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3809 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3810 | } |
| 3811 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3812 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3813 | } // end anonymous namespace |
| 3814 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3815 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 3816 | DeclContext *DC) { |
| 3817 | return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage; |
| 3818 | } |
| 3819 | |
| 3820 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 3821 | DeclContext *DC) { |
| 3822 | for (auto *D : Result.getLookupResult()) |
| 3823 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 3824 | return false; |
| 3825 | |
| 3826 | return true; |
| 3827 | } |
| 3828 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3829 | void |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3830 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3831 | llvm::SmallVectorImpl<char> &LookupTable) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3832 | assert(!ConstDC->HasLazyLocalLexicalLookups && |
| 3833 | !ConstDC->HasLazyExternalLexicalLookups && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3834 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3835 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3836 | // FIXME: We need to build the lookups table, which is logically const. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3837 | auto *DC = const_cast<DeclContext*>(ConstDC); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3838 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 3839 | |
| 3840 | // Create the on-disk hash table representation. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3841 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, |
| 3842 | ASTDeclContextNameLookupTrait> Generator; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3843 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3844 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3845 | // The first step is to collect the declaration names which we need to |
| 3846 | // serialize into the name lookup table, and to collect them in a stable |
| 3847 | // order. |
| 3848 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3849 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3850 | // We also build up small sets of the constructor and conversion function |
| 3851 | // names which are visible. |
| 3852 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3853 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3854 | for (auto &Lookup : *DC->buildLookup()) { |
| 3855 | auto &Name = Lookup.first; |
| 3856 | auto &Result = Lookup.second; |
| 3857 | |
Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 3858 | // If there are no local declarations in our lookup result, we |
| 3859 | // don't need to write an entry for the name at all. If we can't |
| 3860 | // write out a lookup set without performing more deserialization, |
| 3861 | // just skip this entry. |
| 3862 | if (isLookupResultExternal(Result, DC) && |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3863 | isLookupResultEntirelyExternal(Result, DC)) |
| 3864 | continue; |
| 3865 | |
| 3866 | // We also skip empty results. If any of the results could be external and |
| 3867 | // the currently available results are empty, then all of the results are |
| 3868 | // external and we skip it above. So the only way we get here with an empty |
| 3869 | // results is when no results could have been external *and* we have |
| 3870 | // external results. |
| 3871 | // |
| 3872 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 3873 | // lookups into a decl context as an optimization, today we *have* to skip |
| 3874 | // them because there are names with empty lookup results in decl contexts |
| 3875 | // which we can't emit in any stable ordering: we lookup constructors and |
| 3876 | // conversion functions in the enclosing namespace scope creating empty |
| 3877 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 3878 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 3879 | // here by omitting lookups with empty results. |
| 3880 | if (Lookup.second.getLookupResult().empty()) |
| 3881 | continue; |
| 3882 | |
| 3883 | switch (Lookup.first.getNameKind()) { |
| 3884 | default: |
| 3885 | Names.push_back(Lookup.first); |
| 3886 | break; |
| 3887 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3888 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3889 | assert(isa<CXXRecordDecl>(DC) && |
| 3890 | "Cannot have a constructor name outside of a class!"); |
| 3891 | ConstructorNameSet.insert(Name); |
| 3892 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3893 | |
| 3894 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3895 | assert(isa<CXXRecordDecl>(DC) && |
| 3896 | "Cannot have a conversion function name outside of a class!"); |
| 3897 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 3898 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3899 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3900 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3901 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3902 | // Sort the names into a stable order. |
| 3903 | std::sort(Names.begin(), Names.end()); |
| 3904 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3905 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3906 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3907 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3908 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3909 | // First we try the easy case by forming the current context's constructor |
| 3910 | // name and adding that name first. This is a very useful optimization to |
| 3911 | // avoid walking the lexical declarations in many cases, and it also |
| 3912 | // handles the only case where a constructor name can come from some other |
| 3913 | // lexical context -- when that name is an implicit constructor merged from |
| 3914 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 3915 | // conversion function which doesn't occur in all the lexical contexts |
| 3916 | // would be an ODR violation. |
| 3917 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 3918 | Context->getCanonicalType(Context->getRecordType(D))); |
| 3919 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 3920 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3921 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3922 | // If we still have constructors or conversion functions, we walk all the |
| 3923 | // names in the decl and add the constructors and conversion functions |
| 3924 | // which are visible in the order they lexically occur within the context. |
| 3925 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 3926 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 3927 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 3928 | auto Name = ChildND->getDeclName(); |
| 3929 | switch (Name.getNameKind()) { |
| 3930 | default: |
| 3931 | continue; |
| 3932 | |
| 3933 | case DeclarationName::CXXConstructorName: |
| 3934 | if (ConstructorNameSet.erase(Name)) |
| 3935 | Names.push_back(Name); |
| 3936 | break; |
| 3937 | |
| 3938 | case DeclarationName::CXXConversionFunctionName: |
| 3939 | if (ConversionNameSet.erase(Name)) |
| 3940 | Names.push_back(Name); |
| 3941 | break; |
| 3942 | } |
| 3943 | |
| 3944 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 3945 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3946 | } |
| 3947 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3948 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 3949 | "constructors by walking all the " |
| 3950 | "lexical members of the context."); |
| 3951 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 3952 | "conversion functions by walking all " |
| 3953 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3954 | } |
| 3955 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3956 | // Next we need to do a lookup with each name into this decl context to fully |
| 3957 | // populate any results from external sources. We don't actually use the |
| 3958 | // results of these lookups because we only want to use the results after all |
| 3959 | // results have been loaded and the pointers into them will be stable. |
| 3960 | for (auto &Name : Names) |
| 3961 | DC->lookup(Name); |
| 3962 | |
| 3963 | // Now we need to insert the results for each name into the hash table. For |
| 3964 | // constructor names and conversion function names, we actually need to merge |
| 3965 | // all of the results for them into one list of results each and insert |
| 3966 | // those. |
| 3967 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 3968 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 3969 | |
| 3970 | // Now loop over the names, either inserting them or appending for the two |
| 3971 | // special cases. |
| 3972 | for (auto &Name : Names) { |
| 3973 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 3974 | |
| 3975 | switch (Name.getNameKind()) { |
| 3976 | default: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3977 | Generator.insert(Name, Trait.getData(Result), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3978 | break; |
| 3979 | |
| 3980 | case DeclarationName::CXXConstructorName: |
| 3981 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 3982 | break; |
| 3983 | |
| 3984 | case DeclarationName::CXXConversionFunctionName: |
| 3985 | ConversionDecls.append(Result.begin(), Result.end()); |
| 3986 | break; |
| 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 3991 | // the first declaration's name here because the name itself isn't part of |
| 3992 | // the key, only the kind of name is used. |
| 3993 | if (!ConstructorDecls.empty()) |
| 3994 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3995 | Trait.getData(ConstructorDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3996 | if (!ConversionDecls.empty()) |
| 3997 | Generator.insert(ConversionDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3998 | Trait.getData(ConversionDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3999 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4000 | // Create the on-disk hash table. Also emit the existing imported and |
| 4001 | // merged table if there is one. |
| 4002 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; |
| 4003 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 4004 | } |
| 4005 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4006 | /// \brief Write the block containing all of the declaration IDs |
| 4007 | /// visible from the given DeclContext. |
| 4008 | /// |
| 4009 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4010 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4011 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 4012 | DeclContext *DC) { |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4013 | // If we imported a key declaration of this namespace, write the visible |
| 4014 | // lookup results as an update record for it rather than including them |
| 4015 | // on this declaration. We will only look at key declarations on reload. |
| 4016 | if (isa<NamespaceDecl>(DC) && Chain && |
| 4017 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { |
| 4018 | // Only do this once, for the first local declaration of the namespace. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4019 | for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4020 | Prev = Prev->getPreviousDecl()) |
| 4021 | if (!Prev->isFromASTFile()) |
| 4022 | return 0; |
| 4023 | |
| 4024 | // Note that we need to emit an update record for the primary context. |
| 4025 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); |
| 4026 | |
| 4027 | // Make sure all visible decls are written. They will be recorded later. We |
| 4028 | // do this using a side data structure so we can sort the names into |
| 4029 | // a deterministic order. |
| 4030 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); |
| 4031 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> |
| 4032 | LookupResults; |
| 4033 | if (Map) { |
| 4034 | LookupResults.reserve(Map->size()); |
| 4035 | for (auto &Entry : *Map) |
| 4036 | LookupResults.push_back( |
| 4037 | std::make_pair(Entry.first, Entry.second.getLookupResult())); |
| 4038 | } |
| 4039 | |
| 4040 | std::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); |
| 4041 | for (auto &NameAndResult : LookupResults) { |
| 4042 | DeclarationName Name = NameAndResult.first; |
| 4043 | DeclContext::lookup_result Result = NameAndResult.second; |
| 4044 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || |
| 4045 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 4046 | // We have to work around a name lookup bug here where negative lookup |
| 4047 | // results for these names get cached in namespace lookup tables (these |
| 4048 | // names should never be looked up in a namespace). |
| 4049 | assert(Result.empty() && "Cannot have a constructor or conversion " |
| 4050 | "function name in a namespace!"); |
| 4051 | continue; |
| 4052 | } |
| 4053 | |
| 4054 | for (NamedDecl *ND : Result) |
| 4055 | if (!ND->isFromASTFile()) |
| 4056 | GetDeclRef(ND); |
| 4057 | } |
| 4058 | |
| 4059 | return 0; |
| 4060 | } |
| 4061 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4062 | if (DC->getPrimaryContext() != DC) |
| 4063 | return 0; |
| 4064 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4065 | // Skip contexts which don't support name lookup. |
| 4066 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4067 | return 0; |
| 4068 | |
| 4069 | // If not in C++, we perform name lookup for the translation unit via the |
| 4070 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 4071 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4072 | return 0; |
| 4073 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4074 | // Serialize the contents of the mapping used for lookup. Note that, |
| 4075 | // although we have two very different code paths, the serialized |
| 4076 | // representation is the same for both cases: a declaration name, |
| 4077 | // followed by a size, followed by references to the visible |
| 4078 | // declarations that have that name. |
| 4079 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 4080 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4081 | if (!Map || Map->empty()) |
| 4082 | return 0; |
| 4083 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4084 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4085 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4086 | GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4087 | |
| 4088 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4089 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4090 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 4091 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4092 | ++NumVisibleDeclContexts; |
| 4093 | return Offset; |
| 4094 | } |
| 4095 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4096 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 4097 | /// |
| 4098 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 4099 | /// 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] | 4100 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 4101 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4102 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 4103 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4104 | if (!Map || Map->empty()) |
| 4105 | return; |
| 4106 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4107 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4108 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4109 | GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4110 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4111 | // If we're updating a namespace, select a key declaration as the key for the |
| 4112 | // update record; those are the only ones that will be checked on reload. |
| 4113 | if (isa<NamespaceDecl>(DC)) |
| 4114 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); |
| 4115 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4116 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4117 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 4118 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4119 | } |
| 4120 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4121 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 4122 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 4123 | RecordData::value_type Record[] = {Opts.getInt()}; |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4124 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 4125 | } |
| 4126 | |
| 4127 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 4128 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 4129 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4130 | return; |
| 4131 | |
| 4132 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 4133 | RecordData Record; |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4134 | for (const auto &I:Opts.OptMap) { |
| 4135 | AddString(I.getKey(), Record); |
| 4136 | auto V = I.getValue(); |
Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 4137 | Record.push_back(V.Supported ? 1 : 0); |
| 4138 | Record.push_back(V.Enabled ? 1 : 0); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4139 | Record.push_back(V.Avail); |
| 4140 | Record.push_back(V.Core); |
| 4141 | } |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4142 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 4143 | } |
| 4144 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4145 | void ASTWriter::WriteOpenCLExtensionTypes(Sema &SemaRef) { |
| 4146 | if (!SemaRef.Context.getLangOpts().OpenCL) |
| 4147 | return; |
| 4148 | |
| 4149 | RecordData Record; |
| 4150 | for (const auto &I : SemaRef.OpenCLTypeExtMap) { |
| 4151 | Record.push_back( |
| 4152 | static_cast<unsigned>(getTypeID(I.first->getCanonicalTypeInternal()))); |
| 4153 | Record.push_back(I.second.size()); |
| 4154 | for (auto Ext : I.second) |
| 4155 | AddString(Ext, Record); |
| 4156 | } |
| 4157 | Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record); |
| 4158 | } |
| 4159 | |
| 4160 | void ASTWriter::WriteOpenCLExtensionDecls(Sema &SemaRef) { |
| 4161 | if (!SemaRef.Context.getLangOpts().OpenCL) |
| 4162 | return; |
| 4163 | |
| 4164 | RecordData Record; |
| 4165 | for (const auto &I : SemaRef.OpenCLDeclExtMap) { |
| 4166 | Record.push_back(getDeclID(I.first)); |
| 4167 | Record.push_back(static_cast<unsigned>(I.second.size())); |
| 4168 | for (auto Ext : I.second) |
| 4169 | AddString(Ext, Record); |
| 4170 | } |
| 4171 | Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record); |
| 4172 | } |
| 4173 | |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 4174 | void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) { |
| 4175 | if (SemaRef.ForceCUDAHostDeviceDepth > 0) { |
| 4176 | RecordData::value_type Record[] = {SemaRef.ForceCUDAHostDeviceDepth}; |
| 4177 | Stream.EmitRecord(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH, Record); |
| 4178 | } |
| 4179 | } |
| 4180 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4181 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4182 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4183 | RecordData Categories; |
| 4184 | |
| 4185 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 4186 | unsigned Size = 0; |
| 4187 | unsigned StartIndex = Categories.size(); |
| 4188 | |
| 4189 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 4190 | |
| 4191 | // Allocate space for the size. |
| 4192 | Categories.push_back(0); |
| 4193 | |
| 4194 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 4195 | for (ObjCInterfaceDecl::known_categories_iterator |
| 4196 | Cat = Class->known_categories_begin(), |
| 4197 | CatEnd = Class->known_categories_end(); |
| 4198 | Cat != CatEnd; ++Cat, ++Size) { |
| 4199 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 4200 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | // Update the size. |
| 4204 | Categories[StartIndex] = Size; |
| 4205 | |
| 4206 | // Record this interface -> category map. |
| 4207 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 4208 | CategoriesMap.push_back(CatInfo); |
| 4209 | } |
| 4210 | |
| 4211 | // Sort the categories map by the definition ID, since the reader will be |
| 4212 | // performing binary searches on this information. |
| 4213 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 4214 | |
| 4215 | // Emit the categories map. |
| 4216 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4217 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4218 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4219 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 4220 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 4221 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4222 | unsigned AbbrevID = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4223 | |
| 4224 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; |
| 4225 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 4226 | reinterpret_cast<char *>(CategoriesMap.data()), |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4227 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4228 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4229 | // Emit the category lists. |
| 4230 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 4231 | } |
| 4232 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4233 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 4234 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 4235 | |
| 4236 | if (LPTMap.empty()) |
| 4237 | return; |
| 4238 | |
| 4239 | RecordData Record; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4240 | for (auto &LPTMapEntry : LPTMap) { |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4241 | const FunctionDecl *FD = LPTMapEntry.first; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4242 | LateParsedTemplate &LPT = *LPTMapEntry.second; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4243 | AddDeclRef(FD, Record); |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4244 | AddDeclRef(LPT.D, Record); |
| 4245 | Record.push_back(LPT.Toks.size()); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4246 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4247 | for (const auto &Tok : LPT.Toks) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4248 | AddToken(Tok, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4249 | } |
| 4250 | } |
| 4251 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 4252 | } |
| 4253 | |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4254 | /// \brief Write the state of 'pragma clang optimize' at the end of the module. |
| 4255 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 4256 | RecordData Record; |
| 4257 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 4258 | AddSourceLocation(PragmaLoc, Record); |
| 4259 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 4260 | } |
| 4261 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4262 | /// \brief Write the state of 'pragma ms_struct' at the end of the module. |
| 4263 | void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) { |
| 4264 | RecordData Record; |
| 4265 | Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF); |
| 4266 | Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record); |
| 4267 | } |
| 4268 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4269 | /// \brief Write the state of 'pragma pointers_to_members' at the end of the |
| 4270 | //module. |
| 4271 | void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) { |
| 4272 | RecordData Record; |
| 4273 | Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod); |
| 4274 | AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record); |
| 4275 | Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record); |
| 4276 | } |
| 4277 | |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4278 | /// \brief Write the state of 'pragma pack' at the end of the module. |
| 4279 | void ASTWriter::WritePackPragmaOptions(Sema &SemaRef) { |
Duncan P. N. Exon Smith | 03df14c | 2017-04-15 00:07:57 +0000 | [diff] [blame] | 4280 | // Don't serialize pragma pack state for modules, since it should only take |
| 4281 | // effect on a per-submodule basis. |
| 4282 | if (WritingModule) |
| 4283 | return; |
| 4284 | |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4285 | RecordData Record; |
| 4286 | Record.push_back(SemaRef.PackStack.CurrentValue); |
| 4287 | AddSourceLocation(SemaRef.PackStack.CurrentPragmaLocation, Record); |
| 4288 | Record.push_back(SemaRef.PackStack.Stack.size()); |
| 4289 | for (const auto &StackEntry : SemaRef.PackStack.Stack) { |
| 4290 | Record.push_back(StackEntry.Value); |
| 4291 | AddSourceLocation(StackEntry.PragmaLocation, Record); |
| 4292 | AddString(StackEntry.StackSlotLabel, Record); |
| 4293 | } |
| 4294 | Stream.EmitRecord(PACK_PRAGMA_OPTIONS, Record); |
| 4295 | } |
| 4296 | |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4297 | void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, |
| 4298 | ModuleFileExtensionWriter &Writer) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4299 | // Enter the extension block. |
| 4300 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); |
| 4301 | |
| 4302 | // Emit the metadata record abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4303 | auto Abv = std::make_shared<llvm::BitCodeAbbrev>(); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4304 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); |
| 4305 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4306 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4307 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4308 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4309 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4310 | unsigned Abbrev = Stream.EmitAbbrev(std::move(Abv)); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4311 | |
| 4312 | // Emit the metadata record. |
| 4313 | RecordData Record; |
| 4314 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); |
| 4315 | Record.push_back(EXTENSION_METADATA); |
| 4316 | Record.push_back(Metadata.MajorVersion); |
| 4317 | Record.push_back(Metadata.MinorVersion); |
| 4318 | Record.push_back(Metadata.BlockName.size()); |
| 4319 | Record.push_back(Metadata.UserInfo.size()); |
| 4320 | SmallString<64> Buffer; |
| 4321 | Buffer += Metadata.BlockName; |
| 4322 | Buffer += Metadata.UserInfo; |
| 4323 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); |
| 4324 | |
| 4325 | // Emit the contents of the extension block. |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4326 | Writer.writeExtensionContents(SemaRef, Stream); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4327 | |
| 4328 | // Exit the extension block. |
| 4329 | Stream.ExitBlock(); |
| 4330 | } |
| 4331 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4332 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4333 | // General Serialization Routines |
| 4334 | //===----------------------------------------------------------------------===// |
| 4335 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4336 | /// \brief Emit the list of attributes to the specified record. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4337 | void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) { |
| 4338 | auto &Record = *this; |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 4339 | Record.push_back(Attrs.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4340 | for (const auto *A : Attrs) { |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 4341 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4342 | Record.AddSourceRange(A->getRange()); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4343 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 4344 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 4345 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4346 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4347 | } |
| 4348 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 4349 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 4350 | AddSourceLocation(Tok.getLocation(), Record); |
| 4351 | Record.push_back(Tok.getLength()); |
| 4352 | |
| 4353 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 4354 | // if it is needed. |
| 4355 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 4356 | // FIXME: Should translate token kind to a stable encoding. |
| 4357 | Record.push_back(Tok.getKind()); |
| 4358 | // FIXME: Should translate token flags to a stable encoding. |
| 4359 | Record.push_back(Tok.getFlags()); |
| 4360 | } |
| 4361 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4362 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4363 | Record.push_back(Str.size()); |
| 4364 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 4365 | } |
| 4366 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4367 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4368 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4369 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4370 | bool Changed = |
| 4371 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4372 | |
| 4373 | // Remove a prefix to make the path relative, if relevant. |
| 4374 | const char *PathBegin = Path.data(); |
| 4375 | const char *PathPtr = |
| 4376 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 4377 | if (PathPtr != PathBegin) { |
| 4378 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 4379 | Changed = true; |
| 4380 | } |
| 4381 | |
| 4382 | return Changed; |
| 4383 | } |
| 4384 | |
| 4385 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 4386 | SmallString<128> FilePath(Path); |
| 4387 | PreparePathForOutput(FilePath); |
| 4388 | AddString(FilePath, Record); |
| 4389 | } |
| 4390 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4391 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4392 | StringRef Path) { |
| 4393 | SmallString<128> FilePath(Path); |
| 4394 | PreparePathForOutput(FilePath); |
| 4395 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 4396 | } |
| 4397 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4398 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 4399 | RecordDataImpl &Record) { |
| 4400 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4401 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4402 | Record.push_back(*Minor + 1); |
| 4403 | else |
| 4404 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4405 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4406 | Record.push_back(*Subminor + 1); |
| 4407 | else |
| 4408 | Record.push_back(0); |
| 4409 | } |
| 4410 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4411 | /// \brief Note that the identifier II occurs at the given offset |
| 4412 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4413 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4414 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4415 | // 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] | 4416 | // up earlier in the chain and thus don't need an offset. |
| 4417 | if (ID >= FirstIdentID) |
| 4418 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4421 | /// \brief Note that the selector Sel occurs at the given offset |
| 4422 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4423 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4424 | unsigned ID = SelectorIDs[Sel]; |
| 4425 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4426 | // Don't record offsets for selectors that are also available in a different |
| 4427 | // file. |
| 4428 | if (ID < FirstSelectorID) |
| 4429 | return; |
| 4430 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 4433 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream, |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4434 | SmallVectorImpl<char> &Buffer, MemoryBufferCache &PCMCache, |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 4435 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 4436 | bool IncludeTimestamps) |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4437 | : Stream(Stream), Buffer(Buffer), PCMCache(PCMCache), |
| 4438 | IncludeTimestamps(IncludeTimestamps) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4439 | for (const auto &Ext : Extensions) { |
| 4440 | if (auto Writer = Ext->createExtensionWriter(*this)) |
| 4441 | ModuleFileExtensionWriters.push_back(std::move(Writer)); |
| 4442 | } |
| 4443 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4444 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4445 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 4446 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4447 | } |
| 4448 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4449 | const LangOptions &ASTWriter::getLangOpts() const { |
| 4450 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 4451 | return Context->getLangOpts(); |
| 4452 | } |
| 4453 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4454 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { |
| 4455 | return IncludeTimestamps ? E->getModificationTime() : 0; |
| 4456 | } |
| 4457 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4458 | ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, |
| 4459 | const std::string &OutputFile, |
| 4460 | Module *WritingModule, StringRef isysroot, |
| 4461 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4462 | WritingAST = true; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4463 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4464 | ASTHasCompilerErrors = hasErrors; |
| 4465 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4466 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4467 | Stream.Emit((unsigned)'C', 8); |
| 4468 | Stream.Emit((unsigned)'P', 8); |
| 4469 | Stream.Emit((unsigned)'C', 8); |
| 4470 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4472 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4473 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4474 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4475 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4476 | this->WritingModule = WritingModule; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4477 | ASTFileSignature Signature = |
| 4478 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4479 | Context = nullptr; |
| 4480 | PP = nullptr; |
| 4481 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4482 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4483 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4484 | WritingAST = false; |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4485 | if (SemaRef.Context.getLangOpts().ImplicitModules && WritingModule) { |
| 4486 | // Construct MemoryBuffer and update buffer manager. |
| 4487 | PCMCache.addBuffer(OutputFile, |
| 4488 | llvm::MemoryBuffer::getMemBufferCopy( |
| 4489 | StringRef(Buffer.begin(), Buffer.size()))); |
| 4490 | } |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4491 | return Signature; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4492 | } |
| 4493 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4494 | template<typename Vector> |
| 4495 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4496 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4497 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4498 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4499 | Writer.AddDeclRef(*I, Record); |
| 4500 | } |
| 4501 | } |
| 4502 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4503 | ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, |
| 4504 | const std::string &OutputFile, |
| 4505 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4506 | using namespace llvm; |
| 4507 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4508 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4509 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4510 | // Make sure that the AST reader knows to finalize itself. |
| 4511 | if (Chain) |
| 4512 | Chain->finalizeForWriting(); |
| 4513 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4514 | ASTContext &Context = SemaRef.Context; |
| 4515 | Preprocessor &PP = SemaRef.PP; |
| 4516 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4517 | // Set up predefined declaration IDs. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4518 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { |
| 4519 | if (D) { |
| 4520 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); |
| 4521 | DeclIDs[D] = ID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4522 | } |
| 4523 | }; |
| 4524 | RegisterPredefDecl(Context.getTranslationUnitDecl(), |
| 4525 | PREDEF_DECL_TRANSLATION_UNIT_ID); |
| 4526 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); |
| 4527 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); |
| 4528 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); |
| 4529 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, |
| 4530 | PREDEF_DECL_OBJC_PROTOCOL_ID); |
| 4531 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); |
| 4532 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); |
| 4533 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, |
| 4534 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); |
| 4535 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4536 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4537 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, |
| 4538 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4539 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4540 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, |
| 4541 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 4542 | RegisterPredefDecl(Context.CFConstantStringTypeDecl, |
| 4543 | PREDEF_DECL_CF_CONSTANT_STRING_ID); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 4544 | RegisterPredefDecl(Context.CFConstantStringTagDecl, |
| 4545 | PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 4546 | RegisterPredefDecl(Context.TypePackElementDecl, |
| 4547 | PREDEF_DECL_TYPE_PACK_ELEMENT_ID); |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4548 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4549 | // 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] | 4550 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4551 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4552 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4553 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4554 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4555 | // Build a record containing all of the file scoped decls in this file. |
| 4556 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4557 | if (!isModule) |
| 4558 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4559 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4560 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4561 | // Build a record containing all of the delegating constructors we still need |
| 4562 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4563 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4564 | if (!isModule) |
| 4565 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4566 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4567 | // Write the set of weak, undeclared identifiers. We always write the |
| 4568 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4569 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4570 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4571 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4572 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4573 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4574 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4575 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4576 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4577 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4578 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4579 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4580 | // Build a record containing all of the ext_vector declarations. |
| 4581 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4582 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4583 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4584 | // Build a record containing all of the VTable uses information. |
| 4585 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4586 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4587 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4588 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4589 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4590 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4591 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4592 | } |
| 4593 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4594 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4595 | RecordData UnusedLocalTypedefNameCandidates; |
| 4596 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4597 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4598 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4599 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4600 | RecordData PendingInstantiations; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4601 | for (const auto &I : SemaRef.PendingInstantiations) { |
| 4602 | AddDeclRef(I.first, PendingInstantiations); |
| 4603 | AddSourceLocation(I.second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4604 | } |
| 4605 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4606 | "There are local ones at end of translation unit!"); |
| 4607 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4608 | // Build a record containing some declaration references. |
| 4609 | RecordData SemaDeclRefs; |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4610 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) { |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4611 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4612 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4613 | AddDeclRef(SemaRef.getStdAlignValT(), SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4614 | } |
| 4615 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4616 | RecordData CUDASpecialDeclRefs; |
| 4617 | if (Context.getcudaConfigureCallDecl()) { |
| 4618 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4619 | } |
| 4620 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4621 | // Build a record containing all of the known namespaces. |
| 4622 | RecordData KnownNamespaces; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4623 | for (const auto &I : SemaRef.KnownNamespaces) { |
| 4624 | if (!I.second) |
| 4625 | AddDeclRef(I.first, KnownNamespaces); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4626 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4627 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4628 | // Build a record of all used, undefined objects that require definitions. |
| 4629 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4630 | |
| 4631 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4632 | SemaRef.getUndefinedButUsed(Undefined); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4633 | for (const auto &I : Undefined) { |
| 4634 | AddDeclRef(I.first, UndefinedButUsed); |
| 4635 | AddSourceLocation(I.second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4638 | // Build a record containing all delete-expressions that we would like to |
| 4639 | // analyze later in AST. |
| 4640 | RecordData DeleteExprsToAnalyze; |
| 4641 | |
| 4642 | for (const auto &DeleteExprsInfo : |
| 4643 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4644 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4645 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4646 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4647 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4648 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4649 | } |
| 4650 | } |
| 4651 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4652 | // Write the control block |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4653 | WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4654 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4655 | // Write the remaining AST contents. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4656 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4657 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4658 | // This is so that older clang versions, before the introduction |
| 4659 | // of the control block, can read and reject the newer PCH format. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4660 | { |
| 4661 | RecordData Record = {VERSION_MAJOR}; |
| 4662 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4663 | } |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4664 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4665 | // Create a lexical update block containing all of the declarations in the |
| 4666 | // translation unit that do not come from other AST files. |
| 4667 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4668 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; |
| 4669 | for (const auto *D : TU->noload_decls()) { |
| 4670 | if (!D->isFromASTFile()) { |
| 4671 | NewGlobalKindDeclPairs.push_back(D->getKind()); |
| 4672 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); |
| 4673 | } |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4674 | } |
| 4675 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4676 | auto Abv = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4677 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4678 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4679 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4680 | { |
| 4681 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; |
| 4682 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 4683 | bytes(NewGlobalKindDeclPairs)); |
| 4684 | } |
| 4685 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4686 | // And a visible updates block for the translation unit. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4687 | Abv = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4688 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4689 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4690 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4691 | UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4692 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4693 | |
| 4694 | // If we have any extern "C" names, write out a visible update for them. |
| 4695 | if (Context.ExternCContext) |
| 4696 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4697 | |
| 4698 | // If the translation unit has an anonymous namespace, and we don't already |
| 4699 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4700 | // 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] | 4701 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4702 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4703 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4704 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4705 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4706 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4707 | // Add update records for all mangling numbers and static local numbers. |
| 4708 | // These aren't really update records, but this is a convenient way of |
| 4709 | // tagging this rare extra data onto the declarations. |
| 4710 | for (const auto &Number : Context.MangleNumbers) |
| 4711 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4712 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4713 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4714 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4715 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4716 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4717 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4718 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4719 | // Make sure visible decls, added to DeclContexts previously loaded from |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 4720 | // an AST file, are registered for serialization. Likewise for template |
| 4721 | // specializations added to imported templates. |
| 4722 | for (const auto *I : DeclsToEmitEvenIfUnreferenced) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4723 | GetDeclRef(I); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4726 | // Make sure all decls associated with an identifier are registered for |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4727 | // serialization, if we're storing decls with identifiers. |
| 4728 | if (!WritingModule || !getLangOpts().CPlusPlus) { |
| 4729 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4730 | for (const auto &ID : PP.getIdentifierTable()) { |
| 4731 | const IdentifierInfo *II = ID.second; |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4732 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 4733 | IIs.push_back(II); |
| 4734 | } |
| 4735 | // Sort the identifiers to visit based on their name. |
| 4736 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 4737 | for (const IdentifierInfo *II : IIs) { |
| 4738 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4739 | DEnd = SemaRef.IdResolver.end(); |
| 4740 | D != DEnd; ++D) { |
| 4741 | GetDeclRef(*D); |
| 4742 | } |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4743 | } |
| 4744 | } |
| 4745 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 4746 | // For method pool in the module, if it contains an entry for a selector, |
| 4747 | // the entry should be complete, containing everything introduced by that |
| 4748 | // module and all modules it imports. It's possible that the entry is out of |
| 4749 | // date, so we need to pull in the new content here. |
| 4750 | |
| 4751 | // It's possible that updateOutOfDateSelector can update SelectorIDs. To be |
| 4752 | // safe, we copy all selectors out. |
| 4753 | llvm::SmallVector<Selector, 256> AllSelectors; |
| 4754 | for (auto &SelectorAndID : SelectorIDs) |
| 4755 | AllSelectors.push_back(SelectorAndID.first); |
| 4756 | for (auto &Selector : AllSelectors) |
| 4757 | SemaRef.updateOutOfDateSelector(Selector); |
| 4758 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4759 | // Form the record of special types. |
| 4760 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4761 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4762 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 4763 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 4764 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 4765 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 4766 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4767 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4768 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4769 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4770 | if (Chain) { |
| 4771 | // Write the mapping information describing our module dependencies and how |
| 4772 | // each of those modules were mapped into our own offset/ID space, so that |
| 4773 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4774 | // The map consists solely of a blob with the following format: |
| 4775 | // *(module-name-len:i16 module-name:len*i8 |
| 4776 | // source-location-offset:i32 |
| 4777 | // identifier-id:i32 |
| 4778 | // preprocessed-entity-id:i32 |
| 4779 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4780 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4781 | // selector-id:i32 |
| 4782 | // declaration-id:i32 |
| 4783 | // c++-base-specifiers-id:i32 |
| 4784 | // type-id:i32) |
| 4785 | // |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4786 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4787 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4788 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4789 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4790 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4791 | { |
| 4792 | llvm::raw_svector_ostream Out(Buffer); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 4793 | for (ModuleFile &M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4794 | using namespace llvm::support; |
| 4795 | endian::Writer<little> LE(Out); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 4796 | StringRef FileName = M.FileName; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4797 | LE.write<uint16_t>(FileName.size()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4798 | Out.write(FileName.data(), FileName.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4799 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4800 | // Note: if a base ID was uint max, it would not be possible to load |
| 4801 | // another module after it or have more than one entity inside it. |
| 4802 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 4803 | |
| 4804 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 4805 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 4806 | if (ShouldWrite) |
| 4807 | LE.write<uint32_t>(BaseID); |
| 4808 | else |
| 4809 | LE.write<uint32_t>(None); |
| 4810 | }; |
| 4811 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4812 | // These values should be unique within a chain, since they will be read |
| 4813 | // as keys into ContinuousRangeMaps. |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 4814 | writeBaseIDOrNone(M.SLocEntryBaseOffset, M.LocalNumSLocEntries); |
| 4815 | writeBaseIDOrNone(M.BaseIdentifierID, M.LocalNumIdentifiers); |
| 4816 | writeBaseIDOrNone(M.BaseMacroID, M.LocalNumMacros); |
| 4817 | writeBaseIDOrNone(M.BasePreprocessedEntityID, |
| 4818 | M.NumPreprocessedEntities); |
| 4819 | writeBaseIDOrNone(M.BaseSubmoduleID, M.LocalNumSubmodules); |
| 4820 | writeBaseIDOrNone(M.BaseSelectorID, M.LocalNumSelectors); |
| 4821 | writeBaseIDOrNone(M.BaseDeclID, M.LocalNumDecls); |
| 4822 | writeBaseIDOrNone(M.BaseTypeIndex, M.LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4823 | } |
| 4824 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4825 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4826 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4827 | Buffer.data(), Buffer.size()); |
| 4828 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4829 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4830 | RecordData DeclUpdatesOffsetsRecord; |
| 4831 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4832 | // Keep writing types, declarations, and declaration update records |
| 4833 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4834 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 4835 | WriteTypeAbbrevs(); |
| 4836 | WriteDeclAbbrevs(); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4837 | do { |
| 4838 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 4839 | while (!DeclTypesToEmit.empty()) { |
| 4840 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 4841 | DeclTypesToEmit.pop(); |
| 4842 | if (DOT.isType()) |
| 4843 | WriteType(DOT.getType()); |
| 4844 | else |
| 4845 | WriteDecl(Context, DOT.getDecl()); |
| 4846 | } |
| 4847 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4848 | Stream.ExitBlock(); |
| 4849 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4850 | DoneWritingDeclsAndTypes = true; |
| 4851 | |
| 4852 | // These things can only be done once we've written out decls and types. |
| 4853 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4854 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 4855 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4856 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4857 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4858 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4859 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4860 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4861 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4862 | WriteReferencedSelectorsPool(SemaRef); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 4863 | WriteLateParsedTemplates(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4864 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4865 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 4866 | WriteOpenCLExtensions(SemaRef); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4867 | WriteOpenCLExtensionTypes(SemaRef); |
| 4868 | WriteOpenCLExtensionDecls(SemaRef); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 4869 | WriteCUDAPragmas(SemaRef); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4870 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4871 | // If we're emitting a module, write out the submodule information. |
| 4872 | if (WritingModule) |
| 4873 | WriteSubmodules(WritingModule); |
| 4874 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4875 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 4876 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4877 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 4878 | if (!EagerlyDeserializedDecls.empty()) |
| 4879 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4880 | |
David Blaikie | f63556d | 2017-04-12 20:58:33 +0000 | [diff] [blame] | 4881 | if (!ModularCodegenDecls.empty()) |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 4882 | Stream.EmitRecord(MODULAR_CODEGEN_DECLS, ModularCodegenDecls); |
| 4883 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4884 | // Write the record containing tentative definitions. |
| 4885 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4886 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4887 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4888 | // Write the record containing unused file scoped decls. |
| 4889 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4890 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4891 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4892 | // Write the record containing weak undeclared identifiers. |
| 4893 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4894 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4895 | WeakUndeclaredIdentifiers); |
| 4896 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4897 | // Write the record containing ext_vector type names. |
| 4898 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4899 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4900 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4901 | // Write the record containing VTable uses information. |
| 4902 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4903 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4904 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4905 | // Write the record containing potentially unused local typedefs. |
| 4906 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 4907 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 4908 | UnusedLocalTypedefNameCandidates); |
| 4909 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4910 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4911 | if (!PendingInstantiations.empty()) |
| 4912 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4913 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4914 | // Write the record containing declaration references of Sema. |
| 4915 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4916 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4917 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4918 | // Write the record containing CUDA-specific declaration references. |
| 4919 | if (!CUDASpecialDeclRefs.empty()) |
| 4920 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4921 | |
| 4922 | // Write the delegating constructors. |
| 4923 | if (!DelegatingCtorDecls.empty()) |
| 4924 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4925 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4926 | // Write the known namespaces. |
| 4927 | if (!KnownNamespaces.empty()) |
| 4928 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4929 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4930 | // Write the undefined internal functions and variables, and inline functions. |
| 4931 | if (!UndefinedButUsed.empty()) |
| 4932 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4933 | |
| 4934 | if (!DeleteExprsToAnalyze.empty()) |
| 4935 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 4936 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4937 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4938 | for (auto *DC : UpdatedDeclContexts) |
| 4939 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4940 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4941 | if (!WritingModule) { |
| 4942 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4943 | struct ModuleInfo { |
| 4944 | uint64_t ID; |
| 4945 | Module *M; |
| 4946 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 4947 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4948 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 4949 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4950 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4951 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 4952 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4953 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4954 | |
| 4955 | if (!Imports.empty()) { |
| 4956 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4957 | return A.ID < B.ID; |
| 4958 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4959 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4960 | return A.ID == B.ID; |
| 4961 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4962 | |
| 4963 | // Sort and deduplicate module IDs. |
| 4964 | std::sort(Imports.begin(), Imports.end(), Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4965 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4966 | Imports.end()); |
| 4967 | |
| 4968 | RecordData ImportedModules; |
| 4969 | for (const auto &Import : Imports) { |
| 4970 | ImportedModules.push_back(Import.ID); |
| 4971 | // FIXME: If the module has macros imported then later has declarations |
| 4972 | // imported, this location won't be the right one as a location for the |
| 4973 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 4974 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4975 | } |
| 4976 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4977 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 4978 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4979 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4980 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4981 | WriteObjCCategories(); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4982 | if(!WritingModule) { |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4983 | WriteOptimizePragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4984 | WriteMSStructPragmaOptions(SemaRef); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4985 | WriteMSPointersToMembersPragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4986 | } |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4987 | WritePackPragmaOptions(SemaRef); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4988 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4989 | // Some simple statistics |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4990 | RecordData::value_type Record[] = { |
| 4991 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4992 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4993 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4994 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4995 | // Write the module file extension blocks. |
| 4996 | for (const auto &ExtWriter : ModuleFileExtensionWriters) |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4997 | WriteModuleFileExtension(SemaRef, *ExtWriter); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4998 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4999 | return writeUnhashedControlBlock(PP, Context); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5002 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5003 | if (DeclUpdates.empty()) |
| 5004 | return; |
| 5005 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 5006 | DeclUpdateMap LocalUpdates; |
| 5007 | LocalUpdates.swap(DeclUpdates); |
| 5008 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5009 | for (auto &DeclUpdate : LocalUpdates) { |
| 5010 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 5011 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5012 | bool HasUpdatedBody = false; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5013 | RecordData RecordData; |
| 5014 | ASTRecordWriter Record(*this, RecordData); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5015 | for (auto &Update : DeclUpdate.second) { |
| 5016 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 5017 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5018 | // An updated body is emitted last, so that the reader doesn't need |
| 5019 | // to skip over the lazy body to reach statements for other records. |
| 5020 | if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION) |
| 5021 | HasUpdatedBody = true; |
| 5022 | else |
| 5023 | Record.push_back(Kind); |
| 5024 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5025 | switch (Kind) { |
| 5026 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 5027 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 5028 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5029 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5030 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 5031 | break; |
| 5032 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5033 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5034 | break; |
| 5035 | |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame^] | 5036 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: { |
| 5037 | const VarDecl *VD = cast<VarDecl>(D); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5038 | Record.AddSourceLocation(Update.getLoc()); |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame^] | 5039 | if (VD->getInit()) { |
| 5040 | Record.push_back(!VD->isInitKnownICE() ? 1 |
| 5041 | : (VD->isInitICE() ? 3 : 2)); |
| 5042 | Record.AddStmt(const_cast<Expr*>(VD->getInit())); |
| 5043 | } else { |
| 5044 | Record.push_back(0); |
| 5045 | } |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5046 | break; |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame^] | 5047 | } |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5048 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5049 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5050 | Record.AddStmt(const_cast<Expr *>( |
| 5051 | cast<ParmVarDecl>(Update.getDecl())->getDefaultArg())); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5052 | break; |
| 5053 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 5054 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: |
| 5055 | Record.AddStmt( |
| 5056 | cast<FieldDecl>(Update.getDecl())->getInClassInitializer()); |
| 5057 | break; |
| 5058 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5059 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 5060 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 5061 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5062 | Record.AddCXXDefinitionData(RD); |
Richard Smith | 72e50fe | 2016-04-14 00:50:18 +0000 | [diff] [blame] | 5063 | Record.AddOffset(WriteDeclContextLexicalBlock( |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5064 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 5065 | |
| 5066 | // This state is sometimes updated by template instantiation, when we |
| 5067 | // switch from the specialization referring to the template declaration |
| 5068 | // to it referring to the template definition. |
| 5069 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 5070 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5071 | Record.AddSourceLocation(MSInfo->getPointOfInstantiation()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5072 | } else { |
| 5073 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 5074 | Record.push_back(Spec->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5075 | Record.AddSourceLocation(Spec->getPointOfInstantiation()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 5076 | |
| 5077 | // The instantiation might have been resolved to a partial |
| 5078 | // specialization. If so, record which one. |
| 5079 | auto From = Spec->getInstantiatedFrom(); |
| 5080 | if (auto PartialSpec = |
| 5081 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 5082 | Record.push_back(true); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5083 | Record.AddDeclRef(PartialSpec); |
| 5084 | Record.AddTemplateArgumentList( |
| 5085 | &Spec->getTemplateInstantiationArgs()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 5086 | } else { |
| 5087 | Record.push_back(false); |
| 5088 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5089 | } |
| 5090 | Record.push_back(RD->getTagKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5091 | Record.AddSourceLocation(RD->getLocation()); |
| 5092 | Record.AddSourceLocation(RD->getLocStart()); |
Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 5093 | Record.AddSourceRange(RD->getBraceRange()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5094 | |
| 5095 | // Instantiation may change attributes; write them all out afresh. |
| 5096 | Record.push_back(D->hasAttrs()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5097 | if (D->hasAttrs()) |
| 5098 | Record.AddAttributes(D->getAttrs()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5099 | |
| 5100 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 5101 | break; |
| 5102 | } |
| 5103 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5104 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5105 | Record.AddDeclRef(Update.getDecl()); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5106 | break; |
| 5107 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5108 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 5109 | addExceptionSpec( |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5110 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 5111 | Record); |
| 5112 | break; |
| 5113 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5114 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 5115 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 5116 | break; |
| 5117 | |
| 5118 | case UPD_DECL_MARKED_USED: |
| 5119 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 5120 | |
| 5121 | case UPD_MANGLING_NUMBER: |
| 5122 | case UPD_STATIC_LOCAL_NUMBER: |
| 5123 | Record.push_back(Update.getNumber()); |
| 5124 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5125 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5126 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5127 | Record.AddSourceRange( |
| 5128 | D->getAttr<OMPThreadPrivateDeclAttr>()->getRange()); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5129 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5130 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5131 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: |
| 5132 | Record.AddSourceRange( |
| 5133 | D->getAttr<OMPDeclareTargetDeclAttr>()->getRange()); |
| 5134 | break; |
| 5135 | |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5136 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5137 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5138 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5139 | |
| 5140 | case UPD_ADDED_ATTR_TO_RECORD: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5141 | Record.AddAttributes(llvm::makeArrayRef(Update.getAttr())); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5142 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5143 | } |
| 5144 | } |
| 5145 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5146 | if (HasUpdatedBody) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5147 | const auto *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5148 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5149 | Record.push_back(Def->isInlined()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5150 | Record.AddSourceLocation(Def->getInnerLocStart()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5151 | Record.AddFunctionDefinition(Def); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5152 | } |
| 5153 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5154 | OffsetsRecord.push_back(GetDeclRef(D)); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5155 | OffsetsRecord.push_back(Record.Emit(DECL_UPDATES)); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5156 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5157 | } |
| 5158 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5159 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5160 | uint32_t Raw = Loc.getRawEncoding(); |
| 5161 | Record.push_back((Raw << 1) | (Raw >> 31)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5162 | } |
| 5163 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5164 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5165 | AddSourceLocation(Range.getBegin(), Record); |
| 5166 | AddSourceLocation(Range.getEnd(), Record); |
| 5167 | } |
| 5168 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5169 | void ASTRecordWriter::AddAPInt(const llvm::APInt &Value) { |
| 5170 | Record->push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 5171 | const uint64_t *Words = Value.getRawData(); |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5172 | Record->append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5175 | void ASTRecordWriter::AddAPSInt(const llvm::APSInt &Value) { |
| 5176 | Record->push_back(Value.isUnsigned()); |
| 5177 | AddAPInt(Value); |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5178 | } |
| 5179 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5180 | void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) { |
| 5181 | AddAPInt(Value.bitcastToAPInt()); |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5182 | } |
| 5183 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5184 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5185 | Record.push_back(getIdentifierRef(II)); |
| 5186 | } |
| 5187 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5188 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5189 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5190 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5191 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5192 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5193 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5194 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5195 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5196 | } |
| 5197 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5198 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5199 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 5200 | // have been redefined by the header (in which case they are not |
| 5201 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5202 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5203 | return 0; |
| 5204 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5205 | MacroID &ID = MacroIDs[MI]; |
| 5206 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5207 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5208 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 5209 | MacroInfosToEmit.push_back(Info); |
| 5210 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5211 | return ID; |
| 5212 | } |
| 5213 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5214 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5215 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5216 | return 0; |
| 5217 | |
| 5218 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 5219 | return MacroIDs[MI]; |
| 5220 | } |
| 5221 | |
| 5222 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 5223 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5224 | } |
| 5225 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5226 | void ASTRecordWriter::AddSelectorRef(const Selector SelRef) { |
| 5227 | Record->push_back(Writer->getSelectorRef(SelRef)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5228 | } |
| 5229 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5230 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5231 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5232 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5233 | } |
| 5234 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5235 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5236 | if (SID == 0 && Chain) { |
| 5237 | // This might trigger a ReadSelector callback, which will set the ID for |
| 5238 | // this selector. |
| 5239 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5240 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5241 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5242 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5243 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5244 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5245 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5246 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5247 | } |
| 5248 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5249 | void ASTRecordWriter::AddCXXTemporary(const CXXTemporary *Temp) { |
| 5250 | AddDeclRef(Temp->getDestructor()); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5251 | } |
| 5252 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5253 | void ASTRecordWriter::AddTemplateArgumentLocInfo( |
| 5254 | TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5255 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5256 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5257 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5258 | break; |
| 5259 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5260 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5261 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5262 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5263 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5264 | AddSourceLocation(Arg.getTemplateNameLoc()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5265 | break; |
| 5266 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5267 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5268 | AddSourceLocation(Arg.getTemplateNameLoc()); |
| 5269 | AddSourceLocation(Arg.getTemplateEllipsisLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5270 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5271 | case TemplateArgument::Null: |
| 5272 | case TemplateArgument::Integral: |
| 5273 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5274 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5275 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5276 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5277 | break; |
| 5278 | } |
| 5279 | } |
| 5280 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5281 | void ASTRecordWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg) { |
| 5282 | AddTemplateArgument(Arg.getArgument()); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5283 | |
| 5284 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 5285 | bool InfoHasSameExpr |
| 5286 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5287 | Record->push_back(InfoHasSameExpr); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5288 | if (InfoHasSameExpr) |
| 5289 | return; // Avoid storing the same expr twice. |
| 5290 | } |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5291 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo()); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5292 | } |
| 5293 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5294 | void ASTRecordWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5295 | if (!TInfo) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5296 | AddTypeRef(QualType()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5297 | return; |
| 5298 | } |
| 5299 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5300 | AddTypeLoc(TInfo->getTypeLoc()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5301 | } |
| 5302 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5303 | void ASTRecordWriter::AddTypeLoc(TypeLoc TL) { |
| 5304 | AddTypeRef(TL.getType()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5305 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5306 | TypeLocWriter TLW(*this); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5307 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 5308 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5309 | } |
| 5310 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5311 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 5312 | Record.push_back(GetOrCreateTypeID(T)); |
| 5313 | } |
| 5314 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5315 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5316 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5317 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5318 | if (T.isNull()) |
| 5319 | return TypeIdx(); |
| 5320 | assert(!T.getLocalFastQualifiers()); |
| 5321 | |
| 5322 | TypeIdx &Idx = TypeIdxs[T]; |
| 5323 | if (Idx.getIndex() == 0) { |
| 5324 | if (DoneWritingDeclsAndTypes) { |
| 5325 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 5326 | return TypeIdx(); |
| 5327 | } |
| 5328 | |
| 5329 | // We haven't seen this type before. Assign it a new ID and put it |
| 5330 | // into the queue of types to emit. |
| 5331 | Idx = TypeIdx(NextTypeID++); |
| 5332 | DeclTypesToEmit.push(T); |
| 5333 | } |
| 5334 | return Idx; |
| 5335 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 5336 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5337 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 5338 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5339 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5340 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5341 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5342 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5343 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5344 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5345 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 5346 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 5347 | return I->second; |
| 5348 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5349 | } |
| 5350 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5351 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5352 | Record.push_back(GetDeclRef(D)); |
| 5353 | } |
| 5354 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5355 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5356 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5357 | |
| 5358 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5359 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5360 | } |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5361 | |
| 5362 | // If D comes from an AST file, its declaration ID is already known and |
| 5363 | // fixed. |
| 5364 | if (D->isFromASTFile()) |
| 5365 | return D->getGlobalID(); |
| 5366 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5367 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5368 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5369 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5370 | if (DoneWritingDeclsAndTypes) { |
| 5371 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 5372 | return 0; |
| 5373 | } |
| 5374 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5375 | // We haven't seen this declaration before. Give it a new ID and |
| 5376 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5377 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5378 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5379 | } |
| 5380 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5381 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5382 | } |
| 5383 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5384 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5385 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5386 | return 0; |
| 5387 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5388 | // If D comes from an AST file, its declaration ID is already known and |
| 5389 | // fixed. |
| 5390 | if (D->isFromASTFile()) |
| 5391 | return D->getGlobalID(); |
| 5392 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5393 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 5394 | return DeclIDs[D]; |
| 5395 | } |
| 5396 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5397 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5398 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5399 | assert(D); |
| 5400 | |
| 5401 | SourceLocation Loc = D->getLocation(); |
| 5402 | if (Loc.isInvalid()) |
| 5403 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5404 | |
| 5405 | // We only keep track of the file-level declarations of each file. |
| 5406 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 5407 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5408 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 5409 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5410 | if (isa<ParmVarDecl>(D)) |
| 5411 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5412 | |
| 5413 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5414 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5415 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5416 | FileID FID; |
| 5417 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5418 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5419 | if (FID.isInvalid()) |
| 5420 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5421 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5422 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5423 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5424 | if (!Info) |
| 5425 | Info = new DeclIDInFileInfo(); |
| 5426 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5427 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5428 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 5429 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5430 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5431 | Decls.push_back(LocDecl); |
| 5432 | return; |
| 5433 | } |
| 5434 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5435 | LocDeclIDsTy::iterator I = |
| 5436 | std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5437 | |
| 5438 | Decls.insert(I, LocDecl); |
| 5439 | } |
| 5440 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5441 | void ASTRecordWriter::AddDeclarationName(DeclarationName Name) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 5442 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5443 | Record->push_back(Name.getNameKind()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5444 | switch (Name.getNameKind()) { |
| 5445 | case DeclarationName::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5446 | AddIdentifierRef(Name.getAsIdentifierInfo()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5447 | break; |
| 5448 | |
| 5449 | case DeclarationName::ObjCZeroArgSelector: |
| 5450 | case DeclarationName::ObjCOneArgSelector: |
| 5451 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5452 | AddSelectorRef(Name.getObjCSelector()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5453 | break; |
| 5454 | |
| 5455 | case DeclarationName::CXXConstructorName: |
| 5456 | case DeclarationName::CXXDestructorName: |
| 5457 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5458 | AddTypeRef(Name.getCXXNameType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5459 | break; |
| 5460 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 5461 | case DeclarationName::CXXDeductionGuideName: |
| 5462 | AddDeclRef(Name.getCXXDeductionGuideTemplate()); |
| 5463 | break; |
| 5464 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5465 | case DeclarationName::CXXOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5466 | Record->push_back(Name.getCXXOverloadedOperator()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5467 | break; |
| 5468 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5469 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5470 | AddIdentifierRef(Name.getCXXLiteralIdentifier()); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5471 | break; |
| 5472 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5473 | case DeclarationName::CXXUsingDirective: |
| 5474 | // No extra data to emit |
| 5475 | break; |
| 5476 | } |
| 5477 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5478 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5479 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5480 | assert(needsAnonymousDeclarationNumber(D) && |
| 5481 | "expected an anonymous declaration"); |
| 5482 | |
| 5483 | // Number the anonymous declarations within this context, if we've not |
| 5484 | // already done so. |
| 5485 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5486 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5487 | auto *DC = D->getLexicalDeclContext(); |
| 5488 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5489 | AnonymousDeclarationNumbers[ND] = Number; |
| 5490 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5491 | |
| 5492 | It = AnonymousDeclarationNumbers.find(D); |
| 5493 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5494 | "declaration not found within its lexical context"); |
| 5495 | } |
| 5496 | |
| 5497 | return It->second; |
| 5498 | } |
| 5499 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5500 | void ASTRecordWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
| 5501 | DeclarationName Name) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5502 | switch (Name.getNameKind()) { |
| 5503 | case DeclarationName::CXXConstructorName: |
| 5504 | case DeclarationName::CXXDestructorName: |
| 5505 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5506 | AddTypeSourceInfo(DNLoc.NamedType.TInfo); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5507 | break; |
| 5508 | |
| 5509 | case DeclarationName::CXXOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5510 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5511 | DNLoc.CXXOperatorName.BeginOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5512 | AddSourceLocation( |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5513 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5514 | break; |
| 5515 | |
| 5516 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5517 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5518 | DNLoc.CXXLiteralOperatorName.OpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5519 | break; |
| 5520 | |
| 5521 | case DeclarationName::Identifier: |
| 5522 | case DeclarationName::ObjCZeroArgSelector: |
| 5523 | case DeclarationName::ObjCOneArgSelector: |
| 5524 | case DeclarationName::ObjCMultiArgSelector: |
| 5525 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 5526 | case DeclarationName::CXXDeductionGuideName: |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5527 | break; |
| 5528 | } |
| 5529 | } |
| 5530 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5531 | void ASTRecordWriter::AddDeclarationNameInfo( |
| 5532 | const DeclarationNameInfo &NameInfo) { |
| 5533 | AddDeclarationName(NameInfo.getName()); |
| 5534 | AddSourceLocation(NameInfo.getLoc()); |
| 5535 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName()); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5536 | } |
| 5537 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5538 | void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { |
| 5539 | AddNestedNameSpecifierLoc(Info.QualifierLoc); |
| 5540 | Record->push_back(Info.NumTemplParamLists); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5541 | for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5542 | AddTemplateParameterList(Info.TemplParamLists[i]); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5543 | } |
| 5544 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5545 | void ASTRecordWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5546 | // 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] | 5547 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5548 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5549 | |
| 5550 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5551 | while (NNS) { |
| 5552 | NestedNames.push_back(NNS); |
| 5553 | NNS = NNS->getPrefix(); |
| 5554 | } |
| 5555 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5556 | Record->push_back(NestedNames.size()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5557 | while(!NestedNames.empty()) { |
| 5558 | NNS = NestedNames.pop_back_val(); |
| 5559 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5560 | Record->push_back(Kind); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5561 | switch (Kind) { |
| 5562 | case NestedNameSpecifier::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5563 | AddIdentifierRef(NNS->getAsIdentifier()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5564 | break; |
| 5565 | |
| 5566 | case NestedNameSpecifier::Namespace: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5567 | AddDeclRef(NNS->getAsNamespace()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5568 | break; |
| 5569 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5570 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5571 | AddDeclRef(NNS->getAsNamespaceAlias()); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5572 | break; |
| 5573 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5574 | case NestedNameSpecifier::TypeSpec: |
| 5575 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5576 | AddTypeRef(QualType(NNS->getAsType(), 0)); |
| 5577 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5578 | break; |
| 5579 | |
| 5580 | case NestedNameSpecifier::Global: |
| 5581 | // Don't need to write an associated value. |
| 5582 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5583 | |
| 5584 | case NestedNameSpecifier::Super: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5585 | AddDeclRef(NNS->getAsRecordDecl()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5586 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5587 | } |
| 5588 | } |
| 5589 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5590 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5591 | void ASTRecordWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5592 | // 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] | 5593 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5594 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5595 | |
| 5596 | // Push each of the nested-name-specifiers's onto a stack for |
| 5597 | // serialization in reverse order. |
| 5598 | while (NNS) { |
| 5599 | NestedNames.push_back(NNS); |
| 5600 | NNS = NNS.getPrefix(); |
| 5601 | } |
| 5602 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5603 | Record->push_back(NestedNames.size()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5604 | while(!NestedNames.empty()) { |
| 5605 | NNS = NestedNames.pop_back_val(); |
| 5606 | NestedNameSpecifier::SpecifierKind Kind |
| 5607 | = NNS.getNestedNameSpecifier()->getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5608 | Record->push_back(Kind); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5609 | switch (Kind) { |
| 5610 | case NestedNameSpecifier::Identifier: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5611 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier()); |
| 5612 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5613 | break; |
| 5614 | |
| 5615 | case NestedNameSpecifier::Namespace: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5616 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace()); |
| 5617 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5618 | break; |
| 5619 | |
| 5620 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5621 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias()); |
| 5622 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5623 | break; |
| 5624 | |
| 5625 | case NestedNameSpecifier::TypeSpec: |
| 5626 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5627 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5628 | AddTypeLoc(NNS.getTypeLoc()); |
| 5629 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5630 | break; |
| 5631 | |
| 5632 | case NestedNameSpecifier::Global: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5633 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5634 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5635 | |
| 5636 | case NestedNameSpecifier::Super: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5637 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl()); |
| 5638 | AddSourceRange(NNS.getLocalSourceRange()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5639 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5640 | } |
| 5641 | } |
| 5642 | } |
| 5643 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5644 | void ASTRecordWriter::AddTemplateName(TemplateName Name) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5645 | TemplateName::NameKind Kind = Name.getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5646 | Record->push_back(Kind); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5647 | switch (Kind) { |
| 5648 | case TemplateName::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5649 | AddDeclRef(Name.getAsTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5650 | break; |
| 5651 | |
| 5652 | case TemplateName::OverloadedTemplate: { |
| 5653 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5654 | Record->push_back(OvT->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5655 | for (const auto &I : *OvT) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5656 | AddDeclRef(I); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5657 | break; |
| 5658 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5659 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5660 | case TemplateName::QualifiedTemplate: { |
| 5661 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5662 | AddNestedNameSpecifier(QualT->getQualifier()); |
| 5663 | Record->push_back(QualT->hasTemplateKeyword()); |
| 5664 | AddDeclRef(QualT->getTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5665 | break; |
| 5666 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5667 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5668 | case TemplateName::DependentTemplate: { |
| 5669 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5670 | AddNestedNameSpecifier(DepT->getQualifier()); |
| 5671 | Record->push_back(DepT->isIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5672 | if (DepT->isIdentifier()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5673 | AddIdentifierRef(DepT->getIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5674 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5675 | Record->push_back(DepT->getOperator()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5676 | break; |
| 5677 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5678 | |
| 5679 | case TemplateName::SubstTemplateTemplateParm: { |
| 5680 | SubstTemplateTemplateParmStorage *subst |
| 5681 | = Name.getAsSubstTemplateTemplateParm(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5682 | AddDeclRef(subst->getParameter()); |
| 5683 | AddTemplateName(subst->getReplacement()); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5684 | break; |
| 5685 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5686 | |
| 5687 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5688 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5689 | = Name.getAsSubstTemplateTemplateParmPack(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5690 | AddDeclRef(SubstPack->getParameterPack()); |
| 5691 | AddTemplateArgument(SubstPack->getArgumentPack()); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5692 | break; |
| 5693 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5694 | } |
| 5695 | } |
| 5696 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5697 | void ASTRecordWriter::AddTemplateArgument(const TemplateArgument &Arg) { |
| 5698 | Record->push_back(Arg.getKind()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5699 | switch (Arg.getKind()) { |
| 5700 | case TemplateArgument::Null: |
| 5701 | break; |
| 5702 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5703 | AddTypeRef(Arg.getAsType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5704 | break; |
| 5705 | case TemplateArgument::Declaration: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5706 | AddDeclRef(Arg.getAsDecl()); |
| 5707 | AddTypeRef(Arg.getParamTypeForDecl()); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5708 | break; |
| 5709 | case TemplateArgument::NullPtr: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5710 | AddTypeRef(Arg.getNullPtrType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5711 | break; |
| 5712 | case TemplateArgument::Integral: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5713 | AddAPSInt(Arg.getAsIntegral()); |
| 5714 | AddTypeRef(Arg.getIntegralType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5715 | break; |
| 5716 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5717 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5718 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5719 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5720 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5721 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5722 | Record->push_back(*NumExpansions + 1); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5723 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5724 | Record->push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5725 | break; |
| 5726 | case TemplateArgument::Expression: |
| 5727 | AddStmt(Arg.getAsExpr()); |
| 5728 | break; |
| 5729 | case TemplateArgument::Pack: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5730 | Record->push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 5731 | for (const auto &P : Arg.pack_elements()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5732 | AddTemplateArgument(P); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5733 | break; |
| 5734 | } |
| 5735 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5736 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5737 | void ASTRecordWriter::AddTemplateParameterList( |
| 5738 | const TemplateParameterList *TemplateParams) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5739 | assert(TemplateParams && "No TemplateParams!"); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5740 | AddSourceLocation(TemplateParams->getTemplateLoc()); |
| 5741 | AddSourceLocation(TemplateParams->getLAngleLoc()); |
| 5742 | AddSourceLocation(TemplateParams->getRAngleLoc()); |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 5743 | // TODO: Concepts |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5744 | Record->push_back(TemplateParams->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5745 | for (const auto &P : *TemplateParams) |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5746 | AddDeclRef(P); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | /// \brief Emit a template argument list. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5750 | void ASTRecordWriter::AddTemplateArgumentList( |
| 5751 | const TemplateArgumentList *TemplateArgs) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5752 | assert(TemplateArgs && "No TemplateArgs!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5753 | Record->push_back(TemplateArgs->size()); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5754 | for (int i = 0, e = TemplateArgs->size(); i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5755 | AddTemplateArgument(TemplateArgs->get(i)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5756 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5757 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5758 | void ASTRecordWriter::AddASTTemplateArgumentListInfo( |
| 5759 | const ASTTemplateArgumentListInfo *ASTTemplArgList) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5760 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5761 | AddSourceLocation(ASTTemplArgList->LAngleLoc); |
| 5762 | AddSourceLocation(ASTTemplArgList->RAngleLoc); |
| 5763 | Record->push_back(ASTTemplArgList->NumTemplateArgs); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5764 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5765 | for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5766 | AddTemplateArgumentLoc(TemplArgs[i]); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5767 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5768 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5769 | void ASTRecordWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set) { |
| 5770 | Record->push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5771 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5772 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5773 | AddDeclRef(I.getDecl()); |
| 5774 | Record->push_back(I.getAccess()); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5775 | } |
| 5776 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5777 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5778 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5779 | void ASTRecordWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base) { |
| 5780 | Record->push_back(Base.isVirtual()); |
| 5781 | Record->push_back(Base.isBaseOfClass()); |
| 5782 | Record->push_back(Base.getAccessSpecifierAsWritten()); |
| 5783 | Record->push_back(Base.getInheritConstructors()); |
| 5784 | AddTypeSourceInfo(Base.getTypeSourceInfo()); |
| 5785 | AddSourceRange(Base.getSourceRange()); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5786 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5787 | : SourceLocation()); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5788 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5789 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5790 | static uint64_t EmitCXXBaseSpecifiers(ASTWriter &W, |
| 5791 | ArrayRef<CXXBaseSpecifier> Bases) { |
| 5792 | ASTWriter::RecordData Record; |
| 5793 | ASTRecordWriter Writer(W, Record); |
| 5794 | Writer.push_back(Bases.size()); |
Dmitry Polukhin | 790b540 | 2016-04-06 10:01:46 +0000 | [diff] [blame] | 5795 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5796 | for (auto &Base : Bases) |
| 5797 | Writer.AddCXXBaseSpecifier(Base); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5798 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5799 | return Writer.Emit(serialization::DECL_CXX_BASE_SPECIFIERS); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5800 | } |
| 5801 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5802 | // FIXME: Move this out of the main ASTRecordWriter interface. |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5803 | void ASTRecordWriter::AddCXXBaseSpecifiers(ArrayRef<CXXBaseSpecifier> Bases) { |
| 5804 | AddOffset(EmitCXXBaseSpecifiers(*Writer, Bases)); |
| 5805 | } |
| 5806 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5807 | static uint64_t |
| 5808 | EmitCXXCtorInitializers(ASTWriter &W, |
| 5809 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 5810 | ASTWriter::RecordData Record; |
| 5811 | ASTRecordWriter Writer(W, Record); |
| 5812 | Writer.push_back(CtorInits.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5813 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5814 | for (auto *Init : CtorInits) { |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5815 | if (Init->isBaseInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5816 | Writer.push_back(CTOR_INITIALIZER_BASE); |
| 5817 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
| 5818 | Writer.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5819 | } else if (Init->isDelegatingInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5820 | Writer.push_back(CTOR_INITIALIZER_DELEGATING); |
| 5821 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5822 | } else if (Init->isMemberInitializer()){ |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5823 | Writer.push_back(CTOR_INITIALIZER_MEMBER); |
| 5824 | Writer.AddDeclRef(Init->getMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5825 | } else { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5826 | Writer.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 5827 | Writer.AddDeclRef(Init->getIndirectMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5828 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5829 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5830 | Writer.AddSourceLocation(Init->getMemberLocation()); |
| 5831 | Writer.AddStmt(Init->getInit()); |
| 5832 | Writer.AddSourceLocation(Init->getLParenLoc()); |
| 5833 | Writer.AddSourceLocation(Init->getRParenLoc()); |
| 5834 | Writer.push_back(Init->isWritten()); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 5835 | if (Init->isWritten()) |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5836 | Writer.push_back(Init->getSourceOrder()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5837 | } |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5838 | |
| 5839 | return Writer.Emit(serialization::DECL_CXX_CTOR_INITIALIZERS); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5842 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5843 | void ASTRecordWriter::AddCXXCtorInitializers( |
| 5844 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 5845 | AddOffset(EmitCXXCtorInitializers(*Writer, CtorInits)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5846 | } |
| 5847 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5848 | void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5849 | auto &Data = D->data(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5850 | Record->push_back(Data.IsLambda); |
| 5851 | Record->push_back(Data.UserDeclaredConstructor); |
| 5852 | Record->push_back(Data.UserDeclaredSpecialMembers); |
| 5853 | Record->push_back(Data.Aggregate); |
| 5854 | Record->push_back(Data.PlainOldData); |
| 5855 | Record->push_back(Data.Empty); |
| 5856 | Record->push_back(Data.Polymorphic); |
| 5857 | Record->push_back(Data.Abstract); |
| 5858 | Record->push_back(Data.IsStandardLayout); |
| 5859 | Record->push_back(Data.HasNoNonEmptyBases); |
| 5860 | Record->push_back(Data.HasPrivateFields); |
| 5861 | Record->push_back(Data.HasProtectedFields); |
| 5862 | Record->push_back(Data.HasPublicFields); |
| 5863 | Record->push_back(Data.HasMutableFields); |
| 5864 | Record->push_back(Data.HasVariantMembers); |
| 5865 | Record->push_back(Data.HasOnlyCMembers); |
| 5866 | Record->push_back(Data.HasInClassInitializer); |
| 5867 | Record->push_back(Data.HasUninitializedReferenceMember); |
| 5868 | Record->push_back(Data.HasUninitializedFields); |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 5869 | Record->push_back(Data.HasInheritedConstructor); |
| 5870 | Record->push_back(Data.HasInheritedAssignment); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5871 | Record->push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 5872 | Record->push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 5873 | Record->push_back(Data.NeedOverloadResolutionForDestructor); |
| 5874 | Record->push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 5875 | Record->push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 5876 | Record->push_back(Data.DefaultedDestructorIsDeleted); |
| 5877 | Record->push_back(Data.HasTrivialSpecialMembers); |
| 5878 | Record->push_back(Data.DeclaredNonTrivialSpecialMembers); |
| 5879 | Record->push_back(Data.HasIrrelevantDestructor); |
| 5880 | Record->push_back(Data.HasConstexprNonCopyMoveConstructor); |
| 5881 | Record->push_back(Data.HasDefaultedDefaultConstructor); |
| 5882 | Record->push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
| 5883 | Record->push_back(Data.HasConstexprDefaultConstructor); |
| 5884 | Record->push_back(Data.HasNonLiteralTypeFieldsOrBases); |
| 5885 | Record->push_back(Data.ComputedVisibleConversions); |
| 5886 | Record->push_back(Data.UserProvidedDefaultConstructor); |
| 5887 | Record->push_back(Data.DeclaredSpecialMembers); |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 5888 | Record->push_back(Data.ImplicitCopyConstructorCanHaveConstParamForVBase); |
| 5889 | Record->push_back(Data.ImplicitCopyConstructorCanHaveConstParamForNonVBase); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5890 | Record->push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 5891 | Record->push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 5892 | Record->push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 5893 | |
| 5894 | // getODRHash will compute the ODRHash if it has not been previously computed. |
| 5895 | Record->push_back(D->getODRHash()); |
David Blaikie | f63556d | 2017-04-12 20:58:33 +0000 | [diff] [blame] | 5896 | bool ModulesDebugInfo = Writer->Context->getLangOpts().ModulesDebugInfo && |
| 5897 | Writer->WritingModule && !D->isDependentType(); |
| 5898 | Record->push_back(ModulesDebugInfo); |
| 5899 | if (ModulesDebugInfo) |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 5900 | Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(D)); |
| 5901 | |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5902 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5903 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5904 | Record->push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5905 | if (Data.NumBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5906 | AddCXXBaseSpecifiers(Data.bases()); |
| 5907 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5908 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5909 | Record->push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5910 | if (Data.NumVBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5911 | AddCXXBaseSpecifiers(Data.vbases()); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5912 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5913 | AddUnresolvedSet(Data.Conversions.get(*Writer->Context)); |
| 5914 | AddUnresolvedSet(Data.VisibleConversions.get(*Writer->Context)); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5915 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5916 | AddDeclRef(D->getFirstFriend()); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5917 | |
| 5918 | // Add lambda-specific data. |
| 5919 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5920 | auto &Lambda = D->getLambdaData(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5921 | Record->push_back(Lambda.Dependent); |
| 5922 | Record->push_back(Lambda.IsGenericLambda); |
| 5923 | Record->push_back(Lambda.CaptureDefault); |
| 5924 | Record->push_back(Lambda.NumCaptures); |
| 5925 | Record->push_back(Lambda.NumExplicitCaptures); |
| 5926 | Record->push_back(Lambda.ManglingNumber); |
Richard Smith | 0bae624 | 2016-08-25 00:34:00 +0000 | [diff] [blame] | 5927 | AddDeclRef(D->getLambdaContextDecl()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5928 | AddTypeSourceInfo(Lambda.MethodTyInfo); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5929 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 5930 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5931 | AddSourceLocation(Capture.getLocation()); |
| 5932 | Record->push_back(Capture.isImplicit()); |
| 5933 | Record->push_back(Capture.getCaptureKind()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5934 | switch (Capture.getCaptureKind()) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 5935 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5936 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 5937 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5938 | break; |
| 5939 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 5940 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5941 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5942 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5943 | AddDeclRef(Var); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5944 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5945 | : SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5946 | break; |
| 5947 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5948 | } |
| 5949 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5950 | } |
| 5951 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5952 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5953 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5954 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5955 | assert(FirstDeclID == NextDeclID && |
| 5956 | FirstTypeID == NextTypeID && |
| 5957 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5958 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5959 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5960 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5961 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5962 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5963 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5964 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 5965 | // Note, this will get called multiple times, once one the reader starts up |
| 5966 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5967 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 5968 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 5969 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5970 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5971 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5972 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5973 | NextDeclID = FirstDeclID; |
| 5974 | NextTypeID = FirstTypeID; |
| 5975 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5976 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5977 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5978 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5979 | } |
| 5980 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5981 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5982 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5983 | IdentID &StoredID = IdentifierIDs[II]; |
| 5984 | if (ID > StoredID) |
| 5985 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5988 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5989 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5990 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5991 | if (ID > StoredID) |
| 5992 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5993 | } |
| 5994 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5995 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5996 | // Always take the highest-numbered type index. This copes with an interesting |
| 5997 | // 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] | 5998 | // 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] | 5999 | // keep the higher-numbered entry so that we can properly write it out to |
| 6000 | // the AST file. |
| 6001 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 6002 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 6003 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 6004 | } |
| 6005 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 6006 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 6007 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 6008 | SelectorID &StoredID = SelectorIDs[S]; |
| 6009 | if (ID > StoredID) |
| 6010 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 6011 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 6012 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 6013 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 6014 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 6015 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 6016 | MacroDefinitions[MD] = ID; |
| 6017 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6018 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 6019 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 6020 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 6021 | SubmoduleIDs[Mod] = ID; |
| 6022 | } |
| 6023 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6024 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6025 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 6026 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6027 | assert(!WritingAST && "Already writing the AST!"); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 6028 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6029 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6030 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6031 | // A forward reference was mutated into a definition. Rewrite it. |
| 6032 | // FIXME: This happens during template instantiation, should we |
| 6033 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6034 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 6035 | "completed a tag from another module but not by instantiation?"); |
| 6036 | DeclUpdates[RD].push_back( |
| 6037 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6038 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6039 | } |
| 6040 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6041 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6042 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { |
| 6043 | if (D->isFromASTFile()) |
| 6044 | return true; |
| 6045 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6046 | // The predefined __va_list_tag struct is imported if we imported any decls. |
| 6047 | // FIXME: This is a gross hack. |
| 6048 | return D == D->getASTContext().getVaListTagDecl(); |
| 6049 | } |
| 6050 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6051 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6052 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
| 6053 | assert(DC->isLookupContext() && |
Vassil Vassilev | 71eafde | 2016-04-06 20:56:03 +0000 | [diff] [blame] | 6054 | "Should not add lookup results to non-lookup contexts!"); |
| 6055 | |
Vassil Vassilev | 632eac3 | 2016-03-16 11:17:04 +0000 | [diff] [blame] | 6056 | // TU is handled elsewhere. |
| 6057 | if (isa<TranslationUnitDecl>(DC)) |
| 6058 | return; |
| 6059 | |
| 6060 | // Namespaces are handled elsewhere, except for template instantiations of |
| 6061 | // FunctionTemplateDecls in namespaces. We are interested in cases where the |
| 6062 | // local instantiations are added to an imported context. Only happens when |
| 6063 | // adding ADL lookup candidates, for example templated friends. |
| 6064 | if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && |
| 6065 | !isa<FunctionTemplateDecl>(D)) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6066 | return; |
| 6067 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6068 | // We're only interested in cases where a local declaration is added to an |
| 6069 | // imported context. |
| 6070 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) |
| 6071 | return; |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6072 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 6073 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 6074 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 6075 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6076 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { |
| 6077 | // We're adding a visible declaration to a predefined decl context. Ensure |
| 6078 | // that we write out all of its lookup results so we don't get a nasty |
| 6079 | // surprise when we try to emit its lookup table. |
| 6080 | for (auto *Child : DC->decls()) |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6081 | DeclsToEmitEvenIfUnreferenced.push_back(Child); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6082 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6083 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6084 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6085 | |
| 6086 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6087 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6088 | assert(D->isImplicit()); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6089 | |
| 6090 | // We're only interested in cases where a local declaration is added to an |
| 6091 | // imported context. |
| 6092 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) |
| 6093 | return; |
| 6094 | |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6095 | if (!isa<CXXMethodDecl>(D)) |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6096 | return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6097 | |
| 6098 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 6099 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 6100 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 6101 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6102 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 6103 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6104 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6105 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6106 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 6107 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6108 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6109 | // If we don't already know the exception specification for this redecl |
| 6110 | // chain, add an update record for it. |
| 6111 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 6112 | ->getType() |
| 6113 | ->castAs<FunctionProtoType>() |
| 6114 | ->getExceptionSpecType())) |
| 6115 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 6116 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6117 | } |
| 6118 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 6119 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6120 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 6121 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6122 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6123 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6124 | DeclUpdates[D].push_back( |
| 6125 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 6126 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 6129 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
| 6130 | const FunctionDecl *Delete) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6131 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 6132 | assert(!WritingAST && "Already writing the AST!"); |
| 6133 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6134 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6135 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6136 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 6137 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 6138 | } |
| 6139 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 6140 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6141 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6142 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6143 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 6144 | return; // Declaration not imported from PCH. |
| 6145 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 6146 | // Implicit function decl from a PCH was defined. |
| 6147 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 6148 | } |
| 6149 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 6150 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6151 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 6152 | assert(!WritingAST && "Already writing the AST!"); |
| 6153 | if (!D->isFromASTFile()) |
| 6154 | return; |
| 6155 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6156 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 6157 | } |
| 6158 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 6159 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6160 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6161 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6162 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 6163 | return; |
| 6164 | |
| 6165 | // Since the actual instantiation is delayed, this really means that we need |
| 6166 | // to update the instantiation location. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 6167 | DeclUpdates[D].push_back( |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 6168 | DeclUpdate(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER, |
| 6169 | D->getMemberSpecializationInfo()->getPointOfInstantiation())); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 6170 | } |
| 6171 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 6172 | void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6173 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 6174 | assert(!WritingAST && "Already writing the AST!"); |
| 6175 | if (!D->isFromASTFile()) |
| 6176 | return; |
| 6177 | |
| 6178 | DeclUpdates[D].push_back( |
| 6179 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D)); |
| 6180 | } |
| 6181 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 6182 | void ASTWriter::DefaultMemberInitializerInstantiated(const FieldDecl *D) { |
| 6183 | assert(!WritingAST && "Already writing the AST!"); |
| 6184 | if (!D->isFromASTFile()) |
| 6185 | return; |
| 6186 | |
| 6187 | DeclUpdates[D].push_back( |
| 6188 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER, D)); |
| 6189 | } |
| 6190 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 6191 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 6192 | const ObjCInterfaceDecl *IFD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6193 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6194 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6195 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 6196 | return; // Declaration not imported from PCH. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 6197 | |
| 6198 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 6199 | ObjCClassesWithCategories.insert( |
| 6200 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 6201 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 6202 | |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6203 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6204 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6205 | assert(!WritingAST && "Already writing the AST!"); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 6206 | |
| 6207 | // If there is *any* declaration of the entity that's not from an AST file, |
| 6208 | // we can skip writing the update record. We make sure that isUsed() triggers |
| 6209 | // completion of the redeclaration chain of the entity. |
| 6210 | for (auto Prev = D->getMostRecentDecl(); Prev; Prev = Prev->getPreviousDecl()) |
| 6211 | if (IsLocalDecl(Prev)) |
| 6212 | return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6213 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 6214 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6215 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 6216 | |
| 6217 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6218 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 6219 | assert(!WritingAST && "Already writing the AST!"); |
| 6220 | if (!D->isFromASTFile()) |
| 6221 | return; |
| 6222 | |
| 6223 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 6224 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6225 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 6226 | void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, |
| 6227 | const Attr *Attr) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6228 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 6229 | assert(!WritingAST && "Already writing the AST!"); |
| 6230 | if (!D->isFromASTFile()) |
| 6231 | return; |
| 6232 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 6233 | DeclUpdates[D].push_back( |
| 6234 | DeclUpdate(UPD_DECL_MARKED_OPENMP_DECLARETARGET, Attr)); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 6235 | } |
| 6236 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6237 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6238 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6239 | assert(!WritingAST && "Already writing the AST!"); |
| 6240 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6241 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6242 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6243 | |
| 6244 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 6245 | const RecordDecl *Record) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6246 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6247 | assert(!WritingAST && "Already writing the AST!"); |
| 6248 | if (!Record->isFromASTFile()) |
| 6249 | return; |
| 6250 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 6251 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6252 | |
| 6253 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6254 | const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) { |
| 6255 | assert(!WritingAST && "Already writing the AST!"); |
| 6256 | |
| 6257 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6258 | return; |
| 6259 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6260 | return; |
| 6261 | |
| 6262 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6263 | } |
| 6264 | |
| 6265 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6266 | const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) { |
| 6267 | assert(!WritingAST && "Already writing the AST!"); |
| 6268 | |
| 6269 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6270 | return; |
| 6271 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6272 | return; |
| 6273 | |
| 6274 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6275 | } |
| 6276 | |
| 6277 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 6278 | const FunctionDecl *D) { |
| 6279 | assert(!WritingAST && "Already writing the AST!"); |
| 6280 | |
| 6281 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6282 | return; |
| 6283 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6284 | return; |
| 6285 | |
| 6286 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6287 | } |