Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1 | //===- ASTWriter.cpp - AST File Writer ------------------------------------===// |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 10 | // This file defines the ASTWriter class, which writes AST files. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sebastian Redl | 1914c6f | 2010-08-18 23:56:37 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTWriter.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" |
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" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 20 | #include "clang/AST/Attr.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 21 | #include "clang/AST/Decl.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclBase.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclContextInternals.h" |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclFriend.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclObjC.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclTemplate.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclarationName.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 29 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 30 | #include "clang/AST/ExprCXX.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 31 | #include "clang/AST/LambdaCapture.h" |
| 32 | #include "clang/AST/NestedNameSpecifier.h" |
| 33 | #include "clang/AST/RawCommentList.h" |
| 34 | #include "clang/AST/TemplateName.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 35 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 36 | #include "clang/AST/TypeLocVisitor.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 37 | #include "clang/Basic/Diagnostic.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 38 | #include "clang/Basic/DiagnosticOptions.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 39 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 40 | #include "clang/Basic/FileSystemOptions.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 41 | #include "clang/Basic/IdentifierTable.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 42 | #include "clang/Basic/LLVM.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 43 | #include "clang/Basic/Lambda.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 44 | #include "clang/Basic/LangOptions.h" |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 45 | #include "clang/Basic/MemoryBufferCache.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 46 | #include "clang/Basic/Module.h" |
| 47 | #include "clang/Basic/ObjCRuntime.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 48 | #include "clang/Basic/OpenCLOptions.h" |
| 49 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 50 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 51 | #include "clang/Basic/SourceManagerInternals.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 52 | #include "clang/Basic/Specifiers.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 53 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | cb177f1 | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 54 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 55 | #include "clang/Basic/Version.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 56 | #include "clang/Lex/HeaderSearch.h" |
| 57 | #include "clang/Lex/HeaderSearchOptions.h" |
| 58 | #include "clang/Lex/MacroInfo.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 59 | #include "clang/Lex/ModuleMap.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 60 | #include "clang/Lex/PreprocessingRecord.h" |
| 61 | #include "clang/Lex/Preprocessor.h" |
| 62 | #include "clang/Lex/PreprocessorOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 63 | #include "clang/Lex/Token.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 64 | #include "clang/Sema/IdentifierResolver.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 65 | #include "clang/Sema/ObjCMethodList.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 66 | #include "clang/Sema/Sema.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 67 | #include "clang/Sema/Weak.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 68 | #include "clang/Serialization/ASTReader.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 69 | #include "clang/Serialization/Module.h" |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 70 | #include "clang/Serialization/ModuleFileExtension.h" |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 71 | #include "clang/Serialization/SerializationDiagnostic.h" |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 72 | #include "llvm/ADT/APFloat.h" |
| 73 | #include "llvm/ADT/APInt.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 74 | #include "llvm/ADT/APSInt.h" |
| 75 | #include "llvm/ADT/ArrayRef.h" |
| 76 | #include "llvm/ADT/DenseMap.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 77 | #include "llvm/ADT/Hashing.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 78 | #include "llvm/ADT/Optional.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 79 | #include "llvm/ADT/PointerIntPair.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 80 | #include "llvm/ADT/STLExtras.h" |
Ilya Biryukov | 4564310 | 2018-07-09 11:33:23 +0000 | [diff] [blame] | 81 | #include "llvm/ADT/ScopeExit.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 82 | #include "llvm/ADT/SmallSet.h" |
| 83 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 84 | #include "llvm/ADT/SmallVector.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 85 | #include "llvm/ADT/StringMap.h" |
| 86 | #include "llvm/ADT/StringRef.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 87 | #include "llvm/Bitcode/BitCodes.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 88 | #include "llvm/Bitcode/BitstreamWriter.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 89 | #include "llvm/Support/Casting.h" |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 90 | #include "llvm/Support/Compression.h" |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 91 | #include "llvm/Support/DJB.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 92 | #include "llvm/Support/Endian.h" |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 93 | #include "llvm/Support/EndianStream.h" |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 94 | #include "llvm/Support/Error.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 95 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 96 | #include "llvm/Support/MemoryBuffer.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 97 | #include "llvm/Support/OnDiskHashTable.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 98 | #include "llvm/Support/Path.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 99 | #include "llvm/Support/SHA1.h" |
Pavel Labath | d8c6290 | 2018-06-11 10:28:04 +0000 | [diff] [blame] | 100 | #include "llvm/Support/VersionTuple.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 101 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 102 | #include <algorithm> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 103 | #include <cassert> |
| 104 | #include <cstdint> |
| 105 | #include <cstdlib> |
| 106 | #include <cstring> |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 107 | #include <ctime> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 108 | #include <deque> |
| 109 | #include <limits> |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 110 | #include <memory> |
| 111 | #include <queue> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 112 | #include <tuple> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 113 | #include <utility> |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 114 | #include <vector> |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 115 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 116 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 117 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 118 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 119 | template <typename T, typename Allocator> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 120 | static StringRef bytes(const std::vector<T, Allocator> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 121 | if (v.empty()) return StringRef(); |
| 122 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 123 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 124 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 125 | |
| 126 | template <typename T> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 127 | static StringRef bytes(const SmallVectorImpl<T> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 128 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 129 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 132 | //===----------------------------------------------------------------------===// |
| 133 | // Type serialization |
| 134 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 135 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 136 | namespace clang { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 137 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 138 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 139 | ASTWriter &Writer; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 140 | ASTRecordWriter Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 141 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 142 | /// Type code that corresponds to the record generated. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 143 | TypeCode Code = static_cast<TypeCode>(0); |
| 144 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 145 | /// Abbreviation to use for the record, if any. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 146 | unsigned AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 147 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 148 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 149 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 150 | : Writer(Writer), Record(Writer, Record) {} |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 151 | |
| 152 | uint64_t Emit() { |
| 153 | return Record.Emit(Code, AbbrevToUse); |
| 154 | } |
| 155 | |
| 156 | void Visit(QualType T) { |
| 157 | if (T.hasLocalNonFastQualifiers()) { |
| 158 | Qualifiers Qs = T.getLocalQualifiers(); |
| 159 | Record.AddTypeRef(T.getLocalUnqualifiedType()); |
| 160 | Record.push_back(Qs.getAsOpaqueValue()); |
| 161 | Code = TYPE_EXT_QUAL; |
| 162 | AbbrevToUse = Writer.TypeExtQualAbbrev; |
| 163 | } else { |
| 164 | switch (T->getTypeClass()) { |
| 165 | // For all of the concrete, non-dependent types, call the |
| 166 | // appropriate visitor function. |
| 167 | #define TYPE(Class, Base) \ |
| 168 | case Type::Class: Visit##Class##Type(cast<Class##Type>(T)); break; |
| 169 | #define ABSTRACT_TYPE(Class, Base) |
| 170 | #include "clang/AST/TypeNodes.def" |
| 171 | } |
| 172 | } |
| 173 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 174 | |
| 175 | void VisitArrayType(const ArrayType *T); |
| 176 | void VisitFunctionType(const FunctionType *T); |
| 177 | void VisitTagType(const TagType *T); |
| 178 | |
| 179 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 180 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 181 | #include "clang/AST/TypeNodes.def" |
| 182 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 183 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 184 | } // namespace clang |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 185 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 186 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 187 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 190 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 191 | Record.AddTypeRef(T->getElementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 192 | Code = TYPE_COMPLEX; |
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::VisitPointerType(const PointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 196 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 197 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 200 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 201 | Record.AddTypeRef(T->getOriginalType()); |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 202 | Code = TYPE_DECAYED; |
| 203 | } |
| 204 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 205 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 206 | Record.AddTypeRef(T->getOriginalType()); |
| 207 | Record.AddTypeRef(T->getAdjustedType()); |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 208 | Code = TYPE_ADJUSTED; |
| 209 | } |
| 210 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 211 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 212 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 213 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 216 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 217 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 218 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 219 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 222 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 223 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 224 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 227 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 228 | Record.AddTypeRef(T->getPointeeType()); |
| 229 | Record.AddTypeRef(QualType(T->getClass(), 0)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 230 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 233 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 234 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 235 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 236 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 239 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 240 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 241 | Record.AddAPInt(T->getSize()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 242 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 245 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 246 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 247 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 250 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 251 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 252 | Record.AddSourceLocation(T->getLBracketLoc()); |
| 253 | Record.AddSourceLocation(T->getRBracketLoc()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 254 | Record.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 255 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 258 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 259 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 260 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 261 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 262 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 265 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 266 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 267 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 270 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 271 | Record.AddTypeRef(T->getReturnType()); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 272 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 273 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 274 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 275 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 276 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 277 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 278 | Record.push_back(C.getProducesResult()); |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 279 | Record.push_back(C.getNoCallerSavedRegs()); |
Oren Ben Simhon | 220671a | 2018-03-17 13:31:35 +0000 | [diff] [blame] | 280 | Record.push_back(C.getNoCfCheck()); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 281 | |
| 282 | if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult()) |
| 283 | AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 286 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 287 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 288 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 291 | static void addExceptionSpec(const FunctionProtoType *T, |
| 292 | ASTRecordWriter &Record) { |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 293 | Record.push_back(T->getExceptionSpecType()); |
| 294 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 295 | Record.push_back(T->getNumExceptions()); |
| 296 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 297 | Record.AddTypeRef(T->getExceptionType(I)); |
Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 298 | } else if (isComputedNoexcept(T->getExceptionSpecType())) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 299 | Record.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 300 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 301 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
| 302 | Record.AddDeclRef(T->getExceptionSpecTemplate()); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 303 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 304 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 305 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 309 | VisitFunctionType(T); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 310 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 311 | Record.push_back(T->isVariadic()); |
| 312 | Record.push_back(T->hasTrailingReturn()); |
| 313 | Record.push_back(T->getTypeQuals()); |
| 314 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 315 | addExceptionSpec(T, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 316 | |
| 317 | Record.push_back(T->getNumParams()); |
| 318 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 319 | Record.AddTypeRef(T->getParamType(I)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 320 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 321 | if (T->hasExtParameterInfos()) { |
| 322 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 323 | Record.push_back(T->getExtParameterInfo(I).getOpaqueValue()); |
| 324 | } |
| 325 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 326 | if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 327 | T->getRefQualifier() || T->getExceptionSpecType() != EST_None || |
| 328 | T->hasExtParameterInfos()) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 329 | AbbrevToUse = 0; |
| 330 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 331 | Code = TYPE_FUNCTION_PROTO; |
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::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 335 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 336 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 337 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 338 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 339 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 340 | Record.AddDeclRef(T->getDecl()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 341 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 342 | Record.AddTypeRef(T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 343 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 346 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 347 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 348 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 351 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 352 | Record.AddTypeRef(T->getUnderlyingType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 353 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 356 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 357 | Record.AddTypeRef(T->getUnderlyingType()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 358 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 359 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 362 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 363 | Record.AddTypeRef(T->getBaseType()); |
| 364 | Record.AddTypeRef(T->getUnderlyingType()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 365 | Record.push_back(T->getUTTKind()); |
| 366 | Code = TYPE_UNARY_TRANSFORM; |
| 367 | } |
| 368 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 369 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 370 | Record.AddTypeRef(T->getDeducedType()); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 371 | Record.push_back((unsigned)T->getKeyword()); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 372 | if (T->getDeducedType().isNull()) |
| 373 | Record.push_back(T->isDependentType()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 374 | Code = TYPE_AUTO; |
| 375 | } |
| 376 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 377 | void ASTTypeWriter::VisitDeducedTemplateSpecializationType( |
| 378 | const DeducedTemplateSpecializationType *T) { |
| 379 | Record.AddTemplateName(T->getTemplateName()); |
| 380 | Record.AddTypeRef(T->getDeducedType()); |
| 381 | if (T->getDeducedType().isNull()) |
| 382 | Record.push_back(T->isDependentType()); |
| 383 | Code = TYPE_DEDUCED_TEMPLATE_SPECIALIZATION; |
| 384 | } |
| 385 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 386 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 387 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 388 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 390 | "Cannot serialize in the middle of a type definition"); |
| 391 | } |
| 392 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 393 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 394 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 395 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 398 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 399 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 400 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 401 | } |
| 402 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 403 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 404 | Record.AddTypeRef(T->getModifiedType()); |
| 405 | Record.AddTypeRef(T->getEquivalentType()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 406 | Record.push_back(T->getAttrKind()); |
| 407 | Code = TYPE_ATTRIBUTED; |
| 408 | } |
| 409 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 410 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 411 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 412 | const SubstTemplateTypeParmType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 413 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 414 | Record.AddTypeRef(T->getReplacementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 415 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 419 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 420 | const SubstTemplateTypeParmPackType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 421 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 422 | Record.AddTemplateArgument(T->getArgumentPack()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 423 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 424 | } |
| 425 | |
| 426 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 427 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 428 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 429 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 430 | Record.AddTemplateName(T->getTemplateName()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 431 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 432 | for (const auto &ArgI : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 433 | Record.AddTemplateArgument(ArgI); |
| 434 | Record.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() |
| 435 | : T->isCanonicalUnqualified() |
| 436 | ? QualType() |
| 437 | : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 438 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 442 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 443 | VisitArrayType(T); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 444 | Record.AddStmt(T->getSizeExpr()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 445 | Record.AddSourceRange(T->getBracketsRange()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 446 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 450 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 451 | const DependentSizedExtVectorType *T) { |
Alex Lorenz | 00aee43 | 2017-03-22 10:04:48 +0000 | [diff] [blame] | 452 | Record.AddTypeRef(T->getElementType()); |
| 453 | Record.AddStmt(T->getSizeExpr()); |
| 454 | Record.AddSourceLocation(T->getAttributeLoc()); |
| 455 | Code = TYPE_DEPENDENT_SIZED_EXT_VECTOR; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 458 | void ASTTypeWriter::VisitDependentVectorType(const DependentVectorType *T) { |
| 459 | Record.AddTypeRef(T->getElementType()); |
| 460 | Record.AddStmt(const_cast<Expr*>(T->getSizeExpr())); |
| 461 | Record.AddSourceLocation(T->getAttributeLoc()); |
| 462 | Record.push_back(T->getVectorKind()); |
| 463 | Code = TYPE_DEPENDENT_SIZED_VECTOR; |
| 464 | } |
| 465 | |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 466 | void |
Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 467 | ASTTypeWriter::VisitDependentAddressSpaceType( |
| 468 | const DependentAddressSpaceType *T) { |
| 469 | Record.AddTypeRef(T->getPointeeType()); |
| 470 | Record.AddStmt(T->getAddrSpaceExpr()); |
| 471 | Record.AddSourceLocation(T->getAttributeLoc()); |
| 472 | Code = TYPE_DEPENDENT_ADDRESS_SPACE; |
| 473 | } |
| 474 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 475 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 476 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 477 | Record.push_back(T->getDepth()); |
| 478 | Record.push_back(T->getIndex()); |
| 479 | Record.push_back(T->isParameterPack()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 480 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 481 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 485 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 486 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 487 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 488 | Record.AddIdentifierRef(T->getIdentifier()); |
| 489 | Record.AddTypeRef( |
| 490 | T->isCanonicalUnqualified() ? QualType() : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 491 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 495 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 496 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 497 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 498 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 499 | Record.AddIdentifierRef(T->getIdentifier()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 500 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 501 | for (const auto &I : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 502 | Record.AddTemplateArgument(I); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 503 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 506 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 507 | Record.AddTypeRef(T->getPattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 508 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 509 | Record.push_back(*NumExpansions + 1); |
| 510 | else |
| 511 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 512 | Code = TYPE_PACK_EXPANSION; |
| 513 | } |
| 514 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 515 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 516 | Record.AddTypeRef(T->getInnerType()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 517 | Code = TYPE_PAREN; |
| 518 | } |
| 519 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 520 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 521 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 522 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 523 | Record.AddTypeRef(T->getNamedType()); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 524 | Record.AddDeclRef(T->getOwnedTagDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 525 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 528 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 529 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
| 530 | Record.AddTypeRef(T->getInjectedSpecializationType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 531 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 534 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 535 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 536 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 539 | void ASTTypeWriter::VisitObjCTypeParamType(const ObjCTypeParamType *T) { |
| 540 | Record.AddDeclRef(T->getDecl()); |
| 541 | Record.push_back(T->getNumProtocols()); |
| 542 | for (const auto *I : T->quals()) |
| 543 | Record.AddDeclRef(I); |
| 544 | Code = TYPE_OBJC_TYPE_PARAM; |
| 545 | } |
| 546 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 547 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 548 | Record.AddTypeRef(T->getBaseType()); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 549 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 550 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 551 | Record.AddTypeRef(TypeArg); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 552 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 553 | for (const auto *I : T->quals()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 554 | Record.AddDeclRef(I); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 555 | Record.push_back(T->isKindOfTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 556 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 559 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 560 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 561 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 562 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 565 | void |
| 566 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 567 | Record.AddTypeRef(T->getValueType()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 568 | Code = TYPE_ATOMIC; |
| 569 | } |
| 570 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 571 | void |
| 572 | ASTTypeWriter::VisitPipeType(const PipeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 573 | Record.AddTypeRef(T->getElementType()); |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 574 | Record.push_back(T->isReadOnly()); |
| 575 | Code = TYPE_PIPE; |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 576 | } |
| 577 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 578 | namespace { |
| 579 | |
| 580 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 581 | ASTRecordWriter &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 582 | |
| 583 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 584 | TypeLocWriter(ASTRecordWriter &Record) : Record(Record) {} |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 585 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 586 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 587 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 588 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 589 | #include "clang/AST/TypeLocNodes.def" |
| 590 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 591 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 592 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 593 | }; |
| 594 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 595 | } // namespace |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 596 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 597 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 598 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 599 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 600 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 601 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 602 | Record.AddSourceLocation(TL.getBuiltinLoc()); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 603 | if (TL.needsExtraLocalData()) { |
Faisal Vali | 090da2d | 2018-01-01 18:23:28 +0000 | [diff] [blame] | 604 | Record.push_back(TL.getWrittenTypeSpec()); |
| 605 | Record.push_back(TL.getWrittenSignSpec()); |
| 606 | Record.push_back(TL.getWrittenWidthSpec()); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 607 | Record.push_back(TL.hasModeAttr()); |
| 608 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 609 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 610 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 611 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 612 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 613 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 614 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 615 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 616 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 617 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 618 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 619 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 620 | // nothing to do |
| 621 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 622 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 623 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 624 | // nothing to do |
| 625 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 626 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 627 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 628 | Record.AddSourceLocation(TL.getCaretLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 629 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 630 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 631 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 632 | Record.AddSourceLocation(TL.getAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +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::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 636 | Record.AddSourceLocation(TL.getAmpAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +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::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 640 | Record.AddSourceLocation(TL.getStarLoc()); |
| 641 | Record.AddTypeSourceInfo(TL.getClassTInfo()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 642 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 643 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 644 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 645 | Record.AddSourceLocation(TL.getLBracketLoc()); |
| 646 | Record.AddSourceLocation(TL.getRBracketLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 647 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 648 | if (TL.getSizeExpr()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 649 | Record.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 650 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 651 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 652 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 653 | VisitArrayTypeLoc(TL); |
| 654 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 655 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 656 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 657 | VisitArrayTypeLoc(TL); |
| 658 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 659 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 660 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 661 | VisitArrayTypeLoc(TL); |
| 662 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 663 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 664 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 665 | DependentSizedArrayTypeLoc TL) { |
| 666 | VisitArrayTypeLoc(TL); |
| 667 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 668 | |
Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 669 | void TypeLocWriter::VisitDependentAddressSpaceTypeLoc( |
| 670 | DependentAddressSpaceTypeLoc TL) { |
| 671 | Record.AddSourceLocation(TL.getAttrNameLoc()); |
| 672 | SourceRange range = TL.getAttrOperandParensRange(); |
| 673 | Record.AddSourceLocation(range.getBegin()); |
| 674 | Record.AddSourceLocation(range.getEnd()); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 675 | Record.AddStmt(TL.getAttrExprOperand()); |
Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 676 | } |
| 677 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 678 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 679 | DependentSizedExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 680 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 681 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 682 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 683 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 684 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 685 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 686 | |
Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 687 | void TypeLocWriter::VisitDependentVectorTypeLoc( |
| 688 | DependentVectorTypeLoc TL) { |
| 689 | Record.AddSourceLocation(TL.getNameLoc()); |
| 690 | } |
| 691 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 692 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 693 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 694 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 695 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 696 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 697 | Record.AddSourceLocation(TL.getLocalRangeBegin()); |
| 698 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 699 | Record.AddSourceLocation(TL.getRParenLoc()); |
Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 700 | Record.AddSourceRange(TL.getExceptionSpecRange()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 701 | Record.AddSourceLocation(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 702 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 703 | Record.AddDeclRef(TL.getParam(i)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 704 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 705 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 706 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 707 | VisitFunctionTypeLoc(TL); |
| 708 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 709 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 710 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 711 | VisitFunctionTypeLoc(TL); |
| 712 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 713 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 714 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 715 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 716 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 717 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 718 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 719 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 720 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 721 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 722 | void TypeLocWriter::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 723 | if (TL.getNumProtocols()) { |
| 724 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 725 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
| 726 | } |
| 727 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 728 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
| 729 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 730 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 731 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 732 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 733 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 734 | Record.AddSourceLocation(TL.getRParenLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 735 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 736 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 737 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 738 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 739 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 740 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 741 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 742 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 743 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 744 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 745 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 746 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 747 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 748 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 749 | Record.AddSourceLocation(TL.getKWLoc()); |
| 750 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 751 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 752 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 753 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 754 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 755 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 756 | Record.AddSourceLocation(TL.getNameLoc()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 757 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 758 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 759 | void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc( |
| 760 | DeducedTemplateSpecializationTypeLoc TL) { |
| 761 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 762 | } |
| 763 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 764 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 765 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 766 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 767 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 768 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 769 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 770 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 771 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 772 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 773 | Record.AddAttr(TL.getAttr()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 774 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 775 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 776 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 777 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 778 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 779 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 780 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 781 | SubstTemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 782 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 783 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 784 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 785 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 786 | SubstTemplateTypeParmPackTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 787 | Record.AddSourceLocation(TL.getNameLoc()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 788 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 789 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 790 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 791 | TemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 792 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 793 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 794 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 795 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 796 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 797 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 798 | TL.getArgLoc(i).getLocInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 799 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 800 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 801 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 802 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 803 | Record.AddSourceLocation(TL.getRParenLoc()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 804 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 805 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 806 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 807 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 808 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 809 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 810 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 811 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 812 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 813 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 814 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 815 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 816 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 817 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 818 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 819 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 820 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 821 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 822 | DependentTemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 823 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 824 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 825 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 826 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 827 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 828 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 829 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 830 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 831 | TL.getArgLoc(I).getLocInfo()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 832 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 833 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 834 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 835 | Record.AddSourceLocation(TL.getEllipsisLoc()); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 836 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 837 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 838 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 839 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 840 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 841 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 842 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 843 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 844 | Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); |
| 845 | Record.AddSourceLocation(TL.getTypeArgsRAngleLoc()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 846 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 847 | Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i)); |
| 848 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 849 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 850 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 851 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 852 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 853 | |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 854 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 855 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 856 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 857 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 858 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 859 | Record.AddSourceLocation(TL.getKWLoc()); |
| 860 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 861 | Record.AddSourceLocation(TL.getRParenLoc()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 862 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 863 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 864 | void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 865 | Record.AddSourceLocation(TL.getKWLoc()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 866 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 867 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 868 | void ASTWriter::WriteTypeAbbrevs() { |
| 869 | using namespace llvm; |
| 870 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 871 | std::shared_ptr<BitCodeAbbrev> Abv; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 872 | |
| 873 | // Abbreviation for TYPE_EXT_QUAL |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 874 | Abv = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 875 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 876 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 877 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 878 | TypeExtQualAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 879 | |
| 880 | // Abbreviation for TYPE_FUNCTION_PROTO |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 881 | Abv = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 882 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 883 | // FunctionType |
| 884 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 885 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 886 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 887 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 888 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 889 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 890 | Abv->Add(BitCodeAbbrevOp(0)); // NoCallerSavedRegs |
Oren Ben Simhon | 220671a | 2018-03-17 13:31:35 +0000 | [diff] [blame] | 891 | Abv->Add(BitCodeAbbrevOp(0)); // NoCfCheck |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 892 | // FunctionProtoType |
| 893 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 894 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 895 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 896 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 897 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 898 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 899 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 900 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 901 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 904 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 905 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 906 | //===----------------------------------------------------------------------===// |
| 907 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 908 | static void EmitBlockID(unsigned ID, const char *Name, |
| 909 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 910 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 911 | Record.clear(); |
| 912 | Record.push_back(ID); |
| 913 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 914 | |
| 915 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 916 | if (!Name || Name[0] == 0) |
| 917 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 918 | Record.clear(); |
| 919 | while (*Name) |
| 920 | Record.push_back(*Name++); |
| 921 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 922 | } |
| 923 | |
| 924 | static void EmitRecordID(unsigned ID, const char *Name, |
| 925 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 926 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 927 | Record.clear(); |
| 928 | Record.push_back(ID); |
| 929 | while (*Name) |
| 930 | Record.push_back(*Name++); |
| 931 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 935 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 936 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 937 | RECORD(STMT_STOP); |
| 938 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 939 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 940 | RECORD(STMT_NULL); |
| 941 | RECORD(STMT_COMPOUND); |
| 942 | RECORD(STMT_CASE); |
| 943 | RECORD(STMT_DEFAULT); |
| 944 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 945 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 946 | RECORD(STMT_IF); |
| 947 | RECORD(STMT_SWITCH); |
| 948 | RECORD(STMT_WHILE); |
| 949 | RECORD(STMT_DO); |
| 950 | RECORD(STMT_FOR); |
| 951 | RECORD(STMT_GOTO); |
| 952 | RECORD(STMT_INDIRECT_GOTO); |
| 953 | RECORD(STMT_CONTINUE); |
| 954 | RECORD(STMT_BREAK); |
| 955 | RECORD(STMT_RETURN); |
| 956 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 957 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 958 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 959 | RECORD(EXPR_PREDEFINED); |
| 960 | RECORD(EXPR_DECL_REF); |
| 961 | RECORD(EXPR_INTEGER_LITERAL); |
| 962 | RECORD(EXPR_FLOATING_LITERAL); |
| 963 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 964 | RECORD(EXPR_STRING_LITERAL); |
| 965 | RECORD(EXPR_CHARACTER_LITERAL); |
| 966 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 967 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 968 | RECORD(EXPR_UNARY_OPERATOR); |
| 969 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 970 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 971 | RECORD(EXPR_CALL); |
| 972 | RECORD(EXPR_MEMBER); |
| 973 | RECORD(EXPR_BINARY_OPERATOR); |
| 974 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 975 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 976 | RECORD(EXPR_IMPLICIT_CAST); |
| 977 | RECORD(EXPR_CSTYLE_CAST); |
| 978 | RECORD(EXPR_COMPOUND_LITERAL); |
| 979 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 980 | RECORD(EXPR_INIT_LIST); |
| 981 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 982 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 983 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 984 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 985 | RECORD(EXPR_VA_ARG); |
| 986 | RECORD(EXPR_ADDR_LABEL); |
| 987 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 988 | RECORD(EXPR_CHOOSE); |
| 989 | RECORD(EXPR_GNU_NULL); |
| 990 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 991 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 992 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 993 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 994 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 995 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 996 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 997 | RECORD(EXPR_OBJC_ENCODE); |
| 998 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 999 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 1000 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 1001 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 1002 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 1003 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 1004 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 1005 | RECORD(STMT_OBJC_CATCH); |
| 1006 | RECORD(STMT_OBJC_FINALLY); |
| 1007 | RECORD(STMT_OBJC_AT_TRY); |
| 1008 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 1009 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1010 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1011 | RECORD(STMT_CXX_CATCH); |
| 1012 | RECORD(STMT_CXX_TRY); |
| 1013 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1014 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1015 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1016 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1017 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1018 | RECORD(EXPR_CXX_STATIC_CAST); |
| 1019 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 1020 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 1021 | RECORD(EXPR_CXX_CONST_CAST); |
| 1022 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 1023 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 1024 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1025 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 1026 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1027 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 1028 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1029 | RECORD(EXPR_CXX_THIS); |
| 1030 | RECORD(EXPR_CXX_THROW); |
| 1031 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1032 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1033 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 1034 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 1035 | RECORD(EXPR_CXX_NEW); |
| 1036 | RECORD(EXPR_CXX_DELETE); |
| 1037 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 1038 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 1039 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 1040 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 1041 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 1042 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 1043 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1044 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1045 | RECORD(EXPR_CXX_NOEXCEPT); |
| 1046 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1047 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 1048 | RECORD(EXPR_TYPE_TRAIT); |
| 1049 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1050 | RECORD(EXPR_PACK_EXPANSION); |
| 1051 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1052 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1053 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1054 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 1055 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1056 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1057 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 1058 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 1059 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 1060 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1063 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1064 | RecordData Record; |
Peter Collingbourne | d3a6c70 | 2016-11-01 01:18:57 +0000 | [diff] [blame] | 1065 | Stream.EnterBlockInfoBlock(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1067 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 1068 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1070 | // Control Block. |
| 1071 | BLOCK(CONTROL_BLOCK); |
| 1072 | RECORD(METADATA); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1073 | RECORD(MODULE_NAME); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1074 | RECORD(MODULE_DIRECTORY); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1075 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1076 | RECORD(IMPORTS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1077 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1078 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1079 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1080 | RECORD(INPUT_FILE_OFFSETS); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1081 | |
| 1082 | BLOCK(OPTIONS_BLOCK); |
| 1083 | RECORD(LANGUAGE_OPTIONS); |
| 1084 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1085 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1086 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1087 | RECORD(PREPROCESSOR_OPTIONS); |
| 1088 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 1089 | BLOCK(INPUT_FILES_BLOCK); |
| 1090 | RECORD(INPUT_FILE); |
| 1091 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1092 | // AST Top-Level Block. |
| 1093 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1094 | RECORD(TYPE_OFFSET); |
| 1095 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1096 | RECORD(IDENTIFIER_OFFSET); |
| 1097 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 1098 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 1099 | RECORD(MODULAR_CODEGEN_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1100 | RECORD(SPECIAL_TYPES); |
| 1101 | RECORD(STATISTICS); |
| 1102 | RECORD(TENTATIVE_DEFINITIONS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1103 | RECORD(SELECTOR_OFFSETS); |
| 1104 | RECORD(METHOD_POOL); |
| 1105 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1106 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 1107 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1108 | RECORD(EXT_VECTOR_DECLS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1109 | RECORD(UNUSED_FILESCOPED_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1110 | RECORD(PPD_ENTITIES_OFFSETS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1111 | RECORD(VTABLE_USES); |
Cameron Desrochers | b60f1b6 | 2018-01-15 19:14:16 +0000 | [diff] [blame] | 1112 | RECORD(PPD_SKIPPED_RANGES); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 1113 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1114 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1115 | RECORD(SEMA_DECL_REFS); |
| 1116 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 1117 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1118 | RECORD(UPDATE_VISIBLE); |
| 1119 | RECORD(DECL_UPDATE_OFFSETS); |
| 1120 | RECORD(DECL_UPDATES); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1121 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1122 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1123 | RECORD(FP_PRAGMA_OPTIONS); |
| 1124 | RECORD(OPENCL_EXTENSIONS); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 1125 | RECORD(OPENCL_EXTENSION_TYPES); |
| 1126 | RECORD(OPENCL_EXTENSION_DECLS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1127 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 1128 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 1129 | RECORD(MODULE_OFFSET_MAP); |
| 1130 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1131 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 1132 | RECORD(FILE_SORTED_DECLS); |
| 1133 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1134 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1135 | RECORD(MACRO_OFFSET); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1136 | RECORD(INTERESTING_IDENTIFIERS); |
| 1137 | RECORD(UNDEFINED_BUT_USED); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1138 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 1139 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 1140 | RECORD(MSSTRUCT_PRAGMA_OPTIONS); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 1141 | RECORD(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1142 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1143 | RECORD(DELETE_EXPRS_TO_ANALYZE); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 1144 | RECORD(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH); |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 1145 | RECORD(PP_CONDITIONAL_STACK); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 1146 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1147 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1148 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1149 | RECORD(SM_SLOC_FILE_ENTRY); |
| 1150 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 1151 | RECORD(SM_SLOC_BUFFER_BLOB); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1152 | RECORD(SM_SLOC_BUFFER_BLOB_COMPRESSED); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1153 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1154 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1155 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1156 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1157 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1158 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1159 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 1160 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1161 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1162 | |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1163 | // Submodule Block. |
| 1164 | BLOCK(SUBMODULE_BLOCK); |
| 1165 | RECORD(SUBMODULE_METADATA); |
| 1166 | RECORD(SUBMODULE_DEFINITION); |
| 1167 | RECORD(SUBMODULE_UMBRELLA_HEADER); |
| 1168 | RECORD(SUBMODULE_HEADER); |
| 1169 | RECORD(SUBMODULE_TOPHEADER); |
| 1170 | RECORD(SUBMODULE_UMBRELLA_DIR); |
| 1171 | RECORD(SUBMODULE_IMPORTS); |
| 1172 | RECORD(SUBMODULE_EXPORTS); |
| 1173 | RECORD(SUBMODULE_REQUIRES); |
| 1174 | RECORD(SUBMODULE_EXCLUDED_HEADER); |
| 1175 | RECORD(SUBMODULE_LINK_LIBRARY); |
| 1176 | RECORD(SUBMODULE_CONFIG_MACRO); |
| 1177 | RECORD(SUBMODULE_CONFLICT); |
| 1178 | RECORD(SUBMODULE_PRIVATE_HEADER); |
| 1179 | RECORD(SUBMODULE_TEXTUAL_HEADER); |
| 1180 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 1181 | RECORD(SUBMODULE_INITIALIZERS); |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 1182 | RECORD(SUBMODULE_EXPORT_AS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1183 | |
| 1184 | // Comments Block. |
| 1185 | BLOCK(COMMENTS_BLOCK); |
| 1186 | RECORD(COMMENTS_RAW_COMMENT); |
| 1187 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1188 | // Decls and Types block. |
| 1189 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1190 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1191 | RECORD(TYPE_COMPLEX); |
| 1192 | RECORD(TYPE_POINTER); |
| 1193 | RECORD(TYPE_BLOCK_POINTER); |
| 1194 | RECORD(TYPE_LVALUE_REFERENCE); |
| 1195 | RECORD(TYPE_RVALUE_REFERENCE); |
| 1196 | RECORD(TYPE_MEMBER_POINTER); |
| 1197 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1198 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1199 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1200 | RECORD(TYPE_VECTOR); |
| 1201 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1202 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1203 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1204 | RECORD(TYPE_TYPEDEF); |
| 1205 | RECORD(TYPE_TYPEOF_EXPR); |
| 1206 | RECORD(TYPE_TYPEOF); |
| 1207 | RECORD(TYPE_RECORD); |
| 1208 | RECORD(TYPE_ENUM); |
| 1209 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1210 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1211 | RECORD(TYPE_DECLTYPE); |
| 1212 | RECORD(TYPE_ELABORATED); |
| 1213 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 1214 | RECORD(TYPE_UNRESOLVED_USING); |
| 1215 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 1216 | RECORD(TYPE_OBJC_OBJECT); |
| 1217 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 1218 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 1219 | RECORD(TYPE_DEPENDENT_NAME); |
| 1220 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 1221 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 1222 | RECORD(TYPE_PAREN); |
| 1223 | RECORD(TYPE_PACK_EXPANSION); |
| 1224 | RECORD(TYPE_ATTRIBUTED); |
| 1225 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1226 | RECORD(TYPE_AUTO); |
| 1227 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1228 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1229 | RECORD(TYPE_DECAYED); |
| 1230 | RECORD(TYPE_ADJUSTED); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 1231 | RECORD(TYPE_OBJC_TYPE_PARAM); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 1232 | RECORD(LOCAL_REDECLARATIONS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1233 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1234 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1235 | RECORD(DECL_ENUM); |
| 1236 | RECORD(DECL_RECORD); |
| 1237 | RECORD(DECL_ENUM_CONSTANT); |
| 1238 | RECORD(DECL_FUNCTION); |
| 1239 | RECORD(DECL_OBJC_METHOD); |
| 1240 | RECORD(DECL_OBJC_INTERFACE); |
| 1241 | RECORD(DECL_OBJC_PROTOCOL); |
| 1242 | RECORD(DECL_OBJC_IVAR); |
| 1243 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1244 | RECORD(DECL_OBJC_CATEGORY); |
| 1245 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1246 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1247 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1248 | RECORD(DECL_OBJC_PROPERTY); |
| 1249 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1250 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1251 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1252 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1253 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1254 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1255 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1256 | RECORD(DECL_BLOCK); |
| 1257 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1258 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1259 | RECORD(DECL_NAMESPACE); |
| 1260 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1261 | RECORD(DECL_USING); |
| 1262 | RECORD(DECL_USING_SHADOW); |
| 1263 | RECORD(DECL_USING_DIRECTIVE); |
| 1264 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1265 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1266 | RECORD(DECL_LINKAGE_SPEC); |
| 1267 | RECORD(DECL_CXX_RECORD); |
| 1268 | RECORD(DECL_CXX_METHOD); |
| 1269 | RECORD(DECL_CXX_CONSTRUCTOR); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1270 | RECORD(DECL_CXX_INHERITED_CONSTRUCTOR); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1271 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1272 | RECORD(DECL_CXX_CONVERSION); |
| 1273 | RECORD(DECL_ACCESS_SPEC); |
| 1274 | RECORD(DECL_FRIEND); |
| 1275 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1276 | RECORD(DECL_CLASS_TEMPLATE); |
| 1277 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1278 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1279 | RECORD(DECL_VAR_TEMPLATE); |
| 1280 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1281 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1282 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1283 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1284 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1285 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1286 | RECORD(DECL_TYPE_ALIAS_TEMPLATE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1287 | RECORD(DECL_STATIC_ASSERT); |
| 1288 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1289 | RECORD(DECL_CXX_CTOR_INITIALIZERS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1290 | RECORD(DECL_INDIRECTFIELD); |
| 1291 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1292 | RECORD(DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK); |
| 1293 | RECORD(DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION); |
| 1294 | RECORD(DECL_IMPORT); |
| 1295 | RECORD(DECL_OMP_THREADPRIVATE); |
| 1296 | RECORD(DECL_EMPTY); |
| 1297 | RECORD(DECL_OBJC_TYPE_PARAM); |
| 1298 | RECORD(DECL_OMP_CAPTUREDEXPR); |
| 1299 | RECORD(DECL_PRAGMA_COMMENT); |
| 1300 | RECORD(DECL_PRAGMA_DETECT_MISMATCH); |
| 1301 | RECORD(DECL_OMP_DECLARE_REDUCTION); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1302 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1303 | // Statements and Exprs can occur in the Decls and Types block. |
| 1304 | AddStmtsExprs(Stream, Record); |
| 1305 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1306 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1307 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1308 | RECORD(PPD_MACRO_DEFINITION); |
| 1309 | RECORD(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 1310 | |
| 1311 | // Decls and Types block. |
| 1312 | BLOCK(EXTENSION_BLOCK); |
| 1313 | RECORD(EXTENSION_METADATA); |
| 1314 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1315 | BLOCK(UNHASHED_CONTROL_BLOCK); |
| 1316 | RECORD(SIGNATURE); |
| 1317 | RECORD(DIAGNOSTIC_OPTIONS); |
| 1318 | RECORD(DIAG_PRAGMA_MAPPINGS); |
| 1319 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1320 | #undef RECORD |
| 1321 | #undef BLOCK |
| 1322 | Stream.ExitBlock(); |
| 1323 | } |
| 1324 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1325 | /// Prepares a path for being written to an AST file by converting it |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1326 | /// to an absolute path and removing nested './'s. |
| 1327 | /// |
| 1328 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1329 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1330 | SmallVectorImpl<char> &Path) { |
Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 1331 | bool Changed = FileMgr.makeAbsolutePath(Path); |
Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame] | 1332 | return Changed | llvm::sys::path::remove_dots(Path); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1335 | /// Adjusts the given filename to only write out the portion of the |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1336 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1337 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1338 | /// \param Filename the file name to adjust. |
| 1339 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1340 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1341 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1342 | /// |
| 1343 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1344 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1345 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1346 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1347 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1349 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1350 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1351 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1352 | // Verify that the filename and the system root have the same prefix. |
| 1353 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1354 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1355 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1356 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1358 | // We hit the end of the filename before we hit the end of the system root. |
| 1359 | if (!Filename[Pos]) |
| 1360 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1361 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1362 | // If there's not a path separator at the end of the base directory nor |
| 1363 | // immediately after it, then this isn't within the base directory. |
| 1364 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1365 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1366 | return Filename; |
| 1367 | } else { |
| 1368 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1369 | // We distinguish relative paths from absolute paths by the |
| 1370 | // absence of '/' at the beginning of relative paths. |
| 1371 | // |
| 1372 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1373 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1374 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1375 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1376 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1377 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1379 | return Filename + Pos; |
| 1380 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1381 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1382 | ASTFileSignature ASTWriter::createSignature(StringRef Bytes) { |
| 1383 | // Calculate the hash till start of UNHASHED_CONTROL_BLOCK. |
| 1384 | llvm::SHA1 Hasher; |
| 1385 | Hasher.update(ArrayRef<uint8_t>(Bytes.bytes_begin(), Bytes.size())); |
| 1386 | auto Hash = Hasher.result(); |
| 1387 | |
| 1388 | // Convert to an array [5*i32]. |
| 1389 | ASTFileSignature Signature; |
| 1390 | auto LShift = [&](unsigned char Val, unsigned Shift) { |
| 1391 | return (uint32_t)Val << Shift; |
| 1392 | }; |
| 1393 | for (int I = 0; I != 5; ++I) |
| 1394 | Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) | |
| 1395 | LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0); |
| 1396 | |
| 1397 | return Signature; |
| 1398 | } |
| 1399 | |
| 1400 | ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP, |
| 1401 | ASTContext &Context) { |
| 1402 | // Flush first to prepare the PCM hash (signature). |
| 1403 | Stream.FlushToWord(); |
| 1404 | auto StartOfUnhashedControl = Stream.GetCurrentBitNo() >> 3; |
| 1405 | |
| 1406 | // Enter the block and prepare to write records. |
| 1407 | RecordData Record; |
| 1408 | Stream.EnterSubblock(UNHASHED_CONTROL_BLOCK_ID, 5); |
| 1409 | |
| 1410 | // For implicit modules, write the hash of the PCM as its signature. |
| 1411 | ASTFileSignature Signature; |
| 1412 | if (WritingModule && |
| 1413 | PP.getHeaderSearchInfo().getHeaderSearchOpts().ModulesHashContent) { |
| 1414 | Signature = createSignature(StringRef(Buffer.begin(), StartOfUnhashedControl)); |
| 1415 | Record.append(Signature.begin(), Signature.end()); |
| 1416 | Stream.EmitRecord(SIGNATURE, Record); |
| 1417 | Record.clear(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1418 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1419 | |
| 1420 | // Diagnostic options. |
| 1421 | const auto &Diags = Context.getDiagnostics(); |
| 1422 | const DiagnosticOptions &DiagOpts = Diags.getDiagnosticOptions(); |
| 1423 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1424 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1425 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1426 | #include "clang/Basic/DiagnosticOptions.def" |
| 1427 | Record.push_back(DiagOpts.Warnings.size()); |
| 1428 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1429 | AddString(DiagOpts.Warnings[I], Record); |
| 1430 | Record.push_back(DiagOpts.Remarks.size()); |
| 1431 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1432 | AddString(DiagOpts.Remarks[I], Record); |
| 1433 | // Note: we don't serialize the log or serialization file names, because they |
| 1434 | // are generally transient files and will almost always be overridden. |
| 1435 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1436 | |
| 1437 | // Write out the diagnostic/pragma mappings. |
| 1438 | WritePragmaDiagnosticMappings(Diags, /* IsModule = */ WritingModule); |
| 1439 | |
| 1440 | // Leave the options block. |
| 1441 | Stream.ExitBlock(); |
| 1442 | return Signature; |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1445 | /// Write the control block. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1446 | void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, |
| 1447 | StringRef isysroot, |
| 1448 | const std::string &OutputFile) { |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1449 | using namespace llvm; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1450 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1451 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1452 | RecordData Record; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1453 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1454 | // Metadata |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1455 | auto MetadataAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1456 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1457 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1458 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1459 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1460 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1461 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1462 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps |
Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 1463 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PCHHasObjectFile |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1464 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1465 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1466 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(std::move(MetadataAbbrev)); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1467 | assert((!WritingModule || isysroot.empty()) && |
| 1468 | "writing module as a relocatable PCH?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1469 | { |
Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 1470 | RecordData::value_type Record[] = { |
| 1471 | METADATA, |
| 1472 | VERSION_MAJOR, |
| 1473 | VERSION_MINOR, |
| 1474 | CLANG_VERSION_MAJOR, |
| 1475 | CLANG_VERSION_MINOR, |
| 1476 | !isysroot.empty(), |
| 1477 | IncludeTimestamps, |
| 1478 | Context.getLangOpts().BuildingPCHWithObjectFile, |
| 1479 | ASTHasCompilerErrors}; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1480 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1481 | getClangFullRepositoryVersion()); |
| 1482 | } |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1483 | |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 1484 | if (WritingModule) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1485 | // Module name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1486 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1487 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1488 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1489 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1490 | RecordData::value_type Record[] = {MODULE_NAME}; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1491 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1492 | } |
| 1493 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1494 | if (WritingModule && WritingModule->Directory) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1495 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1496 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1497 | |
| 1498 | // If the home of the module is the current working directory, then we |
| 1499 | // want to pick up the cwd of the build process loading the module, not |
| 1500 | // our cwd, when we load this module. |
| 1501 | if (!PP.getHeaderSearchInfo() |
| 1502 | .getHeaderSearchOpts() |
| 1503 | .ModuleMapFileHomeIsCwd || |
| 1504 | WritingModule->Directory->getName() != StringRef(".")) { |
| 1505 | // Module directory. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1506 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1507 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1508 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1509 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1510 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1511 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1512 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1513 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1514 | |
| 1515 | // Write out all other paths relative to the base directory if possible. |
| 1516 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1517 | } else if (!isysroot.empty()) { |
| 1518 | // Write out paths relative to the sysroot if possible. |
| 1519 | BaseDirectory = isysroot; |
| 1520 | } |
| 1521 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1522 | // Module map file |
Richard Smith | d19389a | 2017-07-05 07:47:11 +0000 | [diff] [blame] | 1523 | if (WritingModule && WritingModule->Kind == Module::ModuleMapModule) { |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1524 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1525 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1526 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 1527 | AddPath(WritingModule->PresumedModuleMapFile.empty() |
| 1528 | ? Map.getModuleMapFileForUniquing(WritingModule)->getName() |
| 1529 | : StringRef(WritingModule->PresumedModuleMapFile), |
| 1530 | Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1531 | |
| 1532 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1533 | if (auto *AdditionalModMaps = |
| 1534 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1535 | Record.push_back(AdditionalModMaps->size()); |
| 1536 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1537 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1538 | } else { |
| 1539 | Record.push_back(0); |
| 1540 | } |
| 1541 | |
| 1542 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1545 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1546 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1547 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1548 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1549 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1550 | for (ModuleFile &M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1551 | // Skip modules that weren't directly imported. |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1552 | if (!M.isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1553 | continue; |
| 1554 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1555 | Record.push_back((unsigned)M.Kind); // FIXME: Stable encoding |
| 1556 | AddSourceLocation(M.ImportLoc, Record); |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1557 | |
| 1558 | // If we have calculated signature, there is no need to store |
| 1559 | // the size or timestamp. |
| 1560 | Record.push_back(M.Signature ? 0 : M.File->getSize()); |
| 1561 | Record.push_back(M.Signature ? 0 : getTimestampForOutput(M.File)); |
| 1562 | |
| 1563 | for (auto I : M.Signature) |
| 1564 | Record.push_back(I); |
| 1565 | |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 1566 | AddString(M.ModuleName, Record); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1567 | AddPath(M.FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1568 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1569 | Stream.EmitRecord(IMPORTS, Record); |
| 1570 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1571 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1572 | // Write the options block. |
| 1573 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); |
| 1574 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1575 | // Language options. |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1576 | Record.clear(); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1577 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1578 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1579 | Record.push_back(LangOpts.Name); |
| 1580 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1581 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1582 | #include "clang/Basic/LangOptions.def" |
| 1583 | #define SANITIZER(NAME, ID) \ |
| 1584 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1585 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1586 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1587 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1588 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1589 | AddString(Feature, Record); |
| 1590 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1591 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1592 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1593 | |
| 1594 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1595 | |
| 1596 | // Comment options. |
| 1597 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1598 | for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) { |
| 1599 | AddString(I, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1600 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1601 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1602 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1603 | // OpenMP offloading options. |
| 1604 | Record.push_back(LangOpts.OMPTargetTriples.size()); |
| 1605 | for (auto &T : LangOpts.OMPTargetTriples) |
| 1606 | AddString(T.getTriple(), Record); |
| 1607 | |
| 1608 | AddString(LangOpts.OMPHostIRFile, Record); |
| 1609 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1610 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1611 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1612 | // Target options. |
| 1613 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1614 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1615 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1616 | AddString(TargetOpts.Triple, Record); |
| 1617 | AddString(TargetOpts.CPU, Record); |
| 1618 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1619 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1620 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1621 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1622 | } |
| 1623 | Record.push_back(TargetOpts.Features.size()); |
| 1624 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1625 | AddString(TargetOpts.Features[I], Record); |
| 1626 | } |
| 1627 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1628 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1629 | // File system options. |
| 1630 | Record.clear(); |
Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1631 | const FileSystemOptions &FSOpts = |
| 1632 | Context.getSourceManager().getFileManager().getFileSystemOpts(); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1633 | AddString(FSOpts.WorkingDir, Record); |
| 1634 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1635 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1636 | // Header search options. |
| 1637 | Record.clear(); |
| 1638 | const HeaderSearchOptions &HSOpts |
| 1639 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1640 | AddString(HSOpts.Sysroot, Record); |
| 1641 | |
| 1642 | // Include entries. |
| 1643 | Record.push_back(HSOpts.UserEntries.size()); |
| 1644 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1645 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1646 | AddString(Entry.Path, Record); |
| 1647 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1648 | Record.push_back(Entry.IsFramework); |
| 1649 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | // System header prefixes. |
| 1653 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1654 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1655 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1656 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1657 | } |
| 1658 | |
| 1659 | AddString(HSOpts.ResourceDir, Record); |
| 1660 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1661 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1662 | Record.push_back(HSOpts.DisableModuleHash); |
Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 1663 | Record.push_back(HSOpts.ImplicitModuleMaps); |
| 1664 | Record.push_back(HSOpts.ModuleMapFileHomeIsCwd); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1665 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1666 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1667 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1668 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1669 | // Write out the specific module cache path that contains the module files. |
| 1670 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1671 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1672 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1673 | // Preprocessor options. |
| 1674 | Record.clear(); |
| 1675 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1676 | |
| 1677 | // Macro definitions. |
| 1678 | Record.push_back(PPOpts.Macros.size()); |
| 1679 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1680 | AddString(PPOpts.Macros[I].first, Record); |
| 1681 | Record.push_back(PPOpts.Macros[I].second); |
| 1682 | } |
| 1683 | |
| 1684 | // Includes |
| 1685 | Record.push_back(PPOpts.Includes.size()); |
| 1686 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1687 | AddString(PPOpts.Includes[I], Record); |
| 1688 | |
| 1689 | // Macro includes |
| 1690 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1691 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1692 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1693 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1694 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1695 | // Detailed record is important since it is used for the module cache hash. |
| 1696 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1697 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1698 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1699 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1700 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1701 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1702 | // Leave the options block. |
| 1703 | Stream.ExitBlock(); |
| 1704 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1705 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1706 | SourceManager &SM = Context.getSourceManager(); |
| 1707 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1708 | auto FileAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1709 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1710 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1711 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1712 | unsigned FileAbbrevCode = Stream.EmitAbbrev(std::move(FileAbbrev)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1713 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1714 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1715 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1716 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1717 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1718 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1719 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1720 | Record.clear(); |
| 1721 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1722 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1723 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1724 | // Original PCH directory |
| 1725 | if (!OutputFile.empty() && OutputFile != "-") { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1726 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1727 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1728 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1729 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1730 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1731 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1732 | |
Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1733 | SM.getFileManager().makeAbsolutePath(OutputPath); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1734 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1735 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1736 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1737 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1738 | } |
| 1739 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1740 | WriteInputFiles(Context.SourceMgr, |
| 1741 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1742 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1743 | Stream.ExitBlock(); |
| 1744 | } |
| 1745 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1746 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1747 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1748 | /// An input file. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1749 | struct InputFileEntry { |
| 1750 | const FileEntry *File; |
| 1751 | bool IsSystemFile; |
| 1752 | bool IsTransient; |
| 1753 | bool BufferOverridden; |
| 1754 | bool IsTopLevelModuleMap; |
| 1755 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1756 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1757 | } // namespace |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1758 | |
| 1759 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1760 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1761 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1762 | using namespace llvm; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1763 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1764 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1765 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1766 | // Create input-file abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1767 | auto IFAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1768 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1769 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1770 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1771 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1772 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1773 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1774 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Module map |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1775 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1776 | unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev)); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1777 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1778 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1779 | // 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] | 1780 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1781 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1782 | // Get this source location entry. |
| 1783 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1784 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1785 | |
| 1786 | // We only care about file entries that were not overridden. |
| 1787 | if (!SLoc->isFile()) |
| 1788 | continue; |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1789 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1790 | const SrcMgr::ContentCache *Cache = File.getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1791 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1792 | continue; |
| 1793 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1794 | InputFileEntry Entry; |
| 1795 | Entry.File = Cache->OrigEntry; |
| 1796 | Entry.IsSystemFile = Cache->IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1797 | Entry.IsTransient = Cache->IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1798 | Entry.BufferOverridden = Cache->BufferOverridden; |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1799 | Entry.IsTopLevelModuleMap = isModuleMap(File.getFileCharacteristic()) && |
| 1800 | File.getIncludeLoc().isInvalid(); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1801 | if (Cache->IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1802 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1803 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1804 | SortedFiles.push_front(Entry); |
| 1805 | } |
| 1806 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1807 | unsigned UserFilesNum = 0; |
| 1808 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1809 | std::vector<uint64_t> InputFileOffsets; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1810 | for (const auto &Entry : SortedFiles) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1811 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1812 | if (InputFileID != 0) |
| 1813 | continue; // already recorded this file. |
| 1814 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1815 | // Record this entry's offset. |
| 1816 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1817 | |
| 1818 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1819 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1820 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1821 | ++UserFilesNum; |
| 1822 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1823 | // Emit size/modification time for this file. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1824 | // And whether this file was overridden. |
| 1825 | RecordData::value_type Record[] = { |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1826 | INPUT_FILE, |
| 1827 | InputFileOffsets.size(), |
| 1828 | (uint64_t)Entry.File->getSize(), |
| 1829 | (uint64_t)getTimestampForOutput(Entry.File), |
| 1830 | Entry.BufferOverridden, |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1831 | Entry.IsTransient, |
| 1832 | Entry.IsTopLevelModuleMap}; |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1833 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1834 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1835 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1836 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1837 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1838 | |
| 1839 | // Create input file offsets abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1840 | auto OffsetsAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1841 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1842 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1843 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1844 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1845 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1846 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(std::move(OffsetsAbbrev)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1847 | |
| 1848 | // Write input file offsets. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1849 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, |
| 1850 | InputFileOffsets.size(), UserFilesNum}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1851 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1852 | } |
| 1853 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1854 | //===----------------------------------------------------------------------===// |
| 1855 | // Source Manager Serialization |
| 1856 | //===----------------------------------------------------------------------===// |
| 1857 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1858 | /// Create an abbreviation for the SLocEntry that refers to a |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1859 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1860 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1861 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1862 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1863 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1864 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1865 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1866 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1867 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1868 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1869 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1870 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1871 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1872 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1873 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1874 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1877 | /// Create an abbreviation for the SLocEntry that refers to a |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1878 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1879 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1880 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1881 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1882 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1883 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1884 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1885 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1886 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1887 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1888 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1889 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1892 | /// Create an abbreviation for the SLocEntry that refers to a |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1893 | /// buffer's blob. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1894 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, |
| 1895 | bool Compressed) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1896 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1897 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1898 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1899 | Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED |
| 1900 | : SM_SLOC_BUFFER_BLOB)); |
| 1901 | if (Compressed) |
| 1902 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1903 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1904 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1907 | /// Create an abbreviation for the SLocEntry that refers to a macro |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1908 | /// expansion. |
| 1909 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1910 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1911 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1912 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1913 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1914 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1915 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1916 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1917 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Richard Smith | b5f8171 | 2018-04-30 05:25:48 +0000 | [diff] [blame] | 1918 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is token range |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1919 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1920 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1923 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1924 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1925 | // Trait used for the on-disk hash table of header search information. |
| 1926 | class HeaderFileInfoTrait { |
| 1927 | ASTWriter &Writer; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1928 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1929 | // Keep track of the framework names we've used during serialization. |
| 1930 | SmallVector<char, 128> FrameworkStringData; |
| 1931 | llvm::StringMap<unsigned> FrameworkNameOffset; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1932 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1933 | public: |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1934 | HeaderFileInfoTrait(ASTWriter &Writer) : Writer(Writer) {} |
| 1935 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1936 | struct key_type { |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1937 | StringRef Filename; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1938 | off_t Size; |
| 1939 | time_t ModTime; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1940 | }; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1941 | using key_type_ref = const key_type &; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1942 | |
| 1943 | using UnresolvedModule = |
| 1944 | llvm::PointerIntPair<Module *, 2, ModuleMap::ModuleHeaderRole>; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1945 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1946 | struct data_type { |
| 1947 | const HeaderFileInfo &HFI; |
| 1948 | ArrayRef<ModuleMap::KnownHeader> KnownHeaders; |
| 1949 | UnresolvedModule Unresolved; |
| 1950 | }; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1951 | using data_type_ref = const data_type &; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1952 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1953 | using hash_value_type = unsigned; |
| 1954 | using offset_type = unsigned; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1955 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1956 | hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1957 | // The hash is based only on size/time of the file, so that the reader can |
| 1958 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1959 | // 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] | 1960 | return llvm::hash_combine(key.Size, key.ModTime); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1961 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1962 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1963 | std::pair<unsigned, unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1964 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1965 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1966 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 1967 | endian::Writer LE(Out, little); |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1968 | unsigned KeyLen = key.Filename.size() + 1 + 8 + 8; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1969 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1970 | unsigned DataLen = 1 + 2 + 4 + 4; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1971 | for (auto ModInfo : Data.KnownHeaders) |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1972 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) |
| 1973 | DataLen += 4; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1974 | if (Data.Unresolved.getPointer()) |
| 1975 | DataLen += 4; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1976 | LE.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1977 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1978 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1979 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1980 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1981 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1982 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 1983 | endian::Writer LE(Out, little); |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1984 | LE.write<uint64_t>(key.Size); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1985 | KeyLen -= 8; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1986 | LE.write<uint64_t>(key.ModTime); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1987 | KeyLen -= 8; |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1988 | Out.write(key.Filename.data(), KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1989 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1990 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1991 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1992 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1993 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1994 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 1995 | endian::Writer LE(Out, little); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1996 | uint64_t Start = Out.tell(); (void)Start; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1997 | |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1998 | unsigned char Flags = (Data.HFI.isImport << 5) |
| 1999 | | (Data.HFI.isPragmaOnce << 4) |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2000 | | (Data.HFI.DirInfo << 1) |
| 2001 | | Data.HFI.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2002 | LE.write<uint8_t>(Flags); |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2003 | LE.write<uint16_t>(Data.HFI.NumIncludes); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2004 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2005 | if (!Data.HFI.ControllingMacro) |
| 2006 | LE.write<uint32_t>(Data.HFI.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2007 | else |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2008 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.HFI.ControllingMacro)); |
| 2009 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2010 | unsigned Offset = 0; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2011 | if (!Data.HFI.Framework.empty()) { |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2012 | // If this header refers into a framework, save the framework name. |
| 2013 | llvm::StringMap<unsigned>::iterator Pos |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2014 | = FrameworkNameOffset.find(Data.HFI.Framework); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2015 | if (Pos == FrameworkNameOffset.end()) { |
| 2016 | Offset = FrameworkStringData.size() + 1; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2017 | FrameworkStringData.append(Data.HFI.Framework.begin(), |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2018 | Data.HFI.Framework.end()); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2019 | FrameworkStringData.push_back(0); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2020 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2021 | FrameworkNameOffset[Data.HFI.Framework] = Offset; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2022 | } else |
| 2023 | Offset = Pos->second; |
| 2024 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2025 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2026 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2027 | auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) { |
| 2028 | if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) { |
| 2029 | uint32_t Value = (ModID << 2) | (unsigned)Role; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2030 | assert((Value >> 2) == ModID && "overflow in header module info"); |
| 2031 | LE.write<uint32_t>(Value); |
| 2032 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2033 | }; |
| 2034 | |
| 2035 | // FIXME: If the header is excluded, we should write out some |
| 2036 | // record of that fact. |
| 2037 | for (auto ModInfo : Data.KnownHeaders) |
| 2038 | EmitModule(ModInfo.getModule(), ModInfo.getRole()); |
| 2039 | if (Data.Unresolved.getPointer()) |
| 2040 | EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt()); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2041 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2042 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 2043 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2044 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2045 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 2046 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2047 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2048 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2049 | } // namespace |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2050 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2051 | /// Write the header search block for the list of files that |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2052 | /// |
| 2053 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2054 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2055 | HeaderFileInfoTrait GeneratorTrait(*this); |
| 2056 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
| 2057 | SmallVector<const char *, 4> SavedStrings; |
| 2058 | unsigned NumHeaderSearchEntries = 0; |
| 2059 | |
| 2060 | // Find all unresolved headers for the current module. We generally will |
| 2061 | // have resolved them before we get here, but not necessarily: we might be |
| 2062 | // compiling a preprocessed module, where there is no requirement for the |
| 2063 | // original files to exist any more. |
Benjamin Kramer | ee021d5 | 2017-06-02 17:30:24 +0000 | [diff] [blame] | 2064 | const HeaderFileInfo Empty; // So we can take a reference. |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2065 | if (WritingModule) { |
| 2066 | llvm::SmallVector<Module *, 16> Worklist(1, WritingModule); |
| 2067 | while (!Worklist.empty()) { |
| 2068 | Module *M = Worklist.pop_back_val(); |
| 2069 | if (!M->isAvailable()) |
| 2070 | continue; |
| 2071 | |
| 2072 | // Map to disk files where possible, to pick up any missing stat |
| 2073 | // information. This also means we don't need to check the unresolved |
| 2074 | // headers list when emitting resolved headers in the first loop below. |
| 2075 | // FIXME: It'd be preferable to avoid doing this if we were given |
| 2076 | // sufficient stat information in the module map. |
| 2077 | HS.getModuleMap().resolveHeaderDirectives(M); |
| 2078 | |
| 2079 | // If the file didn't exist, we can still create a module if we were given |
| 2080 | // enough information in the module map. |
| 2081 | for (auto U : M->MissingHeaders) { |
| 2082 | // Check that we were given enough information to build a module |
| 2083 | // without this file existing on disk. |
| 2084 | if (!U.Size || (!U.ModTime && IncludeTimestamps)) { |
| 2085 | PP->Diag(U.FileNameLoc, diag::err_module_no_size_mtime_for_header) |
| 2086 | << WritingModule->getFullModuleName() << U.Size.hasValue() |
| 2087 | << U.FileName; |
| 2088 | continue; |
| 2089 | } |
| 2090 | |
| 2091 | // Form the effective relative pathname for the file. |
| 2092 | SmallString<128> Filename(M->Directory->getName()); |
| 2093 | llvm::sys::path::append(Filename, U.FileName); |
| 2094 | PreparePathForOutput(Filename); |
| 2095 | |
| 2096 | StringRef FilenameDup = strdup(Filename.c_str()); |
| 2097 | SavedStrings.push_back(FilenameDup.data()); |
| 2098 | |
| 2099 | HeaderFileInfoTrait::key_type Key = { |
| 2100 | FilenameDup, *U.Size, IncludeTimestamps ? *U.ModTime : 0 |
| 2101 | }; |
| 2102 | HeaderFileInfoTrait::data_type Data = { |
Benjamin Kramer | ee021d5 | 2017-06-02 17:30:24 +0000 | [diff] [blame] | 2103 | Empty, {}, {M, ModuleMap::headerKindToRole(U.Kind)} |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2104 | }; |
| 2105 | // FIXME: Deal with cases where there are multiple unresolved header |
| 2106 | // directives in different submodules for the same header. |
| 2107 | Generator.insert(Key, Data, GeneratorTrait); |
| 2108 | ++NumHeaderSearchEntries; |
| 2109 | } |
| 2110 | |
| 2111 | Worklist.append(M->submodule_begin(), M->submodule_end()); |
| 2112 | } |
| 2113 | } |
| 2114 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2115 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2116 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2117 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2118 | if (FilesByUID.size() > HS.header_file_size()) |
| 2119 | FilesByUID.resize(HS.header_file_size()); |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2120 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2121 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 2122 | const FileEntry *File = FilesByUID[UID]; |
| 2123 | if (!File) |
| 2124 | continue; |
| 2125 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2126 | // Get the file info. This will load info from the external source if |
| 2127 | // necessary. Skip emitting this file if we have no information on it |
| 2128 | // as a header file (in which case HFI will be null) or if it hasn't |
| 2129 | // changed since it was loaded. Also skip it if it's for a modular header |
| 2130 | // from a different module; in that case, we rely on the module(s) |
| 2131 | // containing the header to provide this information. |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 2132 | const HeaderFileInfo *HFI = |
| 2133 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); |
| 2134 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 2135 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2136 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2137 | // Massage the file path into an appropriate form. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 2138 | StringRef Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2139 | SmallString<128> FilenameTmp(Filename); |
| 2140 | if (PreparePathForOutput(FilenameTmp)) { |
| 2141 | // If we performed any translation on the file name at all, we need to |
| 2142 | // save this string, since the generator will refer to it later. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 2143 | Filename = StringRef(strdup(FilenameTmp.c_str())); |
| 2144 | SavedStrings.push_back(Filename.data()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2145 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2146 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2147 | HeaderFileInfoTrait::key_type Key = { |
| 2148 | Filename, File->getSize(), getTimestampForOutput(File) |
| 2149 | }; |
| 2150 | HeaderFileInfoTrait::data_type Data = { |
| 2151 | *HFI, HS.getModuleMap().findAllModulesForHeader(File), {} |
| 2152 | }; |
| 2153 | Generator.insert(Key, Data, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2154 | ++NumHeaderSearchEntries; |
| 2155 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2156 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2157 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2158 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2159 | uint32_t BucketOffset; |
| 2160 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2161 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2162 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2163 | llvm::raw_svector_ostream Out(TableData); |
| 2164 | // Make sure that no bucket is at offset 0 |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 2165 | endian::write<uint32_t>(Out, 0, little); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2166 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 2167 | } |
| 2168 | |
| 2169 | // Create a blob abbreviation |
| 2170 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2171 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2172 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2173 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 2174 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 2175 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2176 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2177 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2178 | unsigned TableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2179 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2180 | // Write the header search table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2181 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, |
| 2182 | NumHeaderSearchEntries, TableData.size()}; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2183 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 2184 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2185 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2186 | // Free all of the strings we had to duplicate. |
| 2187 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 2188 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 2191 | static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob, |
| 2192 | unsigned SLocBufferBlobCompressedAbbrv, |
| 2193 | unsigned SLocBufferBlobAbbrv) { |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2194 | using RecordDataType = ASTWriter::RecordData::value_type; |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 2195 | |
| 2196 | // Compress the buffer if possible. We expect that almost all PCM |
| 2197 | // consumers will not want its contents. |
| 2198 | SmallString<0> CompressedBuffer; |
| 2199 | if (llvm::zlib::isAvailable()) { |
| 2200 | llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer); |
| 2201 | if (!E) { |
| 2202 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, |
| 2203 | Blob.size() - 1}; |
| 2204 | Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, |
| 2205 | CompressedBuffer); |
| 2206 | return; |
| 2207 | } |
| 2208 | llvm::consumeError(std::move(E)); |
| 2209 | } |
| 2210 | |
| 2211 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB}; |
| 2212 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob); |
| 2213 | } |
| 2214 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2215 | /// Writes the block containing the serialized form of the |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2216 | /// source manager. |
| 2217 | /// |
| 2218 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 2219 | /// blob), indexed based on the file name, so that we only create |
| 2220 | /// entries for files that we actually need. In the common case (no |
| 2221 | /// errors), we probably won't have to create file entries for any of |
| 2222 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2223 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2224 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2225 | RecordData Record; |
| 2226 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2227 | // Enter the source manager block. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2228 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2229 | |
| 2230 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 2231 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 2232 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2233 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false); |
| 2234 | unsigned SLocBufferBlobCompressedAbbrv = |
| 2235 | CreateSLocBufferBlobAbbrev(Stream, true); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2236 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2237 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2238 | // Write out the source location entry table. We skip the first |
| 2239 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 2240 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2241 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2242 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 2243 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2244 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2245 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2246 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2247 | FileID FID = FileID::get(I); |
| 2248 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2249 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2250 | // Record the offset of this source-location entry. |
| 2251 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2252 | |
| 2253 | // Figure out which record code to use. |
| 2254 | unsigned Code; |
| 2255 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2256 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 2257 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2258 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2259 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2260 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2261 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2262 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2263 | Record.clear(); |
| 2264 | Record.push_back(Code); |
| 2265 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2266 | // Starting offset of this entry within this module, so skip the dummy. |
| 2267 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2268 | if (SLoc->isFile()) { |
| 2269 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2270 | AddSourceLocation(File.getIncludeLoc(), Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2271 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 2272 | Record.push_back(File.hasLineDirectives()); |
| 2273 | |
| 2274 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2275 | bool EmitBlob = false; |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2276 | if (Content->OrigEntry) { |
| 2277 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2278 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2279 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2280 | // The source location entry is a file. Emit input file ID. |
| 2281 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 2282 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2283 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 2284 | Record.push_back(File.NumCreatedFIDs); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2285 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2286 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2287 | if (FDI != FileDeclIDs.end()) { |
| 2288 | Record.push_back(FDI->second->FirstDeclIndex); |
| 2289 | Record.push_back(FDI->second->DeclIDs.size()); |
| 2290 | } else { |
| 2291 | Record.push_back(0); |
| 2292 | Record.push_back(0); |
| 2293 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2294 | |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2295 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2296 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2297 | if (Content->BufferOverridden || Content->IsTransient) |
| 2298 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2299 | } else { |
| 2300 | // The source location entry is a buffer. The blob associated |
| 2301 | // with this entry contains the contents of the buffer. |
| 2302 | |
| 2303 | // We add one to the size so that we capture the trailing NULL |
| 2304 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 2305 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 2306 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 2307 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2308 | StringRef Name = Buffer->getBufferIdentifier(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2309 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2310 | StringRef(Name.data(), Name.size() + 1)); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2311 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2312 | |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2313 | if (Name == "<built-in>") |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2314 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2315 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2316 | |
| 2317 | if (EmitBlob) { |
| 2318 | // Include the implicit terminating null character in the on-disk buffer |
| 2319 | // if we're writing it uncompressed. |
| 2320 | const llvm::MemoryBuffer *Buffer = |
| 2321 | Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 2322 | StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1); |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 2323 | emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv, |
| 2324 | SLocBufferBlobAbbrv); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2325 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2326 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2327 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 2328 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2329 | AddSourceLocation(Expansion.getSpellingLoc(), Record); |
| 2330 | AddSourceLocation(Expansion.getExpansionLocStart(), Record); |
| 2331 | AddSourceLocation(Expansion.isMacroArgExpansion() |
| 2332 | ? SourceLocation() |
| 2333 | : Expansion.getExpansionLocEnd(), |
| 2334 | Record); |
Richard Smith | b5f8171 | 2018-04-30 05:25:48 +0000 | [diff] [blame] | 2335 | Record.push_back(Expansion.isExpansionTokenRange()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2336 | |
| 2337 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2338 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2339 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2340 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2341 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2342 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2343 | } |
| 2344 | } |
| 2345 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2346 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2347 | |
| 2348 | if (SLocEntryOffsets.empty()) |
| 2349 | return; |
| 2350 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2351 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2352 | // table is used for lazily loading source-location information. |
| 2353 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2354 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2355 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2356 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2357 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2358 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2359 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2360 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2361 | { |
| 2362 | RecordData::value_type Record[] = { |
| 2363 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), |
| 2364 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */}; |
| 2365 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
| 2366 | bytes(SLocEntryOffsets)); |
| 2367 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2368 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2369 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2370 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2371 | |
| 2372 | // Write the line table. It depends on remapping working, so it must come |
| 2373 | // after the source location offsets. |
| 2374 | if (SourceMgr.hasLineTable()) { |
| 2375 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 2376 | |
| 2377 | Record.clear(); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2378 | |
| 2379 | // Emit the needed file names. |
| 2380 | llvm::DenseMap<int, int> FilenameMap; |
Hans Wennborg | 1448736 | 2017-12-04 22:28:45 +0000 | [diff] [blame] | 2381 | FilenameMap[-1] = -1; // For unspecified filenames. |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2382 | for (const auto &L : LineTable) { |
| 2383 | if (L.first.ID < 0) |
| 2384 | continue; |
| 2385 | for (auto &LE : L.second) { |
| 2386 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, |
Hans Wennborg | 1448736 | 2017-12-04 22:28:45 +0000 | [diff] [blame] | 2387 | FilenameMap.size() - 1)).second) |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2388 | AddPath(LineTable.getFilename(LE.FilenameID), Record); |
| 2389 | } |
| 2390 | } |
| 2391 | Record.push_back(0); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2392 | |
| 2393 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2394 | for (const auto &L : LineTable) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2395 | // Only emit entries for local files. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2396 | if (L.first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2397 | continue; |
| 2398 | |
| 2399 | // Emit the file ID |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2400 | Record.push_back(L.first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2401 | |
| 2402 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2403 | Record.push_back(L.second.size()); |
| 2404 | for (const auto &LE : L.second) { |
| 2405 | Record.push_back(LE.FileOffset); |
| 2406 | Record.push_back(LE.LineNo); |
| 2407 | Record.push_back(FilenameMap[LE.FilenameID]); |
| 2408 | Record.push_back((unsigned)LE.FileKind); |
| 2409 | Record.push_back(LE.IncludeOffset); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2410 | } |
| 2411 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2412 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2413 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 2414 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2417 | //===----------------------------------------------------------------------===// |
| 2418 | // Preprocessor Serialization |
| 2419 | //===----------------------------------------------------------------------===// |
| 2420 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2421 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 2422 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2423 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 2424 | if (MI->isBuiltinMacro()) |
| 2425 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2426 | |
| 2427 | if (IsModule) { |
| 2428 | SourceLocation Loc = MD->getLocation(); |
| 2429 | if (Loc.isInvalid()) |
| 2430 | return true; |
| 2431 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 2432 | return true; |
| 2433 | } |
| 2434 | |
| 2435 | return false; |
| 2436 | } |
| 2437 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2438 | /// Writes the block containing the serialized form of the |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2439 | /// preprocessor. |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2440 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2441 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2442 | if (PPRec) |
| 2443 | WritePreprocessorDetail(*PPRec); |
| 2444 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2445 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2446 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2447 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2448 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2449 | if (PP.getCounterValue() != 0) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2450 | RecordData::value_type Record[] = {PP.getCounterValue()}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2451 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 2454 | if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) { |
| 2455 | assert(!IsModule); |
Erik Verbruggen | 4d1eb2d | 2017-11-03 09:40:07 +0000 | [diff] [blame] | 2456 | auto SkipInfo = PP.getPreambleSkipInfo(); |
| 2457 | if (SkipInfo.hasValue()) { |
| 2458 | Record.push_back(true); |
| 2459 | AddSourceLocation(SkipInfo->HashTokenLoc, Record); |
| 2460 | AddSourceLocation(SkipInfo->IfTokenLoc, Record); |
| 2461 | Record.push_back(SkipInfo->FoundNonSkipPortion); |
| 2462 | Record.push_back(SkipInfo->FoundElse); |
| 2463 | AddSourceLocation(SkipInfo->ElseLoc, Record); |
| 2464 | } else { |
| 2465 | Record.push_back(false); |
| 2466 | } |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 2467 | for (const auto &Cond : PP.getPreambleConditionalStack()) { |
| 2468 | AddSourceLocation(Cond.IfLoc, Record); |
| 2469 | Record.push_back(Cond.WasSkipping); |
| 2470 | Record.push_back(Cond.FoundNonSkip); |
| 2471 | Record.push_back(Cond.FoundElse); |
| 2472 | } |
| 2473 | Stream.EmitRecord(PP_CONDITIONAL_STACK, Record); |
| 2474 | Record.clear(); |
| 2475 | } |
| 2476 | |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2477 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2478 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2479 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2480 | // 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] | 2481 | // 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] | 2482 | if (PP.SawDateOrTime()) |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2483 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2484 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2485 | // 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] | 2486 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2487 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2488 | // Construct the list of identifiers with macro directives that need to be |
| 2489 | // serialized. |
| 2490 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2491 | for (auto &Id : PP.getIdentifierTable()) |
| 2492 | if (Id.second->hadMacroDefinition() && |
| 2493 | (!Id.second->isFromAST() || |
| 2494 | Id.second->hasChangedSinceDeserialization())) |
| 2495 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2496 | // Sort the set of macro definitions that need to be serialized by the |
| 2497 | // name of the macro, to provide a stable ordering. |
Mandeep Singh Grang | c205d8c | 2018-03-27 16:50:00 +0000 | [diff] [blame] | 2498 | llvm::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(), |
| 2499 | llvm::less_ptr<IdentifierInfo>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2500 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2501 | // Emit the macro directives as a list and associate the offset with the |
| 2502 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2503 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2504 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2505 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2506 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2507 | // Emit the macro directives in reverse source order. |
| 2508 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2509 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2510 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2511 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2512 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2513 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2514 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2515 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2516 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2517 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2518 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2519 | Record.push_back(VisMD->isPublic()); |
| 2520 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2521 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2522 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2523 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2524 | bool EmittedModuleMacros = false; |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2525 | // We write out exported module macros for PCH as well. |
| 2526 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2527 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2528 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2529 | while (!Worklist.empty()) { |
| 2530 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2531 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2532 | // Emit a record indicating this submodule exports this macro. |
| 2533 | ModuleMacroRecord.push_back( |
| 2534 | getSubmoduleID(Macro->getOwningModule())); |
| 2535 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
| 2536 | for (auto *M : Macro->overrides()) |
| 2537 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2538 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2539 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2540 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2541 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2542 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2543 | for (auto *M : Macro->overrides()) |
| 2544 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2545 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2546 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2547 | EmittedModuleMacros = true; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2548 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2549 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2550 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2551 | continue; |
| 2552 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2553 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2554 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2555 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2556 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2557 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2558 | /// Offsets of each of the macros into the bitstream, indexed by |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2559 | /// the local macro ID |
| 2560 | /// |
| 2561 | /// For each identifier that is associated with a macro, this map |
| 2562 | /// provides the offset into the bitstream where that macro is |
| 2563 | /// defined. |
| 2564 | std::vector<uint32_t> MacroOffsets; |
| 2565 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2566 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2567 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2568 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2569 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2570 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2571 | if (ID < FirstMacroID) { |
| 2572 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2573 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2574 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2575 | |
| 2576 | // Record the local offset of this macro. |
| 2577 | unsigned Index = ID - FirstMacroID; |
| 2578 | if (Index == MacroOffsets.size()) |
| 2579 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2580 | else { |
| 2581 | if (Index > MacroOffsets.size()) |
| 2582 | MacroOffsets.resize(Index + 1); |
| 2583 | |
| 2584 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2585 | } |
| 2586 | |
| 2587 | AddIdentifierRef(Name, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2588 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2589 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2590 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2591 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2592 | unsigned Code; |
| 2593 | if (MI->isObjectLike()) { |
| 2594 | Code = PP_MACRO_OBJECT_LIKE; |
| 2595 | } else { |
| 2596 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2597 | |
| 2598 | Record.push_back(MI->isC99Varargs()); |
| 2599 | Record.push_back(MI->isGNUVarargs()); |
| 2600 | Record.push_back(MI->hasCommaPasting()); |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 2601 | Record.push_back(MI->getNumParams()); |
| 2602 | for (const IdentifierInfo *Param : MI->params()) |
| 2603 | AddIdentifierRef(Param, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | // If we have a detailed preprocessing record, record the macro definition |
| 2607 | // ID that corresponds to this macro. |
| 2608 | if (PPRec) |
| 2609 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2610 | |
| 2611 | Stream.EmitRecord(Code, Record); |
| 2612 | Record.clear(); |
| 2613 | |
| 2614 | // Emit the tokens array. |
| 2615 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2616 | // Note that we know that the preprocessor does not have any annotation |
| 2617 | // tokens in it because they are created by the parser, and thus can't |
| 2618 | // be in a macro definition. |
| 2619 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2620 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2621 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2622 | Record.clear(); |
| 2623 | } |
| 2624 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2625 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2626 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2627 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2628 | |
| 2629 | // Write the offsets table for macro IDs. |
| 2630 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2631 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2632 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2633 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2634 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2635 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2636 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2637 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2638 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2639 | { |
| 2640 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), |
| 2641 | FirstMacroID - NUM_PREDEF_MACRO_IDS}; |
| 2642 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); |
| 2643 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2647 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2648 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2649 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2650 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2651 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2652 | // Enter the preprocessor block. |
| 2653 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2654 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2655 | // If the preprocessor has a preprocessing record, emit it. |
| 2656 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2657 | using namespace llvm; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2658 | |
| 2659 | // Set up the abbreviation for |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2660 | unsigned InclusionAbbrev = 0; |
| 2661 | { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2662 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2663 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2664 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2665 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2666 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2667 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2668 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2669 | InclusionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2670 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2671 | |
| 2672 | unsigned FirstPreprocessorEntityID |
| 2673 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2674 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2675 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2676 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2677 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2678 | EEnd = PPRec.local_end(); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2679 | E != EEnd; |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2680 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2681 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2682 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2683 | PreprocessedEntityOffsets.push_back( |
| 2684 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2685 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2686 | if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2687 | // Record this macro definition's ID. |
| 2688 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2689 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2690 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2691 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2692 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2693 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2694 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2695 | if (auto *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2696 | Record.push_back(ME->isBuiltinMacro()); |
| 2697 | if (ME->isBuiltinMacro()) |
| 2698 | AddIdentifierRef(ME->getName(), Record); |
| 2699 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2700 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2701 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2702 | continue; |
| 2703 | } |
| 2704 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2705 | if (auto *ID = dyn_cast<InclusionDirective>(*E)) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2706 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2707 | Record.push_back(ID->getFileName().size()); |
| 2708 | Record.push_back(ID->wasInQuotes()); |
| 2709 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2710 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2711 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2712 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2713 | // Check that the FileEntry is not null because it was not resolved and |
| 2714 | // we create a PCH even with compiler errors. |
| 2715 | if (ID->getFile()) |
| 2716 | Buffer += ID->getFile()->getName(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2717 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2718 | continue; |
| 2719 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2720 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2721 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2722 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2723 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2724 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2725 | // Write the offsets table for the preprocessing record. |
| 2726 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2727 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2728 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2729 | // Write the offsets table for identifier IDs. |
| 2730 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2731 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2732 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2733 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2734 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2735 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2736 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2737 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2738 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, |
| 2739 | FirstPreprocessorEntityID - |
| 2740 | NUM_PREDEF_PP_ENTITY_IDS}; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2741 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2742 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2743 | } |
Cameron Desrochers | b60f1b6 | 2018-01-15 19:14:16 +0000 | [diff] [blame] | 2744 | |
| 2745 | // Write the skipped region table for the preprocessing record. |
| 2746 | ArrayRef<SourceRange> SkippedRanges = PPRec.getSkippedRanges(); |
| 2747 | if (SkippedRanges.size() > 0) { |
| 2748 | std::vector<PPSkippedRange> SerializedSkippedRanges; |
| 2749 | SerializedSkippedRanges.reserve(SkippedRanges.size()); |
| 2750 | for (auto const& Range : SkippedRanges) |
| 2751 | SerializedSkippedRanges.emplace_back(Range); |
| 2752 | |
| 2753 | using namespace llvm; |
| 2754 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
| 2755 | Abbrev->Add(BitCodeAbbrevOp(PPD_SKIPPED_RANGES)); |
| 2756 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2757 | unsigned PPESkippedRangeAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
| 2758 | |
| 2759 | Record.clear(); |
| 2760 | Record.push_back(PPD_SKIPPED_RANGES); |
| 2761 | Stream.EmitRecordWithBlob(PPESkippedRangeAbbrev, Record, |
| 2762 | bytes(SerializedSkippedRanges)); |
| 2763 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2764 | } |
| 2765 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2766 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2767 | if (!Mod) |
| 2768 | return 0; |
| 2769 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2770 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2771 | if (Known != SubmoduleIDs.end()) |
| 2772 | return Known->second; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2773 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2774 | auto *Top = Mod->getTopLevelModule(); |
| 2775 | if (Top != WritingModule && |
Bruno Cardoso Lopes | 17da34d | 2017-02-07 21:54:57 +0000 | [diff] [blame] | 2776 | (getLangOpts().CompilingPCH || |
| 2777 | !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule)))) |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2778 | return 0; |
| 2779 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2780 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2781 | } |
| 2782 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2783 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2784 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2785 | // did not result in us loading a module file for that submodule. For |
| 2786 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2787 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); |
| 2788 | assert((ID || !Mod) && |
| 2789 | "asked for module ID for non-local, non-imported module"); |
| 2790 | return ID; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2793 | /// Compute the number of modules within the given tree (including the |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2794 | /// given module). |
| 2795 | static unsigned getNumberOfModules(Module *Mod) { |
| 2796 | unsigned ChildModules = 0; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2797 | for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2798 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2799 | ChildModules += getNumberOfModules(*Sub); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2800 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2801 | return ChildModules + 1; |
| 2802 | } |
| 2803 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2804 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2805 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2806 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2807 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2808 | // Write the abbreviations needed for the submodules block. |
| 2809 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2810 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2811 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2812 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2813 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2814 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 2815 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Kind |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2816 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2817 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2818 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2819 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2820 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2821 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2822 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2823 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Jordan Rose | 90b0a1f | 2018-04-20 17:16:04 +0000 | [diff] [blame] | 2824 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModuleMapIsPriv... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2825 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2826 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2827 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2828 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2829 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2830 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2831 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2832 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2833 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2834 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2835 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2836 | unsigned HeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2837 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2838 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2839 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2840 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2841 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2842 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2843 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2844 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2845 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2846 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2847 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2848 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2849 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2850 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2851 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2852 | unsigned RequiresAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2853 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2854 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2855 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2856 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2857 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2858 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2859 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2860 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2861 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2862 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2863 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2864 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2865 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2866 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2867 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2868 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2869 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2870 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2871 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2872 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2873 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2874 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2875 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2876 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2877 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2878 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2879 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2880 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2881 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2882 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2883 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2884 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2885 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2886 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2887 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2888 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2889 | unsigned ConflictAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2890 | |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 2891 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
| 2892 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXPORT_AS)); |
| 2893 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
| 2894 | unsigned ExportAsAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
| 2895 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2896 | // Write the submodule metadata block. |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 2897 | RecordData::value_type Record[] = { |
| 2898 | getNumberOfModules(WritingModule), |
Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 2899 | FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS}; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2900 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2901 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2902 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2903 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2904 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2905 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2906 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2907 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2908 | unsigned ID = getSubmoduleID(Mod); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2909 | |
| 2910 | uint64_t ParentID = 0; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2911 | if (Mod->Parent) { |
| 2912 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2913 | ParentID = SubmoduleIDs[Mod->Parent]; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2914 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2915 | |
| 2916 | // Emit the definition of the block. |
| 2917 | { |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2918 | RecordData::value_type Record[] = {SUBMODULE_DEFINITION, |
| 2919 | ID, |
| 2920 | ParentID, |
Simon Pilgrim | f331a66 | 2017-09-04 10:54:39 +0000 | [diff] [blame] | 2921 | (RecordData::value_type)Mod->Kind, |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2922 | Mod->IsFramework, |
| 2923 | Mod->IsExplicit, |
| 2924 | Mod->IsSystem, |
| 2925 | Mod->IsExternC, |
| 2926 | Mod->InferSubmodules, |
| 2927 | Mod->InferExplicitSubmodules, |
| 2928 | Mod->InferExportWildcard, |
Jordan Rose | 90b0a1f | 2018-04-20 17:16:04 +0000 | [diff] [blame] | 2929 | Mod->ConfigMacrosExhaustive, |
| 2930 | Mod->ModuleMapIsPrivate}; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2931 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2932 | } |
| 2933 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2934 | // Emit the requirements. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2935 | for (const auto &R : Mod->Requirements) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2936 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2937 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2938 | } |
| 2939 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2940 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2941 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2942 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2943 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2944 | UmbrellaHeader.NameAsWritten); |
| 2945 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2946 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; |
| 2947 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2948 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2949 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2950 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2951 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2952 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2953 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2954 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2955 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2956 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2957 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 2958 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 2959 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2960 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2961 | Module::HK_PrivateTextual}, |
| 2962 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2963 | }; |
| 2964 | for (auto &HL : HeaderLists) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2965 | RecordData::value_type Record[] = {HL.RecordKind}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2966 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 2967 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 2968 | } |
| 2969 | |
| 2970 | // Emit the top headers. |
| 2971 | { |
| 2972 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2973 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2974 | for (auto *H : TopHeaders) |
| 2975 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2976 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2977 | |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2978 | // Emit the imports. |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2979 | if (!Mod->Imports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2980 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2981 | for (auto *I : Mod->Imports) |
| 2982 | Record.push_back(getSubmoduleID(I)); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2983 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2984 | } |
| 2985 | |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2986 | // Emit the exports. |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2987 | if (!Mod->Exports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2988 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2989 | for (const auto &E : Mod->Exports) { |
| 2990 | // FIXME: This may fail; we don't require that all exported modules |
| 2991 | // are local or imported. |
| 2992 | Record.push_back(getSubmoduleID(E.getPointer())); |
| 2993 | Record.push_back(E.getInt()); |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2994 | } |
| 2995 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2996 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2997 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2998 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 2999 | // Might be unnecessary as use declarations are only used to build the |
| 3000 | // module itself. |
| 3001 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 3002 | // Emit the link libraries. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3003 | for (const auto &LL : Mod->LinkLibraries) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3004 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, |
| 3005 | LL.IsFramework}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3006 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 3007 | } |
| 3008 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3009 | // Emit the conflicts. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3010 | for (const auto &C : Mod->Conflicts) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3011 | // FIXME: This may fail; we don't require that all conflicting modules |
| 3012 | // are local or imported. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3013 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, |
| 3014 | getSubmoduleID(C.Other)}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3015 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 3018 | // Emit the configuration macros. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3019 | for (const auto &CM : Mod->ConfigMacros) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3020 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3021 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 3022 | } |
| 3023 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 3024 | // Emit the initializers, if any. |
| 3025 | RecordData Inits; |
| 3026 | for (Decl *D : Context->getModuleInitializers(Mod)) |
| 3027 | Inits.push_back(GetDeclRef(D)); |
| 3028 | if (!Inits.empty()) |
| 3029 | Stream.EmitRecord(SUBMODULE_INITIALIZERS, Inits); |
| 3030 | |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 3031 | // Emit the name of the re-exported module, if any. |
| 3032 | if (!Mod->ExportAsModule.empty()) { |
| 3033 | RecordData::value_type Record[] = {SUBMODULE_EXPORT_AS}; |
| 3034 | Stream.EmitRecordWithBlob(ExportAsAbbrev, Record, Mod->ExportAsModule); |
| 3035 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3036 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3037 | // Queue up the submodules of this module. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3038 | for (auto *M : Mod->submodules()) |
| 3039 | Q.push(M); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3040 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3041 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3042 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 3043 | |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 3044 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 3045 | getNumberOfModules(WritingModule)) && |
| 3046 | "Wrong # of submodules; found a reference to a non-local, " |
| 3047 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 3050 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 3051 | bool isModule) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 3052 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 3053 | DiagStateIDMap; |
| 3054 | unsigned CurrID = 0; |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3055 | RecordData Record; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3056 | |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 3057 | auto EncodeDiagStateFlags = |
| 3058 | [](const DiagnosticsEngine::DiagState *DS) -> unsigned { |
| 3059 | unsigned Result = (unsigned)DS->ExtBehavior; |
| 3060 | for (unsigned Val : |
Daniel Jasper | ba9aefc | 2017-05-03 07:48:27 +0000 | [diff] [blame] | 3061 | {(unsigned)DS->IgnoreAllWarnings, (unsigned)DS->EnableAllWarnings, |
| 3062 | (unsigned)DS->WarningsAsErrors, (unsigned)DS->ErrorsAsFatal, |
| 3063 | (unsigned)DS->SuppressSystemWarnings}) |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 3064 | Result = (Result << 1) | Val; |
| 3065 | return Result; |
| 3066 | }; |
| 3067 | |
| 3068 | unsigned Flags = EncodeDiagStateFlags(Diag.DiagStatesByLoc.FirstDiagState); |
| 3069 | Record.push_back(Flags); |
| 3070 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3071 | auto AddDiagState = [&](const DiagnosticsEngine::DiagState *State, |
| 3072 | bool IncludeNonPragmaStates) { |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 3073 | // Ensure that the diagnostic state wasn't modified since it was created. |
| 3074 | // We will not correctly round-trip this information otherwise. |
| 3075 | assert(Flags == EncodeDiagStateFlags(State) && |
| 3076 | "diag state flags vary in single AST file"); |
| 3077 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3078 | unsigned &DiagStateID = DiagStateIDMap[State]; |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 3079 | Record.push_back(DiagStateID); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3080 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 3081 | if (DiagStateID == 0) { |
| 3082 | DiagStateID = ++CurrID; |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 3083 | |
| 3084 | // Add a placeholder for the number of mappings. |
| 3085 | auto SizeIdx = Record.size(); |
| 3086 | Record.emplace_back(); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3087 | for (const auto &I : *State) { |
| 3088 | if (I.second.isPragma() || IncludeNonPragmaStates) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3089 | Record.push_back(I.first); |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 3090 | Record.push_back(I.second.serialize()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 3091 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3092 | } |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 3093 | // Update the placeholder. |
| 3094 | Record[SizeIdx] = (Record.size() - SizeIdx) / 2; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3095 | } |
| 3096 | }; |
| 3097 | |
| 3098 | AddDiagState(Diag.DiagStatesByLoc.FirstDiagState, isModule); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3099 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3100 | // Reserve a spot for the number of locations with state transitions. |
| 3101 | auto NumLocationsIdx = Record.size(); |
| 3102 | Record.emplace_back(); |
| 3103 | |
| 3104 | // Emit the state transitions. |
| 3105 | unsigned NumLocations = 0; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3106 | for (auto &FileIDAndFile : Diag.DiagStatesByLoc.Files) { |
| 3107 | if (!FileIDAndFile.first.isValid() || |
| 3108 | !FileIDAndFile.second.HasLocalTransitions) |
| 3109 | continue; |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3110 | ++NumLocations; |
Richard Smith | 6c2b5a8 | 2018-02-09 01:15:13 +0000 | [diff] [blame] | 3111 | |
| 3112 | SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FileIDAndFile.first, 0); |
| 3113 | assert(!Loc.isInvalid() && "start loc for valid FileID is invalid"); |
| 3114 | AddSourceLocation(Loc, Record); |
| 3115 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3116 | Record.push_back(FileIDAndFile.second.StateTransitions.size()); |
| 3117 | for (auto &StatePoint : FileIDAndFile.second.StateTransitions) { |
| 3118 | Record.push_back(StatePoint.Offset); |
| 3119 | AddDiagState(StatePoint.State, false); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3120 | } |
| 3121 | } |
| 3122 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3123 | // Backpatch the number of locations. |
| 3124 | Record[NumLocationsIdx] = NumLocations; |
| 3125 | |
| 3126 | // 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] | 3127 | // |
| 3128 | // This also protects against a hypothetical corner case with simulating |
| 3129 | // -Werror settings for implicit modules in the ASTReader, where reading |
| 3130 | // CurDiagState out of context could change whether warning pragmas are |
| 3131 | // treated as errors. |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3132 | AddSourceLocation(Diag.DiagStatesByLoc.CurDiagStateLoc, Record); |
| 3133 | AddDiagState(Diag.DiagStatesByLoc.CurDiagState, false); |
| 3134 | |
Duncan P. N. Exon Smith | f2435b9 | 2017-04-12 02:31:17 +0000 | [diff] [blame] | 3135 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3136 | } |
| 3137 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3138 | //===----------------------------------------------------------------------===// |
| 3139 | // Type Serialization |
| 3140 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 3141 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3142 | /// Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3143 | void ASTWriter::WriteType(QualType T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3144 | TypeIdx &IdxRef = TypeIdxs[T]; |
| 3145 | if (IdxRef.getIndex() == 0) // we haven't seen this type before. |
| 3146 | IdxRef = TypeIdx(NextTypeID++); |
| 3147 | TypeIdx Idx = IdxRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3148 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3149 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 3150 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3151 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3152 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3153 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3154 | ASTTypeWriter W(*this, Record); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3155 | W.Visit(T); |
| 3156 | uint64_t Offset = W.Emit(); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3157 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3158 | // Record the offset for this type. |
| 3159 | unsigned Index = Idx.getIndex() - FirstTypeID; |
| 3160 | if (TypeOffsets.size() == Index) |
| 3161 | TypeOffsets.push_back(Offset); |
| 3162 | else if (TypeOffsets.size() < Index) { |
| 3163 | TypeOffsets.resize(Index + 1); |
| 3164 | TypeOffsets[Index] = Offset; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3165 | } else { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3166 | llvm_unreachable("Types emitted in wrong order"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3167 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3168 | } |
| 3169 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3170 | //===----------------------------------------------------------------------===// |
| 3171 | // Declaration Serialization |
| 3172 | //===----------------------------------------------------------------------===// |
| 3173 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3174 | /// Write the block containing all of the declaration IDs |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3175 | /// lexically declared within the given DeclContext. |
| 3176 | /// |
| 3177 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 3178 | /// bitstream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3179 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3180 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 3181 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3182 | return 0; |
| 3183 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3184 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 3185 | SmallVector<uint32_t, 128> KindDeclPairs; |
| 3186 | for (const auto *D : DC->decls()) { |
| 3187 | KindDeclPairs.push_back(D->getKind()); |
| 3188 | KindDeclPairs.push_back(GetDeclRef(D)); |
| 3189 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3190 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3191 | ++NumLexicalDeclContexts; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3192 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 3193 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, |
| 3194 | bytes(KindDeclPairs)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3195 | return Offset; |
| 3196 | } |
| 3197 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3198 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3199 | using namespace llvm; |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3200 | |
| 3201 | // Write the type offsets array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3202 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3203 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3204 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3205 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3206 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3207 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3208 | { |
| 3209 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), |
| 3210 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; |
| 3211 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
| 3212 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3213 | |
| 3214 | // Write the declaration offsets array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3215 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3216 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3217 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3218 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3219 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3220 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3221 | { |
| 3222 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), |
| 3223 | FirstDeclID - NUM_PREDEF_DECL_IDS}; |
| 3224 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
| 3225 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3226 | } |
| 3227 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3228 | void ASTWriter::WriteFileDeclIDsMap() { |
| 3229 | using namespace llvm; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3230 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 3231 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 3232 | FileDeclIDs.begin(), FileDeclIDs.end()); |
Mandeep Singh Grang | c205d8c | 2018-03-27 16:50:00 +0000 | [diff] [blame] | 3233 | llvm::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), |
| 3234 | llvm::less_first()); |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 3235 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3236 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 3237 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 3238 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 3239 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 3240 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 3241 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 3242 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3245 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3246 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 3247 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3248 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3249 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3250 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, |
| 3251 | FileGroupedDeclIDs.size()}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3252 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3253 | } |
| 3254 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3255 | void ASTWriter::WriteComments() { |
| 3256 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Ilya Biryukov | 4564310 | 2018-07-09 11:33:23 +0000 | [diff] [blame] | 3257 | auto _ = llvm::make_scope_exit([this] { Stream.ExitBlock(); }); |
| 3258 | if (!PP->getPreprocessorOpts().WriteCommentListToPCH) |
| 3259 | return; |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 3260 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3261 | RecordData Record; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3262 | for (const auto *I : RawComments) { |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3263 | Record.clear(); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3264 | AddSourceRange(I->getSourceRange(), Record); |
| 3265 | Record.push_back(I->getKind()); |
| 3266 | Record.push_back(I->isTrailingComment()); |
| 3267 | Record.push_back(I->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3268 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 3269 | } |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3272 | //===----------------------------------------------------------------------===// |
| 3273 | // Global Method Pool and Selector Serialization |
| 3274 | //===----------------------------------------------------------------------===// |
| 3275 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3276 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3277 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3278 | // 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] | 3279 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3280 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3281 | |
| 3282 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3283 | using key_type = Selector; |
| 3284 | using key_type_ref = key_type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3285 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3286 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3287 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3288 | ObjCMethodList Instance, Factory; |
| 3289 | }; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3290 | using data_type_ref = const data_type &; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3291 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3292 | using hash_value_type = unsigned; |
| 3293 | using offset_type = unsigned; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3294 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3295 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) {} |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3296 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3297 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 3298 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3299 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3300 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3301 | std::pair<unsigned, unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3302 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3303 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3304 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3305 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3306 | endian::Writer LE(Out, little); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3307 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3308 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3309 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 3310 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3311 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3312 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3313 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3314 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3315 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3316 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3317 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3318 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3319 | return std::make_pair(KeyLen, DataLen); |
| 3320 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3321 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3322 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3323 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3324 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3325 | endian::Writer LE(Out, little); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3326 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3327 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 3328 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3329 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3330 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3331 | if (N == 0) |
| 3332 | N = 1; |
| 3333 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3334 | LE.write<uint32_t>( |
| 3335 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3336 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3337 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3338 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3339 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3340 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3341 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3342 | endian::Writer LE(Out, little); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3343 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3344 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3345 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3346 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3347 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3348 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3349 | ++NumInstanceMethods; |
| 3350 | |
| 3351 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3352 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3353 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3354 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3355 | ++NumFactoryMethods; |
| 3356 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3357 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 3358 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3359 | unsigned InstanceHasMoreThanOneDeclBit = |
| 3360 | Methods.Instance.hasMoreThanOneDecl(); |
| 3361 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 3362 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 3363 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3364 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 3365 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3366 | unsigned FactoryHasMoreThanOneDeclBit = |
| 3367 | Methods.Factory.hasMoreThanOneDecl(); |
| 3368 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 3369 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 3370 | FactoryBits; |
| 3371 | LE.write<uint16_t>(FullInstanceBits); |
| 3372 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3373 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3374 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3375 | if (Method->getMethod()) |
| 3376 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3377 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3378 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3379 | if (Method->getMethod()) |
| 3380 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3381 | |
| 3382 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3383 | } |
| 3384 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3385 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3386 | } // namespace |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3387 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3388 | /// Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3389 | /// |
| 3390 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3391 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 3392 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3393 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3394 | using namespace llvm; |
| 3395 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3396 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3397 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3398 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3399 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3400 | // 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] | 3401 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3402 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3403 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3404 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3405 | // Create the on-disk hash table representation. We walk through every |
| 3406 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3407 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3408 | for (auto &SelectorAndID : SelectorIDs) { |
| 3409 | Selector S = SelectorAndID.first; |
| 3410 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3411 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3412 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3413 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3414 | ObjCMethodList(), |
| 3415 | ObjCMethodList() |
| 3416 | }; |
| 3417 | if (F != SemaRef.MethodPool.end()) { |
| 3418 | Data.Instance = F->second.first; |
| 3419 | Data.Factory = F->second.second; |
| 3420 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3421 | // 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] | 3422 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3423 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3424 | // Selector already exists. Did it change? |
| 3425 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3426 | for (ObjCMethodList *M = &Data.Instance; |
| 3427 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 3428 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3429 | changed = true; |
| 3430 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3431 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3432 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3433 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3434 | changed = true; |
| 3435 | } |
| 3436 | if (!changed) |
| 3437 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3438 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3439 | // A new method pool entry. |
| 3440 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3441 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3442 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3445 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3446 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3447 | uint32_t BucketOffset; |
| 3448 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3449 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3450 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3451 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3452 | llvm::raw_svector_ostream Out(MethodPool); |
| 3453 | // Make sure that no bucket is at offset 0 |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3454 | endian::write<uint32_t>(Out, 0, little); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3455 | BucketOffset = Generator.Emit(Out, Trait); |
| 3456 | } |
| 3457 | |
| 3458 | // Create a blob abbreviation |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3459 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3460 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3461 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3462 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3463 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3464 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3465 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3466 | // Write the method pool |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3467 | { |
| 3468 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, |
| 3469 | NumTableEntries}; |
| 3470 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
| 3471 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3472 | |
| 3473 | // Create a blob abbreviation for the selector table offsets. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3474 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3475 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3476 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3477 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3478 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3479 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3480 | |
| 3481 | // Write the selector offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3482 | { |
| 3483 | RecordData::value_type Record[] = { |
| 3484 | SELECTOR_OFFSETS, SelectorOffsets.size(), |
| 3485 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; |
| 3486 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 3487 | bytes(SelectorOffsets)); |
| 3488 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3489 | } |
| 3490 | } |
| 3491 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3492 | /// Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3493 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3494 | using namespace llvm; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3495 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3496 | if (SemaRef.ReferencedSelectors.empty()) |
| 3497 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3498 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3499 | RecordData Record; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3500 | ASTRecordWriter Writer(*this, Record); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3501 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3502 | // 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] | 3503 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3504 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3505 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3506 | Selector Sel = SelectorAndLocation.first; |
| 3507 | SourceLocation Loc = SelectorAndLocation.second; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3508 | Writer.AddSelectorRef(Sel); |
| 3509 | Writer.AddSourceLocation(Loc); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3510 | } |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3511 | Writer.Emit(REFERENCED_SELECTOR_POOL); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3512 | } |
| 3513 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3514 | //===----------------------------------------------------------------------===// |
| 3515 | // Identifier Table Serialization |
| 3516 | //===----------------------------------------------------------------------===// |
| 3517 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3518 | /// Determine the declaration that should be put into the name lookup table to |
| 3519 | /// represent the given declaration in this module. This is usually D itself, |
| 3520 | /// but if D was imported and merged into a local declaration, we want the most |
| 3521 | /// recent local declaration instead. The chosen declaration will be the most |
| 3522 | /// recent declaration in any module that imports this one. |
| 3523 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3524 | NamedDecl *D) { |
| 3525 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3526 | return D; |
| 3527 | |
| 3528 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3529 | // For Redeclarable decls, a prior declaration might be local. |
| 3530 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3531 | // If we find a local decl, we're done. |
| 3532 | if (!Redecl->isFromASTFile()) { |
| 3533 | // Exception: in very rare cases (for injected-class-names), not all |
| 3534 | // redeclarations are in the same semantic context. Skip ones in a |
| 3535 | // different context. They don't go in this lookup table at all. |
| 3536 | if (!Redecl->getDeclContext()->getRedeclContext()->Equals( |
| 3537 | D->getDeclContext()->getRedeclContext())) |
| 3538 | continue; |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3539 | return cast<NamedDecl>(Redecl); |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3540 | } |
| 3541 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3542 | // 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] | 3543 | // local one. |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3544 | if (Redecl->getOwningModuleID() == 0) |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3545 | break; |
| 3546 | } |
| 3547 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3548 | // For Mergeable decls, the first decl might be local. |
| 3549 | if (!First->isFromASTFile()) |
| 3550 | return cast<NamedDecl>(First); |
| 3551 | } |
| 3552 | |
| 3553 | // All declarations are imported. Our most recent declaration will also be |
| 3554 | // the most recent one in anyone who imports us. |
| 3555 | return D; |
| 3556 | } |
| 3557 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3558 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3559 | |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3560 | class ASTIdentifierTableTrait { |
| 3561 | ASTWriter &Writer; |
| 3562 | Preprocessor &PP; |
| 3563 | IdentifierResolver &IdResolver; |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3564 | bool IsModule; |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3565 | bool NeedDecls; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3566 | ASTWriter::RecordData *InterestingIdentifierOffsets; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3567 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3568 | /// Determines whether this is an "interesting" identifier that needs a |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3569 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3570 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3571 | /// to check that. |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3572 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3573 | if (MacroOffset || |
| 3574 | II->isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3575 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3576 | II->hasRevertedTokenIDToIdentifier() || |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3577 | (NeedDecls && II->getFETokenInfo<void>())) |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3578 | return true; |
| 3579 | |
| 3580 | return false; |
| 3581 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3582 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3583 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3584 | using key_type = IdentifierInfo *; |
| 3585 | using key_type_ref = key_type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3586 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3587 | using data_type = IdentID; |
| 3588 | using data_type_ref = data_type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3589 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3590 | using hash_value_type = unsigned; |
| 3591 | using offset_type = unsigned; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3592 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3593 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3594 | IdentifierResolver &IdResolver, bool IsModule, |
| 3595 | ASTWriter::RecordData *InterestingIdentifierOffsets) |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3596 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3597 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), |
| 3598 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3599 | |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3600 | bool needDecls() const { return NeedDecls; } |
| 3601 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3602 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3603 | return llvm::djbHash(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3604 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3605 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3606 | bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 3607 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3608 | return isInterestingIdentifier(II, MacroOffset); |
| 3609 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3610 | |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3611 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { |
| 3612 | return isInterestingIdentifier(II, 0); |
| 3613 | } |
| 3614 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3615 | std::pair<unsigned, unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3616 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3617 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3618 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3619 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3620 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3621 | DataLen += 2; // 2 bytes for builtin ID |
| 3622 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3623 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3624 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3625 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3626 | if (NeedDecls) { |
| 3627 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3628 | DEnd = IdResolver.end(); |
| 3629 | D != DEnd; ++D) |
| 3630 | DataLen += 4; |
| 3631 | } |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3632 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3633 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3634 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3635 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3636 | endian::Writer LE(Out, little); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3637 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3638 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3639 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3640 | // We emit the key length after the data length so that every |
| 3641 | // string is preceded by a 16-bit length. This matches the PTH |
| 3642 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3643 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3644 | return std::make_pair(KeyLen, DataLen); |
| 3645 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3646 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3647 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3648 | unsigned KeyLen) { |
| 3649 | // Record the location of the key data. This is used when generating |
| 3650 | // the mapping from persistent IDs to strings. |
| 3651 | Writer.SetIdentifierOffset(II, Out.tell()); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3652 | |
| 3653 | // Emit the offset of the key/data length information to the interesting |
| 3654 | // identifiers table if necessary. |
| 3655 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) |
| 3656 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); |
| 3657 | |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3658 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3659 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3660 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3661 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3662 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3663 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3664 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3665 | endian::Writer LE(Out, little); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3666 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3667 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3668 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3669 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3670 | return; |
| 3671 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3672 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3673 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3674 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3675 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3676 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3677 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3678 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3679 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3680 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3681 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3682 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3683 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3684 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3685 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3686 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3687 | if (HadMacroDefinition) |
| 3688 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3689 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3690 | if (NeedDecls) { |
| 3691 | // Emit the declaration IDs in reverse order, because the |
| 3692 | // IdentifierResolver provides the declarations as they would be |
| 3693 | // visible (e.g., the function "stat" would come before the struct |
| 3694 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3695 | // (so we need to see the struct "stat" before the function "stat"). |
| 3696 | // Only emit declarations that aren't from a chained PCH, though. |
| 3697 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), |
| 3698 | IdResolver.end()); |
| 3699 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3700 | DEnd = Decls.rend(); |
| 3701 | D != DEnd; ++D) |
| 3702 | LE.write<uint32_t>( |
| 3703 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
| 3704 | } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3705 | } |
| 3706 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3707 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3708 | } // namespace |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3709 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3710 | /// Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3711 | /// |
| 3712 | /// The identifier table consists of a blob containing string data |
| 3713 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3714 | /// that maps identifier IDs to locations within the blob. |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3715 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3716 | IdentifierResolver &IdResolver, |
| 3717 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3718 | using namespace llvm; |
| 3719 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3720 | RecordData InterestingIdents; |
| 3721 | |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3722 | // Create and write out the blob that contains the identifier |
| 3723 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3724 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3725 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3726 | ASTIdentifierTableTrait Trait( |
| 3727 | *this, PP, IdResolver, IsModule, |
| 3728 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3729 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3730 | // Look for any identifiers that were named while processing the |
| 3731 | // headers, but are otherwise not needed. We add these to the hash |
| 3732 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3733 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3734 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3735 | SmallVector<const IdentifierInfo *, 128> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3736 | for (const auto &ID : PP.getIdentifierTable()) |
| 3737 | IIs.push_back(ID.second); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3738 | // Sort the identifiers lexicographically before getting them references so |
| 3739 | // that their order is stable. |
Mandeep Singh Grang | c205d8c | 2018-03-27 16:50:00 +0000 | [diff] [blame] | 3740 | llvm::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3741 | for (const IdentifierInfo *II : IIs) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3742 | if (Trait.isInterestingNonMacroIdentifier(II)) |
| 3743 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3744 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3745 | // Create the on-disk hash table representation. We only store offsets |
| 3746 | // for identifiers that appear here for the first time. |
| 3747 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3748 | for (auto IdentIDPair : IdentifierIDs) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3749 | auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3750 | IdentID ID = IdentIDPair.second; |
| 3751 | assert(II && "NULL identifier in identifier table"); |
Vassil Vassilev | 262f41e | 2016-03-30 20:16:03 +0000 | [diff] [blame] | 3752 | // Write out identifiers if either the ID is local or the identifier has |
| 3753 | // changed since it was loaded. |
| 3754 | if (ID >= FirstIdentID || !Chain || !II->isFromAST() |
| 3755 | || II->hasChangedSinceDeserialization() || |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3756 | (Trait.needDecls() && |
| 3757 | II->hasFETokenInfoChangedSinceDeserialization())) |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3758 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3759 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3760 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3761 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3762 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3763 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3764 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3765 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3766 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3767 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3768 | // Make sure that no bucket is at offset 0 |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3769 | endian::write<uint32_t>(Out, 0, little); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3770 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | // Create a blob abbreviation |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3774 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3775 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3776 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3777 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3778 | unsigned IDTableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3779 | |
| 3780 | // Write the identifier table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3781 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3782 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | // Write the offsets table for identifier IDs. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3786 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3787 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3788 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3789 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3790 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3791 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3792 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3793 | #ifndef NDEBUG |
| 3794 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3795 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3796 | #endif |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3797 | |
| 3798 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, |
| 3799 | IdentifierOffsets.size(), |
| 3800 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3801 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3802 | bytes(IdentifierOffsets)); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3803 | |
| 3804 | // In C++, write the list of interesting identifiers (those that are |
| 3805 | // defined as macros, poisoned, or similar unusual things). |
| 3806 | if (!InterestingIdents.empty()) |
| 3807 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3810 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3811 | // DeclContext's Name Lookup Table Serialization |
| 3812 | //===----------------------------------------------------------------------===// |
| 3813 | |
| 3814 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3815 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3816 | // Trait used for the on-disk hash table used in the method pool. |
| 3817 | class ASTDeclContextNameLookupTrait { |
| 3818 | ASTWriter &Writer; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3819 | llvm::SmallVector<DeclID, 64> DeclIDs; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3820 | |
| 3821 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3822 | using key_type = DeclarationNameKey; |
| 3823 | using key_type_ref = key_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3824 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3825 | /// A start and end index into DeclIDs, representing a sequence of decls. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3826 | using data_type = std::pair<unsigned, unsigned>; |
| 3827 | using data_type_ref = const data_type &; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3828 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3829 | using hash_value_type = unsigned; |
| 3830 | using offset_type = unsigned; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3831 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3832 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) {} |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3833 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3834 | template<typename Coll> |
| 3835 | data_type getData(const Coll &Decls) { |
| 3836 | unsigned Start = DeclIDs.size(); |
| 3837 | for (NamedDecl *D : Decls) { |
| 3838 | DeclIDs.push_back( |
| 3839 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); |
| 3840 | } |
| 3841 | return std::make_pair(Start, DeclIDs.size()); |
| 3842 | } |
| 3843 | |
| 3844 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { |
| 3845 | unsigned Start = DeclIDs.size(); |
| 3846 | for (auto ID : FromReader) |
| 3847 | DeclIDs.push_back(ID); |
| 3848 | return std::make_pair(Start, DeclIDs.size()); |
| 3849 | } |
| 3850 | |
| 3851 | static bool EqualKey(key_type_ref a, key_type_ref b) { |
| 3852 | return a == b; |
| 3853 | } |
| 3854 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3855 | hash_value_type ComputeHash(DeclarationNameKey Name) { |
| 3856 | return Name.getHash(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3859 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { |
| 3860 | assert(Writer.hasChain() && |
| 3861 | "have reference to loaded module file but no chain?"); |
| 3862 | |
| 3863 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3864 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3865 | endian::write<uint32_t>(Out, Writer.getChain()->getModuleFileID(F), little); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3866 | } |
| 3867 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3868 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, |
| 3869 | DeclarationNameKey Name, |
| 3870 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3871 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3872 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3873 | endian::Writer LE(Out, little); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3874 | unsigned KeyLen = 1; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3875 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3876 | case DeclarationName::Identifier: |
| 3877 | case DeclarationName::ObjCZeroArgSelector: |
| 3878 | case DeclarationName::ObjCOneArgSelector: |
| 3879 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3880 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3881 | case DeclarationName::CXXDeductionGuideName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3882 | KeyLen += 4; |
| 3883 | break; |
| 3884 | case DeclarationName::CXXOperatorName: |
| 3885 | KeyLen += 1; |
| 3886 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3887 | case DeclarationName::CXXConstructorName: |
| 3888 | case DeclarationName::CXXDestructorName: |
| 3889 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3890 | case DeclarationName::CXXUsingDirective: |
| 3891 | break; |
| 3892 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3893 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3894 | |
Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3895 | // 4 bytes for each DeclID. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3896 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); |
| 3897 | assert(uint16_t(DataLen) == DataLen && |
| 3898 | "too many decls for serialized lookup result"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3899 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3900 | |
| 3901 | return std::make_pair(KeyLen, DataLen); |
| 3902 | } |
| 3903 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3904 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3905 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3906 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3907 | endian::Writer LE(Out, little); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3908 | LE.write<uint8_t>(Name.getKind()); |
| 3909 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3910 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3911 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3912 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3913 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3914 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3915 | case DeclarationName::ObjCZeroArgSelector: |
| 3916 | case DeclarationName::ObjCOneArgSelector: |
| 3917 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3918 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3919 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3920 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3921 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3922 | "Invalid operator?"); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3923 | LE.write<uint8_t>(Name.getOperatorKind()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3924 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3925 | case DeclarationName::CXXConstructorName: |
| 3926 | case DeclarationName::CXXDestructorName: |
| 3927 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3928 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3929 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3930 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3931 | |
| 3932 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3933 | } |
| 3934 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3935 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, |
| 3936 | unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3937 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3938 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3939 | endian::Writer LE(Out, little); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3940 | uint64_t Start = Out.tell(); (void)Start; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3941 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) |
| 3942 | LE.write<uint32_t>(DeclIDs[I]); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3943 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3944 | } |
| 3945 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3946 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3947 | } // namespace |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3948 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3949 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 3950 | DeclContext *DC) { |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 3951 | return Result.hasExternalDecls() && |
| 3952 | DC->hasNeedToReconcileExternalVisibleStorage(); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 3956 | DeclContext *DC) { |
| 3957 | for (auto *D : Result.getLookupResult()) |
| 3958 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 3959 | return false; |
| 3960 | |
| 3961 | return true; |
| 3962 | } |
| 3963 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3964 | void |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3965 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3966 | llvm::SmallVectorImpl<char> &LookupTable) { |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 3967 | assert(!ConstDC->hasLazyLocalLexicalLookups() && |
| 3968 | !ConstDC->hasLazyExternalLexicalLookups() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3969 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3970 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3971 | // FIXME: We need to build the lookups table, which is logically const. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3972 | auto *DC = const_cast<DeclContext*>(ConstDC); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3973 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 3974 | |
| 3975 | // Create the on-disk hash table representation. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3976 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, |
| 3977 | ASTDeclContextNameLookupTrait> Generator; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3978 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3979 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3980 | // The first step is to collect the declaration names which we need to |
| 3981 | // serialize into the name lookup table, and to collect them in a stable |
| 3982 | // order. |
| 3983 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3984 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3985 | // We also build up small sets of the constructor and conversion function |
| 3986 | // names which are visible. |
| 3987 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3988 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3989 | for (auto &Lookup : *DC->buildLookup()) { |
| 3990 | auto &Name = Lookup.first; |
| 3991 | auto &Result = Lookup.second; |
| 3992 | |
Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 3993 | // If there are no local declarations in our lookup result, we |
| 3994 | // don't need to write an entry for the name at all. If we can't |
| 3995 | // write out a lookup set without performing more deserialization, |
| 3996 | // just skip this entry. |
| 3997 | if (isLookupResultExternal(Result, DC) && |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3998 | isLookupResultEntirelyExternal(Result, DC)) |
| 3999 | continue; |
| 4000 | |
| 4001 | // We also skip empty results. If any of the results could be external and |
| 4002 | // the currently available results are empty, then all of the results are |
| 4003 | // external and we skip it above. So the only way we get here with an empty |
| 4004 | // results is when no results could have been external *and* we have |
| 4005 | // external results. |
| 4006 | // |
| 4007 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 4008 | // lookups into a decl context as an optimization, today we *have* to skip |
| 4009 | // them because there are names with empty lookup results in decl contexts |
| 4010 | // which we can't emit in any stable ordering: we lookup constructors and |
| 4011 | // conversion functions in the enclosing namespace scope creating empty |
| 4012 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 4013 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 4014 | // here by omitting lookups with empty results. |
| 4015 | if (Lookup.second.getLookupResult().empty()) |
| 4016 | continue; |
| 4017 | |
| 4018 | switch (Lookup.first.getNameKind()) { |
| 4019 | default: |
| 4020 | Names.push_back(Lookup.first); |
| 4021 | break; |
| 4022 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4023 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4024 | assert(isa<CXXRecordDecl>(DC) && |
| 4025 | "Cannot have a constructor name outside of a class!"); |
| 4026 | ConstructorNameSet.insert(Name); |
| 4027 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4028 | |
| 4029 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4030 | assert(isa<CXXRecordDecl>(DC) && |
| 4031 | "Cannot have a conversion function name outside of a class!"); |
| 4032 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 4033 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4034 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 4035 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 4036 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4037 | // Sort the names into a stable order. |
Mandeep Singh Grang | c205d8c | 2018-03-27 16:50:00 +0000 | [diff] [blame] | 4038 | llvm::sort(Names.begin(), Names.end()); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4039 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 4040 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4041 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 4042 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4043 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 4044 | // First we try the easy case by forming the current context's constructor |
| 4045 | // name and adding that name first. This is a very useful optimization to |
| 4046 | // avoid walking the lexical declarations in many cases, and it also |
| 4047 | // handles the only case where a constructor name can come from some other |
| 4048 | // lexical context -- when that name is an implicit constructor merged from |
| 4049 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 4050 | // conversion function which doesn't occur in all the lexical contexts |
| 4051 | // would be an ODR violation. |
| 4052 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 4053 | Context->getCanonicalType(Context->getRecordType(D))); |
| 4054 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 4055 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4056 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 4057 | // If we still have constructors or conversion functions, we walk all the |
| 4058 | // names in the decl and add the constructors and conversion functions |
| 4059 | // which are visible in the order they lexically occur within the context. |
| 4060 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 4061 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 4062 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 4063 | auto Name = ChildND->getDeclName(); |
| 4064 | switch (Name.getNameKind()) { |
| 4065 | default: |
| 4066 | continue; |
| 4067 | |
| 4068 | case DeclarationName::CXXConstructorName: |
| 4069 | if (ConstructorNameSet.erase(Name)) |
| 4070 | Names.push_back(Name); |
| 4071 | break; |
| 4072 | |
| 4073 | case DeclarationName::CXXConversionFunctionName: |
| 4074 | if (ConversionNameSet.erase(Name)) |
| 4075 | Names.push_back(Name); |
| 4076 | break; |
| 4077 | } |
| 4078 | |
| 4079 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 4080 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4081 | } |
| 4082 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4083 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 4084 | "constructors by walking all the " |
| 4085 | "lexical members of the context."); |
| 4086 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 4087 | "conversion functions by walking all " |
| 4088 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4091 | // Next we need to do a lookup with each name into this decl context to fully |
| 4092 | // populate any results from external sources. We don't actually use the |
| 4093 | // results of these lookups because we only want to use the results after all |
| 4094 | // results have been loaded and the pointers into them will be stable. |
| 4095 | for (auto &Name : Names) |
| 4096 | DC->lookup(Name); |
| 4097 | |
| 4098 | // Now we need to insert the results for each name into the hash table. For |
| 4099 | // constructor names and conversion function names, we actually need to merge |
| 4100 | // all of the results for them into one list of results each and insert |
| 4101 | // those. |
| 4102 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 4103 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 4104 | |
| 4105 | // Now loop over the names, either inserting them or appending for the two |
| 4106 | // special cases. |
| 4107 | for (auto &Name : Names) { |
| 4108 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 4109 | |
| 4110 | switch (Name.getNameKind()) { |
| 4111 | default: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4112 | Generator.insert(Name, Trait.getData(Result), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4113 | break; |
| 4114 | |
| 4115 | case DeclarationName::CXXConstructorName: |
| 4116 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 4117 | break; |
| 4118 | |
| 4119 | case DeclarationName::CXXConversionFunctionName: |
| 4120 | ConversionDecls.append(Result.begin(), Result.end()); |
| 4121 | break; |
| 4122 | } |
| 4123 | } |
| 4124 | |
| 4125 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 4126 | // the first declaration's name here because the name itself isn't part of |
| 4127 | // the key, only the kind of name is used. |
| 4128 | if (!ConstructorDecls.empty()) |
| 4129 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4130 | Trait.getData(ConstructorDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4131 | if (!ConversionDecls.empty()) |
| 4132 | Generator.insert(ConversionDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4133 | Trait.getData(ConversionDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4134 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4135 | // Create the on-disk hash table. Also emit the existing imported and |
| 4136 | // merged table if there is one. |
| 4137 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; |
| 4138 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 4139 | } |
| 4140 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4141 | /// Write the block containing all of the declaration IDs |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4142 | /// visible from the given DeclContext. |
| 4143 | /// |
| 4144 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4145 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4146 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 4147 | DeclContext *DC) { |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4148 | // If we imported a key declaration of this namespace, write the visible |
| 4149 | // lookup results as an update record for it rather than including them |
| 4150 | // on this declaration. We will only look at key declarations on reload. |
| 4151 | if (isa<NamespaceDecl>(DC) && Chain && |
| 4152 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { |
| 4153 | // Only do this once, for the first local declaration of the namespace. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4154 | for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4155 | Prev = Prev->getPreviousDecl()) |
| 4156 | if (!Prev->isFromASTFile()) |
| 4157 | return 0; |
| 4158 | |
| 4159 | // Note that we need to emit an update record for the primary context. |
| 4160 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); |
| 4161 | |
| 4162 | // Make sure all visible decls are written. They will be recorded later. We |
| 4163 | // do this using a side data structure so we can sort the names into |
| 4164 | // a deterministic order. |
| 4165 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); |
| 4166 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> |
| 4167 | LookupResults; |
| 4168 | if (Map) { |
| 4169 | LookupResults.reserve(Map->size()); |
| 4170 | for (auto &Entry : *Map) |
| 4171 | LookupResults.push_back( |
| 4172 | std::make_pair(Entry.first, Entry.second.getLookupResult())); |
| 4173 | } |
| 4174 | |
Mandeep Singh Grang | c205d8c | 2018-03-27 16:50:00 +0000 | [diff] [blame] | 4175 | llvm::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4176 | for (auto &NameAndResult : LookupResults) { |
| 4177 | DeclarationName Name = NameAndResult.first; |
| 4178 | DeclContext::lookup_result Result = NameAndResult.second; |
| 4179 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || |
| 4180 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 4181 | // We have to work around a name lookup bug here where negative lookup |
| 4182 | // results for these names get cached in namespace lookup tables (these |
| 4183 | // names should never be looked up in a namespace). |
| 4184 | assert(Result.empty() && "Cannot have a constructor or conversion " |
| 4185 | "function name in a namespace!"); |
| 4186 | continue; |
| 4187 | } |
| 4188 | |
| 4189 | for (NamedDecl *ND : Result) |
| 4190 | if (!ND->isFromASTFile()) |
| 4191 | GetDeclRef(ND); |
| 4192 | } |
| 4193 | |
| 4194 | return 0; |
| 4195 | } |
| 4196 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4197 | if (DC->getPrimaryContext() != DC) |
| 4198 | return 0; |
| 4199 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4200 | // Skip contexts which don't support name lookup. |
| 4201 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4202 | return 0; |
| 4203 | |
| 4204 | // If not in C++, we perform name lookup for the translation unit via the |
| 4205 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 4206 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4207 | return 0; |
| 4208 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4209 | // Serialize the contents of the mapping used for lookup. Note that, |
| 4210 | // although we have two very different code paths, the serialized |
| 4211 | // representation is the same for both cases: a declaration name, |
| 4212 | // followed by a size, followed by references to the visible |
| 4213 | // declarations that have that name. |
| 4214 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 4215 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4216 | if (!Map || Map->empty()) |
| 4217 | return 0; |
| 4218 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4219 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4220 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4221 | GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4222 | |
| 4223 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4224 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4225 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 4226 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4227 | ++NumVisibleDeclContexts; |
| 4228 | return Offset; |
| 4229 | } |
| 4230 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4231 | /// Write an UPDATE_VISIBLE block for the given context. |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4232 | /// |
| 4233 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 4234 | /// 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] | 4235 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 4236 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4237 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 4238 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4239 | if (!Map || Map->empty()) |
| 4240 | return; |
| 4241 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4242 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4243 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4244 | GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4245 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4246 | // If we're updating a namespace, select a key declaration as the key for the |
| 4247 | // update record; those are the only ones that will be checked on reload. |
| 4248 | if (isa<NamespaceDecl>(DC)) |
| 4249 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); |
| 4250 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4251 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4252 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 4253 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4254 | } |
| 4255 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4256 | /// Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4257 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 4258 | RecordData::value_type Record[] = {Opts.getInt()}; |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4259 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 4260 | } |
| 4261 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4262 | /// Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4263 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 4264 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4265 | return; |
| 4266 | |
| 4267 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 4268 | RecordData Record; |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4269 | for (const auto &I:Opts.OptMap) { |
| 4270 | AddString(I.getKey(), Record); |
| 4271 | auto V = I.getValue(); |
Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 4272 | Record.push_back(V.Supported ? 1 : 0); |
| 4273 | Record.push_back(V.Enabled ? 1 : 0); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4274 | Record.push_back(V.Avail); |
| 4275 | Record.push_back(V.Core); |
| 4276 | } |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4277 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 4278 | } |
| 4279 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4280 | void ASTWriter::WriteOpenCLExtensionTypes(Sema &SemaRef) { |
| 4281 | if (!SemaRef.Context.getLangOpts().OpenCL) |
| 4282 | return; |
| 4283 | |
| 4284 | RecordData Record; |
| 4285 | for (const auto &I : SemaRef.OpenCLTypeExtMap) { |
| 4286 | Record.push_back( |
| 4287 | static_cast<unsigned>(getTypeID(I.first->getCanonicalTypeInternal()))); |
| 4288 | Record.push_back(I.second.size()); |
| 4289 | for (auto Ext : I.second) |
| 4290 | AddString(Ext, Record); |
| 4291 | } |
| 4292 | Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record); |
| 4293 | } |
| 4294 | |
| 4295 | void ASTWriter::WriteOpenCLExtensionDecls(Sema &SemaRef) { |
| 4296 | if (!SemaRef.Context.getLangOpts().OpenCL) |
| 4297 | return; |
| 4298 | |
| 4299 | RecordData Record; |
| 4300 | for (const auto &I : SemaRef.OpenCLDeclExtMap) { |
| 4301 | Record.push_back(getDeclID(I.first)); |
| 4302 | Record.push_back(static_cast<unsigned>(I.second.size())); |
| 4303 | for (auto Ext : I.second) |
| 4304 | AddString(Ext, Record); |
| 4305 | } |
| 4306 | Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record); |
| 4307 | } |
| 4308 | |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 4309 | void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) { |
| 4310 | if (SemaRef.ForceCUDAHostDeviceDepth > 0) { |
| 4311 | RecordData::value_type Record[] = {SemaRef.ForceCUDAHostDeviceDepth}; |
| 4312 | Stream.EmitRecord(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH, Record); |
| 4313 | } |
| 4314 | } |
| 4315 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4316 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4317 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4318 | RecordData Categories; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4319 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4320 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 4321 | unsigned Size = 0; |
| 4322 | unsigned StartIndex = Categories.size(); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4323 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4324 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4325 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4326 | // Allocate space for the size. |
| 4327 | Categories.push_back(0); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4328 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4329 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 4330 | for (ObjCInterfaceDecl::known_categories_iterator |
| 4331 | Cat = Class->known_categories_begin(), |
| 4332 | CatEnd = Class->known_categories_end(); |
| 4333 | Cat != CatEnd; ++Cat, ++Size) { |
| 4334 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 4335 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4336 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4337 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4338 | // Update the size. |
| 4339 | Categories[StartIndex] = Size; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4340 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4341 | // Record this interface -> category map. |
| 4342 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 4343 | CategoriesMap.push_back(CatInfo); |
| 4344 | } |
| 4345 | |
| 4346 | // Sort the categories map by the definition ID, since the reader will be |
| 4347 | // performing binary searches on this information. |
| 4348 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 4349 | |
| 4350 | // Emit the categories map. |
| 4351 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4352 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4353 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4354 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 4355 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 4356 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4357 | unsigned AbbrevID = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4358 | |
| 4359 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; |
| 4360 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 4361 | reinterpret_cast<char *>(CategoriesMap.data()), |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4362 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4363 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4364 | // Emit the category lists. |
| 4365 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 4366 | } |
| 4367 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4368 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 4369 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 4370 | |
| 4371 | if (LPTMap.empty()) |
| 4372 | return; |
| 4373 | |
| 4374 | RecordData Record; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4375 | for (auto &LPTMapEntry : LPTMap) { |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4376 | const FunctionDecl *FD = LPTMapEntry.first; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4377 | LateParsedTemplate &LPT = *LPTMapEntry.second; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4378 | AddDeclRef(FD, Record); |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4379 | AddDeclRef(LPT.D, Record); |
| 4380 | Record.push_back(LPT.Toks.size()); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4381 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4382 | for (const auto &Tok : LPT.Toks) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4383 | AddToken(Tok, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4384 | } |
| 4385 | } |
| 4386 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 4387 | } |
| 4388 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4389 | /// Write the state of 'pragma clang optimize' at the end of the module. |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4390 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 4391 | RecordData Record; |
| 4392 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 4393 | AddSourceLocation(PragmaLoc, Record); |
| 4394 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 4395 | } |
| 4396 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4397 | /// Write the state of 'pragma ms_struct' at the end of the module. |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4398 | void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) { |
| 4399 | RecordData Record; |
| 4400 | Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF); |
| 4401 | Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record); |
| 4402 | } |
| 4403 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4404 | /// Write the state of 'pragma pointers_to_members' at the end of the |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4405 | //module. |
| 4406 | void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) { |
| 4407 | RecordData Record; |
| 4408 | Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod); |
| 4409 | AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record); |
| 4410 | Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record); |
| 4411 | } |
| 4412 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4413 | /// Write the state of 'pragma pack' at the end of the module. |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4414 | void ASTWriter::WritePackPragmaOptions(Sema &SemaRef) { |
Duncan P. N. Exon Smith | 03df14c | 2017-04-15 00:07:57 +0000 | [diff] [blame] | 4415 | // Don't serialize pragma pack state for modules, since it should only take |
| 4416 | // effect on a per-submodule basis. |
| 4417 | if (WritingModule) |
| 4418 | return; |
| 4419 | |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4420 | RecordData Record; |
| 4421 | Record.push_back(SemaRef.PackStack.CurrentValue); |
| 4422 | AddSourceLocation(SemaRef.PackStack.CurrentPragmaLocation, Record); |
| 4423 | Record.push_back(SemaRef.PackStack.Stack.size()); |
| 4424 | for (const auto &StackEntry : SemaRef.PackStack.Stack) { |
| 4425 | Record.push_back(StackEntry.Value); |
| 4426 | AddSourceLocation(StackEntry.PragmaLocation, Record); |
Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 4427 | AddSourceLocation(StackEntry.PragmaPushLocation, Record); |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4428 | AddString(StackEntry.StackSlotLabel, Record); |
| 4429 | } |
| 4430 | Stream.EmitRecord(PACK_PRAGMA_OPTIONS, Record); |
| 4431 | } |
| 4432 | |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4433 | void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, |
| 4434 | ModuleFileExtensionWriter &Writer) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4435 | // Enter the extension block. |
| 4436 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); |
| 4437 | |
| 4438 | // Emit the metadata record abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4439 | auto Abv = std::make_shared<llvm::BitCodeAbbrev>(); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4440 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); |
| 4441 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4442 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4443 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4444 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4445 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4446 | unsigned Abbrev = Stream.EmitAbbrev(std::move(Abv)); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4447 | |
| 4448 | // Emit the metadata record. |
| 4449 | RecordData Record; |
| 4450 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); |
| 4451 | Record.push_back(EXTENSION_METADATA); |
| 4452 | Record.push_back(Metadata.MajorVersion); |
| 4453 | Record.push_back(Metadata.MinorVersion); |
| 4454 | Record.push_back(Metadata.BlockName.size()); |
| 4455 | Record.push_back(Metadata.UserInfo.size()); |
| 4456 | SmallString<64> Buffer; |
| 4457 | Buffer += Metadata.BlockName; |
| 4458 | Buffer += Metadata.UserInfo; |
| 4459 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); |
| 4460 | |
| 4461 | // Emit the contents of the extension block. |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4462 | Writer.writeExtensionContents(SemaRef, Stream); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4463 | |
| 4464 | // Exit the extension block. |
| 4465 | Stream.ExitBlock(); |
| 4466 | } |
| 4467 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4468 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4469 | // General Serialization Routines |
| 4470 | //===----------------------------------------------------------------------===// |
| 4471 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4472 | void ASTRecordWriter::AddAttr(const Attr *A) { |
Reid Kleckner | 11f9f8a | 2018-08-14 01:55:37 +0000 | [diff] [blame] | 4473 | auto &Record = *this; |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4474 | if (!A) |
| 4475 | return Record.push_back(0); |
| 4476 | Record.push_back(A->getKind() + 1); // FIXME: stable encoding, target attrs |
| 4477 | Record.AddSourceRange(A->getRange()); |
Reid Kleckner | 11f9f8a | 2018-08-14 01:55:37 +0000 | [diff] [blame] | 4478 | |
| 4479 | #include "clang/Serialization/AttrPCHWrite.inc" |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | /// Emit the list of attributes to the specified record. |
| 4483 | void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) { |
| 4484 | push_back(Attrs.size()); |
| 4485 | for (const auto *A : Attrs) |
| 4486 | AddAttr(A); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4487 | } |
| 4488 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 4489 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 4490 | AddSourceLocation(Tok.getLocation(), Record); |
| 4491 | Record.push_back(Tok.getLength()); |
| 4492 | |
| 4493 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 4494 | // if it is needed. |
| 4495 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 4496 | // FIXME: Should translate token kind to a stable encoding. |
| 4497 | Record.push_back(Tok.getKind()); |
| 4498 | // FIXME: Should translate token flags to a stable encoding. |
| 4499 | Record.push_back(Tok.getFlags()); |
| 4500 | } |
| 4501 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4502 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4503 | Record.push_back(Str.size()); |
| 4504 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 4505 | } |
| 4506 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4507 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4508 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4509 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4510 | bool Changed = |
| 4511 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4512 | |
| 4513 | // Remove a prefix to make the path relative, if relevant. |
| 4514 | const char *PathBegin = Path.data(); |
| 4515 | const char *PathPtr = |
| 4516 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 4517 | if (PathPtr != PathBegin) { |
| 4518 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 4519 | Changed = true; |
| 4520 | } |
| 4521 | |
| 4522 | return Changed; |
| 4523 | } |
| 4524 | |
| 4525 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 4526 | SmallString<128> FilePath(Path); |
| 4527 | PreparePathForOutput(FilePath); |
| 4528 | AddString(FilePath, Record); |
| 4529 | } |
| 4530 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4531 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4532 | StringRef Path) { |
| 4533 | SmallString<128> FilePath(Path); |
| 4534 | PreparePathForOutput(FilePath); |
| 4535 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 4536 | } |
| 4537 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4538 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 4539 | RecordDataImpl &Record) { |
| 4540 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4541 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4542 | Record.push_back(*Minor + 1); |
| 4543 | else |
| 4544 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4545 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4546 | Record.push_back(*Subminor + 1); |
| 4547 | else |
| 4548 | Record.push_back(0); |
| 4549 | } |
| 4550 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4551 | /// Note that the identifier II occurs at the given offset |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4552 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4553 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4554 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4555 | // 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] | 4556 | // up earlier in the chain and thus don't need an offset. |
| 4557 | if (ID >= FirstIdentID) |
| 4558 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4559 | } |
| 4560 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4561 | /// Note that the selector Sel occurs at the given offset |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4562 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4563 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4564 | unsigned ID = SelectorIDs[Sel]; |
| 4565 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4566 | // Don't record offsets for selectors that are also available in a different |
| 4567 | // file. |
| 4568 | if (ID < FirstSelectorID) |
| 4569 | return; |
| 4570 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4571 | } |
| 4572 | |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 4573 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream, |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4574 | SmallVectorImpl<char> &Buffer, MemoryBufferCache &PCMCache, |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 4575 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 4576 | bool IncludeTimestamps) |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4577 | : Stream(Stream), Buffer(Buffer), PCMCache(PCMCache), |
| 4578 | IncludeTimestamps(IncludeTimestamps) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4579 | for (const auto &Ext : Extensions) { |
| 4580 | if (auto Writer = Ext->createExtensionWriter(*this)) |
| 4581 | ModuleFileExtensionWriters.push_back(std::move(Writer)); |
| 4582 | } |
| 4583 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4584 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4585 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 4586 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4587 | } |
| 4588 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4589 | const LangOptions &ASTWriter::getLangOpts() const { |
| 4590 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 4591 | return Context->getLangOpts(); |
| 4592 | } |
| 4593 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4594 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { |
| 4595 | return IncludeTimestamps ? E->getModificationTime() : 0; |
| 4596 | } |
| 4597 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4598 | ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, |
| 4599 | const std::string &OutputFile, |
| 4600 | Module *WritingModule, StringRef isysroot, |
| 4601 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4602 | WritingAST = true; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4603 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4604 | ASTHasCompilerErrors = hasErrors; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4605 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4606 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4607 | Stream.Emit((unsigned)'C', 8); |
| 4608 | Stream.Emit((unsigned)'P', 8); |
| 4609 | Stream.Emit((unsigned)'C', 8); |
| 4610 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4611 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4612 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4613 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4614 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4615 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4616 | this->WritingModule = WritingModule; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4617 | ASTFileSignature Signature = |
| 4618 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4619 | Context = nullptr; |
| 4620 | PP = nullptr; |
| 4621 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4622 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4623 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4624 | WritingAST = false; |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4625 | if (SemaRef.Context.getLangOpts().ImplicitModules && WritingModule) { |
| 4626 | // Construct MemoryBuffer and update buffer manager. |
| 4627 | PCMCache.addBuffer(OutputFile, |
| 4628 | llvm::MemoryBuffer::getMemBufferCopy( |
| 4629 | StringRef(Buffer.begin(), Buffer.size()))); |
| 4630 | } |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4631 | return Signature; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4632 | } |
| 4633 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4634 | template<typename Vector> |
| 4635 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4636 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4637 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4638 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4639 | Writer.AddDeclRef(*I, Record); |
| 4640 | } |
| 4641 | } |
| 4642 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4643 | ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, |
| 4644 | const std::string &OutputFile, |
| 4645 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4646 | using namespace llvm; |
| 4647 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4648 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4649 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4650 | // Make sure that the AST reader knows to finalize itself. |
| 4651 | if (Chain) |
| 4652 | Chain->finalizeForWriting(); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4653 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4654 | ASTContext &Context = SemaRef.Context; |
| 4655 | Preprocessor &PP = SemaRef.PP; |
| 4656 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4657 | // Set up predefined declaration IDs. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4658 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { |
| 4659 | if (D) { |
| 4660 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); |
| 4661 | DeclIDs[D] = ID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4662 | } |
| 4663 | }; |
| 4664 | RegisterPredefDecl(Context.getTranslationUnitDecl(), |
| 4665 | PREDEF_DECL_TRANSLATION_UNIT_ID); |
| 4666 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); |
| 4667 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); |
| 4668 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); |
| 4669 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, |
| 4670 | PREDEF_DECL_OBJC_PROTOCOL_ID); |
| 4671 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); |
| 4672 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); |
| 4673 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, |
| 4674 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); |
| 4675 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4676 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4677 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, |
| 4678 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4679 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4680 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, |
| 4681 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 4682 | RegisterPredefDecl(Context.CFConstantStringTypeDecl, |
| 4683 | PREDEF_DECL_CF_CONSTANT_STRING_ID); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 4684 | RegisterPredefDecl(Context.CFConstantStringTagDecl, |
| 4685 | PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 4686 | RegisterPredefDecl(Context.TypePackElementDecl, |
| 4687 | PREDEF_DECL_TYPE_PACK_ELEMENT_ID); |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4688 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4689 | // 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] | 4690 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4691 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4692 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4693 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4694 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4695 | // Build a record containing all of the file scoped decls in this file. |
| 4696 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4697 | if (!isModule) |
| 4698 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4699 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4700 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4701 | // Build a record containing all of the delegating constructors we still need |
| 4702 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4703 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4704 | if (!isModule) |
| 4705 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4706 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4707 | // Write the set of weak, undeclared identifiers. We always write the |
| 4708 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4709 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4710 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4711 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4712 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4713 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4714 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4715 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4716 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4717 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4718 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4719 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4720 | // Build a record containing all of the ext_vector declarations. |
| 4721 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4722 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4723 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4724 | // Build a record containing all of the VTable uses information. |
| 4725 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4726 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4727 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4728 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4729 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4730 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4731 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4734 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4735 | RecordData UnusedLocalTypedefNameCandidates; |
| 4736 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4737 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4738 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4739 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4740 | RecordData PendingInstantiations; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4741 | for (const auto &I : SemaRef.PendingInstantiations) { |
| 4742 | AddDeclRef(I.first, PendingInstantiations); |
| 4743 | AddSourceLocation(I.second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4744 | } |
| 4745 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4746 | "There are local ones at end of translation unit!"); |
| 4747 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4748 | // Build a record containing some declaration references. |
| 4749 | RecordData SemaDeclRefs; |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4750 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) { |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4751 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4752 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4753 | AddDeclRef(SemaRef.getStdAlignValT(), SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4754 | } |
| 4755 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4756 | RecordData CUDASpecialDeclRefs; |
| 4757 | if (Context.getcudaConfigureCallDecl()) { |
| 4758 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4759 | } |
| 4760 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4761 | // Build a record containing all of the known namespaces. |
| 4762 | RecordData KnownNamespaces; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4763 | for (const auto &I : SemaRef.KnownNamespaces) { |
| 4764 | if (!I.second) |
| 4765 | AddDeclRef(I.first, KnownNamespaces); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4766 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4767 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4768 | // Build a record of all used, undefined objects that require definitions. |
| 4769 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4770 | |
| 4771 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4772 | SemaRef.getUndefinedButUsed(Undefined); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4773 | for (const auto &I : Undefined) { |
| 4774 | AddDeclRef(I.first, UndefinedButUsed); |
| 4775 | AddSourceLocation(I.second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4776 | } |
| 4777 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4778 | // Build a record containing all delete-expressions that we would like to |
| 4779 | // analyze later in AST. |
| 4780 | RecordData DeleteExprsToAnalyze; |
| 4781 | |
Richard Smith | f5262c6 | 2018-06-28 01:57:04 +0000 | [diff] [blame] | 4782 | if (!isModule) { |
| 4783 | for (const auto &DeleteExprsInfo : |
| 4784 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4785 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4786 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4787 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4788 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4789 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4790 | } |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4791 | } |
| 4792 | } |
| 4793 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4794 | // Write the control block |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4795 | WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4796 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4797 | // Write the remaining AST contents. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4798 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4799 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4800 | // This is so that older clang versions, before the introduction |
| 4801 | // of the control block, can read and reject the newer PCH format. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4802 | { |
| 4803 | RecordData Record = {VERSION_MAJOR}; |
| 4804 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4805 | } |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4806 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4807 | // Create a lexical update block containing all of the declarations in the |
| 4808 | // translation unit that do not come from other AST files. |
| 4809 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4810 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; |
| 4811 | for (const auto *D : TU->noload_decls()) { |
| 4812 | if (!D->isFromASTFile()) { |
| 4813 | NewGlobalKindDeclPairs.push_back(D->getKind()); |
| 4814 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); |
| 4815 | } |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4816 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4817 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4818 | auto Abv = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4819 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4820 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4821 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4822 | { |
| 4823 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; |
| 4824 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 4825 | bytes(NewGlobalKindDeclPairs)); |
| 4826 | } |
| 4827 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4828 | // And a visible updates block for the translation unit. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4829 | Abv = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4830 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4831 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4832 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4833 | UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4834 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4835 | |
| 4836 | // If we have any extern "C" names, write out a visible update for them. |
| 4837 | if (Context.ExternCContext) |
| 4838 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4839 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4840 | // If the translation unit has an anonymous namespace, and we don't already |
| 4841 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4842 | // 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] | 4843 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4844 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4845 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4846 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4847 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4848 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4849 | // Add update records for all mangling numbers and static local numbers. |
| 4850 | // These aren't really update records, but this is a convenient way of |
| 4851 | // tagging this rare extra data onto the declarations. |
| 4852 | for (const auto &Number : Context.MangleNumbers) |
| 4853 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4854 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4855 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4856 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4857 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4858 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4859 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4860 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4861 | // Make sure visible decls, added to DeclContexts previously loaded from |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 4862 | // an AST file, are registered for serialization. Likewise for template |
| 4863 | // specializations added to imported templates. |
| 4864 | for (const auto *I : DeclsToEmitEvenIfUnreferenced) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4865 | GetDeclRef(I); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4866 | } |
| 4867 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4868 | // Make sure all decls associated with an identifier are registered for |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4869 | // serialization, if we're storing decls with identifiers. |
| 4870 | if (!WritingModule || !getLangOpts().CPlusPlus) { |
| 4871 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4872 | for (const auto &ID : PP.getIdentifierTable()) { |
| 4873 | const IdentifierInfo *II = ID.second; |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4874 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 4875 | IIs.push_back(II); |
| 4876 | } |
| 4877 | // Sort the identifiers to visit based on their name. |
Mandeep Singh Grang | c205d8c | 2018-03-27 16:50:00 +0000 | [diff] [blame] | 4878 | llvm::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4879 | for (const IdentifierInfo *II : IIs) { |
| 4880 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4881 | DEnd = SemaRef.IdResolver.end(); |
| 4882 | D != DEnd; ++D) { |
| 4883 | GetDeclRef(*D); |
| 4884 | } |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4885 | } |
| 4886 | } |
| 4887 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 4888 | // For method pool in the module, if it contains an entry for a selector, |
| 4889 | // the entry should be complete, containing everything introduced by that |
| 4890 | // module and all modules it imports. It's possible that the entry is out of |
| 4891 | // date, so we need to pull in the new content here. |
| 4892 | |
| 4893 | // It's possible that updateOutOfDateSelector can update SelectorIDs. To be |
| 4894 | // safe, we copy all selectors out. |
| 4895 | llvm::SmallVector<Selector, 256> AllSelectors; |
| 4896 | for (auto &SelectorAndID : SelectorIDs) |
| 4897 | AllSelectors.push_back(SelectorAndID.first); |
| 4898 | for (auto &Selector : AllSelectors) |
| 4899 | SemaRef.updateOutOfDateSelector(Selector); |
| 4900 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4901 | // Form the record of special types. |
| 4902 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4903 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4904 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 4905 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 4906 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 4907 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 4908 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4909 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4910 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4911 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4912 | if (Chain) { |
| 4913 | // Write the mapping information describing our module dependencies and how |
| 4914 | // each of those modules were mapped into our own offset/ID space, so that |
| 4915 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4916 | // The map consists solely of a blob with the following format: |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 4917 | // *(module-kind:i8 |
| 4918 | // module-name-len:i16 module-name:len*i8 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4919 | // source-location-offset:i32 |
| 4920 | // identifier-id:i32 |
| 4921 | // preprocessed-entity-id:i32 |
| 4922 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4923 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4924 | // selector-id:i32 |
| 4925 | // declaration-id:i32 |
| 4926 | // c++-base-specifiers-id:i32 |
| 4927 | // type-id:i32) |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4928 | // |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 4929 | // module-kind is the ModuleKind enum value. If it is MK_PrebuiltModule or |
| 4930 | // MK_ExplicitModule, then the module-name is the module name. Otherwise, |
| 4931 | // it is the module file name. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4932 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4933 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4934 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4935 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4936 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4937 | { |
| 4938 | llvm::raw_svector_ostream Out(Buffer); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 4939 | for (ModuleFile &M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4940 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 4941 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 4942 | endian::Writer LE(Out, little); |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 4943 | LE.write<uint8_t>(static_cast<uint8_t>(M.Kind)); |
| 4944 | StringRef Name = |
| 4945 | M.Kind == MK_PrebuiltModule || M.Kind == MK_ExplicitModule |
| 4946 | ? M.ModuleName |
| 4947 | : M.FileName; |
| 4948 | LE.write<uint16_t>(Name.size()); |
| 4949 | Out.write(Name.data(), Name.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4950 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4951 | // Note: if a base ID was uint max, it would not be possible to load |
| 4952 | // another module after it or have more than one entity inside it. |
| 4953 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 4954 | |
| 4955 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 4956 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 4957 | if (ShouldWrite) |
| 4958 | LE.write<uint32_t>(BaseID); |
| 4959 | else |
| 4960 | LE.write<uint32_t>(None); |
| 4961 | }; |
| 4962 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4963 | // These values should be unique within a chain, since they will be read |
| 4964 | // as keys into ContinuousRangeMaps. |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 4965 | writeBaseIDOrNone(M.SLocEntryBaseOffset, M.LocalNumSLocEntries); |
| 4966 | writeBaseIDOrNone(M.BaseIdentifierID, M.LocalNumIdentifiers); |
| 4967 | writeBaseIDOrNone(M.BaseMacroID, M.LocalNumMacros); |
| 4968 | writeBaseIDOrNone(M.BasePreprocessedEntityID, |
| 4969 | M.NumPreprocessedEntities); |
| 4970 | writeBaseIDOrNone(M.BaseSubmoduleID, M.LocalNumSubmodules); |
| 4971 | writeBaseIDOrNone(M.BaseSelectorID, M.LocalNumSelectors); |
| 4972 | writeBaseIDOrNone(M.BaseDeclID, M.LocalNumDecls); |
| 4973 | writeBaseIDOrNone(M.BaseTypeIndex, M.LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4974 | } |
| 4975 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4976 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4977 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4978 | Buffer.data(), Buffer.size()); |
| 4979 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4980 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4981 | RecordData DeclUpdatesOffsetsRecord; |
| 4982 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4983 | // Keep writing types, declarations, and declaration update records |
| 4984 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4985 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 4986 | WriteTypeAbbrevs(); |
| 4987 | WriteDeclAbbrevs(); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4988 | do { |
| 4989 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 4990 | while (!DeclTypesToEmit.empty()) { |
| 4991 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 4992 | DeclTypesToEmit.pop(); |
| 4993 | if (DOT.isType()) |
| 4994 | WriteType(DOT.getType()); |
| 4995 | else |
| 4996 | WriteDecl(Context, DOT.getDecl()); |
| 4997 | } |
| 4998 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4999 | Stream.ExitBlock(); |
| 5000 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5001 | DoneWritingDeclsAndTypes = true; |
| 5002 | |
| 5003 | // These things can only be done once we've written out decls and types. |
| 5004 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 5005 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 5006 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5007 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 5008 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5009 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 5010 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 5011 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 5012 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 5013 | WriteReferencedSelectorsPool(SemaRef); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 5014 | WriteLateParsedTemplates(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 5015 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 5016 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 5017 | WriteOpenCLExtensions(SemaRef); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 5018 | WriteOpenCLExtensionTypes(SemaRef); |
| 5019 | WriteOpenCLExtensionDecls(SemaRef); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 5020 | WriteCUDAPragmas(SemaRef); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 5021 | |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5022 | // If we're emitting a module, write out the submodule information. |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 5023 | if (WritingModule) |
| 5024 | WriteSubmodules(WritingModule); |
| 5025 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 5026 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 5027 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5028 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 5029 | if (!EagerlyDeserializedDecls.empty()) |
| 5030 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5031 | |
David Blaikie | f63556d | 2017-04-12 20:58:33 +0000 | [diff] [blame] | 5032 | if (!ModularCodegenDecls.empty()) |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 5033 | Stream.EmitRecord(MODULAR_CODEGEN_DECLS, ModularCodegenDecls); |
| 5034 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5035 | // Write the record containing tentative definitions. |
| 5036 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5037 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 5038 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 5039 | // Write the record containing unused file scoped decls. |
| 5040 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5041 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 5042 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 5043 | // Write the record containing weak undeclared identifiers. |
| 5044 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5045 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 5046 | WeakUndeclaredIdentifiers); |
| 5047 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 5048 | // Write the record containing ext_vector type names. |
| 5049 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5050 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5051 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 5052 | // Write the record containing VTable uses information. |
| 5053 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5054 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 5055 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 5056 | // Write the record containing potentially unused local typedefs. |
| 5057 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 5058 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 5059 | UnusedLocalTypedefNameCandidates); |
| 5060 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 5061 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 5062 | if (!PendingInstantiations.empty()) |
| 5063 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 5064 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5065 | // Write the record containing declaration references of Sema. |
| 5066 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5067 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5068 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 5069 | // Write the record containing CUDA-specific declaration references. |
| 5070 | if (!CUDASpecialDeclRefs.empty()) |
| 5071 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5072 | |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 5073 | // Write the delegating constructors. |
| 5074 | if (!DelegatingCtorDecls.empty()) |
| 5075 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 5076 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5077 | // Write the known namespaces. |
| 5078 | if (!KnownNamespaces.empty()) |
| 5079 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 5080 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 5081 | // Write the undefined internal functions and variables, and inline functions. |
| 5082 | if (!UndefinedButUsed.empty()) |
| 5083 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 5084 | |
| 5085 | if (!DeleteExprsToAnalyze.empty()) |
| 5086 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 5087 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 5088 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5089 | for (auto *DC : UpdatedDeclContexts) |
| 5090 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 5091 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 5092 | if (!WritingModule) { |
| 5093 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5094 | struct ModuleInfo { |
| 5095 | uint64_t ID; |
| 5096 | Module *M; |
| 5097 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 5098 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5099 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 5100 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 5101 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5102 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 5103 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 5104 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5105 | |
| 5106 | if (!Imports.empty()) { |
| 5107 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 5108 | return A.ID < B.ID; |
| 5109 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 5110 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 5111 | return A.ID == B.ID; |
| 5112 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5113 | |
| 5114 | // Sort and deduplicate module IDs. |
Mandeep Singh Grang | c205d8c | 2018-03-27 16:50:00 +0000 | [diff] [blame] | 5115 | llvm::sort(Imports.begin(), Imports.end(), Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 5116 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5117 | Imports.end()); |
| 5118 | |
| 5119 | RecordData ImportedModules; |
| 5120 | for (const auto &Import : Imports) { |
| 5121 | ImportedModules.push_back(Import.ID); |
| 5122 | // FIXME: If the module has macros imported then later has declarations |
| 5123 | // imported, this location won't be the right one as a location for the |
| 5124 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 5125 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5126 | } |
| 5127 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 5128 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 5129 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 5130 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5131 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5132 | WriteObjCCategories(); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 5133 | if(!WritingModule) { |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 5134 | WriteOptimizePragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 5135 | WriteMSStructPragmaOptions(SemaRef); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 5136 | WriteMSPointersToMembersPragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 5137 | } |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 5138 | WritePackPragmaOptions(SemaRef); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 5139 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 5140 | // Some simple statistics |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 5141 | RecordData::value_type Record[] = { |
| 5142 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5143 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 5144 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 5145 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 5146 | // Write the module file extension blocks. |
| 5147 | for (const auto &ExtWriter : ModuleFileExtensionWriters) |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 5148 | WriteModuleFileExtension(SemaRef, *ExtWriter); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 5149 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 5150 | return writeUnhashedControlBlock(PP, Context); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5151 | } |
| 5152 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5153 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5154 | if (DeclUpdates.empty()) |
| 5155 | return; |
| 5156 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 5157 | DeclUpdateMap LocalUpdates; |
| 5158 | LocalUpdates.swap(DeclUpdates); |
| 5159 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5160 | for (auto &DeclUpdate : LocalUpdates) { |
| 5161 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 5162 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5163 | bool HasUpdatedBody = false; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5164 | RecordData RecordData; |
| 5165 | ASTRecordWriter Record(*this, RecordData); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5166 | for (auto &Update : DeclUpdate.second) { |
| 5167 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 5168 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5169 | // An updated body is emitted last, so that the reader doesn't need |
| 5170 | // to skip over the lazy body to reach statements for other records. |
| 5171 | if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION) |
| 5172 | HasUpdatedBody = true; |
| 5173 | else |
| 5174 | Record.push_back(Kind); |
| 5175 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5176 | switch (Kind) { |
| 5177 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 5178 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 5179 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5180 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5181 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 5182 | break; |
| 5183 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5184 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5185 | break; |
| 5186 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 5187 | case UPD_CXX_POINT_OF_INSTANTIATION: |
| 5188 | // FIXME: Do we need to also save the template specialization kind here? |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5189 | Record.AddSourceLocation(Update.getLoc()); |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 5190 | break; |
| 5191 | |
| 5192 | case UPD_CXX_ADDED_VAR_DEFINITION: { |
| 5193 | const VarDecl *VD = cast<VarDecl>(D); |
Richard Smith | f501759 | 2017-11-02 01:06:00 +0000 | [diff] [blame] | 5194 | Record.push_back(VD->isInline()); |
| 5195 | Record.push_back(VD->isInlineSpecified()); |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 5196 | if (VD->getInit()) { |
| 5197 | Record.push_back(!VD->isInitKnownICE() ? 1 |
| 5198 | : (VD->isInitICE() ? 3 : 2)); |
| 5199 | Record.AddStmt(const_cast<Expr*>(VD->getInit())); |
| 5200 | } else { |
| 5201 | Record.push_back(0); |
| 5202 | } |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5203 | break; |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 5204 | } |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5205 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5206 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5207 | Record.AddStmt(const_cast<Expr *>( |
| 5208 | cast<ParmVarDecl>(Update.getDecl())->getDefaultArg())); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5209 | break; |
| 5210 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 5211 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: |
| 5212 | Record.AddStmt( |
| 5213 | cast<FieldDecl>(Update.getDecl())->getInClassInitializer()); |
| 5214 | break; |
| 5215 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5216 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 5217 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 5218 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Akira Hatanaka | fcbe17c | 2018-03-28 21:13:14 +0000 | [diff] [blame] | 5219 | Record.push_back(RD->isParamDestroyedInCallee()); |
Akira Hatanaka | e6313ac | 2018-04-09 22:48:22 +0000 | [diff] [blame] | 5220 | Record.push_back(RD->getArgPassingRestrictions()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5221 | Record.AddCXXDefinitionData(RD); |
Richard Smith | 72e50fe | 2016-04-14 00:50:18 +0000 | [diff] [blame] | 5222 | Record.AddOffset(WriteDeclContextLexicalBlock( |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5223 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 5224 | |
| 5225 | // This state is sometimes updated by template instantiation, when we |
| 5226 | // switch from the specialization referring to the template declaration |
| 5227 | // to it referring to the template definition. |
| 5228 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 5229 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5230 | Record.AddSourceLocation(MSInfo->getPointOfInstantiation()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5231 | } else { |
| 5232 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 5233 | Record.push_back(Spec->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5234 | Record.AddSourceLocation(Spec->getPointOfInstantiation()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 5235 | |
| 5236 | // The instantiation might have been resolved to a partial |
| 5237 | // specialization. If so, record which one. |
| 5238 | auto From = Spec->getInstantiatedFrom(); |
| 5239 | if (auto PartialSpec = |
| 5240 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 5241 | Record.push_back(true); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5242 | Record.AddDeclRef(PartialSpec); |
| 5243 | Record.AddTemplateArgumentList( |
| 5244 | &Spec->getTemplateInstantiationArgs()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 5245 | } else { |
| 5246 | Record.push_back(false); |
| 5247 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5248 | } |
| 5249 | Record.push_back(RD->getTagKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5250 | Record.AddSourceLocation(RD->getLocation()); |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5251 | Record.AddSourceLocation(RD->getBeginLoc()); |
Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 5252 | Record.AddSourceRange(RD->getBraceRange()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5253 | |
| 5254 | // Instantiation may change attributes; write them all out afresh. |
| 5255 | Record.push_back(D->hasAttrs()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5256 | if (D->hasAttrs()) |
| 5257 | Record.AddAttributes(D->getAttrs()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5258 | |
| 5259 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 5260 | break; |
| 5261 | } |
| 5262 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5263 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5264 | Record.AddDeclRef(Update.getDecl()); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 5265 | Record.AddStmt(cast<CXXDestructorDecl>(D)->getOperatorDeleteThisArg()); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5266 | break; |
| 5267 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5268 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 5269 | addExceptionSpec( |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5270 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 5271 | Record); |
| 5272 | break; |
| 5273 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5274 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 5275 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 5276 | break; |
| 5277 | |
| 5278 | case UPD_DECL_MARKED_USED: |
| 5279 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 5280 | |
| 5281 | case UPD_MANGLING_NUMBER: |
| 5282 | case UPD_STATIC_LOCAL_NUMBER: |
| 5283 | Record.push_back(Update.getNumber()); |
| 5284 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5285 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5286 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5287 | Record.AddSourceRange( |
| 5288 | D->getAttr<OMPThreadPrivateDeclAttr>()->getRange()); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5289 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5290 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5291 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 5292 | Record.push_back(D->getAttr<OMPDeclareTargetDeclAttr>()->getMapType()); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5293 | Record.AddSourceRange( |
| 5294 | D->getAttr<OMPDeclareTargetDeclAttr>()->getRange()); |
| 5295 | break; |
| 5296 | |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5297 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5298 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5299 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5300 | |
| 5301 | case UPD_ADDED_ATTR_TO_RECORD: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5302 | Record.AddAttributes(llvm::makeArrayRef(Update.getAttr())); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5303 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5304 | } |
| 5305 | } |
| 5306 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5307 | if (HasUpdatedBody) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5308 | const auto *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5309 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5310 | Record.push_back(Def->isInlined()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5311 | Record.AddSourceLocation(Def->getInnerLocStart()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5312 | Record.AddFunctionDefinition(Def); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5313 | } |
| 5314 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5315 | OffsetsRecord.push_back(GetDeclRef(D)); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5316 | OffsetsRecord.push_back(Record.Emit(DECL_UPDATES)); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5317 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5318 | } |
| 5319 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5320 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5321 | uint32_t Raw = Loc.getRawEncoding(); |
| 5322 | Record.push_back((Raw << 1) | (Raw >> 31)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5323 | } |
| 5324 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5325 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5326 | AddSourceLocation(Range.getBegin(), Record); |
| 5327 | AddSourceLocation(Range.getEnd(), Record); |
| 5328 | } |
| 5329 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5330 | void ASTRecordWriter::AddAPInt(const llvm::APInt &Value) { |
| 5331 | Record->push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 5332 | const uint64_t *Words = Value.getRawData(); |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5333 | Record->append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5334 | } |
| 5335 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5336 | void ASTRecordWriter::AddAPSInt(const llvm::APSInt &Value) { |
| 5337 | Record->push_back(Value.isUnsigned()); |
| 5338 | AddAPInt(Value); |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5339 | } |
| 5340 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5341 | void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) { |
| 5342 | AddAPInt(Value.bitcastToAPInt()); |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5343 | } |
| 5344 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5345 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5346 | Record.push_back(getIdentifierRef(II)); |
| 5347 | } |
| 5348 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5349 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5350 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5351 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5352 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5353 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5354 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5355 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5356 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5357 | } |
| 5358 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5359 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5360 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 5361 | // have been redefined by the header (in which case they are not |
| 5362 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5363 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5364 | return 0; |
| 5365 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5366 | MacroID &ID = MacroIDs[MI]; |
| 5367 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5368 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5369 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 5370 | MacroInfosToEmit.push_back(Info); |
| 5371 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5372 | return ID; |
| 5373 | } |
| 5374 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5375 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5376 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5377 | return 0; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5378 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5379 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 5380 | return MacroIDs[MI]; |
| 5381 | } |
| 5382 | |
| 5383 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 5384 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5385 | } |
| 5386 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5387 | void ASTRecordWriter::AddSelectorRef(const Selector SelRef) { |
| 5388 | Record->push_back(Writer->getSelectorRef(SelRef)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5389 | } |
| 5390 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5391 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5392 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5393 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5394 | } |
| 5395 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5396 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5397 | if (SID == 0 && Chain) { |
| 5398 | // This might trigger a ReadSelector callback, which will set the ID for |
| 5399 | // this selector. |
| 5400 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5401 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5402 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5403 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5404 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5405 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5406 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5407 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5408 | } |
| 5409 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5410 | void ASTRecordWriter::AddCXXTemporary(const CXXTemporary *Temp) { |
| 5411 | AddDeclRef(Temp->getDestructor()); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5412 | } |
| 5413 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5414 | void ASTRecordWriter::AddTemplateArgumentLocInfo( |
| 5415 | TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5416 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5417 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5418 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5419 | break; |
| 5420 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5421 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5422 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5423 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5424 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5425 | AddSourceLocation(Arg.getTemplateNameLoc()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5426 | break; |
| 5427 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5428 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5429 | AddSourceLocation(Arg.getTemplateNameLoc()); |
| 5430 | AddSourceLocation(Arg.getTemplateEllipsisLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5431 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5432 | case TemplateArgument::Null: |
| 5433 | case TemplateArgument::Integral: |
| 5434 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5435 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5436 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5437 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5438 | break; |
| 5439 | } |
| 5440 | } |
| 5441 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5442 | void ASTRecordWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg) { |
| 5443 | AddTemplateArgument(Arg.getArgument()); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5444 | |
| 5445 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 5446 | bool InfoHasSameExpr |
| 5447 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5448 | Record->push_back(InfoHasSameExpr); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5449 | if (InfoHasSameExpr) |
| 5450 | return; // Avoid storing the same expr twice. |
| 5451 | } |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5452 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo()); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5453 | } |
| 5454 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5455 | void ASTRecordWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5456 | if (!TInfo) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5457 | AddTypeRef(QualType()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5458 | return; |
| 5459 | } |
| 5460 | |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 5461 | AddTypeRef(TInfo->getType()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5462 | AddTypeLoc(TInfo->getTypeLoc()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5463 | } |
| 5464 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5465 | void ASTRecordWriter::AddTypeLoc(TypeLoc TL) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5466 | TypeLocWriter TLW(*this); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5467 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 5468 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5469 | } |
| 5470 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5471 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 5472 | Record.push_back(GetOrCreateTypeID(T)); |
| 5473 | } |
| 5474 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5475 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5476 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5477 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5478 | if (T.isNull()) |
| 5479 | return TypeIdx(); |
| 5480 | assert(!T.getLocalFastQualifiers()); |
| 5481 | |
| 5482 | TypeIdx &Idx = TypeIdxs[T]; |
| 5483 | if (Idx.getIndex() == 0) { |
| 5484 | if (DoneWritingDeclsAndTypes) { |
| 5485 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 5486 | return TypeIdx(); |
| 5487 | } |
| 5488 | |
| 5489 | // We haven't seen this type before. Assign it a new ID and put it |
| 5490 | // into the queue of types to emit. |
| 5491 | Idx = TypeIdx(NextTypeID++); |
| 5492 | DeclTypesToEmit.push(T); |
| 5493 | } |
| 5494 | return Idx; |
| 5495 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 5496 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5497 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 5498 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5499 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5500 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5501 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5502 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5503 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5504 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5505 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 5506 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 5507 | return I->second; |
| 5508 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5509 | } |
| 5510 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5511 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5512 | Record.push_back(GetDeclRef(D)); |
| 5513 | } |
| 5514 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5515 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5516 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5517 | |
| 5518 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5519 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5520 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5521 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5522 | // If D comes from an AST file, its declaration ID is already known and |
| 5523 | // fixed. |
| 5524 | if (D->isFromASTFile()) |
| 5525 | return D->getGlobalID(); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5526 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5527 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5528 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5529 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5530 | if (DoneWritingDeclsAndTypes) { |
| 5531 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 5532 | return 0; |
| 5533 | } |
| 5534 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5535 | // We haven't seen this declaration before. Give it a new ID and |
| 5536 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5537 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5538 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5539 | } |
| 5540 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5541 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5542 | } |
| 5543 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5544 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5545 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5546 | return 0; |
| 5547 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5548 | // If D comes from an AST file, its declaration ID is already known and |
| 5549 | // fixed. |
| 5550 | if (D->isFromASTFile()) |
| 5551 | return D->getGlobalID(); |
| 5552 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5553 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 5554 | return DeclIDs[D]; |
| 5555 | } |
| 5556 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5557 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5558 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5559 | assert(D); |
| 5560 | |
| 5561 | SourceLocation Loc = D->getLocation(); |
| 5562 | if (Loc.isInvalid()) |
| 5563 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5564 | |
| 5565 | // We only keep track of the file-level declarations of each file. |
| 5566 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 5567 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5568 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 5569 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | 71b74eb | 2018-01-26 19:26:12 +0000 | [diff] [blame] | 5570 | // TemplateTemplateParmDecls that are part of an alias template, should not |
| 5571 | // have TU as lexical context. |
| 5572 | if (isa<ParmVarDecl>(D) || isa<TemplateTemplateParmDecl>(D)) |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5573 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5574 | |
| 5575 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5576 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5577 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5578 | FileID FID; |
| 5579 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5580 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5581 | if (FID.isInvalid()) |
| 5582 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5583 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5584 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5585 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5586 | if (!Info) |
| 5587 | Info = new DeclIDInFileInfo(); |
| 5588 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5589 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5590 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 5591 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5592 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5593 | Decls.push_back(LocDecl); |
| 5594 | return; |
| 5595 | } |
| 5596 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5597 | LocDeclIDsTy::iterator I = |
| 5598 | std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5599 | |
| 5600 | Decls.insert(I, LocDecl); |
| 5601 | } |
| 5602 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5603 | void ASTRecordWriter::AddDeclarationName(DeclarationName Name) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 5604 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5605 | Record->push_back(Name.getNameKind()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5606 | switch (Name.getNameKind()) { |
| 5607 | case DeclarationName::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5608 | AddIdentifierRef(Name.getAsIdentifierInfo()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5609 | break; |
| 5610 | |
| 5611 | case DeclarationName::ObjCZeroArgSelector: |
| 5612 | case DeclarationName::ObjCOneArgSelector: |
| 5613 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5614 | AddSelectorRef(Name.getObjCSelector()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5615 | break; |
| 5616 | |
| 5617 | case DeclarationName::CXXConstructorName: |
| 5618 | case DeclarationName::CXXDestructorName: |
| 5619 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5620 | AddTypeRef(Name.getCXXNameType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5621 | break; |
| 5622 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 5623 | case DeclarationName::CXXDeductionGuideName: |
| 5624 | AddDeclRef(Name.getCXXDeductionGuideTemplate()); |
| 5625 | break; |
| 5626 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5627 | case DeclarationName::CXXOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5628 | Record->push_back(Name.getCXXOverloadedOperator()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5629 | break; |
| 5630 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5631 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5632 | AddIdentifierRef(Name.getCXXLiteralIdentifier()); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5633 | break; |
| 5634 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5635 | case DeclarationName::CXXUsingDirective: |
| 5636 | // No extra data to emit |
| 5637 | break; |
| 5638 | } |
| 5639 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5640 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5641 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5642 | assert(needsAnonymousDeclarationNumber(D) && |
| 5643 | "expected an anonymous declaration"); |
| 5644 | |
| 5645 | // Number the anonymous declarations within this context, if we've not |
| 5646 | // already done so. |
| 5647 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5648 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5649 | auto *DC = D->getLexicalDeclContext(); |
| 5650 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5651 | AnonymousDeclarationNumbers[ND] = Number; |
| 5652 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5653 | |
| 5654 | It = AnonymousDeclarationNumbers.find(D); |
| 5655 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5656 | "declaration not found within its lexical context"); |
| 5657 | } |
| 5658 | |
| 5659 | return It->second; |
| 5660 | } |
| 5661 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5662 | void ASTRecordWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
| 5663 | DeclarationName Name) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5664 | switch (Name.getNameKind()) { |
| 5665 | case DeclarationName::CXXConstructorName: |
| 5666 | case DeclarationName::CXXDestructorName: |
| 5667 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5668 | AddTypeSourceInfo(DNLoc.NamedType.TInfo); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5669 | break; |
| 5670 | |
| 5671 | case DeclarationName::CXXOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5672 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5673 | DNLoc.CXXOperatorName.BeginOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5674 | AddSourceLocation( |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5675 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5676 | break; |
| 5677 | |
| 5678 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5679 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5680 | DNLoc.CXXLiteralOperatorName.OpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5681 | break; |
| 5682 | |
| 5683 | case DeclarationName::Identifier: |
| 5684 | case DeclarationName::ObjCZeroArgSelector: |
| 5685 | case DeclarationName::ObjCOneArgSelector: |
| 5686 | case DeclarationName::ObjCMultiArgSelector: |
| 5687 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 5688 | case DeclarationName::CXXDeductionGuideName: |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5689 | break; |
| 5690 | } |
| 5691 | } |
| 5692 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5693 | void ASTRecordWriter::AddDeclarationNameInfo( |
| 5694 | const DeclarationNameInfo &NameInfo) { |
| 5695 | AddDeclarationName(NameInfo.getName()); |
| 5696 | AddSourceLocation(NameInfo.getLoc()); |
| 5697 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName()); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5698 | } |
| 5699 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5700 | void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { |
| 5701 | AddNestedNameSpecifierLoc(Info.QualifierLoc); |
| 5702 | Record->push_back(Info.NumTemplParamLists); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5703 | for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5704 | AddTemplateParameterList(Info.TemplParamLists[i]); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5705 | } |
| 5706 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5707 | void ASTRecordWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5708 | // 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] | 5709 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5710 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5711 | |
| 5712 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5713 | while (NNS) { |
| 5714 | NestedNames.push_back(NNS); |
| 5715 | NNS = NNS->getPrefix(); |
| 5716 | } |
| 5717 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5718 | Record->push_back(NestedNames.size()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5719 | while(!NestedNames.empty()) { |
| 5720 | NNS = NestedNames.pop_back_val(); |
| 5721 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5722 | Record->push_back(Kind); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5723 | switch (Kind) { |
| 5724 | case NestedNameSpecifier::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5725 | AddIdentifierRef(NNS->getAsIdentifier()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5726 | break; |
| 5727 | |
| 5728 | case NestedNameSpecifier::Namespace: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5729 | AddDeclRef(NNS->getAsNamespace()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5730 | break; |
| 5731 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5732 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5733 | AddDeclRef(NNS->getAsNamespaceAlias()); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5734 | break; |
| 5735 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5736 | case NestedNameSpecifier::TypeSpec: |
| 5737 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5738 | AddTypeRef(QualType(NNS->getAsType(), 0)); |
| 5739 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5740 | break; |
| 5741 | |
| 5742 | case NestedNameSpecifier::Global: |
| 5743 | // Don't need to write an associated value. |
| 5744 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5745 | |
| 5746 | case NestedNameSpecifier::Super: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5747 | AddDeclRef(NNS->getAsRecordDecl()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5748 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5749 | } |
| 5750 | } |
| 5751 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5752 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5753 | void ASTRecordWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5754 | // 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] | 5755 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5756 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5757 | |
| 5758 | // Push each of the nested-name-specifiers's onto a stack for |
| 5759 | // serialization in reverse order. |
| 5760 | while (NNS) { |
| 5761 | NestedNames.push_back(NNS); |
| 5762 | NNS = NNS.getPrefix(); |
| 5763 | } |
| 5764 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5765 | Record->push_back(NestedNames.size()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5766 | while(!NestedNames.empty()) { |
| 5767 | NNS = NestedNames.pop_back_val(); |
| 5768 | NestedNameSpecifier::SpecifierKind Kind |
| 5769 | = NNS.getNestedNameSpecifier()->getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5770 | Record->push_back(Kind); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5771 | switch (Kind) { |
| 5772 | case NestedNameSpecifier::Identifier: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5773 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier()); |
| 5774 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5775 | break; |
| 5776 | |
| 5777 | case NestedNameSpecifier::Namespace: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5778 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace()); |
| 5779 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5780 | break; |
| 5781 | |
| 5782 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5783 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias()); |
| 5784 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5785 | break; |
| 5786 | |
| 5787 | case NestedNameSpecifier::TypeSpec: |
| 5788 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5789 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 5790 | AddTypeRef(NNS.getTypeLoc().getType()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5791 | AddTypeLoc(NNS.getTypeLoc()); |
| 5792 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5793 | break; |
| 5794 | |
| 5795 | case NestedNameSpecifier::Global: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5796 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5797 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5798 | |
| 5799 | case NestedNameSpecifier::Super: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5800 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl()); |
| 5801 | AddSourceRange(NNS.getLocalSourceRange()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5802 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5803 | } |
| 5804 | } |
| 5805 | } |
| 5806 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5807 | void ASTRecordWriter::AddTemplateName(TemplateName Name) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5808 | TemplateName::NameKind Kind = Name.getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5809 | Record->push_back(Kind); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5810 | switch (Kind) { |
| 5811 | case TemplateName::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5812 | AddDeclRef(Name.getAsTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5813 | break; |
| 5814 | |
| 5815 | case TemplateName::OverloadedTemplate: { |
| 5816 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5817 | Record->push_back(OvT->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5818 | for (const auto &I : *OvT) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5819 | AddDeclRef(I); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5820 | break; |
| 5821 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5822 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5823 | case TemplateName::QualifiedTemplate: { |
| 5824 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5825 | AddNestedNameSpecifier(QualT->getQualifier()); |
| 5826 | Record->push_back(QualT->hasTemplateKeyword()); |
| 5827 | AddDeclRef(QualT->getTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5828 | break; |
| 5829 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5830 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5831 | case TemplateName::DependentTemplate: { |
| 5832 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5833 | AddNestedNameSpecifier(DepT->getQualifier()); |
| 5834 | Record->push_back(DepT->isIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5835 | if (DepT->isIdentifier()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5836 | AddIdentifierRef(DepT->getIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5837 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5838 | Record->push_back(DepT->getOperator()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5839 | break; |
| 5840 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5841 | |
| 5842 | case TemplateName::SubstTemplateTemplateParm: { |
| 5843 | SubstTemplateTemplateParmStorage *subst |
| 5844 | = Name.getAsSubstTemplateTemplateParm(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5845 | AddDeclRef(subst->getParameter()); |
| 5846 | AddTemplateName(subst->getReplacement()); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5847 | break; |
| 5848 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5849 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5850 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5851 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5852 | = Name.getAsSubstTemplateTemplateParmPack(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5853 | AddDeclRef(SubstPack->getParameterPack()); |
| 5854 | AddTemplateArgument(SubstPack->getArgumentPack()); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5855 | break; |
| 5856 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5857 | } |
| 5858 | } |
| 5859 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5860 | void ASTRecordWriter::AddTemplateArgument(const TemplateArgument &Arg) { |
| 5861 | Record->push_back(Arg.getKind()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5862 | switch (Arg.getKind()) { |
| 5863 | case TemplateArgument::Null: |
| 5864 | break; |
| 5865 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5866 | AddTypeRef(Arg.getAsType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5867 | break; |
| 5868 | case TemplateArgument::Declaration: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5869 | AddDeclRef(Arg.getAsDecl()); |
| 5870 | AddTypeRef(Arg.getParamTypeForDecl()); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5871 | break; |
| 5872 | case TemplateArgument::NullPtr: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5873 | AddTypeRef(Arg.getNullPtrType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5874 | break; |
| 5875 | case TemplateArgument::Integral: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5876 | AddAPSInt(Arg.getAsIntegral()); |
| 5877 | AddTypeRef(Arg.getIntegralType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5878 | break; |
| 5879 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5880 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5881 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5882 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5883 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5884 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5885 | Record->push_back(*NumExpansions + 1); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5886 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5887 | Record->push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5888 | break; |
| 5889 | case TemplateArgument::Expression: |
| 5890 | AddStmt(Arg.getAsExpr()); |
| 5891 | break; |
| 5892 | case TemplateArgument::Pack: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5893 | Record->push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 5894 | for (const auto &P : Arg.pack_elements()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5895 | AddTemplateArgument(P); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5896 | break; |
| 5897 | } |
| 5898 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5899 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5900 | void ASTRecordWriter::AddTemplateParameterList( |
| 5901 | const TemplateParameterList *TemplateParams) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5902 | assert(TemplateParams && "No TemplateParams!"); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5903 | AddSourceLocation(TemplateParams->getTemplateLoc()); |
| 5904 | AddSourceLocation(TemplateParams->getLAngleLoc()); |
| 5905 | AddSourceLocation(TemplateParams->getRAngleLoc()); |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 5906 | // TODO: Concepts |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5907 | Record->push_back(TemplateParams->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5908 | for (const auto &P : *TemplateParams) |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5909 | AddDeclRef(P); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5910 | } |
| 5911 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5912 | /// Emit a template argument list. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5913 | void ASTRecordWriter::AddTemplateArgumentList( |
| 5914 | const TemplateArgumentList *TemplateArgs) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5915 | assert(TemplateArgs && "No TemplateArgs!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5916 | Record->push_back(TemplateArgs->size()); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5917 | for (int i = 0, e = TemplateArgs->size(); i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5918 | AddTemplateArgument(TemplateArgs->get(i)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5919 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5920 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5921 | void ASTRecordWriter::AddASTTemplateArgumentListInfo( |
| 5922 | const ASTTemplateArgumentListInfo *ASTTemplArgList) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5923 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5924 | AddSourceLocation(ASTTemplArgList->LAngleLoc); |
| 5925 | AddSourceLocation(ASTTemplArgList->RAngleLoc); |
| 5926 | Record->push_back(ASTTemplArgList->NumTemplateArgs); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5927 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5928 | for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5929 | AddTemplateArgumentLoc(TemplArgs[i]); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5930 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5931 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5932 | void ASTRecordWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set) { |
| 5933 | Record->push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5934 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5935 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5936 | AddDeclRef(I.getDecl()); |
| 5937 | Record->push_back(I.getAccess()); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5938 | } |
| 5939 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5940 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5941 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5942 | void ASTRecordWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base) { |
| 5943 | Record->push_back(Base.isVirtual()); |
| 5944 | Record->push_back(Base.isBaseOfClass()); |
| 5945 | Record->push_back(Base.getAccessSpecifierAsWritten()); |
| 5946 | Record->push_back(Base.getInheritConstructors()); |
| 5947 | AddTypeSourceInfo(Base.getTypeSourceInfo()); |
| 5948 | AddSourceRange(Base.getSourceRange()); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5949 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5950 | : SourceLocation()); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5951 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5952 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5953 | static uint64_t EmitCXXBaseSpecifiers(ASTWriter &W, |
| 5954 | ArrayRef<CXXBaseSpecifier> Bases) { |
| 5955 | ASTWriter::RecordData Record; |
| 5956 | ASTRecordWriter Writer(W, Record); |
| 5957 | Writer.push_back(Bases.size()); |
Dmitry Polukhin | 790b540 | 2016-04-06 10:01:46 +0000 | [diff] [blame] | 5958 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5959 | for (auto &Base : Bases) |
| 5960 | Writer.AddCXXBaseSpecifier(Base); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5961 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5962 | return Writer.Emit(serialization::DECL_CXX_BASE_SPECIFIERS); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5963 | } |
| 5964 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5965 | // FIXME: Move this out of the main ASTRecordWriter interface. |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5966 | void ASTRecordWriter::AddCXXBaseSpecifiers(ArrayRef<CXXBaseSpecifier> Bases) { |
| 5967 | AddOffset(EmitCXXBaseSpecifiers(*Writer, Bases)); |
| 5968 | } |
| 5969 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5970 | static uint64_t |
| 5971 | EmitCXXCtorInitializers(ASTWriter &W, |
| 5972 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 5973 | ASTWriter::RecordData Record; |
| 5974 | ASTRecordWriter Writer(W, Record); |
| 5975 | Writer.push_back(CtorInits.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5976 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5977 | for (auto *Init : CtorInits) { |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5978 | if (Init->isBaseInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5979 | Writer.push_back(CTOR_INITIALIZER_BASE); |
| 5980 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
| 5981 | Writer.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5982 | } else if (Init->isDelegatingInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5983 | Writer.push_back(CTOR_INITIALIZER_DELEGATING); |
| 5984 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5985 | } else if (Init->isMemberInitializer()){ |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5986 | Writer.push_back(CTOR_INITIALIZER_MEMBER); |
| 5987 | Writer.AddDeclRef(Init->getMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5988 | } else { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5989 | Writer.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 5990 | Writer.AddDeclRef(Init->getIndirectMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5991 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5992 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5993 | Writer.AddSourceLocation(Init->getMemberLocation()); |
| 5994 | Writer.AddStmt(Init->getInit()); |
| 5995 | Writer.AddSourceLocation(Init->getLParenLoc()); |
| 5996 | Writer.AddSourceLocation(Init->getRParenLoc()); |
| 5997 | Writer.push_back(Init->isWritten()); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 5998 | if (Init->isWritten()) |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5999 | Writer.push_back(Init->getSourceOrder()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6000 | } |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6001 | |
| 6002 | return Writer.Emit(serialization::DECL_CXX_CTOR_INITIALIZERS); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6003 | } |
| 6004 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6005 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 6006 | void ASTRecordWriter::AddCXXCtorInitializers( |
| 6007 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 6008 | AddOffset(EmitCXXCtorInitializers(*Writer, CtorInits)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 6009 | } |
| 6010 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6011 | void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6012 | auto &Data = D->data(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6013 | Record->push_back(Data.IsLambda); |
| 6014 | Record->push_back(Data.UserDeclaredConstructor); |
| 6015 | Record->push_back(Data.UserDeclaredSpecialMembers); |
| 6016 | Record->push_back(Data.Aggregate); |
| 6017 | Record->push_back(Data.PlainOldData); |
| 6018 | Record->push_back(Data.Empty); |
| 6019 | Record->push_back(Data.Polymorphic); |
| 6020 | Record->push_back(Data.Abstract); |
| 6021 | Record->push_back(Data.IsStandardLayout); |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 6022 | Record->push_back(Data.IsCXX11StandardLayout); |
| 6023 | Record->push_back(Data.HasBasesWithFields); |
| 6024 | Record->push_back(Data.HasBasesWithNonStaticDataMembers); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6025 | Record->push_back(Data.HasPrivateFields); |
| 6026 | Record->push_back(Data.HasProtectedFields); |
| 6027 | Record->push_back(Data.HasPublicFields); |
| 6028 | Record->push_back(Data.HasMutableFields); |
| 6029 | Record->push_back(Data.HasVariantMembers); |
| 6030 | Record->push_back(Data.HasOnlyCMembers); |
| 6031 | Record->push_back(Data.HasInClassInitializer); |
| 6032 | Record->push_back(Data.HasUninitializedReferenceMember); |
| 6033 | Record->push_back(Data.HasUninitializedFields); |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 6034 | Record->push_back(Data.HasInheritedConstructor); |
| 6035 | Record->push_back(Data.HasInheritedAssignment); |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 6036 | Record->push_back(Data.NeedOverloadResolutionForCopyConstructor); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6037 | Record->push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 6038 | Record->push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 6039 | Record->push_back(Data.NeedOverloadResolutionForDestructor); |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 6040 | Record->push_back(Data.DefaultedCopyConstructorIsDeleted); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6041 | Record->push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 6042 | Record->push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 6043 | Record->push_back(Data.DefaultedDestructorIsDeleted); |
| 6044 | Record->push_back(Data.HasTrivialSpecialMembers); |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 6045 | Record->push_back(Data.HasTrivialSpecialMembersForCall); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6046 | Record->push_back(Data.DeclaredNonTrivialSpecialMembers); |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 6047 | Record->push_back(Data.DeclaredNonTrivialSpecialMembersForCall); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6048 | Record->push_back(Data.HasIrrelevantDestructor); |
| 6049 | Record->push_back(Data.HasConstexprNonCopyMoveConstructor); |
| 6050 | Record->push_back(Data.HasDefaultedDefaultConstructor); |
| 6051 | Record->push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
| 6052 | Record->push_back(Data.HasConstexprDefaultConstructor); |
| 6053 | Record->push_back(Data.HasNonLiteralTypeFieldsOrBases); |
| 6054 | Record->push_back(Data.ComputedVisibleConversions); |
| 6055 | Record->push_back(Data.UserProvidedDefaultConstructor); |
| 6056 | Record->push_back(Data.DeclaredSpecialMembers); |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 6057 | Record->push_back(Data.ImplicitCopyConstructorCanHaveConstParamForVBase); |
| 6058 | Record->push_back(Data.ImplicitCopyConstructorCanHaveConstParamForNonVBase); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6059 | Record->push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 6060 | Record->push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 6061 | Record->push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 6062 | |
| 6063 | // getODRHash will compute the ODRHash if it has not been previously computed. |
| 6064 | Record->push_back(D->getODRHash()); |
David Blaikie | f63556d | 2017-04-12 20:58:33 +0000 | [diff] [blame] | 6065 | bool ModulesDebugInfo = Writer->Context->getLangOpts().ModulesDebugInfo && |
| 6066 | Writer->WritingModule && !D->isDependentType(); |
| 6067 | Record->push_back(ModulesDebugInfo); |
| 6068 | if (ModulesDebugInfo) |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 6069 | Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(D)); |
| 6070 | |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 6071 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 6072 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6073 | Record->push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 6074 | if (Data.NumBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 6075 | AddCXXBaseSpecifiers(Data.bases()); |
| 6076 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 6077 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6078 | Record->push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 6079 | if (Data.NumVBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 6080 | AddCXXBaseSpecifiers(Data.vbases()); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 6081 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6082 | AddUnresolvedSet(Data.Conversions.get(*Writer->Context)); |
| 6083 | AddUnresolvedSet(Data.VisibleConversions.get(*Writer->Context)); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 6084 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6085 | AddDeclRef(D->getFirstFriend()); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 6086 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 6087 | // Add lambda-specific data. |
| 6088 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6089 | auto &Lambda = D->getLambdaData(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6090 | Record->push_back(Lambda.Dependent); |
| 6091 | Record->push_back(Lambda.IsGenericLambda); |
| 6092 | Record->push_back(Lambda.CaptureDefault); |
| 6093 | Record->push_back(Lambda.NumCaptures); |
| 6094 | Record->push_back(Lambda.NumExplicitCaptures); |
| 6095 | Record->push_back(Lambda.ManglingNumber); |
Richard Smith | 0bae624 | 2016-08-25 00:34:00 +0000 | [diff] [blame] | 6096 | AddDeclRef(D->getLambdaContextDecl()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6097 | AddTypeSourceInfo(Lambda.MethodTyInfo); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 6098 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 6099 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6100 | AddSourceLocation(Capture.getLocation()); |
| 6101 | Record->push_back(Capture.isImplicit()); |
| 6102 | Record->push_back(Capture.getCaptureKind()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6103 | switch (Capture.getCaptureKind()) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 6104 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6105 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 6106 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6107 | break; |
| 6108 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 6109 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6110 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6111 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6112 | AddDeclRef(Var); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6113 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6114 | : SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6115 | break; |
| 6116 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 6117 | } |
| 6118 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 6119 | } |
| 6120 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 6121 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6122 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 6123 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6124 | assert(FirstDeclID == NextDeclID && |
| 6125 | FirstTypeID == NextTypeID && |
| 6126 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6127 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6128 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 6129 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6130 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6131 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6132 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 6133 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 6134 | // Note, this will get called multiple times, once one the reader starts up |
| 6135 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 6136 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 6137 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 6138 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6139 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6140 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 6141 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 6142 | NextDeclID = FirstDeclID; |
| 6143 | NextTypeID = FirstTypeID; |
| 6144 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6145 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 6146 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6147 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6148 | } |
| 6149 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 6150 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 6151 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 6152 | IdentID &StoredID = IdentifierIDs[II]; |
| 6153 | if (ID > StoredID) |
| 6154 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 6155 | } |
| 6156 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 6157 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 6158 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 6159 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 6160 | if (ID > StoredID) |
| 6161 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 6164 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 6165 | // Always take the highest-numbered type index. This copes with an interesting |
| 6166 | // 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] | 6167 | // 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] | 6168 | // keep the higher-numbered entry so that we can properly write it out to |
| 6169 | // the AST file. |
| 6170 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 6171 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 6172 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 6173 | } |
| 6174 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 6175 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 6176 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 6177 | SelectorID &StoredID = SelectorIDs[S]; |
| 6178 | if (ID > StoredID) |
| 6179 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 6180 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 6181 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 6182 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 6183 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 6184 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 6185 | MacroDefinitions[MD] = ID; |
| 6186 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6187 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 6188 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 6189 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 6190 | SubmoduleIDs[Mod] = ID; |
| 6191 | } |
| 6192 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6193 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6194 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 6195 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6196 | assert(!WritingAST && "Already writing the AST!"); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 6197 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6198 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6199 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6200 | // A forward reference was mutated into a definition. Rewrite it. |
| 6201 | // FIXME: This happens during template instantiation, should we |
| 6202 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6203 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 6204 | "completed a tag from another module but not by instantiation?"); |
| 6205 | DeclUpdates[RD].push_back( |
| 6206 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6207 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6208 | } |
| 6209 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6210 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6211 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { |
| 6212 | if (D->isFromASTFile()) |
| 6213 | return true; |
| 6214 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6215 | // The predefined __va_list_tag struct is imported if we imported any decls. |
| 6216 | // FIXME: This is a gross hack. |
| 6217 | return D == D->getASTContext().getVaListTagDecl(); |
| 6218 | } |
| 6219 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6220 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6221 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
| 6222 | assert(DC->isLookupContext() && |
Vassil Vassilev | 71eafde | 2016-04-06 20:56:03 +0000 | [diff] [blame] | 6223 | "Should not add lookup results to non-lookup contexts!"); |
| 6224 | |
Vassil Vassilev | 632eac3 | 2016-03-16 11:17:04 +0000 | [diff] [blame] | 6225 | // TU is handled elsewhere. |
| 6226 | if (isa<TranslationUnitDecl>(DC)) |
| 6227 | return; |
| 6228 | |
| 6229 | // Namespaces are handled elsewhere, except for template instantiations of |
| 6230 | // FunctionTemplateDecls in namespaces. We are interested in cases where the |
| 6231 | // local instantiations are added to an imported context. Only happens when |
| 6232 | // adding ADL lookup candidates, for example templated friends. |
| 6233 | if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && |
| 6234 | !isa<FunctionTemplateDecl>(D)) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6235 | return; |
| 6236 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6237 | // We're only interested in cases where a local declaration is added to an |
| 6238 | // imported context. |
| 6239 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) |
| 6240 | return; |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6241 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 6242 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 6243 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 6244 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6245 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { |
| 6246 | // We're adding a visible declaration to a predefined decl context. Ensure |
| 6247 | // that we write out all of its lookup results so we don't get a nasty |
| 6248 | // surprise when we try to emit its lookup table. |
| 6249 | for (auto *Child : DC->decls()) |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6250 | DeclsToEmitEvenIfUnreferenced.push_back(Child); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6251 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6252 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6253 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6254 | |
| 6255 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6256 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6257 | assert(D->isImplicit()); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6258 | |
| 6259 | // We're only interested in cases where a local declaration is added to an |
| 6260 | // imported context. |
| 6261 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) |
| 6262 | return; |
| 6263 | |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6264 | if (!isa<CXXMethodDecl>(D)) |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6265 | return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6266 | |
| 6267 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 6268 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 6269 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 6270 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6271 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 6272 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6273 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6274 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6275 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 6276 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6277 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6278 | // If we don't already know the exception specification for this redecl |
| 6279 | // chain, add an update record for it. |
| 6280 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 6281 | ->getType() |
| 6282 | ->castAs<FunctionProtoType>() |
| 6283 | ->getExceptionSpecType())) |
| 6284 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 6285 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 6288 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6289 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 6290 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6291 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6292 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6293 | DeclUpdates[D].push_back( |
| 6294 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 6295 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 6296 | } |
| 6297 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 6298 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 6299 | const FunctionDecl *Delete, |
| 6300 | Expr *ThisArg) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6301 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 6302 | assert(!WritingAST && "Already writing the AST!"); |
| 6303 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6304 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6305 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6306 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 6307 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 6308 | } |
| 6309 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 6310 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6311 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6312 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6313 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 6314 | return; // Declaration not imported from PCH. |
| 6315 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 6316 | // Implicit function decl from a PCH was defined. |
| 6317 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 6318 | } |
| 6319 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 6320 | void ASTWriter::VariableDefinitionInstantiated(const VarDecl *D) { |
| 6321 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
| 6322 | assert(!WritingAST && "Already writing the AST!"); |
| 6323 | if (!D->isFromASTFile()) |
| 6324 | return; |
| 6325 | |
| 6326 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_VAR_DEFINITION)); |
| 6327 | } |
| 6328 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 6329 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6330 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 6331 | assert(!WritingAST && "Already writing the AST!"); |
| 6332 | if (!D->isFromASTFile()) |
| 6333 | return; |
| 6334 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6335 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 6338 | void ASTWriter::InstantiationRequested(const ValueDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6339 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6340 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6341 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 6342 | return; |
| 6343 | |
| 6344 | // Since the actual instantiation is delayed, this really means that we need |
| 6345 | // to update the instantiation location. |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 6346 | SourceLocation POI; |
| 6347 | if (auto *VD = dyn_cast<VarDecl>(D)) |
| 6348 | POI = VD->getPointOfInstantiation(); |
| 6349 | else |
| 6350 | POI = cast<FunctionDecl>(D)->getPointOfInstantiation(); |
| 6351 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_POINT_OF_INSTANTIATION, POI)); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 6352 | } |
| 6353 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 6354 | void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6355 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 6356 | assert(!WritingAST && "Already writing the AST!"); |
| 6357 | if (!D->isFromASTFile()) |
| 6358 | return; |
| 6359 | |
| 6360 | DeclUpdates[D].push_back( |
| 6361 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D)); |
| 6362 | } |
| 6363 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 6364 | void ASTWriter::DefaultMemberInitializerInstantiated(const FieldDecl *D) { |
| 6365 | assert(!WritingAST && "Already writing the AST!"); |
| 6366 | if (!D->isFromASTFile()) |
| 6367 | return; |
| 6368 | |
| 6369 | DeclUpdates[D].push_back( |
| 6370 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER, D)); |
| 6371 | } |
| 6372 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 6373 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 6374 | const ObjCInterfaceDecl *IFD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6375 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6376 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6377 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 6378 | return; // Declaration not imported from PCH. |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 6379 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 6380 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 6381 | ObjCClassesWithCategories.insert( |
| 6382 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 6383 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 6384 | |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6385 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6386 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6387 | assert(!WritingAST && "Already writing the AST!"); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 6388 | |
| 6389 | // If there is *any* declaration of the entity that's not from an AST file, |
| 6390 | // we can skip writing the update record. We make sure that isUsed() triggers |
| 6391 | // completion of the redeclaration chain of the entity. |
| 6392 | for (auto Prev = D->getMostRecentDecl(); Prev; Prev = Prev->getPreviousDecl()) |
| 6393 | if (IsLocalDecl(Prev)) |
| 6394 | return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6395 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 6396 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6397 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 6398 | |
| 6399 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6400 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 6401 | assert(!WritingAST && "Already writing the AST!"); |
| 6402 | if (!D->isFromASTFile()) |
| 6403 | return; |
| 6404 | |
| 6405 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 6406 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6407 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 6408 | void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, |
| 6409 | const Attr *Attr) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6410 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 6411 | assert(!WritingAST && "Already writing the AST!"); |
| 6412 | if (!D->isFromASTFile()) |
| 6413 | return; |
| 6414 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 6415 | DeclUpdates[D].push_back( |
| 6416 | DeclUpdate(UPD_DECL_MARKED_OPENMP_DECLARETARGET, Attr)); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 6417 | } |
| 6418 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6419 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6420 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6421 | assert(!WritingAST && "Already writing the AST!"); |
| 6422 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6423 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6424 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6425 | |
| 6426 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 6427 | const RecordDecl *Record) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6428 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6429 | assert(!WritingAST && "Already writing the AST!"); |
| 6430 | if (!Record->isFromASTFile()) |
| 6431 | return; |
| 6432 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 6433 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6434 | |
| 6435 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6436 | const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) { |
| 6437 | assert(!WritingAST && "Already writing the AST!"); |
| 6438 | |
| 6439 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6440 | return; |
| 6441 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6442 | return; |
| 6443 | |
| 6444 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6445 | } |
| 6446 | |
| 6447 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6448 | const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) { |
| 6449 | assert(!WritingAST && "Already writing the AST!"); |
| 6450 | |
| 6451 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6452 | return; |
| 6453 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6454 | return; |
| 6455 | |
| 6456 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6457 | } |
| 6458 | |
| 6459 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 6460 | const FunctionDecl *D) { |
| 6461 | assert(!WritingAST && "Already writing the AST!"); |
| 6462 | |
| 6463 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6464 | return; |
| 6465 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6466 | return; |
| 6467 | |
| 6468 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6469 | } |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame^] | 6470 | |
| 6471 | //===----------------------------------------------------------------------===// |
| 6472 | //// OMPClause Serialization |
| 6473 | ////===----------------------------------------------------------------------===// |
| 6474 | |
| 6475 | void OMPClauseWriter::writeClause(OMPClause *C) { |
| 6476 | Record.push_back(C->getClauseKind()); |
| 6477 | Visit(C); |
| 6478 | Record.AddSourceLocation(C->getBeginLoc()); |
| 6479 | Record.AddSourceLocation(C->getEndLoc()); |
| 6480 | } |
| 6481 | |
| 6482 | void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) { |
| 6483 | Record.push_back(C->getCaptureRegion()); |
| 6484 | Record.AddStmt(C->getPreInitStmt()); |
| 6485 | } |
| 6486 | |
| 6487 | void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) { |
| 6488 | VisitOMPClauseWithPreInit(C); |
| 6489 | Record.AddStmt(C->getPostUpdateExpr()); |
| 6490 | } |
| 6491 | |
| 6492 | void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) { |
| 6493 | VisitOMPClauseWithPreInit(C); |
| 6494 | Record.push_back(C->getNameModifier()); |
| 6495 | Record.AddSourceLocation(C->getNameModifierLoc()); |
| 6496 | Record.AddSourceLocation(C->getColonLoc()); |
| 6497 | Record.AddStmt(C->getCondition()); |
| 6498 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6499 | } |
| 6500 | |
| 6501 | void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) { |
| 6502 | Record.AddStmt(C->getCondition()); |
| 6503 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6504 | } |
| 6505 | |
| 6506 | void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 6507 | VisitOMPClauseWithPreInit(C); |
| 6508 | Record.AddStmt(C->getNumThreads()); |
| 6509 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6510 | } |
| 6511 | |
| 6512 | void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) { |
| 6513 | Record.AddStmt(C->getSafelen()); |
| 6514 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6515 | } |
| 6516 | |
| 6517 | void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) { |
| 6518 | Record.AddStmt(C->getSimdlen()); |
| 6519 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6520 | } |
| 6521 | |
| 6522 | void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) { |
| 6523 | Record.AddStmt(C->getNumForLoops()); |
| 6524 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6525 | } |
| 6526 | |
| 6527 | void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) { |
| 6528 | Record.push_back(C->getDefaultKind()); |
| 6529 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6530 | Record.AddSourceLocation(C->getDefaultKindKwLoc()); |
| 6531 | } |
| 6532 | |
| 6533 | void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) { |
| 6534 | Record.push_back(C->getProcBindKind()); |
| 6535 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6536 | Record.AddSourceLocation(C->getProcBindKindKwLoc()); |
| 6537 | } |
| 6538 | |
| 6539 | void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) { |
| 6540 | VisitOMPClauseWithPreInit(C); |
| 6541 | Record.push_back(C->getScheduleKind()); |
| 6542 | Record.push_back(C->getFirstScheduleModifier()); |
| 6543 | Record.push_back(C->getSecondScheduleModifier()); |
| 6544 | Record.AddStmt(C->getChunkSize()); |
| 6545 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6546 | Record.AddSourceLocation(C->getFirstScheduleModifierLoc()); |
| 6547 | Record.AddSourceLocation(C->getSecondScheduleModifierLoc()); |
| 6548 | Record.AddSourceLocation(C->getScheduleKindLoc()); |
| 6549 | Record.AddSourceLocation(C->getCommaLoc()); |
| 6550 | } |
| 6551 | |
| 6552 | void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) { |
| 6553 | Record.push_back(C->getLoopNumIterations().size()); |
| 6554 | Record.AddStmt(C->getNumForLoops()); |
| 6555 | for (Expr *NumIter : C->getLoopNumIterations()) |
| 6556 | Record.AddStmt(NumIter); |
| 6557 | for (unsigned I = 0, E = C->getLoopNumIterations().size(); I <E; ++I) |
| 6558 | Record.AddStmt(C->getLoopCunter(I)); |
| 6559 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6560 | } |
| 6561 | |
| 6562 | void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {} |
| 6563 | |
| 6564 | void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {} |
| 6565 | |
| 6566 | void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {} |
| 6567 | |
| 6568 | void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {} |
| 6569 | |
| 6570 | void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {} |
| 6571 | |
| 6572 | void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {} |
| 6573 | |
| 6574 | void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {} |
| 6575 | |
| 6576 | void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {} |
| 6577 | |
| 6578 | void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {} |
| 6579 | |
| 6580 | void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {} |
| 6581 | |
| 6582 | void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {} |
| 6583 | |
| 6584 | void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) { |
| 6585 | Record.push_back(C->varlist_size()); |
| 6586 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6587 | for (auto *VE : C->varlists()) { |
| 6588 | Record.AddStmt(VE); |
| 6589 | } |
| 6590 | for (auto *VE : C->private_copies()) { |
| 6591 | Record.AddStmt(VE); |
| 6592 | } |
| 6593 | } |
| 6594 | |
| 6595 | void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) { |
| 6596 | Record.push_back(C->varlist_size()); |
| 6597 | VisitOMPClauseWithPreInit(C); |
| 6598 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6599 | for (auto *VE : C->varlists()) { |
| 6600 | Record.AddStmt(VE); |
| 6601 | } |
| 6602 | for (auto *VE : C->private_copies()) { |
| 6603 | Record.AddStmt(VE); |
| 6604 | } |
| 6605 | for (auto *VE : C->inits()) { |
| 6606 | Record.AddStmt(VE); |
| 6607 | } |
| 6608 | } |
| 6609 | |
| 6610 | void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) { |
| 6611 | Record.push_back(C->varlist_size()); |
| 6612 | VisitOMPClauseWithPostUpdate(C); |
| 6613 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6614 | for (auto *VE : C->varlists()) |
| 6615 | Record.AddStmt(VE); |
| 6616 | for (auto *E : C->private_copies()) |
| 6617 | Record.AddStmt(E); |
| 6618 | for (auto *E : C->source_exprs()) |
| 6619 | Record.AddStmt(E); |
| 6620 | for (auto *E : C->destination_exprs()) |
| 6621 | Record.AddStmt(E); |
| 6622 | for (auto *E : C->assignment_ops()) |
| 6623 | Record.AddStmt(E); |
| 6624 | } |
| 6625 | |
| 6626 | void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) { |
| 6627 | Record.push_back(C->varlist_size()); |
| 6628 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6629 | for (auto *VE : C->varlists()) |
| 6630 | Record.AddStmt(VE); |
| 6631 | } |
| 6632 | |
| 6633 | void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) { |
| 6634 | Record.push_back(C->varlist_size()); |
| 6635 | VisitOMPClauseWithPostUpdate(C); |
| 6636 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6637 | Record.AddSourceLocation(C->getColonLoc()); |
| 6638 | Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); |
| 6639 | Record.AddDeclarationNameInfo(C->getNameInfo()); |
| 6640 | for (auto *VE : C->varlists()) |
| 6641 | Record.AddStmt(VE); |
| 6642 | for (auto *VE : C->privates()) |
| 6643 | Record.AddStmt(VE); |
| 6644 | for (auto *E : C->lhs_exprs()) |
| 6645 | Record.AddStmt(E); |
| 6646 | for (auto *E : C->rhs_exprs()) |
| 6647 | Record.AddStmt(E); |
| 6648 | for (auto *E : C->reduction_ops()) |
| 6649 | Record.AddStmt(E); |
| 6650 | } |
| 6651 | |
| 6652 | void OMPClauseWriter::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) { |
| 6653 | Record.push_back(C->varlist_size()); |
| 6654 | VisitOMPClauseWithPostUpdate(C); |
| 6655 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6656 | Record.AddSourceLocation(C->getColonLoc()); |
| 6657 | Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); |
| 6658 | Record.AddDeclarationNameInfo(C->getNameInfo()); |
| 6659 | for (auto *VE : C->varlists()) |
| 6660 | Record.AddStmt(VE); |
| 6661 | for (auto *VE : C->privates()) |
| 6662 | Record.AddStmt(VE); |
| 6663 | for (auto *E : C->lhs_exprs()) |
| 6664 | Record.AddStmt(E); |
| 6665 | for (auto *E : C->rhs_exprs()) |
| 6666 | Record.AddStmt(E); |
| 6667 | for (auto *E : C->reduction_ops()) |
| 6668 | Record.AddStmt(E); |
| 6669 | } |
| 6670 | |
| 6671 | void OMPClauseWriter::VisitOMPInReductionClause(OMPInReductionClause *C) { |
| 6672 | Record.push_back(C->varlist_size()); |
| 6673 | VisitOMPClauseWithPostUpdate(C); |
| 6674 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6675 | Record.AddSourceLocation(C->getColonLoc()); |
| 6676 | Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); |
| 6677 | Record.AddDeclarationNameInfo(C->getNameInfo()); |
| 6678 | for (auto *VE : C->varlists()) |
| 6679 | Record.AddStmt(VE); |
| 6680 | for (auto *VE : C->privates()) |
| 6681 | Record.AddStmt(VE); |
| 6682 | for (auto *E : C->lhs_exprs()) |
| 6683 | Record.AddStmt(E); |
| 6684 | for (auto *E : C->rhs_exprs()) |
| 6685 | Record.AddStmt(E); |
| 6686 | for (auto *E : C->reduction_ops()) |
| 6687 | Record.AddStmt(E); |
| 6688 | for (auto *E : C->taskgroup_descriptors()) |
| 6689 | Record.AddStmt(E); |
| 6690 | } |
| 6691 | |
| 6692 | void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) { |
| 6693 | Record.push_back(C->varlist_size()); |
| 6694 | VisitOMPClauseWithPostUpdate(C); |
| 6695 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6696 | Record.AddSourceLocation(C->getColonLoc()); |
| 6697 | Record.push_back(C->getModifier()); |
| 6698 | Record.AddSourceLocation(C->getModifierLoc()); |
| 6699 | for (auto *VE : C->varlists()) { |
| 6700 | Record.AddStmt(VE); |
| 6701 | } |
| 6702 | for (auto *VE : C->privates()) { |
| 6703 | Record.AddStmt(VE); |
| 6704 | } |
| 6705 | for (auto *VE : C->inits()) { |
| 6706 | Record.AddStmt(VE); |
| 6707 | } |
| 6708 | for (auto *VE : C->updates()) { |
| 6709 | Record.AddStmt(VE); |
| 6710 | } |
| 6711 | for (auto *VE : C->finals()) { |
| 6712 | Record.AddStmt(VE); |
| 6713 | } |
| 6714 | Record.AddStmt(C->getStep()); |
| 6715 | Record.AddStmt(C->getCalcStep()); |
| 6716 | } |
| 6717 | |
| 6718 | void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) { |
| 6719 | Record.push_back(C->varlist_size()); |
| 6720 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6721 | Record.AddSourceLocation(C->getColonLoc()); |
| 6722 | for (auto *VE : C->varlists()) |
| 6723 | Record.AddStmt(VE); |
| 6724 | Record.AddStmt(C->getAlignment()); |
| 6725 | } |
| 6726 | |
| 6727 | void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) { |
| 6728 | Record.push_back(C->varlist_size()); |
| 6729 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6730 | for (auto *VE : C->varlists()) |
| 6731 | Record.AddStmt(VE); |
| 6732 | for (auto *E : C->source_exprs()) |
| 6733 | Record.AddStmt(E); |
| 6734 | for (auto *E : C->destination_exprs()) |
| 6735 | Record.AddStmt(E); |
| 6736 | for (auto *E : C->assignment_ops()) |
| 6737 | Record.AddStmt(E); |
| 6738 | } |
| 6739 | |
| 6740 | void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 6741 | Record.push_back(C->varlist_size()); |
| 6742 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6743 | for (auto *VE : C->varlists()) |
| 6744 | Record.AddStmt(VE); |
| 6745 | for (auto *E : C->source_exprs()) |
| 6746 | Record.AddStmt(E); |
| 6747 | for (auto *E : C->destination_exprs()) |
| 6748 | Record.AddStmt(E); |
| 6749 | for (auto *E : C->assignment_ops()) |
| 6750 | Record.AddStmt(E); |
| 6751 | } |
| 6752 | |
| 6753 | void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) { |
| 6754 | Record.push_back(C->varlist_size()); |
| 6755 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6756 | for (auto *VE : C->varlists()) |
| 6757 | Record.AddStmt(VE); |
| 6758 | } |
| 6759 | |
| 6760 | void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) { |
| 6761 | Record.push_back(C->varlist_size()); |
| 6762 | Record.push_back(C->getNumLoops()); |
| 6763 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6764 | Record.push_back(C->getDependencyKind()); |
| 6765 | Record.AddSourceLocation(C->getDependencyLoc()); |
| 6766 | Record.AddSourceLocation(C->getColonLoc()); |
| 6767 | for (auto *VE : C->varlists()) |
| 6768 | Record.AddStmt(VE); |
| 6769 | for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I) |
| 6770 | Record.AddStmt(C->getLoopData(I)); |
| 6771 | } |
| 6772 | |
| 6773 | void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) { |
| 6774 | VisitOMPClauseWithPreInit(C); |
| 6775 | Record.AddStmt(C->getDevice()); |
| 6776 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6777 | } |
| 6778 | |
| 6779 | void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) { |
| 6780 | Record.push_back(C->varlist_size()); |
| 6781 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 6782 | Record.push_back(C->getTotalComponentListNum()); |
| 6783 | Record.push_back(C->getTotalComponentsNum()); |
| 6784 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6785 | Record.push_back(C->getMapTypeModifier()); |
| 6786 | Record.push_back(C->getMapType()); |
| 6787 | Record.AddSourceLocation(C->getMapLoc()); |
| 6788 | Record.AddSourceLocation(C->getColonLoc()); |
| 6789 | for (auto *E : C->varlists()) |
| 6790 | Record.AddStmt(E); |
| 6791 | for (auto *D : C->all_decls()) |
| 6792 | Record.AddDeclRef(D); |
| 6793 | for (auto N : C->all_num_lists()) |
| 6794 | Record.push_back(N); |
| 6795 | for (auto N : C->all_lists_sizes()) |
| 6796 | Record.push_back(N); |
| 6797 | for (auto &M : C->all_components()) { |
| 6798 | Record.AddStmt(M.getAssociatedExpression()); |
| 6799 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 6800 | } |
| 6801 | } |
| 6802 | |
| 6803 | void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 6804 | VisitOMPClauseWithPreInit(C); |
| 6805 | Record.AddStmt(C->getNumTeams()); |
| 6806 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6807 | } |
| 6808 | |
| 6809 | void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 6810 | VisitOMPClauseWithPreInit(C); |
| 6811 | Record.AddStmt(C->getThreadLimit()); |
| 6812 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6813 | } |
| 6814 | |
| 6815 | void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) { |
| 6816 | Record.AddStmt(C->getPriority()); |
| 6817 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6818 | } |
| 6819 | |
| 6820 | void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) { |
| 6821 | Record.AddStmt(C->getGrainsize()); |
| 6822 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6823 | } |
| 6824 | |
| 6825 | void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) { |
| 6826 | Record.AddStmt(C->getNumTasks()); |
| 6827 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6828 | } |
| 6829 | |
| 6830 | void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) { |
| 6831 | Record.AddStmt(C->getHint()); |
| 6832 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6833 | } |
| 6834 | |
| 6835 | void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) { |
| 6836 | VisitOMPClauseWithPreInit(C); |
| 6837 | Record.push_back(C->getDistScheduleKind()); |
| 6838 | Record.AddStmt(C->getChunkSize()); |
| 6839 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6840 | Record.AddSourceLocation(C->getDistScheduleKindLoc()); |
| 6841 | Record.AddSourceLocation(C->getCommaLoc()); |
| 6842 | } |
| 6843 | |
| 6844 | void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 6845 | Record.push_back(C->getDefaultmapKind()); |
| 6846 | Record.push_back(C->getDefaultmapModifier()); |
| 6847 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6848 | Record.AddSourceLocation(C->getDefaultmapModifierLoc()); |
| 6849 | Record.AddSourceLocation(C->getDefaultmapKindLoc()); |
| 6850 | } |
| 6851 | |
| 6852 | void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) { |
| 6853 | Record.push_back(C->varlist_size()); |
| 6854 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 6855 | Record.push_back(C->getTotalComponentListNum()); |
| 6856 | Record.push_back(C->getTotalComponentsNum()); |
| 6857 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6858 | for (auto *E : C->varlists()) |
| 6859 | Record.AddStmt(E); |
| 6860 | for (auto *D : C->all_decls()) |
| 6861 | Record.AddDeclRef(D); |
| 6862 | for (auto N : C->all_num_lists()) |
| 6863 | Record.push_back(N); |
| 6864 | for (auto N : C->all_lists_sizes()) |
| 6865 | Record.push_back(N); |
| 6866 | for (auto &M : C->all_components()) { |
| 6867 | Record.AddStmt(M.getAssociatedExpression()); |
| 6868 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 6869 | } |
| 6870 | } |
| 6871 | |
| 6872 | void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) { |
| 6873 | Record.push_back(C->varlist_size()); |
| 6874 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 6875 | Record.push_back(C->getTotalComponentListNum()); |
| 6876 | Record.push_back(C->getTotalComponentsNum()); |
| 6877 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6878 | for (auto *E : C->varlists()) |
| 6879 | Record.AddStmt(E); |
| 6880 | for (auto *D : C->all_decls()) |
| 6881 | Record.AddDeclRef(D); |
| 6882 | for (auto N : C->all_num_lists()) |
| 6883 | Record.push_back(N); |
| 6884 | for (auto N : C->all_lists_sizes()) |
| 6885 | Record.push_back(N); |
| 6886 | for (auto &M : C->all_components()) { |
| 6887 | Record.AddStmt(M.getAssociatedExpression()); |
| 6888 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 6889 | } |
| 6890 | } |
| 6891 | |
| 6892 | void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) { |
| 6893 | Record.push_back(C->varlist_size()); |
| 6894 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 6895 | Record.push_back(C->getTotalComponentListNum()); |
| 6896 | Record.push_back(C->getTotalComponentsNum()); |
| 6897 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6898 | for (auto *E : C->varlists()) |
| 6899 | Record.AddStmt(E); |
| 6900 | for (auto *VE : C->private_copies()) |
| 6901 | Record.AddStmt(VE); |
| 6902 | for (auto *VE : C->inits()) |
| 6903 | Record.AddStmt(VE); |
| 6904 | for (auto *D : C->all_decls()) |
| 6905 | Record.AddDeclRef(D); |
| 6906 | for (auto N : C->all_num_lists()) |
| 6907 | Record.push_back(N); |
| 6908 | for (auto N : C->all_lists_sizes()) |
| 6909 | Record.push_back(N); |
| 6910 | for (auto &M : C->all_components()) { |
| 6911 | Record.AddStmt(M.getAssociatedExpression()); |
| 6912 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 6913 | } |
| 6914 | } |
| 6915 | |
| 6916 | void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { |
| 6917 | Record.push_back(C->varlist_size()); |
| 6918 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 6919 | Record.push_back(C->getTotalComponentListNum()); |
| 6920 | Record.push_back(C->getTotalComponentsNum()); |
| 6921 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6922 | for (auto *E : C->varlists()) |
| 6923 | Record.AddStmt(E); |
| 6924 | for (auto *D : C->all_decls()) |
| 6925 | Record.AddDeclRef(D); |
| 6926 | for (auto N : C->all_num_lists()) |
| 6927 | Record.push_back(N); |
| 6928 | for (auto N : C->all_lists_sizes()) |
| 6929 | Record.push_back(N); |
| 6930 | for (auto &M : C->all_components()) { |
| 6931 | Record.AddStmt(M.getAssociatedExpression()); |
| 6932 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 6933 | } |
| 6934 | } |