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 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 9 | // This file defines the ASTWriter class, which writes AST files. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Sebastian Redl | 1914c6f | 2010-08-18 23:56:37 +0000 | [diff] [blame] | 13 | #include "clang/Serialization/ASTWriter.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 14 | #include "ASTCommon.h" |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 15 | #include "ASTReaderInternals.h" |
| 16 | #include "MultiOnDiskHashTable.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTUnresolvedSet.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 19 | #include "clang/AST/Attr.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 20 | #include "clang/AST/Decl.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclBase.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclCXX.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclContextInternals.h" |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclFriend.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclObjC.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclTemplate.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclarationName.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 28 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 29 | #include "clang/AST/ExprCXX.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 30 | #include "clang/AST/LambdaCapture.h" |
| 31 | #include "clang/AST/NestedNameSpecifier.h" |
| 32 | #include "clang/AST/RawCommentList.h" |
| 33 | #include "clang/AST/TemplateName.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 34 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 35 | #include "clang/AST/TypeLocVisitor.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 36 | #include "clang/Basic/Diagnostic.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 37 | #include "clang/Basic/DiagnosticOptions.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 38 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 39 | #include "clang/Basic/FileSystemOptions.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 40 | #include "clang/Basic/IdentifierTable.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 41 | #include "clang/Basic/LLVM.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 42 | #include "clang/Basic/Lambda.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 43 | #include "clang/Basic/LangOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 44 | #include "clang/Basic/Module.h" |
| 45 | #include "clang/Basic/ObjCRuntime.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 46 | #include "clang/Basic/OpenCLOptions.h" |
| 47 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 48 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 49 | #include "clang/Basic/SourceManagerInternals.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 50 | #include "clang/Basic/Specifiers.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 51 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | cb177f1 | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 52 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 53 | #include "clang/Basic/Version.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 54 | #include "clang/Lex/HeaderSearch.h" |
| 55 | #include "clang/Lex/HeaderSearchOptions.h" |
| 56 | #include "clang/Lex/MacroInfo.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 57 | #include "clang/Lex/ModuleMap.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 58 | #include "clang/Lex/PreprocessingRecord.h" |
| 59 | #include "clang/Lex/Preprocessor.h" |
| 60 | #include "clang/Lex/PreprocessorOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 61 | #include "clang/Lex/Token.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 62 | #include "clang/Sema/IdentifierResolver.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 63 | #include "clang/Sema/ObjCMethodList.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 64 | #include "clang/Sema/Sema.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 65 | #include "clang/Sema/Weak.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 66 | #include "clang/Serialization/ASTReader.h" |
Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 67 | #include "clang/Serialization/InMemoryModuleCache.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 68 | #include "clang/Serialization/Module.h" |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 69 | #include "clang/Serialization/ModuleFileExtension.h" |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 70 | #include "clang/Serialization/SerializationDiagnostic.h" |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 71 | #include "llvm/ADT/APFloat.h" |
| 72 | #include "llvm/ADT/APInt.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 73 | #include "llvm/ADT/APSInt.h" |
| 74 | #include "llvm/ADT/ArrayRef.h" |
| 75 | #include "llvm/ADT/DenseMap.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 76 | #include "llvm/ADT/Hashing.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 77 | #include "llvm/ADT/Optional.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 78 | #include "llvm/ADT/PointerIntPair.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 79 | #include "llvm/ADT/STLExtras.h" |
Ilya Biryukov | 4564310 | 2018-07-09 11:33:23 +0000 | [diff] [blame] | 80 | #include "llvm/ADT/ScopeExit.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 81 | #include "llvm/ADT/SmallSet.h" |
| 82 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 83 | #include "llvm/ADT/SmallVector.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 84 | #include "llvm/ADT/StringMap.h" |
| 85 | #include "llvm/ADT/StringRef.h" |
Francis Visoiu Mistrih | e030827 | 2019-07-03 22:40:07 +0000 | [diff] [blame] | 86 | #include "llvm/Bitstream/BitCodes.h" |
| 87 | #include "llvm/Bitstream/BitstreamWriter.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 88 | #include "llvm/Support/Casting.h" |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 89 | #include "llvm/Support/Compression.h" |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 90 | #include "llvm/Support/DJB.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 91 | #include "llvm/Support/Endian.h" |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 92 | #include "llvm/Support/EndianStream.h" |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 93 | #include "llvm/Support/Error.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 94 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 95 | #include "llvm/Support/MemoryBuffer.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 96 | #include "llvm/Support/OnDiskHashTable.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 97 | #include "llvm/Support/Path.h" |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 98 | #include "llvm/Support/SHA1.h" |
Pavel Labath | d8c6290 | 2018-06-11 10:28:04 +0000 | [diff] [blame] | 99 | #include "llvm/Support/VersionTuple.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 100 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 101 | #include <algorithm> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 102 | #include <cassert> |
| 103 | #include <cstdint> |
| 104 | #include <cstdlib> |
| 105 | #include <cstring> |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 106 | #include <ctime> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 107 | #include <deque> |
| 108 | #include <limits> |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 109 | #include <memory> |
| 110 | #include <queue> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 111 | #include <tuple> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 112 | #include <utility> |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 113 | #include <vector> |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 115 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 116 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 117 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 118 | template <typename T, typename Allocator> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 119 | static StringRef bytes(const std::vector<T, Allocator> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 120 | if (v.empty()) return StringRef(); |
| 121 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 122 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 123 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 124 | |
| 125 | template <typename T> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 126 | static StringRef bytes(const SmallVectorImpl<T> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 127 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 128 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 131 | //===----------------------------------------------------------------------===// |
| 132 | // Type serialization |
| 133 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 134 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 135 | namespace clang { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 136 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 137 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 138 | ASTWriter &Writer; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 139 | ASTRecordWriter Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 140 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 141 | /// Type code that corresponds to the record generated. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 142 | TypeCode Code = static_cast<TypeCode>(0); |
| 143 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 144 | /// Abbreviation to use for the record, if any. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 145 | unsigned AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 146 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 147 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 148 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 149 | : Writer(Writer), Record(Writer, Record) {} |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 150 | |
| 151 | uint64_t Emit() { |
| 152 | return Record.Emit(Code, AbbrevToUse); |
| 153 | } |
| 154 | |
| 155 | void Visit(QualType T) { |
| 156 | if (T.hasLocalNonFastQualifiers()) { |
| 157 | Qualifiers Qs = T.getLocalQualifiers(); |
| 158 | Record.AddTypeRef(T.getLocalUnqualifiedType()); |
| 159 | Record.push_back(Qs.getAsOpaqueValue()); |
| 160 | Code = TYPE_EXT_QUAL; |
| 161 | AbbrevToUse = Writer.TypeExtQualAbbrev; |
| 162 | } else { |
| 163 | switch (T->getTypeClass()) { |
| 164 | // For all of the concrete, non-dependent types, call the |
| 165 | // appropriate visitor function. |
| 166 | #define TYPE(Class, Base) \ |
| 167 | case Type::Class: Visit##Class##Type(cast<Class##Type>(T)); break; |
| 168 | #define ABSTRACT_TYPE(Class, Base) |
John McCall | 36b12a8 | 2019-10-02 06:35:23 +0000 | [diff] [blame] | 169 | #include "clang/AST/TypeNodes.inc" |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 173 | |
| 174 | void VisitArrayType(const ArrayType *T); |
| 175 | void VisitFunctionType(const FunctionType *T); |
| 176 | void VisitTagType(const TagType *T); |
| 177 | |
| 178 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 179 | #define ABSTRACT_TYPE(Class, Base) |
John McCall | 36b12a8 | 2019-10-02 06:35:23 +0000 | [diff] [blame] | 180 | #include "clang/AST/TypeNodes.inc" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 181 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 182 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 183 | } // namespace clang |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 184 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 185 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 186 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 189 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 190 | Record.AddTypeRef(T->getElementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 191 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 194 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 195 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 196 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 199 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 200 | Record.AddTypeRef(T->getOriginalType()); |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 201 | Code = TYPE_DECAYED; |
| 202 | } |
| 203 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 204 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 205 | Record.AddTypeRef(T->getOriginalType()); |
| 206 | Record.AddTypeRef(T->getAdjustedType()); |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 207 | Code = TYPE_ADJUSTED; |
| 208 | } |
| 209 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 210 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 211 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 212 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 215 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 216 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 217 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 218 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 221 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 222 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 223 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 226 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 227 | Record.AddTypeRef(T->getPointeeType()); |
| 228 | Record.AddTypeRef(QualType(T->getClass(), 0)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 229 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 232 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 233 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 234 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 235 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 238 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 239 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 240 | Record.AddAPInt(T->getSize()); |
Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 241 | Record.AddStmt(const_cast<Expr*>(T->getSizeExpr())); |
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()); |
Anastasia Stulova | c61eaa5 | 2019-01-28 11:37:49 +0000 | [diff] [blame] | 313 | Record.push_back(T->getMethodQuals().getAsOpaqueValue()); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 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 | |
Anastasia Stulova | c61eaa5 | 2019-01-28 11:37:49 +0000 | [diff] [blame] | 326 | if (T->isVariadic() || T->hasTrailingReturn() || T->getMethodQuals() || |
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()) |
Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 373 | Record.push_back(T->containsUnexpandedParameterPack() ? 2 : |
| 374 | T->isDependentType() ? 1 : 0); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 375 | Code = TYPE_AUTO; |
| 376 | } |
| 377 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 378 | void ASTTypeWriter::VisitDeducedTemplateSpecializationType( |
| 379 | const DeducedTemplateSpecializationType *T) { |
| 380 | Record.AddTemplateName(T->getTemplateName()); |
| 381 | Record.AddTypeRef(T->getDeducedType()); |
| 382 | if (T->getDeducedType().isNull()) |
| 383 | Record.push_back(T->isDependentType()); |
| 384 | Code = TYPE_DEDUCED_TEMPLATE_SPECIALIZATION; |
| 385 | } |
| 386 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 387 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 388 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 389 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 390 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 391 | "Cannot serialize in the middle of a type definition"); |
| 392 | } |
| 393 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 394 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 395 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 396 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 399 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 400 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 401 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 402 | } |
| 403 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 404 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 405 | Record.AddTypeRef(T->getModifiedType()); |
| 406 | Record.AddTypeRef(T->getEquivalentType()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 407 | Record.push_back(T->getAttrKind()); |
| 408 | Code = TYPE_ATTRIBUTED; |
| 409 | } |
| 410 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 412 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 413 | const SubstTemplateTypeParmType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 414 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 415 | Record.AddTypeRef(T->getReplacementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 416 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 420 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 421 | const SubstTemplateTypeParmPackType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 422 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 423 | Record.AddTemplateArgument(T->getArgumentPack()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 424 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 425 | } |
| 426 | |
| 427 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 428 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 429 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 430 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 431 | Record.AddTemplateName(T->getTemplateName()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 432 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 433 | for (const auto &ArgI : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 434 | Record.AddTemplateArgument(ArgI); |
| 435 | Record.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() |
| 436 | : T->isCanonicalUnqualified() |
| 437 | ? QualType() |
| 438 | : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 439 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 443 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 444 | VisitArrayType(T); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 445 | Record.AddStmt(T->getSizeExpr()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 446 | Record.AddSourceRange(T->getBracketsRange()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 447 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 451 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 452 | const DependentSizedExtVectorType *T) { |
Alex Lorenz | 00aee43 | 2017-03-22 10:04:48 +0000 | [diff] [blame] | 453 | Record.AddTypeRef(T->getElementType()); |
| 454 | Record.AddStmt(T->getSizeExpr()); |
| 455 | Record.AddSourceLocation(T->getAttributeLoc()); |
| 456 | Code = TYPE_DEPENDENT_SIZED_EXT_VECTOR; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 459 | void ASTTypeWriter::VisitDependentVectorType(const DependentVectorType *T) { |
| 460 | Record.AddTypeRef(T->getElementType()); |
| 461 | Record.AddStmt(const_cast<Expr*>(T->getSizeExpr())); |
| 462 | Record.AddSourceLocation(T->getAttributeLoc()); |
| 463 | Record.push_back(T->getVectorKind()); |
| 464 | Code = TYPE_DEPENDENT_SIZED_VECTOR; |
| 465 | } |
| 466 | |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 467 | void |
Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 468 | ASTTypeWriter::VisitDependentAddressSpaceType( |
| 469 | const DependentAddressSpaceType *T) { |
| 470 | Record.AddTypeRef(T->getPointeeType()); |
| 471 | Record.AddStmt(T->getAddrSpaceExpr()); |
| 472 | Record.AddSourceLocation(T->getAttributeLoc()); |
| 473 | Code = TYPE_DEPENDENT_ADDRESS_SPACE; |
| 474 | } |
| 475 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 476 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 477 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 478 | Record.push_back(T->getDepth()); |
| 479 | Record.push_back(T->getIndex()); |
| 480 | Record.push_back(T->isParameterPack()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 481 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 482 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 486 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 487 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 488 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 489 | Record.AddIdentifierRef(T->getIdentifier()); |
| 490 | Record.AddTypeRef( |
| 491 | T->isCanonicalUnqualified() ? QualType() : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 492 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 496 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 497 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 498 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 499 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 500 | Record.AddIdentifierRef(T->getIdentifier()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 501 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 502 | for (const auto &I : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 503 | Record.AddTemplateArgument(I); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 504 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 507 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 508 | Record.AddTypeRef(T->getPattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 509 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 510 | Record.push_back(*NumExpansions + 1); |
| 511 | else |
| 512 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 513 | Code = TYPE_PACK_EXPANSION; |
| 514 | } |
| 515 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 516 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 517 | Record.AddTypeRef(T->getInnerType()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 518 | Code = TYPE_PAREN; |
| 519 | } |
| 520 | |
Leonard Chan | c72aaf6 | 2019-05-07 03:20:17 +0000 | [diff] [blame] | 521 | void ASTTypeWriter::VisitMacroQualifiedType(const MacroQualifiedType *T) { |
| 522 | Record.AddTypeRef(T->getUnderlyingType()); |
| 523 | Record.AddIdentifierRef(T->getMacroIdentifier()); |
| 524 | Code = TYPE_MACRO_QUALIFIED; |
| 525 | } |
| 526 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 527 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 528 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 529 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 530 | Record.AddTypeRef(T->getNamedType()); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 531 | Record.AddDeclRef(T->getOwnedTagDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 532 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 535 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 536 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
| 537 | Record.AddTypeRef(T->getInjectedSpecializationType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 538 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 541 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 542 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 543 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 546 | void ASTTypeWriter::VisitObjCTypeParamType(const ObjCTypeParamType *T) { |
| 547 | Record.AddDeclRef(T->getDecl()); |
| 548 | Record.push_back(T->getNumProtocols()); |
| 549 | for (const auto *I : T->quals()) |
| 550 | Record.AddDeclRef(I); |
| 551 | Code = TYPE_OBJC_TYPE_PARAM; |
| 552 | } |
| 553 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 554 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 555 | Record.AddTypeRef(T->getBaseType()); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 556 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 557 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 558 | Record.AddTypeRef(TypeArg); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 559 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 560 | for (const auto *I : T->quals()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 561 | Record.AddDeclRef(I); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 562 | Record.push_back(T->isKindOfTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 563 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 566 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 567 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 568 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 569 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 572 | void |
| 573 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 574 | Record.AddTypeRef(T->getValueType()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 575 | Code = TYPE_ATOMIC; |
| 576 | } |
| 577 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 578 | void |
| 579 | ASTTypeWriter::VisitPipeType(const PipeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 580 | Record.AddTypeRef(T->getElementType()); |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 581 | Record.push_back(T->isReadOnly()); |
| 582 | Code = TYPE_PIPE; |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 583 | } |
| 584 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 585 | namespace { |
| 586 | |
| 587 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 588 | ASTRecordWriter &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 589 | |
| 590 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 591 | TypeLocWriter(ASTRecordWriter &Record) : Record(Record) {} |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 592 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 593 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 594 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 595 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 596 | #include "clang/AST/TypeLocNodes.def" |
| 597 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 598 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 599 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 600 | }; |
| 601 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 602 | } // namespace |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 603 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 604 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 605 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 606 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 607 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 608 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 609 | Record.AddSourceLocation(TL.getBuiltinLoc()); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 610 | if (TL.needsExtraLocalData()) { |
Faisal Vali | 090da2d | 2018-01-01 18:23:28 +0000 | [diff] [blame] | 611 | Record.push_back(TL.getWrittenTypeSpec()); |
| 612 | Record.push_back(TL.getWrittenSignSpec()); |
| 613 | Record.push_back(TL.getWrittenWidthSpec()); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 614 | Record.push_back(TL.hasModeAttr()); |
| 615 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 616 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 617 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 618 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 619 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 620 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 621 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 622 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 623 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 624 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 625 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 626 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 627 | // nothing to do |
| 628 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 629 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 630 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 631 | // nothing to do |
| 632 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 633 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 634 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 635 | Record.AddSourceLocation(TL.getCaretLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 636 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 637 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 638 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 639 | Record.AddSourceLocation(TL.getAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 640 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 641 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 642 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 643 | Record.AddSourceLocation(TL.getAmpAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 644 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 645 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 646 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 647 | Record.AddSourceLocation(TL.getStarLoc()); |
| 648 | Record.AddTypeSourceInfo(TL.getClassTInfo()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 649 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 650 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 651 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 652 | Record.AddSourceLocation(TL.getLBracketLoc()); |
| 653 | Record.AddSourceLocation(TL.getRBracketLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 654 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 655 | if (TL.getSizeExpr()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 656 | Record.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 657 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 658 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 659 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 660 | VisitArrayTypeLoc(TL); |
| 661 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 662 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 663 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 664 | VisitArrayTypeLoc(TL); |
| 665 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 666 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 667 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 668 | VisitArrayTypeLoc(TL); |
| 669 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 670 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 671 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 672 | DependentSizedArrayTypeLoc TL) { |
| 673 | VisitArrayTypeLoc(TL); |
| 674 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 675 | |
Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 676 | void TypeLocWriter::VisitDependentAddressSpaceTypeLoc( |
| 677 | DependentAddressSpaceTypeLoc TL) { |
| 678 | Record.AddSourceLocation(TL.getAttrNameLoc()); |
| 679 | SourceRange range = TL.getAttrOperandParensRange(); |
| 680 | Record.AddSourceLocation(range.getBegin()); |
| 681 | Record.AddSourceLocation(range.getEnd()); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 682 | Record.AddStmt(TL.getAttrExprOperand()); |
Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 683 | } |
| 684 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 685 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 686 | DependentSizedExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 687 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 688 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 689 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 690 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 691 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 692 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 693 | |
Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 694 | void TypeLocWriter::VisitDependentVectorTypeLoc( |
| 695 | DependentVectorTypeLoc TL) { |
| 696 | Record.AddSourceLocation(TL.getNameLoc()); |
| 697 | } |
| 698 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 699 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 700 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 701 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 702 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 703 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 704 | Record.AddSourceLocation(TL.getLocalRangeBegin()); |
| 705 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 706 | Record.AddSourceLocation(TL.getRParenLoc()); |
Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 707 | Record.AddSourceRange(TL.getExceptionSpecRange()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 708 | Record.AddSourceLocation(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 709 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 710 | Record.AddDeclRef(TL.getParam(i)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 711 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 712 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 713 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 714 | VisitFunctionTypeLoc(TL); |
| 715 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 716 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 717 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 718 | VisitFunctionTypeLoc(TL); |
| 719 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 720 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 721 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 722 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 723 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 724 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 725 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 726 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 727 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 728 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 729 | void TypeLocWriter::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 730 | if (TL.getNumProtocols()) { |
| 731 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 732 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
| 733 | } |
| 734 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 735 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
| 736 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 737 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 738 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 739 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 740 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 741 | Record.AddSourceLocation(TL.getRParenLoc()); |
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::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 745 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 746 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 747 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 748 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 749 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 750 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 751 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 752 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 753 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 754 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 755 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 756 | Record.AddSourceLocation(TL.getKWLoc()); |
| 757 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 758 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 759 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 760 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 761 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 762 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 763 | Record.AddSourceLocation(TL.getNameLoc()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 764 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 765 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 766 | void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc( |
| 767 | DeducedTemplateSpecializationTypeLoc TL) { |
| 768 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 769 | } |
| 770 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 771 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 772 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 773 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 774 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 775 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 776 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 777 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 778 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 779 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 780 | Record.AddAttr(TL.getAttr()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 781 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 782 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 783 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 784 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 785 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 786 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 787 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 788 | SubstTemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 789 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 790 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 791 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 792 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 793 | SubstTemplateTypeParmPackTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 794 | Record.AddSourceLocation(TL.getNameLoc()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 795 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 796 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 797 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 798 | TemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 799 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 800 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 801 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 802 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 803 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 804 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 805 | TL.getArgLoc(i).getLocInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 806 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 807 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 808 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 809 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 810 | Record.AddSourceLocation(TL.getRParenLoc()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 811 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 812 | |
Leonard Chan | c72aaf6 | 2019-05-07 03:20:17 +0000 | [diff] [blame] | 813 | void TypeLocWriter::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) { |
| 814 | Record.AddSourceLocation(TL.getExpansionLoc()); |
| 815 | } |
| 816 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 817 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 818 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 819 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 820 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 821 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 822 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 823 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 824 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 825 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 826 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 827 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 828 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 829 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 830 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 831 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 832 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 833 | DependentTemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 834 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 835 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 836 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 837 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 838 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 839 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 840 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 841 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 842 | TL.getArgLoc(I).getLocInfo()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 843 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 844 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 845 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 846 | Record.AddSourceLocation(TL.getEllipsisLoc()); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 847 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 848 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 849 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 850 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 851 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 852 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 853 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 854 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 855 | Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); |
| 856 | Record.AddSourceLocation(TL.getTypeArgsRAngleLoc()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 857 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 858 | Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i)); |
| 859 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 860 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 861 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 862 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 863 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 864 | |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 865 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 866 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 867 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 868 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 869 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 870 | Record.AddSourceLocation(TL.getKWLoc()); |
| 871 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 872 | Record.AddSourceLocation(TL.getRParenLoc()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 873 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 874 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 875 | void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 876 | Record.AddSourceLocation(TL.getKWLoc()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 877 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 878 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 879 | void ASTWriter::WriteTypeAbbrevs() { |
| 880 | using namespace llvm; |
| 881 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 882 | std::shared_ptr<BitCodeAbbrev> Abv; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 883 | |
| 884 | // Abbreviation for TYPE_EXT_QUAL |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 885 | Abv = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 886 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 887 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 888 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 889 | TypeExtQualAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 890 | |
| 891 | // Abbreviation for TYPE_FUNCTION_PROTO |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 892 | Abv = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 893 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 894 | // FunctionType |
| 895 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 896 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 897 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 898 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 899 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 900 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 901 | Abv->Add(BitCodeAbbrevOp(0)); // NoCallerSavedRegs |
Oren Ben Simhon | 220671a | 2018-03-17 13:31:35 +0000 | [diff] [blame] | 902 | Abv->Add(BitCodeAbbrevOp(0)); // NoCfCheck |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 903 | // FunctionProtoType |
| 904 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 905 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 906 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 907 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 908 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 909 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 910 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 911 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 912 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 915 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 916 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 917 | //===----------------------------------------------------------------------===// |
| 918 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 919 | static void EmitBlockID(unsigned ID, const char *Name, |
| 920 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 921 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 922 | Record.clear(); |
| 923 | Record.push_back(ID); |
| 924 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 925 | |
| 926 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 927 | if (!Name || Name[0] == 0) |
| 928 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 929 | Record.clear(); |
| 930 | while (*Name) |
| 931 | Record.push_back(*Name++); |
| 932 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 933 | } |
| 934 | |
| 935 | static void EmitRecordID(unsigned ID, const char *Name, |
| 936 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 937 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 938 | Record.clear(); |
| 939 | Record.push_back(ID); |
| 940 | while (*Name) |
| 941 | Record.push_back(*Name++); |
| 942 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 946 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 947 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 948 | RECORD(STMT_STOP); |
| 949 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 950 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 951 | RECORD(STMT_NULL); |
| 952 | RECORD(STMT_COMPOUND); |
| 953 | RECORD(STMT_CASE); |
| 954 | RECORD(STMT_DEFAULT); |
| 955 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 956 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 957 | RECORD(STMT_IF); |
| 958 | RECORD(STMT_SWITCH); |
| 959 | RECORD(STMT_WHILE); |
| 960 | RECORD(STMT_DO); |
| 961 | RECORD(STMT_FOR); |
| 962 | RECORD(STMT_GOTO); |
| 963 | RECORD(STMT_INDIRECT_GOTO); |
| 964 | RECORD(STMT_CONTINUE); |
| 965 | RECORD(STMT_BREAK); |
| 966 | RECORD(STMT_RETURN); |
| 967 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 968 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 969 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 970 | RECORD(EXPR_PREDEFINED); |
| 971 | RECORD(EXPR_DECL_REF); |
| 972 | RECORD(EXPR_INTEGER_LITERAL); |
| 973 | RECORD(EXPR_FLOATING_LITERAL); |
| 974 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 975 | RECORD(EXPR_STRING_LITERAL); |
| 976 | RECORD(EXPR_CHARACTER_LITERAL); |
| 977 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 978 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 979 | RECORD(EXPR_UNARY_OPERATOR); |
| 980 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 981 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 982 | RECORD(EXPR_CALL); |
| 983 | RECORD(EXPR_MEMBER); |
| 984 | RECORD(EXPR_BINARY_OPERATOR); |
| 985 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 986 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 987 | RECORD(EXPR_IMPLICIT_CAST); |
| 988 | RECORD(EXPR_CSTYLE_CAST); |
| 989 | RECORD(EXPR_COMPOUND_LITERAL); |
| 990 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 991 | RECORD(EXPR_INIT_LIST); |
| 992 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 993 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 994 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 995 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 996 | RECORD(EXPR_VA_ARG); |
| 997 | RECORD(EXPR_ADDR_LABEL); |
| 998 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 999 | RECORD(EXPR_CHOOSE); |
| 1000 | RECORD(EXPR_GNU_NULL); |
| 1001 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 1002 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1003 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 1004 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 1005 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1006 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 1007 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 1008 | RECORD(EXPR_OBJC_ENCODE); |
| 1009 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 1010 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 1011 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 1012 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 1013 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 1014 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 1015 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 1016 | RECORD(STMT_OBJC_CATCH); |
| 1017 | RECORD(STMT_OBJC_FINALLY); |
| 1018 | RECORD(STMT_OBJC_AT_TRY); |
| 1019 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 1020 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1021 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1022 | RECORD(STMT_CXX_CATCH); |
| 1023 | RECORD(STMT_CXX_TRY); |
| 1024 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1025 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1026 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1027 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1028 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1029 | RECORD(EXPR_CXX_STATIC_CAST); |
| 1030 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 1031 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 1032 | RECORD(EXPR_CXX_CONST_CAST); |
| 1033 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 1034 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 1035 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 1036 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 1037 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1038 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 1039 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1040 | RECORD(EXPR_CXX_THIS); |
| 1041 | RECORD(EXPR_CXX_THROW); |
| 1042 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1043 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1044 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 1045 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 1046 | RECORD(EXPR_CXX_NEW); |
| 1047 | RECORD(EXPR_CXX_DELETE); |
| 1048 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 1049 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 1050 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 1051 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 1052 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 1053 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 1054 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1055 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1056 | RECORD(EXPR_CXX_NOEXCEPT); |
| 1057 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1058 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 1059 | RECORD(EXPR_TYPE_TRAIT); |
| 1060 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1061 | RECORD(EXPR_PACK_EXPANSION); |
| 1062 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1063 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1064 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1065 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 1066 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1067 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1068 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 1069 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 1070 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 1071 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1072 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1073 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1074 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1075 | RecordData Record; |
Peter Collingbourne | d3a6c70 | 2016-11-01 01:18:57 +0000 | [diff] [blame] | 1076 | Stream.EnterBlockInfoBlock(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1078 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 1079 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1081 | // Control Block. |
| 1082 | BLOCK(CONTROL_BLOCK); |
| 1083 | RECORD(METADATA); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1084 | RECORD(MODULE_NAME); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1085 | RECORD(MODULE_DIRECTORY); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1086 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1087 | RECORD(IMPORTS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1088 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1089 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1090 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1091 | RECORD(INPUT_FILE_OFFSETS); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1092 | |
| 1093 | BLOCK(OPTIONS_BLOCK); |
| 1094 | RECORD(LANGUAGE_OPTIONS); |
| 1095 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1096 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1097 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1098 | RECORD(PREPROCESSOR_OPTIONS); |
| 1099 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 1100 | BLOCK(INPUT_FILES_BLOCK); |
| 1101 | RECORD(INPUT_FILE); |
Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1102 | RECORD(INPUT_FILE_HASH); |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 1103 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1104 | // AST Top-Level Block. |
| 1105 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1106 | RECORD(TYPE_OFFSET); |
| 1107 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1108 | RECORD(IDENTIFIER_OFFSET); |
| 1109 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 1110 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 1111 | RECORD(MODULAR_CODEGEN_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1112 | RECORD(SPECIAL_TYPES); |
| 1113 | RECORD(STATISTICS); |
| 1114 | RECORD(TENTATIVE_DEFINITIONS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1115 | RECORD(SELECTOR_OFFSETS); |
| 1116 | RECORD(METHOD_POOL); |
| 1117 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1118 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 1119 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1120 | RECORD(EXT_VECTOR_DECLS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1121 | RECORD(UNUSED_FILESCOPED_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1122 | RECORD(PPD_ENTITIES_OFFSETS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1123 | RECORD(VTABLE_USES); |
Cameron Desrochers | b60f1b6 | 2018-01-15 19:14:16 +0000 | [diff] [blame] | 1124 | RECORD(PPD_SKIPPED_RANGES); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 1125 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1126 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1127 | RECORD(SEMA_DECL_REFS); |
| 1128 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 1129 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1130 | RECORD(UPDATE_VISIBLE); |
| 1131 | RECORD(DECL_UPDATE_OFFSETS); |
| 1132 | RECORD(DECL_UPDATES); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1133 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1134 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1135 | RECORD(FP_PRAGMA_OPTIONS); |
| 1136 | RECORD(OPENCL_EXTENSIONS); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 1137 | RECORD(OPENCL_EXTENSION_TYPES); |
| 1138 | RECORD(OPENCL_EXTENSION_DECLS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1139 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 1140 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 1141 | RECORD(MODULE_OFFSET_MAP); |
| 1142 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1143 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 1144 | RECORD(FILE_SORTED_DECLS); |
| 1145 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1146 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1147 | RECORD(MACRO_OFFSET); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1148 | RECORD(INTERESTING_IDENTIFIERS); |
| 1149 | RECORD(UNDEFINED_BUT_USED); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1150 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 1151 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 1152 | RECORD(MSSTRUCT_PRAGMA_OPTIONS); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 1153 | RECORD(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1154 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1155 | RECORD(DELETE_EXPRS_TO_ANALYZE); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 1156 | RECORD(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH); |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 1157 | RECORD(PP_CONDITIONAL_STACK); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 1158 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1159 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1160 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1161 | RECORD(SM_SLOC_FILE_ENTRY); |
| 1162 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 1163 | RECORD(SM_SLOC_BUFFER_BLOB); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1164 | RECORD(SM_SLOC_BUFFER_BLOB_COMPRESSED); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1165 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1166 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1167 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1168 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1169 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1170 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1171 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 1172 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1173 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1174 | |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1175 | // Submodule Block. |
| 1176 | BLOCK(SUBMODULE_BLOCK); |
| 1177 | RECORD(SUBMODULE_METADATA); |
| 1178 | RECORD(SUBMODULE_DEFINITION); |
| 1179 | RECORD(SUBMODULE_UMBRELLA_HEADER); |
| 1180 | RECORD(SUBMODULE_HEADER); |
| 1181 | RECORD(SUBMODULE_TOPHEADER); |
| 1182 | RECORD(SUBMODULE_UMBRELLA_DIR); |
| 1183 | RECORD(SUBMODULE_IMPORTS); |
| 1184 | RECORD(SUBMODULE_EXPORTS); |
| 1185 | RECORD(SUBMODULE_REQUIRES); |
| 1186 | RECORD(SUBMODULE_EXCLUDED_HEADER); |
| 1187 | RECORD(SUBMODULE_LINK_LIBRARY); |
| 1188 | RECORD(SUBMODULE_CONFIG_MACRO); |
| 1189 | RECORD(SUBMODULE_CONFLICT); |
| 1190 | RECORD(SUBMODULE_PRIVATE_HEADER); |
| 1191 | RECORD(SUBMODULE_TEXTUAL_HEADER); |
| 1192 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 1193 | RECORD(SUBMODULE_INITIALIZERS); |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 1194 | RECORD(SUBMODULE_EXPORT_AS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1195 | |
| 1196 | // Comments Block. |
| 1197 | BLOCK(COMMENTS_BLOCK); |
| 1198 | RECORD(COMMENTS_RAW_COMMENT); |
| 1199 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1200 | // Decls and Types block. |
| 1201 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1202 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1203 | RECORD(TYPE_COMPLEX); |
| 1204 | RECORD(TYPE_POINTER); |
| 1205 | RECORD(TYPE_BLOCK_POINTER); |
| 1206 | RECORD(TYPE_LVALUE_REFERENCE); |
| 1207 | RECORD(TYPE_RVALUE_REFERENCE); |
| 1208 | RECORD(TYPE_MEMBER_POINTER); |
| 1209 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1210 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1211 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1212 | RECORD(TYPE_VECTOR); |
| 1213 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1214 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1215 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1216 | RECORD(TYPE_TYPEDEF); |
| 1217 | RECORD(TYPE_TYPEOF_EXPR); |
| 1218 | RECORD(TYPE_TYPEOF); |
| 1219 | RECORD(TYPE_RECORD); |
| 1220 | RECORD(TYPE_ENUM); |
| 1221 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1222 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1223 | RECORD(TYPE_DECLTYPE); |
| 1224 | RECORD(TYPE_ELABORATED); |
| 1225 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 1226 | RECORD(TYPE_UNRESOLVED_USING); |
| 1227 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 1228 | RECORD(TYPE_OBJC_OBJECT); |
| 1229 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 1230 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 1231 | RECORD(TYPE_DEPENDENT_NAME); |
| 1232 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 1233 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 1234 | RECORD(TYPE_PAREN); |
Leonard Chan | c72aaf6 | 2019-05-07 03:20:17 +0000 | [diff] [blame] | 1235 | RECORD(TYPE_MACRO_QUALIFIED); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1236 | RECORD(TYPE_PACK_EXPANSION); |
| 1237 | RECORD(TYPE_ATTRIBUTED); |
| 1238 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1239 | RECORD(TYPE_AUTO); |
| 1240 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1241 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1242 | RECORD(TYPE_DECAYED); |
| 1243 | RECORD(TYPE_ADJUSTED); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 1244 | RECORD(TYPE_OBJC_TYPE_PARAM); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 1245 | RECORD(LOCAL_REDECLARATIONS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1246 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1247 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1248 | RECORD(DECL_ENUM); |
| 1249 | RECORD(DECL_RECORD); |
| 1250 | RECORD(DECL_ENUM_CONSTANT); |
| 1251 | RECORD(DECL_FUNCTION); |
| 1252 | RECORD(DECL_OBJC_METHOD); |
| 1253 | RECORD(DECL_OBJC_INTERFACE); |
| 1254 | RECORD(DECL_OBJC_PROTOCOL); |
| 1255 | RECORD(DECL_OBJC_IVAR); |
| 1256 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1257 | RECORD(DECL_OBJC_CATEGORY); |
| 1258 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1259 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1260 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1261 | RECORD(DECL_OBJC_PROPERTY); |
| 1262 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1263 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1264 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1265 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1266 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1267 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1268 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1269 | RECORD(DECL_BLOCK); |
| 1270 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1271 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1272 | RECORD(DECL_NAMESPACE); |
| 1273 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1274 | RECORD(DECL_USING); |
| 1275 | RECORD(DECL_USING_SHADOW); |
| 1276 | RECORD(DECL_USING_DIRECTIVE); |
| 1277 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1278 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1279 | RECORD(DECL_LINKAGE_SPEC); |
| 1280 | RECORD(DECL_CXX_RECORD); |
| 1281 | RECORD(DECL_CXX_METHOD); |
| 1282 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 1283 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1284 | RECORD(DECL_CXX_CONVERSION); |
| 1285 | RECORD(DECL_ACCESS_SPEC); |
| 1286 | RECORD(DECL_FRIEND); |
| 1287 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1288 | RECORD(DECL_CLASS_TEMPLATE); |
| 1289 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1290 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1291 | RECORD(DECL_VAR_TEMPLATE); |
| 1292 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1293 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1294 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1295 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1296 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1297 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
Saar Raz | d7aae33 | 2019-07-10 21:25:49 +0000 | [diff] [blame] | 1298 | RECORD(DECL_CONCEPT); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1299 | RECORD(DECL_TYPE_ALIAS_TEMPLATE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1300 | RECORD(DECL_STATIC_ASSERT); |
| 1301 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1302 | RECORD(DECL_CXX_CTOR_INITIALIZERS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1303 | RECORD(DECL_INDIRECTFIELD); |
| 1304 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1305 | RECORD(DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK); |
| 1306 | RECORD(DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION); |
| 1307 | RECORD(DECL_IMPORT); |
| 1308 | RECORD(DECL_OMP_THREADPRIVATE); |
| 1309 | RECORD(DECL_EMPTY); |
| 1310 | RECORD(DECL_OBJC_TYPE_PARAM); |
| 1311 | RECORD(DECL_OMP_CAPTUREDEXPR); |
| 1312 | RECORD(DECL_PRAGMA_COMMENT); |
| 1313 | RECORD(DECL_PRAGMA_DETECT_MISMATCH); |
| 1314 | RECORD(DECL_OMP_DECLARE_REDUCTION); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1315 | RECORD(DECL_OMP_ALLOCATE); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1316 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1317 | // Statements and Exprs can occur in the Decls and Types block. |
| 1318 | AddStmtsExprs(Stream, Record); |
| 1319 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1320 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1321 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1322 | RECORD(PPD_MACRO_DEFINITION); |
| 1323 | RECORD(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 1324 | |
| 1325 | // Decls and Types block. |
| 1326 | BLOCK(EXTENSION_BLOCK); |
| 1327 | RECORD(EXTENSION_METADATA); |
| 1328 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1329 | BLOCK(UNHASHED_CONTROL_BLOCK); |
| 1330 | RECORD(SIGNATURE); |
| 1331 | RECORD(DIAGNOSTIC_OPTIONS); |
| 1332 | RECORD(DIAG_PRAGMA_MAPPINGS); |
| 1333 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1334 | #undef RECORD |
| 1335 | #undef BLOCK |
| 1336 | Stream.ExitBlock(); |
| 1337 | } |
| 1338 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1339 | /// 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] | 1340 | /// to an absolute path and removing nested './'s. |
| 1341 | /// |
| 1342 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1343 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1344 | SmallVectorImpl<char> &Path) { |
Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 1345 | bool Changed = FileMgr.makeAbsolutePath(Path); |
Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame] | 1346 | return Changed | llvm::sys::path::remove_dots(Path); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1349 | /// Adjusts the given filename to only write out the portion of the |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1350 | /// filename that is not part of the system root directory. |
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 | /// \param Filename the file name to adjust. |
| 1353 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1354 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1355 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1356 | /// |
| 1357 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1358 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1360 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1361 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1363 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1364 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1365 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1366 | // Verify that the filename and the system root have the same prefix. |
| 1367 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1368 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1369 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1370 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1371 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1372 | // We hit the end of the filename before we hit the end of the system root. |
| 1373 | if (!Filename[Pos]) |
| 1374 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1376 | // If there's not a path separator at the end of the base directory nor |
| 1377 | // immediately after it, then this isn't within the base directory. |
| 1378 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1379 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1380 | return Filename; |
| 1381 | } else { |
| 1382 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1383 | // We distinguish relative paths from absolute paths by the |
| 1384 | // absence of '/' at the beginning of relative paths. |
| 1385 | // |
| 1386 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1387 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1388 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1389 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1390 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1392 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1393 | return Filename + Pos; |
| 1394 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1395 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1396 | ASTFileSignature ASTWriter::createSignature(StringRef Bytes) { |
| 1397 | // Calculate the hash till start of UNHASHED_CONTROL_BLOCK. |
| 1398 | llvm::SHA1 Hasher; |
| 1399 | Hasher.update(ArrayRef<uint8_t>(Bytes.bytes_begin(), Bytes.size())); |
| 1400 | auto Hash = Hasher.result(); |
| 1401 | |
| 1402 | // Convert to an array [5*i32]. |
| 1403 | ASTFileSignature Signature; |
| 1404 | auto LShift = [&](unsigned char Val, unsigned Shift) { |
| 1405 | return (uint32_t)Val << Shift; |
| 1406 | }; |
| 1407 | for (int I = 0; I != 5; ++I) |
| 1408 | Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) | |
| 1409 | LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0); |
| 1410 | |
| 1411 | return Signature; |
| 1412 | } |
| 1413 | |
| 1414 | ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP, |
| 1415 | ASTContext &Context) { |
| 1416 | // Flush first to prepare the PCM hash (signature). |
| 1417 | Stream.FlushToWord(); |
| 1418 | auto StartOfUnhashedControl = Stream.GetCurrentBitNo() >> 3; |
| 1419 | |
| 1420 | // Enter the block and prepare to write records. |
| 1421 | RecordData Record; |
| 1422 | Stream.EnterSubblock(UNHASHED_CONTROL_BLOCK_ID, 5); |
| 1423 | |
| 1424 | // For implicit modules, write the hash of the PCM as its signature. |
| 1425 | ASTFileSignature Signature; |
| 1426 | if (WritingModule && |
| 1427 | PP.getHeaderSearchInfo().getHeaderSearchOpts().ModulesHashContent) { |
| 1428 | Signature = createSignature(StringRef(Buffer.begin(), StartOfUnhashedControl)); |
| 1429 | Record.append(Signature.begin(), Signature.end()); |
| 1430 | Stream.EmitRecord(SIGNATURE, Record); |
| 1431 | Record.clear(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1432 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1433 | |
| 1434 | // Diagnostic options. |
| 1435 | const auto &Diags = Context.getDiagnostics(); |
| 1436 | const DiagnosticOptions &DiagOpts = Diags.getDiagnosticOptions(); |
| 1437 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1438 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1439 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1440 | #include "clang/Basic/DiagnosticOptions.def" |
| 1441 | Record.push_back(DiagOpts.Warnings.size()); |
| 1442 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1443 | AddString(DiagOpts.Warnings[I], Record); |
| 1444 | Record.push_back(DiagOpts.Remarks.size()); |
| 1445 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1446 | AddString(DiagOpts.Remarks[I], Record); |
| 1447 | // Note: we don't serialize the log or serialization file names, because they |
| 1448 | // are generally transient files and will almost always be overridden. |
| 1449 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1450 | |
| 1451 | // Write out the diagnostic/pragma mappings. |
Rui Ueyama | 49a3ad2 | 2019-07-16 04:46:31 +0000 | [diff] [blame] | 1452 | WritePragmaDiagnosticMappings(Diags, /* isModule = */ WritingModule); |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1453 | |
| 1454 | // Leave the options block. |
| 1455 | Stream.ExitBlock(); |
| 1456 | return Signature; |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1459 | /// Write the control block. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1460 | void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, |
| 1461 | StringRef isysroot, |
| 1462 | const std::string &OutputFile) { |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1463 | using namespace llvm; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1464 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1465 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1466 | RecordData Record; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1467 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1468 | // Metadata |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1469 | auto MetadataAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1470 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1471 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1472 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1473 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1474 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1475 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1476 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps |
Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 1477 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PCHHasObjectFile |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1478 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1479 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1480 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(std::move(MetadataAbbrev)); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1481 | assert((!WritingModule || isysroot.empty()) && |
| 1482 | "writing module as a relocatable PCH?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1483 | { |
Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 1484 | RecordData::value_type Record[] = { |
| 1485 | METADATA, |
| 1486 | VERSION_MAJOR, |
| 1487 | VERSION_MINOR, |
| 1488 | CLANG_VERSION_MAJOR, |
| 1489 | CLANG_VERSION_MINOR, |
| 1490 | !isysroot.empty(), |
| 1491 | IncludeTimestamps, |
| 1492 | Context.getLangOpts().BuildingPCHWithObjectFile, |
| 1493 | ASTHasCompilerErrors}; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1494 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1495 | getClangFullRepositoryVersion()); |
| 1496 | } |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1497 | |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 1498 | if (WritingModule) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1499 | // Module name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1500 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1501 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1502 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1503 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1504 | RecordData::value_type Record[] = {MODULE_NAME}; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1505 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1506 | } |
| 1507 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1508 | if (WritingModule && WritingModule->Directory) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1509 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1510 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1511 | |
| 1512 | // If the home of the module is the current working directory, then we |
| 1513 | // want to pick up the cwd of the build process loading the module, not |
| 1514 | // our cwd, when we load this module. |
| 1515 | if (!PP.getHeaderSearchInfo() |
| 1516 | .getHeaderSearchOpts() |
| 1517 | .ModuleMapFileHomeIsCwd || |
| 1518 | WritingModule->Directory->getName() != StringRef(".")) { |
| 1519 | // Module directory. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1520 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1521 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1522 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1523 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1524 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1525 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1526 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1527 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1528 | |
| 1529 | // Write out all other paths relative to the base directory if possible. |
| 1530 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1531 | } else if (!isysroot.empty()) { |
| 1532 | // Write out paths relative to the sysroot if possible. |
| 1533 | BaseDirectory = isysroot; |
| 1534 | } |
| 1535 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1536 | // Module map file |
Richard Smith | d19389a | 2017-07-05 07:47:11 +0000 | [diff] [blame] | 1537 | if (WritingModule && WritingModule->Kind == Module::ModuleMapModule) { |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1538 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1539 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1540 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 1541 | AddPath(WritingModule->PresumedModuleMapFile.empty() |
| 1542 | ? Map.getModuleMapFileForUniquing(WritingModule)->getName() |
| 1543 | : StringRef(WritingModule->PresumedModuleMapFile), |
| 1544 | Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1545 | |
| 1546 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1547 | if (auto *AdditionalModMaps = |
| 1548 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1549 | Record.push_back(AdditionalModMaps->size()); |
| 1550 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1551 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1552 | } else { |
| 1553 | Record.push_back(0); |
| 1554 | } |
| 1555 | |
| 1556 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1559 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1560 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1561 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1562 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1563 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1564 | for (ModuleFile &M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1565 | // Skip modules that weren't directly imported. |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1566 | if (!M.isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1567 | continue; |
| 1568 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1569 | Record.push_back((unsigned)M.Kind); // FIXME: Stable encoding |
| 1570 | AddSourceLocation(M.ImportLoc, Record); |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1571 | |
| 1572 | // If we have calculated signature, there is no need to store |
| 1573 | // the size or timestamp. |
| 1574 | Record.push_back(M.Signature ? 0 : M.File->getSize()); |
| 1575 | Record.push_back(M.Signature ? 0 : getTimestampForOutput(M.File)); |
| 1576 | |
| 1577 | for (auto I : M.Signature) |
| 1578 | Record.push_back(I); |
| 1579 | |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 1580 | AddString(M.ModuleName, Record); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1581 | AddPath(M.FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1582 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1583 | Stream.EmitRecord(IMPORTS, Record); |
| 1584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1585 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1586 | // Write the options block. |
| 1587 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); |
| 1588 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1589 | // Language options. |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1590 | Record.clear(); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1591 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1592 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1593 | Record.push_back(LangOpts.Name); |
| 1594 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1595 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1596 | #include "clang/Basic/LangOptions.def" |
| 1597 | #define SANITIZER(NAME, ID) \ |
| 1598 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1599 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1600 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1601 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1602 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1603 | AddString(Feature, Record); |
| 1604 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1605 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1606 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1607 | |
| 1608 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1609 | |
| 1610 | // Comment options. |
| 1611 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1612 | for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) { |
| 1613 | AddString(I, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1614 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1615 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1616 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1617 | // OpenMP offloading options. |
| 1618 | Record.push_back(LangOpts.OMPTargetTriples.size()); |
| 1619 | for (auto &T : LangOpts.OMPTargetTriples) |
| 1620 | AddString(T.getTriple(), Record); |
| 1621 | |
| 1622 | AddString(LangOpts.OMPHostIRFile, Record); |
| 1623 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1624 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1625 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1626 | // Target options. |
| 1627 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1628 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1629 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1630 | AddString(TargetOpts.Triple, Record); |
| 1631 | AddString(TargetOpts.CPU, Record); |
| 1632 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1633 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1634 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1635 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1636 | } |
| 1637 | Record.push_back(TargetOpts.Features.size()); |
| 1638 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1639 | AddString(TargetOpts.Features[I], Record); |
| 1640 | } |
| 1641 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1642 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1643 | // File system options. |
| 1644 | Record.clear(); |
Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1645 | const FileSystemOptions &FSOpts = |
| 1646 | Context.getSourceManager().getFileManager().getFileSystemOpts(); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1647 | AddString(FSOpts.WorkingDir, Record); |
| 1648 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1649 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1650 | // Header search options. |
| 1651 | Record.clear(); |
| 1652 | const HeaderSearchOptions &HSOpts |
| 1653 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1654 | AddString(HSOpts.Sysroot, Record); |
| 1655 | |
| 1656 | // Include entries. |
| 1657 | Record.push_back(HSOpts.UserEntries.size()); |
| 1658 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1659 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1660 | AddString(Entry.Path, Record); |
| 1661 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1662 | Record.push_back(Entry.IsFramework); |
| 1663 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | // System header prefixes. |
| 1667 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1668 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1669 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1670 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1671 | } |
| 1672 | |
| 1673 | AddString(HSOpts.ResourceDir, Record); |
| 1674 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1675 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1676 | Record.push_back(HSOpts.DisableModuleHash); |
Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 1677 | Record.push_back(HSOpts.ImplicitModuleMaps); |
| 1678 | Record.push_back(HSOpts.ModuleMapFileHomeIsCwd); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1679 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1680 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1681 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1682 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1683 | // Write out the specific module cache path that contains the module files. |
| 1684 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1685 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1686 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1687 | // Preprocessor options. |
| 1688 | Record.clear(); |
| 1689 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1690 | |
| 1691 | // Macro definitions. |
| 1692 | Record.push_back(PPOpts.Macros.size()); |
| 1693 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1694 | AddString(PPOpts.Macros[I].first, Record); |
| 1695 | Record.push_back(PPOpts.Macros[I].second); |
| 1696 | } |
| 1697 | |
| 1698 | // Includes |
| 1699 | Record.push_back(PPOpts.Includes.size()); |
| 1700 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1701 | AddString(PPOpts.Includes[I], Record); |
| 1702 | |
| 1703 | // Macro includes |
| 1704 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1705 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1706 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1707 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1708 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1709 | // Detailed record is important since it is used for the module cache hash. |
| 1710 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1711 | AddString(PPOpts.ImplicitPCHInclude, Record); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1712 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1713 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1714 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1715 | // Leave the options block. |
| 1716 | Stream.ExitBlock(); |
| 1717 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1718 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1719 | SourceManager &SM = Context.getSourceManager(); |
| 1720 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1721 | auto FileAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1722 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1723 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1724 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1725 | unsigned FileAbbrevCode = Stream.EmitAbbrev(std::move(FileAbbrev)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1726 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1727 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1728 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1729 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1730 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1731 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1732 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1733 | Record.clear(); |
| 1734 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1735 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1736 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1737 | // Original PCH directory |
| 1738 | if (!OutputFile.empty() && OutputFile != "-") { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1739 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1740 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1741 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1742 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1743 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1744 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1745 | |
Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1746 | SM.getFileManager().makeAbsolutePath(OutputPath); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1747 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1748 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1749 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1750 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1751 | } |
| 1752 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1753 | WriteInputFiles(Context.SourceMgr, |
| 1754 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1755 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1756 | Stream.ExitBlock(); |
| 1757 | } |
| 1758 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1759 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1760 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1761 | /// An input file. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1762 | struct InputFileEntry { |
| 1763 | const FileEntry *File; |
| 1764 | bool IsSystemFile; |
| 1765 | bool IsTransient; |
| 1766 | bool BufferOverridden; |
| 1767 | bool IsTopLevelModuleMap; |
Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1768 | uint32_t ContentHash[2]; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1769 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1770 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1771 | } // namespace |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1772 | |
| 1773 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1774 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1775 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1776 | using namespace llvm; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1777 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1778 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1779 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1780 | // Create input-file abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1781 | auto IFAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1782 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1783 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1784 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1785 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1786 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1787 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1788 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Module map |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1789 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1790 | unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev)); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1791 | |
Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1792 | // Create input file hash abbreviation. |
| 1793 | auto IFHAbbrev = std::make_shared<BitCodeAbbrev>(); |
| 1794 | IFHAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_HASH)); |
| 1795 | IFHAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1796 | IFHAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1797 | unsigned IFHAbbrevCode = Stream.EmitAbbrev(std::move(IFHAbbrev)); |
| 1798 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1799 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1800 | // 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] | 1801 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1802 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1803 | // Get this source location entry. |
| 1804 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1805 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1806 | |
| 1807 | // We only care about file entries that were not overridden. |
| 1808 | if (!SLoc->isFile()) |
| 1809 | continue; |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1810 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1811 | const SrcMgr::ContentCache *Cache = File.getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1812 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1813 | continue; |
| 1814 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1815 | InputFileEntry Entry; |
| 1816 | Entry.File = Cache->OrigEntry; |
Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 1817 | Entry.IsSystemFile = isSystem(File.getFileCharacteristic()); |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1818 | Entry.IsTransient = Cache->IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1819 | Entry.BufferOverridden = Cache->BufferOverridden; |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1820 | Entry.IsTopLevelModuleMap = isModuleMap(File.getFileCharacteristic()) && |
| 1821 | File.getIncludeLoc().isInvalid(); |
Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1822 | |
| 1823 | auto ContentHash = hash_code(-1); |
| 1824 | if (PP->getHeaderSearchInfo() |
| 1825 | .getHeaderSearchOpts() |
| 1826 | .ValidateASTInputFilesContent) { |
| 1827 | auto *MemBuff = Cache->getRawBuffer(); |
| 1828 | if (MemBuff) |
| 1829 | ContentHash = hash_value(MemBuff->getBuffer()); |
| 1830 | else |
| 1831 | // FIXME: The path should be taken from the FileEntryRef. |
| 1832 | PP->Diag(SourceLocation(), diag::err_module_unable_to_hash_content) |
| 1833 | << Entry.File->getName(); |
| 1834 | } |
| 1835 | auto CH = llvm::APInt(64, ContentHash); |
| 1836 | Entry.ContentHash[0] = |
| 1837 | static_cast<uint32_t>(CH.getLoBits(32).getZExtValue()); |
| 1838 | Entry.ContentHash[1] = |
| 1839 | static_cast<uint32_t>(CH.getHiBits(32).getZExtValue()); |
| 1840 | |
Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 1841 | if (Entry.IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1842 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1843 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1844 | SortedFiles.push_front(Entry); |
| 1845 | } |
| 1846 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1847 | unsigned UserFilesNum = 0; |
| 1848 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1849 | std::vector<uint64_t> InputFileOffsets; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1850 | for (const auto &Entry : SortedFiles) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1851 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1852 | if (InputFileID != 0) |
| 1853 | continue; // already recorded this file. |
| 1854 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1855 | // Record this entry's offset. |
| 1856 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1857 | |
| 1858 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1860 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1861 | ++UserFilesNum; |
| 1862 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1863 | // Emit size/modification time for this file. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1864 | // And whether this file was overridden. |
Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1865 | { |
| 1866 | RecordData::value_type Record[] = { |
| 1867 | INPUT_FILE, |
| 1868 | InputFileOffsets.size(), |
| 1869 | (uint64_t)Entry.File->getSize(), |
| 1870 | (uint64_t)getTimestampForOutput(Entry.File), |
| 1871 | Entry.BufferOverridden, |
| 1872 | Entry.IsTransient, |
| 1873 | Entry.IsTopLevelModuleMap}; |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1874 | |
Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1875 | // FIXME: The path should be taken from the FileEntryRef. |
| 1876 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1877 | } |
| 1878 | |
| 1879 | // Emit content hash for this file. |
| 1880 | { |
| 1881 | RecordData::value_type Record[] = {INPUT_FILE_HASH, Entry.ContentHash[0], |
| 1882 | Entry.ContentHash[1]}; |
| 1883 | Stream.EmitRecordWithAbbrev(IFHAbbrevCode, Record); |
| 1884 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1885 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1886 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1887 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1888 | |
| 1889 | // Create input file offsets abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1890 | auto OffsetsAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1891 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1892 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1893 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1894 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1895 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1896 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(std::move(OffsetsAbbrev)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1897 | |
| 1898 | // Write input file offsets. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1899 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, |
| 1900 | InputFileOffsets.size(), UserFilesNum}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1901 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1904 | //===----------------------------------------------------------------------===// |
| 1905 | // Source Manager Serialization |
| 1906 | //===----------------------------------------------------------------------===// |
| 1907 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1908 | /// Create an abbreviation for the SLocEntry that refers to a |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1909 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1910 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1911 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1912 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1913 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1914 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1915 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1916 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1917 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1918 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1919 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1920 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1921 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1922 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1923 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1924 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1927 | /// Create an abbreviation for the SLocEntry that refers to a |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1928 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1929 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1930 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1931 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1932 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1933 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1934 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1935 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1936 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1937 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1938 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1939 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1942 | /// Create an abbreviation for the SLocEntry that refers to a |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1943 | /// buffer's blob. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1944 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, |
| 1945 | bool Compressed) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1946 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1947 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1948 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1949 | Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED |
| 1950 | : SM_SLOC_BUFFER_BLOB)); |
| 1951 | if (Compressed) |
| 1952 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1953 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1954 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1955 | } |
| 1956 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1957 | /// Create an abbreviation for the SLocEntry that refers to a macro |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1958 | /// expansion. |
| 1959 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1960 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1961 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1962 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1963 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1964 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1965 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1966 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1967 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Richard Smith | b5f8171 | 2018-04-30 05:25:48 +0000 | [diff] [blame] | 1968 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is token range |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1969 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1970 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1973 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1974 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1975 | // Trait used for the on-disk hash table of header search information. |
| 1976 | class HeaderFileInfoTrait { |
| 1977 | ASTWriter &Writer; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1978 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1979 | // Keep track of the framework names we've used during serialization. |
| 1980 | SmallVector<char, 128> FrameworkStringData; |
| 1981 | llvm::StringMap<unsigned> FrameworkNameOffset; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1982 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1983 | public: |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1984 | HeaderFileInfoTrait(ASTWriter &Writer) : Writer(Writer) {} |
| 1985 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1986 | struct key_type { |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1987 | StringRef Filename; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1988 | off_t Size; |
| 1989 | time_t ModTime; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1990 | }; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1991 | using key_type_ref = const key_type &; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1992 | |
| 1993 | using UnresolvedModule = |
| 1994 | llvm::PointerIntPair<Module *, 2, ModuleMap::ModuleHeaderRole>; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1995 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1996 | struct data_type { |
| 1997 | const HeaderFileInfo &HFI; |
| 1998 | ArrayRef<ModuleMap::KnownHeader> KnownHeaders; |
| 1999 | UnresolvedModule Unresolved; |
| 2000 | }; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2001 | using data_type_ref = const data_type &; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2002 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2003 | using hash_value_type = unsigned; |
| 2004 | using offset_type = unsigned; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2005 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2006 | hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 2007 | // The hash is based only on size/time of the file, so that the reader can |
| 2008 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 2009 | // 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] | 2010 | return llvm::hash_combine(key.Size, key.ModTime); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2011 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2012 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2013 | std::pair<unsigned, unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 2014 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2015 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2016 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 2017 | endian::Writer LE(Out, little); |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 2018 | unsigned KeyLen = key.Filename.size() + 1 + 8 + 8; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2019 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2020 | unsigned DataLen = 1 + 2 + 4 + 4; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2021 | for (auto ModInfo : Data.KnownHeaders) |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2022 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) |
| 2023 | DataLen += 4; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2024 | if (Data.Unresolved.getPointer()) |
| 2025 | DataLen += 4; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2026 | LE.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 2027 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2028 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2029 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 2030 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2031 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2032 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 2033 | endian::Writer LE(Out, little); |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2034 | LE.write<uint64_t>(key.Size); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 2035 | KeyLen -= 8; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2036 | LE.write<uint64_t>(key.ModTime); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 2037 | KeyLen -= 8; |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 2038 | Out.write(key.Filename.data(), KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2039 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2040 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2041 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2042 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2043 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2044 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 2045 | endian::Writer LE(Out, little); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2046 | uint64_t Start = Out.tell(); (void)Start; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2047 | |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 2048 | unsigned char Flags = (Data.HFI.isImport << 5) |
| 2049 | | (Data.HFI.isPragmaOnce << 4) |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2050 | | (Data.HFI.DirInfo << 1) |
| 2051 | | Data.HFI.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2052 | LE.write<uint8_t>(Flags); |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2053 | LE.write<uint16_t>(Data.HFI.NumIncludes); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2054 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2055 | if (!Data.HFI.ControllingMacro) |
| 2056 | LE.write<uint32_t>(Data.HFI.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2057 | else |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2058 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.HFI.ControllingMacro)); |
| 2059 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2060 | unsigned Offset = 0; |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2061 | if (!Data.HFI.Framework.empty()) { |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2062 | // If this header refers into a framework, save the framework name. |
| 2063 | llvm::StringMap<unsigned>::iterator Pos |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2064 | = FrameworkNameOffset.find(Data.HFI.Framework); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2065 | if (Pos == FrameworkNameOffset.end()) { |
| 2066 | Offset = FrameworkStringData.size() + 1; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2067 | FrameworkStringData.append(Data.HFI.Framework.begin(), |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2068 | Data.HFI.Framework.end()); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2069 | FrameworkStringData.push_back(0); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2070 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2071 | FrameworkNameOffset[Data.HFI.Framework] = Offset; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2072 | } else |
| 2073 | Offset = Pos->second; |
| 2074 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2075 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2076 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2077 | auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) { |
| 2078 | if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) { |
| 2079 | uint32_t Value = (ModID << 2) | (unsigned)Role; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2080 | assert((Value >> 2) == ModID && "overflow in header module info"); |
| 2081 | LE.write<uint32_t>(Value); |
| 2082 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2083 | }; |
| 2084 | |
| 2085 | // FIXME: If the header is excluded, we should write out some |
| 2086 | // record of that fact. |
| 2087 | for (auto ModInfo : Data.KnownHeaders) |
| 2088 | EmitModule(ModInfo.getModule(), ModInfo.getRole()); |
| 2089 | if (Data.Unresolved.getPointer()) |
| 2090 | EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt()); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2091 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2092 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 2093 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2094 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2095 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 2096 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2097 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2098 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2099 | } // namespace |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2100 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2101 | /// Write the header search block for the list of files that |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2102 | /// |
| 2103 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2104 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2105 | HeaderFileInfoTrait GeneratorTrait(*this); |
| 2106 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
| 2107 | SmallVector<const char *, 4> SavedStrings; |
| 2108 | unsigned NumHeaderSearchEntries = 0; |
| 2109 | |
| 2110 | // Find all unresolved headers for the current module. We generally will |
| 2111 | // have resolved them before we get here, but not necessarily: we might be |
| 2112 | // compiling a preprocessed module, where there is no requirement for the |
| 2113 | // original files to exist any more. |
Benjamin Kramer | ee021d5 | 2017-06-02 17:30:24 +0000 | [diff] [blame] | 2114 | const HeaderFileInfo Empty; // So we can take a reference. |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2115 | if (WritingModule) { |
| 2116 | llvm::SmallVector<Module *, 16> Worklist(1, WritingModule); |
| 2117 | while (!Worklist.empty()) { |
| 2118 | Module *M = Worklist.pop_back_val(); |
| 2119 | if (!M->isAvailable()) |
| 2120 | continue; |
| 2121 | |
| 2122 | // Map to disk files where possible, to pick up any missing stat |
| 2123 | // information. This also means we don't need to check the unresolved |
| 2124 | // headers list when emitting resolved headers in the first loop below. |
| 2125 | // FIXME: It'd be preferable to avoid doing this if we were given |
| 2126 | // sufficient stat information in the module map. |
| 2127 | HS.getModuleMap().resolveHeaderDirectives(M); |
| 2128 | |
| 2129 | // If the file didn't exist, we can still create a module if we were given |
| 2130 | // enough information in the module map. |
| 2131 | for (auto U : M->MissingHeaders) { |
| 2132 | // Check that we were given enough information to build a module |
| 2133 | // without this file existing on disk. |
| 2134 | if (!U.Size || (!U.ModTime && IncludeTimestamps)) { |
| 2135 | PP->Diag(U.FileNameLoc, diag::err_module_no_size_mtime_for_header) |
| 2136 | << WritingModule->getFullModuleName() << U.Size.hasValue() |
| 2137 | << U.FileName; |
| 2138 | continue; |
| 2139 | } |
| 2140 | |
| 2141 | // Form the effective relative pathname for the file. |
| 2142 | SmallString<128> Filename(M->Directory->getName()); |
| 2143 | llvm::sys::path::append(Filename, U.FileName); |
| 2144 | PreparePathForOutput(Filename); |
| 2145 | |
| 2146 | StringRef FilenameDup = strdup(Filename.c_str()); |
| 2147 | SavedStrings.push_back(FilenameDup.data()); |
| 2148 | |
| 2149 | HeaderFileInfoTrait::key_type Key = { |
| 2150 | FilenameDup, *U.Size, IncludeTimestamps ? *U.ModTime : 0 |
| 2151 | }; |
| 2152 | HeaderFileInfoTrait::data_type Data = { |
Benjamin Kramer | ee021d5 | 2017-06-02 17:30:24 +0000 | [diff] [blame] | 2153 | Empty, {}, {M, ModuleMap::headerKindToRole(U.Kind)} |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2154 | }; |
| 2155 | // FIXME: Deal with cases where there are multiple unresolved header |
| 2156 | // directives in different submodules for the same header. |
| 2157 | Generator.insert(Key, Data, GeneratorTrait); |
| 2158 | ++NumHeaderSearchEntries; |
| 2159 | } |
| 2160 | |
| 2161 | Worklist.append(M->submodule_begin(), M->submodule_end()); |
| 2162 | } |
| 2163 | } |
| 2164 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2165 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2166 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2167 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2168 | if (FilesByUID.size() > HS.header_file_size()) |
| 2169 | FilesByUID.resize(HS.header_file_size()); |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2170 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2171 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 2172 | const FileEntry *File = FilesByUID[UID]; |
| 2173 | if (!File) |
| 2174 | continue; |
| 2175 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2176 | // Get the file info. This will load info from the external source if |
| 2177 | // necessary. Skip emitting this file if we have no information on it |
| 2178 | // as a header file (in which case HFI will be null) or if it hasn't |
| 2179 | // changed since it was loaded. Also skip it if it's for a modular header |
| 2180 | // from a different module; in that case, we rely on the module(s) |
| 2181 | // containing the header to provide this information. |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 2182 | const HeaderFileInfo *HFI = |
| 2183 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); |
| 2184 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 2185 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2186 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2187 | // Massage the file path into an appropriate form. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 2188 | StringRef Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2189 | SmallString<128> FilenameTmp(Filename); |
| 2190 | if (PreparePathForOutput(FilenameTmp)) { |
| 2191 | // If we performed any translation on the file name at all, we need to |
| 2192 | // save this string, since the generator will refer to it later. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 2193 | Filename = StringRef(strdup(FilenameTmp.c_str())); |
| 2194 | SavedStrings.push_back(Filename.data()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2195 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2196 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2197 | HeaderFileInfoTrait::key_type Key = { |
| 2198 | Filename, File->getSize(), getTimestampForOutput(File) |
| 2199 | }; |
| 2200 | HeaderFileInfoTrait::data_type Data = { |
| 2201 | *HFI, HS.getModuleMap().findAllModulesForHeader(File), {} |
| 2202 | }; |
| 2203 | Generator.insert(Key, Data, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2204 | ++NumHeaderSearchEntries; |
| 2205 | } |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 2206 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2207 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2208 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2209 | uint32_t BucketOffset; |
| 2210 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2211 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2213 | llvm::raw_svector_ostream Out(TableData); |
| 2214 | // Make sure that no bucket is at offset 0 |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 2215 | endian::write<uint32_t>(Out, 0, little); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2216 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 2217 | } |
| 2218 | |
| 2219 | // Create a blob abbreviation |
| 2220 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2221 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2222 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2223 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 2224 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 2225 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2226 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2227 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2228 | unsigned TableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2229 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2230 | // Write the header search table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2231 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, |
| 2232 | NumHeaderSearchEntries, TableData.size()}; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2233 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 2234 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2235 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2236 | // Free all of the strings we had to duplicate. |
| 2237 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 2238 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 2241 | static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob, |
| 2242 | unsigned SLocBufferBlobCompressedAbbrv, |
| 2243 | unsigned SLocBufferBlobAbbrv) { |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2244 | using RecordDataType = ASTWriter::RecordData::value_type; |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 2245 | |
| 2246 | // Compress the buffer if possible. We expect that almost all PCM |
| 2247 | // consumers will not want its contents. |
| 2248 | SmallString<0> CompressedBuffer; |
| 2249 | if (llvm::zlib::isAvailable()) { |
| 2250 | llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer); |
| 2251 | if (!E) { |
| 2252 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, |
| 2253 | Blob.size() - 1}; |
| 2254 | Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, |
| 2255 | CompressedBuffer); |
| 2256 | return; |
| 2257 | } |
| 2258 | llvm::consumeError(std::move(E)); |
| 2259 | } |
| 2260 | |
| 2261 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB}; |
| 2262 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob); |
| 2263 | } |
| 2264 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2265 | /// Writes the block containing the serialized form of the |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2266 | /// source manager. |
| 2267 | /// |
| 2268 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 2269 | /// blob), indexed based on the file name, so that we only create |
| 2270 | /// entries for files that we actually need. In the common case (no |
| 2271 | /// errors), we probably won't have to create file entries for any of |
| 2272 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2273 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2274 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2275 | RecordData Record; |
| 2276 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2277 | // Enter the source manager block. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2278 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2279 | |
| 2280 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 2281 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 2282 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2283 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false); |
| 2284 | unsigned SLocBufferBlobCompressedAbbrv = |
| 2285 | CreateSLocBufferBlobAbbrev(Stream, true); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2286 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2287 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2288 | // Write out the source location entry table. We skip the first |
| 2289 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 2290 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2291 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2292 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 2293 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2294 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2295 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2296 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2297 | FileID FID = FileID::get(I); |
| 2298 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2299 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2300 | // Record the offset of this source-location entry. |
| 2301 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2302 | |
| 2303 | // Figure out which record code to use. |
| 2304 | unsigned Code; |
| 2305 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2306 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 2307 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2308 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2309 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2310 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2311 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2312 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2313 | Record.clear(); |
| 2314 | Record.push_back(Code); |
| 2315 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2316 | // Starting offset of this entry within this module, so skip the dummy. |
| 2317 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2318 | if (SLoc->isFile()) { |
| 2319 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2320 | AddSourceLocation(File.getIncludeLoc(), Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2321 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 2322 | Record.push_back(File.hasLineDirectives()); |
| 2323 | |
| 2324 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2325 | bool EmitBlob = false; |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2326 | if (Content->OrigEntry) { |
| 2327 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2328 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2329 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2330 | // The source location entry is a file. Emit input file ID. |
| 2331 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 2332 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2333 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 2334 | Record.push_back(File.NumCreatedFIDs); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2335 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2336 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2337 | if (FDI != FileDeclIDs.end()) { |
| 2338 | Record.push_back(FDI->second->FirstDeclIndex); |
| 2339 | Record.push_back(FDI->second->DeclIDs.size()); |
| 2340 | } else { |
| 2341 | Record.push_back(0); |
| 2342 | Record.push_back(0); |
| 2343 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2344 | |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2345 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2346 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2347 | if (Content->BufferOverridden || Content->IsTransient) |
| 2348 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2349 | } else { |
| 2350 | // The source location entry is a buffer. The blob associated |
| 2351 | // with this entry contains the contents of the buffer. |
| 2352 | |
| 2353 | // We add one to the size so that we capture the trailing NULL |
| 2354 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 2355 | // the reader side). |
Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 2356 | const llvm::MemoryBuffer *Buffer = |
| 2357 | Content->getBuffer(PP.getDiagnostics(), PP.getFileManager()); |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2358 | StringRef Name = Buffer->getBufferIdentifier(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2359 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2360 | StringRef(Name.data(), Name.size() + 1)); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2361 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2362 | |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2363 | if (Name == "<built-in>") |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2364 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2365 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2366 | |
| 2367 | if (EmitBlob) { |
| 2368 | // Include the implicit terminating null character in the on-disk buffer |
| 2369 | // if we're writing it uncompressed. |
| 2370 | const llvm::MemoryBuffer *Buffer = |
Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 2371 | Content->getBuffer(PP.getDiagnostics(), PP.getFileManager()); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2372 | StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1); |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 2373 | emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv, |
| 2374 | SLocBufferBlobAbbrv); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2375 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2376 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2377 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 2378 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2379 | AddSourceLocation(Expansion.getSpellingLoc(), Record); |
| 2380 | AddSourceLocation(Expansion.getExpansionLocStart(), Record); |
| 2381 | AddSourceLocation(Expansion.isMacroArgExpansion() |
| 2382 | ? SourceLocation() |
| 2383 | : Expansion.getExpansionLocEnd(), |
| 2384 | Record); |
Richard Smith | b5f8171 | 2018-04-30 05:25:48 +0000 | [diff] [blame] | 2385 | Record.push_back(Expansion.isExpansionTokenRange()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2386 | |
| 2387 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2388 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2389 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2390 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2391 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2392 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2393 | } |
| 2394 | } |
| 2395 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2396 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2397 | |
| 2398 | if (SLocEntryOffsets.empty()) |
| 2399 | return; |
| 2400 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2401 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2402 | // table is used for lazily loading source-location information. |
| 2403 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2404 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2405 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2406 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2407 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2408 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2409 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2410 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2411 | { |
| 2412 | RecordData::value_type Record[] = { |
| 2413 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), |
| 2414 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */}; |
| 2415 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
| 2416 | bytes(SLocEntryOffsets)); |
| 2417 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2418 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2419 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2420 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2421 | |
| 2422 | // Write the line table. It depends on remapping working, so it must come |
| 2423 | // after the source location offsets. |
| 2424 | if (SourceMgr.hasLineTable()) { |
| 2425 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 2426 | |
| 2427 | Record.clear(); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2428 | |
| 2429 | // Emit the needed file names. |
| 2430 | llvm::DenseMap<int, int> FilenameMap; |
Hans Wennborg | 1448736 | 2017-12-04 22:28:45 +0000 | [diff] [blame] | 2431 | FilenameMap[-1] = -1; // For unspecified filenames. |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2432 | for (const auto &L : LineTable) { |
| 2433 | if (L.first.ID < 0) |
| 2434 | continue; |
| 2435 | for (auto &LE : L.second) { |
| 2436 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, |
Hans Wennborg | 1448736 | 2017-12-04 22:28:45 +0000 | [diff] [blame] | 2437 | FilenameMap.size() - 1)).second) |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2438 | AddPath(LineTable.getFilename(LE.FilenameID), Record); |
| 2439 | } |
| 2440 | } |
| 2441 | Record.push_back(0); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2442 | |
| 2443 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2444 | for (const auto &L : LineTable) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2445 | // Only emit entries for local files. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2446 | if (L.first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2447 | continue; |
| 2448 | |
| 2449 | // Emit the file ID |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2450 | Record.push_back(L.first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2451 | |
| 2452 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2453 | Record.push_back(L.second.size()); |
| 2454 | for (const auto &LE : L.second) { |
| 2455 | Record.push_back(LE.FileOffset); |
| 2456 | Record.push_back(LE.LineNo); |
| 2457 | Record.push_back(FilenameMap[LE.FilenameID]); |
| 2458 | Record.push_back((unsigned)LE.FileKind); |
| 2459 | Record.push_back(LE.IncludeOffset); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2460 | } |
| 2461 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2462 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2463 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 2464 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2467 | //===----------------------------------------------------------------------===// |
| 2468 | // Preprocessor Serialization |
| 2469 | //===----------------------------------------------------------------------===// |
| 2470 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2471 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 2472 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2473 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 2474 | if (MI->isBuiltinMacro()) |
| 2475 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2476 | |
| 2477 | if (IsModule) { |
| 2478 | SourceLocation Loc = MD->getLocation(); |
| 2479 | if (Loc.isInvalid()) |
| 2480 | return true; |
| 2481 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 2482 | return true; |
| 2483 | } |
| 2484 | |
| 2485 | return false; |
| 2486 | } |
| 2487 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2488 | /// Writes the block containing the serialized form of the |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2489 | /// preprocessor. |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2490 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2491 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2492 | if (PPRec) |
| 2493 | WritePreprocessorDetail(*PPRec); |
| 2494 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2495 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2496 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2497 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2498 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2499 | if (PP.getCounterValue() != 0) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2500 | RecordData::value_type Record[] = {PP.getCounterValue()}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2501 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 2504 | if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) { |
| 2505 | assert(!IsModule); |
Erik Verbruggen | 4d1eb2d | 2017-11-03 09:40:07 +0000 | [diff] [blame] | 2506 | auto SkipInfo = PP.getPreambleSkipInfo(); |
| 2507 | if (SkipInfo.hasValue()) { |
| 2508 | Record.push_back(true); |
| 2509 | AddSourceLocation(SkipInfo->HashTokenLoc, Record); |
| 2510 | AddSourceLocation(SkipInfo->IfTokenLoc, Record); |
| 2511 | Record.push_back(SkipInfo->FoundNonSkipPortion); |
| 2512 | Record.push_back(SkipInfo->FoundElse); |
| 2513 | AddSourceLocation(SkipInfo->ElseLoc, Record); |
| 2514 | } else { |
| 2515 | Record.push_back(false); |
| 2516 | } |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 2517 | for (const auto &Cond : PP.getPreambleConditionalStack()) { |
| 2518 | AddSourceLocation(Cond.IfLoc, Record); |
| 2519 | Record.push_back(Cond.WasSkipping); |
| 2520 | Record.push_back(Cond.FoundNonSkip); |
| 2521 | Record.push_back(Cond.FoundElse); |
| 2522 | } |
| 2523 | Stream.EmitRecord(PP_CONDITIONAL_STACK, Record); |
| 2524 | Record.clear(); |
| 2525 | } |
| 2526 | |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2527 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2528 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2529 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2530 | // 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] | 2531 | // 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] | 2532 | if (PP.SawDateOrTime()) |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2533 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2534 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2535 | // 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] | 2536 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2537 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2538 | // Construct the list of identifiers with macro directives that need to be |
| 2539 | // serialized. |
| 2540 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2541 | for (auto &Id : PP.getIdentifierTable()) |
| 2542 | if (Id.second->hadMacroDefinition() && |
| 2543 | (!Id.second->isFromAST() || |
| 2544 | Id.second->hasChangedSinceDeserialization())) |
| 2545 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2546 | // Sort the set of macro definitions that need to be serialized by the |
| 2547 | // name of the macro, to provide a stable ordering. |
Benjamin Kramer | cd2bae3 | 2019-08-22 17:32:16 +0000 | [diff] [blame] | 2548 | llvm::sort(MacroIdentifiers, llvm::deref<std::less<>>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2549 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2550 | // Emit the macro directives as a list and associate the offset with the |
| 2551 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2552 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2553 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2554 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2555 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2556 | // Emit the macro directives in reverse source order. |
| 2557 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2558 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2559 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2560 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2561 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2562 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2563 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2564 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2565 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2566 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2567 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2568 | Record.push_back(VisMD->isPublic()); |
| 2569 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2570 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2571 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2572 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2573 | bool EmittedModuleMacros = false; |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2574 | // We write out exported module macros for PCH as well. |
| 2575 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2576 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2577 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2578 | while (!Worklist.empty()) { |
| 2579 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2580 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2581 | // Emit a record indicating this submodule exports this macro. |
| 2582 | ModuleMacroRecord.push_back( |
| 2583 | getSubmoduleID(Macro->getOwningModule())); |
| 2584 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
| 2585 | for (auto *M : Macro->overrides()) |
| 2586 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2587 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2588 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2589 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2590 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2591 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2592 | for (auto *M : Macro->overrides()) |
| 2593 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2594 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2595 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2596 | EmittedModuleMacros = true; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2597 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2598 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2599 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2600 | continue; |
| 2601 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2602 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2603 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2604 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2605 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2606 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2607 | /// Offsets of each of the macros into the bitstream, indexed by |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2608 | /// the local macro ID |
| 2609 | /// |
| 2610 | /// For each identifier that is associated with a macro, this map |
| 2611 | /// provides the offset into the bitstream where that macro is |
| 2612 | /// defined. |
| 2613 | std::vector<uint32_t> MacroOffsets; |
| 2614 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2615 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2616 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2617 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2618 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2619 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2620 | if (ID < FirstMacroID) { |
| 2621 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2622 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2623 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2624 | |
| 2625 | // Record the local offset of this macro. |
| 2626 | unsigned Index = ID - FirstMacroID; |
| 2627 | if (Index == MacroOffsets.size()) |
| 2628 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2629 | else { |
| 2630 | if (Index > MacroOffsets.size()) |
| 2631 | MacroOffsets.resize(Index + 1); |
| 2632 | |
| 2633 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2634 | } |
| 2635 | |
| 2636 | AddIdentifierRef(Name, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2637 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2638 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2639 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2640 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2641 | unsigned Code; |
| 2642 | if (MI->isObjectLike()) { |
| 2643 | Code = PP_MACRO_OBJECT_LIKE; |
| 2644 | } else { |
| 2645 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2646 | |
| 2647 | Record.push_back(MI->isC99Varargs()); |
| 2648 | Record.push_back(MI->isGNUVarargs()); |
| 2649 | Record.push_back(MI->hasCommaPasting()); |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 2650 | Record.push_back(MI->getNumParams()); |
| 2651 | for (const IdentifierInfo *Param : MI->params()) |
| 2652 | AddIdentifierRef(Param, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | // If we have a detailed preprocessing record, record the macro definition |
| 2656 | // ID that corresponds to this macro. |
| 2657 | if (PPRec) |
| 2658 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2659 | |
| 2660 | Stream.EmitRecord(Code, Record); |
| 2661 | Record.clear(); |
| 2662 | |
| 2663 | // Emit the tokens array. |
| 2664 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2665 | // Note that we know that the preprocessor does not have any annotation |
| 2666 | // tokens in it because they are created by the parser, and thus can't |
| 2667 | // be in a macro definition. |
| 2668 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2669 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2670 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2671 | Record.clear(); |
| 2672 | } |
| 2673 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2674 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2675 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2676 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2677 | |
| 2678 | // Write the offsets table for macro IDs. |
| 2679 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2680 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2681 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2682 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2683 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2684 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2685 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2686 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2687 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2688 | { |
| 2689 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), |
| 2690 | FirstMacroID - NUM_PREDEF_MACRO_IDS}; |
| 2691 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); |
| 2692 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2696 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2697 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2698 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2699 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2700 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2701 | // Enter the preprocessor block. |
| 2702 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2703 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2704 | // If the preprocessor has a preprocessing record, emit it. |
| 2705 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2706 | using namespace llvm; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2707 | |
| 2708 | // Set up the abbreviation for |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2709 | unsigned InclusionAbbrev = 0; |
| 2710 | { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2711 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2712 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2713 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2714 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2715 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2716 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2717 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2718 | InclusionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2719 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2720 | |
| 2721 | unsigned FirstPreprocessorEntityID |
| 2722 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2723 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2724 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2725 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2726 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2727 | EEnd = PPRec.local_end(); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2728 | E != EEnd; |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2729 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2730 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2731 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2732 | PreprocessedEntityOffsets.push_back( |
| 2733 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2734 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2735 | if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2736 | // Record this macro definition's ID. |
| 2737 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2738 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2739 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2740 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2741 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2742 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2743 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2744 | if (auto *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2745 | Record.push_back(ME->isBuiltinMacro()); |
| 2746 | if (ME->isBuiltinMacro()) |
| 2747 | AddIdentifierRef(ME->getName(), Record); |
| 2748 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2749 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2750 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2751 | continue; |
| 2752 | } |
| 2753 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2754 | if (auto *ID = dyn_cast<InclusionDirective>(*E)) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2755 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2756 | Record.push_back(ID->getFileName().size()); |
| 2757 | Record.push_back(ID->wasInQuotes()); |
| 2758 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2759 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2760 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2761 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2762 | // Check that the FileEntry is not null because it was not resolved and |
| 2763 | // we create a PCH even with compiler errors. |
| 2764 | if (ID->getFile()) |
| 2765 | Buffer += ID->getFile()->getName(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2766 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2767 | continue; |
| 2768 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2769 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2770 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2771 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2772 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2773 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2774 | // Write the offsets table for the preprocessing record. |
| 2775 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2776 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2777 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2778 | // Write the offsets table for identifier IDs. |
| 2779 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2780 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2781 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2782 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2783 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2784 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2785 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2786 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2787 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, |
| 2788 | FirstPreprocessorEntityID - |
| 2789 | NUM_PREDEF_PP_ENTITY_IDS}; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2790 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2791 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2792 | } |
Cameron Desrochers | b60f1b6 | 2018-01-15 19:14:16 +0000 | [diff] [blame] | 2793 | |
| 2794 | // Write the skipped region table for the preprocessing record. |
| 2795 | ArrayRef<SourceRange> SkippedRanges = PPRec.getSkippedRanges(); |
| 2796 | if (SkippedRanges.size() > 0) { |
| 2797 | std::vector<PPSkippedRange> SerializedSkippedRanges; |
| 2798 | SerializedSkippedRanges.reserve(SkippedRanges.size()); |
| 2799 | for (auto const& Range : SkippedRanges) |
| 2800 | SerializedSkippedRanges.emplace_back(Range); |
| 2801 | |
| 2802 | using namespace llvm; |
| 2803 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
| 2804 | Abbrev->Add(BitCodeAbbrevOp(PPD_SKIPPED_RANGES)); |
| 2805 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2806 | unsigned PPESkippedRangeAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
| 2807 | |
| 2808 | Record.clear(); |
| 2809 | Record.push_back(PPD_SKIPPED_RANGES); |
| 2810 | Stream.EmitRecordWithBlob(PPESkippedRangeAbbrev, Record, |
| 2811 | bytes(SerializedSkippedRanges)); |
| 2812 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2815 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2816 | if (!Mod) |
| 2817 | return 0; |
| 2818 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2819 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2820 | if (Known != SubmoduleIDs.end()) |
| 2821 | return Known->second; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2822 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2823 | auto *Top = Mod->getTopLevelModule(); |
| 2824 | if (Top != WritingModule && |
Bruno Cardoso Lopes | 17da34d | 2017-02-07 21:54:57 +0000 | [diff] [blame] | 2825 | (getLangOpts().CompilingPCH || |
| 2826 | !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule)))) |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2827 | return 0; |
| 2828 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2829 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2830 | } |
| 2831 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2832 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2833 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2834 | // did not result in us loading a module file for that submodule. For |
| 2835 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2836 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); |
| 2837 | assert((ID || !Mod) && |
| 2838 | "asked for module ID for non-local, non-imported module"); |
| 2839 | return ID; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2840 | } |
| 2841 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2842 | /// Compute the number of modules within the given tree (including the |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2843 | /// given module). |
| 2844 | static unsigned getNumberOfModules(Module *Mod) { |
| 2845 | unsigned ChildModules = 0; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2846 | for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2847 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2848 | ChildModules += getNumberOfModules(*Sub); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2849 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2850 | return ChildModules + 1; |
| 2851 | } |
| 2852 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2853 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2854 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2855 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2856 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2857 | // Write the abbreviations needed for the submodules block. |
| 2858 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2859 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2860 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2861 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2862 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2863 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 2864 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Kind |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2865 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2866 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2867 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2868 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2869 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2870 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2871 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2872 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Jordan Rose | 90b0a1f | 2018-04-20 17:16:04 +0000 | [diff] [blame] | 2873 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModuleMapIsPriv... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2874 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2875 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2876 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2877 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2878 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2879 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2880 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2881 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2882 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2883 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2884 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2885 | unsigned HeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2886 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2887 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2888 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2889 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2890 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2891 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2892 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2893 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2894 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2895 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2896 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2897 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2898 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2899 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2900 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2901 | unsigned RequiresAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2902 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2903 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2904 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2905 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2906 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2907 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2908 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2909 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2910 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2911 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2912 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2913 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2914 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2915 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2916 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2917 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2918 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2919 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2920 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2921 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2922 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2923 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2924 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2925 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2926 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2927 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2928 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2929 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2930 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2931 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2932 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2933 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2934 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2935 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2936 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2937 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2938 | unsigned ConflictAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2939 | |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 2940 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
| 2941 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXPORT_AS)); |
| 2942 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
| 2943 | unsigned ExportAsAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
| 2944 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2945 | // Write the submodule metadata block. |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 2946 | RecordData::value_type Record[] = { |
| 2947 | getNumberOfModules(WritingModule), |
Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 2948 | FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS}; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2949 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2950 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2951 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2952 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2953 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2954 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2955 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2956 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2957 | unsigned ID = getSubmoduleID(Mod); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2958 | |
| 2959 | uint64_t ParentID = 0; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2960 | if (Mod->Parent) { |
| 2961 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2962 | ParentID = SubmoduleIDs[Mod->Parent]; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2963 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2964 | |
| 2965 | // Emit the definition of the block. |
| 2966 | { |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2967 | RecordData::value_type Record[] = {SUBMODULE_DEFINITION, |
| 2968 | ID, |
| 2969 | ParentID, |
Simon Pilgrim | f331a66 | 2017-09-04 10:54:39 +0000 | [diff] [blame] | 2970 | (RecordData::value_type)Mod->Kind, |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2971 | Mod->IsFramework, |
| 2972 | Mod->IsExplicit, |
| 2973 | Mod->IsSystem, |
| 2974 | Mod->IsExternC, |
| 2975 | Mod->InferSubmodules, |
| 2976 | Mod->InferExplicitSubmodules, |
| 2977 | Mod->InferExportWildcard, |
Jordan Rose | 90b0a1f | 2018-04-20 17:16:04 +0000 | [diff] [blame] | 2978 | Mod->ConfigMacrosExhaustive, |
| 2979 | Mod->ModuleMapIsPrivate}; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2980 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2981 | } |
| 2982 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2983 | // Emit the requirements. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2984 | for (const auto &R : Mod->Requirements) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2985 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2986 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2987 | } |
| 2988 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2989 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2990 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2991 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2992 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2993 | UmbrellaHeader.NameAsWritten); |
| 2994 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2995 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; |
| 2996 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2997 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2998 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2999 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3000 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 3001 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 3002 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 3003 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 3004 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 3005 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 3006 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 3007 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 3008 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 3009 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 3010 | Module::HK_PrivateTextual}, |
| 3011 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 3012 | }; |
| 3013 | for (auto &HL : HeaderLists) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3014 | RecordData::value_type Record[] = {HL.RecordKind}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 3015 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 3016 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 3017 | } |
| 3018 | |
| 3019 | // Emit the top headers. |
| 3020 | { |
| 3021 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3022 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 3023 | for (auto *H : TopHeaders) |
| 3024 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 3025 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3026 | |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3027 | // Emit the imports. |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3028 | if (!Mod->Imports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3029 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3030 | for (auto *I : Mod->Imports) |
| 3031 | Record.push_back(getSubmoduleID(I)); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3032 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 3033 | } |
| 3034 | |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3035 | // Emit the exports. |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3036 | if (!Mod->Exports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3037 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3038 | for (const auto &E : Mod->Exports) { |
| 3039 | // FIXME: This may fail; we don't require that all exported modules |
| 3040 | // are local or imported. |
| 3041 | Record.push_back(getSubmoduleID(E.getPointer())); |
| 3042 | Record.push_back(E.getInt()); |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3043 | } |
| 3044 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 3045 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 3046 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 3047 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 3048 | // Might be unnecessary as use declarations are only used to build the |
| 3049 | // module itself. |
| 3050 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 3051 | // Emit the link libraries. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3052 | for (const auto &LL : Mod->LinkLibraries) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3053 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, |
| 3054 | LL.IsFramework}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3055 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3058 | // Emit the conflicts. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3059 | for (const auto &C : Mod->Conflicts) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3060 | // FIXME: This may fail; we don't require that all conflicting modules |
| 3061 | // are local or imported. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3062 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, |
| 3063 | getSubmoduleID(C.Other)}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3064 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3065 | } |
| 3066 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 3067 | // Emit the configuration macros. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3068 | for (const auto &CM : Mod->ConfigMacros) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3069 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3070 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 3071 | } |
| 3072 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 3073 | // Emit the initializers, if any. |
| 3074 | RecordData Inits; |
| 3075 | for (Decl *D : Context->getModuleInitializers(Mod)) |
| 3076 | Inits.push_back(GetDeclRef(D)); |
| 3077 | if (!Inits.empty()) |
| 3078 | Stream.EmitRecord(SUBMODULE_INITIALIZERS, Inits); |
| 3079 | |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 3080 | // Emit the name of the re-exported module, if any. |
| 3081 | if (!Mod->ExportAsModule.empty()) { |
| 3082 | RecordData::value_type Record[] = {SUBMODULE_EXPORT_AS}; |
| 3083 | Stream.EmitRecordWithBlob(ExportAsAbbrev, Record, Mod->ExportAsModule); |
| 3084 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3085 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3086 | // Queue up the submodules of this module. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 3087 | for (auto *M : Mod->submodules()) |
| 3088 | Q.push(M); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3089 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3090 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3091 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 3092 | |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 3093 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 3094 | getNumberOfModules(WritingModule)) && |
| 3095 | "Wrong # of submodules; found a reference to a non-local, " |
| 3096 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 3099 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 3100 | bool isModule) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 3101 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 3102 | DiagStateIDMap; |
| 3103 | unsigned CurrID = 0; |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3104 | RecordData Record; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3105 | |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 3106 | auto EncodeDiagStateFlags = |
| 3107 | [](const DiagnosticsEngine::DiagState *DS) -> unsigned { |
| 3108 | unsigned Result = (unsigned)DS->ExtBehavior; |
| 3109 | for (unsigned Val : |
Daniel Jasper | ba9aefc | 2017-05-03 07:48:27 +0000 | [diff] [blame] | 3110 | {(unsigned)DS->IgnoreAllWarnings, (unsigned)DS->EnableAllWarnings, |
| 3111 | (unsigned)DS->WarningsAsErrors, (unsigned)DS->ErrorsAsFatal, |
| 3112 | (unsigned)DS->SuppressSystemWarnings}) |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 3113 | Result = (Result << 1) | Val; |
| 3114 | return Result; |
| 3115 | }; |
| 3116 | |
| 3117 | unsigned Flags = EncodeDiagStateFlags(Diag.DiagStatesByLoc.FirstDiagState); |
| 3118 | Record.push_back(Flags); |
| 3119 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3120 | auto AddDiagState = [&](const DiagnosticsEngine::DiagState *State, |
| 3121 | bool IncludeNonPragmaStates) { |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 3122 | // Ensure that the diagnostic state wasn't modified since it was created. |
| 3123 | // We will not correctly round-trip this information otherwise. |
| 3124 | assert(Flags == EncodeDiagStateFlags(State) && |
| 3125 | "diag state flags vary in single AST file"); |
| 3126 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3127 | unsigned &DiagStateID = DiagStateIDMap[State]; |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 3128 | Record.push_back(DiagStateID); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3129 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 3130 | if (DiagStateID == 0) { |
| 3131 | DiagStateID = ++CurrID; |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 3132 | |
| 3133 | // Add a placeholder for the number of mappings. |
| 3134 | auto SizeIdx = Record.size(); |
| 3135 | Record.emplace_back(); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3136 | for (const auto &I : *State) { |
| 3137 | if (I.second.isPragma() || IncludeNonPragmaStates) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3138 | Record.push_back(I.first); |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 3139 | Record.push_back(I.second.serialize()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 3140 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3141 | } |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 3142 | // Update the placeholder. |
| 3143 | Record[SizeIdx] = (Record.size() - SizeIdx) / 2; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3144 | } |
| 3145 | }; |
| 3146 | |
| 3147 | AddDiagState(Diag.DiagStatesByLoc.FirstDiagState, isModule); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3148 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3149 | // Reserve a spot for the number of locations with state transitions. |
| 3150 | auto NumLocationsIdx = Record.size(); |
| 3151 | Record.emplace_back(); |
| 3152 | |
| 3153 | // Emit the state transitions. |
| 3154 | unsigned NumLocations = 0; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3155 | for (auto &FileIDAndFile : Diag.DiagStatesByLoc.Files) { |
| 3156 | if (!FileIDAndFile.first.isValid() || |
| 3157 | !FileIDAndFile.second.HasLocalTransitions) |
| 3158 | continue; |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3159 | ++NumLocations; |
Richard Smith | 6c2b5a8 | 2018-02-09 01:15:13 +0000 | [diff] [blame] | 3160 | |
| 3161 | SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FileIDAndFile.first, 0); |
| 3162 | assert(!Loc.isInvalid() && "start loc for valid FileID is invalid"); |
| 3163 | AddSourceLocation(Loc, Record); |
| 3164 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 3165 | Record.push_back(FileIDAndFile.second.StateTransitions.size()); |
| 3166 | for (auto &StatePoint : FileIDAndFile.second.StateTransitions) { |
| 3167 | Record.push_back(StatePoint.Offset); |
| 3168 | AddDiagState(StatePoint.State, false); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3172 | // Backpatch the number of locations. |
| 3173 | Record[NumLocationsIdx] = NumLocations; |
| 3174 | |
| 3175 | // 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] | 3176 | // |
| 3177 | // This also protects against a hypothetical corner case with simulating |
| 3178 | // -Werror settings for implicit modules in the ASTReader, where reading |
| 3179 | // CurDiagState out of context could change whether warning pragmas are |
| 3180 | // treated as errors. |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 3181 | AddSourceLocation(Diag.DiagStatesByLoc.CurDiagStateLoc, Record); |
| 3182 | AddDiagState(Diag.DiagStatesByLoc.CurDiagState, false); |
| 3183 | |
Duncan P. N. Exon Smith | f2435b9 | 2017-04-12 02:31:17 +0000 | [diff] [blame] | 3184 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3185 | } |
| 3186 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3187 | //===----------------------------------------------------------------------===// |
| 3188 | // Type Serialization |
| 3189 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 3190 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3191 | /// Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3192 | void ASTWriter::WriteType(QualType T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3193 | TypeIdx &IdxRef = TypeIdxs[T]; |
| 3194 | if (IdxRef.getIndex() == 0) // we haven't seen this type before. |
| 3195 | IdxRef = TypeIdx(NextTypeID++); |
| 3196 | TypeIdx Idx = IdxRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3197 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3198 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 3199 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3200 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3201 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3202 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3203 | ASTTypeWriter W(*this, Record); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3204 | W.Visit(T); |
| 3205 | uint64_t Offset = W.Emit(); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3206 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3207 | // Record the offset for this type. |
| 3208 | unsigned Index = Idx.getIndex() - FirstTypeID; |
| 3209 | if (TypeOffsets.size() == Index) |
| 3210 | TypeOffsets.push_back(Offset); |
| 3211 | else if (TypeOffsets.size() < Index) { |
| 3212 | TypeOffsets.resize(Index + 1); |
| 3213 | TypeOffsets[Index] = Offset; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3214 | } else { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 3215 | llvm_unreachable("Types emitted in wrong order"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3216 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3219 | //===----------------------------------------------------------------------===// |
| 3220 | // Declaration Serialization |
| 3221 | //===----------------------------------------------------------------------===// |
| 3222 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3223 | /// Write the block containing all of the declaration IDs |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3224 | /// lexically declared within the given DeclContext. |
| 3225 | /// |
| 3226 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 3227 | /// bitstream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3228 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3229 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 3230 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3231 | return 0; |
| 3232 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3233 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 3234 | SmallVector<uint32_t, 128> KindDeclPairs; |
| 3235 | for (const auto *D : DC->decls()) { |
| 3236 | KindDeclPairs.push_back(D->getKind()); |
| 3237 | KindDeclPairs.push_back(GetDeclRef(D)); |
| 3238 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3239 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3240 | ++NumLexicalDeclContexts; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3241 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 3242 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, |
| 3243 | bytes(KindDeclPairs)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3244 | return Offset; |
| 3245 | } |
| 3246 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3247 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3248 | using namespace llvm; |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3249 | |
| 3250 | // Write the type offsets array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3251 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3252 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3253 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3254 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3255 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3256 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3257 | { |
| 3258 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), |
| 3259 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; |
| 3260 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
| 3261 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3262 | |
| 3263 | // Write the declaration offsets array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3264 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3265 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3266 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3267 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3268 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3269 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3270 | { |
| 3271 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), |
| 3272 | FirstDeclID - NUM_PREDEF_DECL_IDS}; |
| 3273 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
| 3274 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3277 | void ASTWriter::WriteFileDeclIDsMap() { |
| 3278 | using namespace llvm; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3279 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 3280 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 3281 | FileDeclIDs.begin(), FileDeclIDs.end()); |
Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 3282 | llvm::sort(SortedFileDeclIDs, llvm::less_first()); |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 3283 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3284 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 3285 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 3286 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 3287 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 3288 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 3289 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 3290 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3291 | } |
| 3292 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3293 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3294 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 3295 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3296 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3297 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3298 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, |
| 3299 | FileGroupedDeclIDs.size()}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3300 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3301 | } |
| 3302 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3303 | void ASTWriter::WriteComments() { |
| 3304 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Ilya Biryukov | 4564310 | 2018-07-09 11:33:23 +0000 | [diff] [blame] | 3305 | auto _ = llvm::make_scope_exit([this] { Stream.ExitBlock(); }); |
| 3306 | if (!PP->getPreprocessorOpts().WriteCommentListToPCH) |
| 3307 | return; |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3308 | RecordData Record; |
Jan Korous | f31d8df | 2019-08-13 18:11:44 +0000 | [diff] [blame] | 3309 | for (const auto &FO : Context->Comments.OrderedComments) { |
| 3310 | for (const auto &OC : FO.second) { |
| 3311 | const RawComment *I = OC.second; |
| 3312 | Record.clear(); |
| 3313 | AddSourceRange(I->getSourceRange(), Record); |
| 3314 | Record.push_back(I->getKind()); |
| 3315 | Record.push_back(I->isTrailingComment()); |
| 3316 | Record.push_back(I->isAlmostTrailingComment()); |
| 3317 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 3318 | } |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3319 | } |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3320 | } |
| 3321 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3322 | //===----------------------------------------------------------------------===// |
| 3323 | // Global Method Pool and Selector Serialization |
| 3324 | //===----------------------------------------------------------------------===// |
| 3325 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3326 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3327 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3328 | // 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] | 3329 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3330 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3331 | |
| 3332 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3333 | using key_type = Selector; |
| 3334 | using key_type_ref = key_type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3335 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3336 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3337 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3338 | ObjCMethodList Instance, Factory; |
| 3339 | }; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3340 | using data_type_ref = const data_type &; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3341 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3342 | using hash_value_type = unsigned; |
| 3343 | using offset_type = unsigned; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3344 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3345 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) {} |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3346 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3347 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 3348 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3349 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3351 | std::pair<unsigned, unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3352 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3353 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3354 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3355 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3356 | endian::Writer LE(Out, little); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3357 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3358 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3359 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 3360 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3361 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3362 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3363 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3364 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3365 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3366 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3367 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3368 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3369 | return std::make_pair(KeyLen, DataLen); |
| 3370 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3371 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3372 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3373 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3374 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3375 | endian::Writer LE(Out, little); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3376 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3377 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 3378 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3379 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3380 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3381 | if (N == 0) |
| 3382 | N = 1; |
| 3383 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3384 | LE.write<uint32_t>( |
| 3385 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3386 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3387 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3388 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3389 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3390 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3391 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3392 | endian::Writer LE(Out, little); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3393 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3394 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3395 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3396 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3397 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3398 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3399 | ++NumInstanceMethods; |
| 3400 | |
| 3401 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3402 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3403 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3404 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3405 | ++NumFactoryMethods; |
| 3406 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3407 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 3408 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3409 | unsigned InstanceHasMoreThanOneDeclBit = |
| 3410 | Methods.Instance.hasMoreThanOneDecl(); |
| 3411 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 3412 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 3413 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3414 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 3415 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3416 | unsigned FactoryHasMoreThanOneDeclBit = |
| 3417 | Methods.Factory.hasMoreThanOneDecl(); |
| 3418 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 3419 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 3420 | FactoryBits; |
| 3421 | LE.write<uint16_t>(FullInstanceBits); |
| 3422 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3423 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3424 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3425 | if (Method->getMethod()) |
| 3426 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3427 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3428 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3429 | if (Method->getMethod()) |
| 3430 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3431 | |
| 3432 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3433 | } |
| 3434 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3435 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3436 | } // namespace |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3437 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3438 | /// Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3439 | /// |
| 3440 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3441 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 3442 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3443 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3444 | using namespace llvm; |
| 3445 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3446 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3447 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3448 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3449 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3450 | // 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] | 3451 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3452 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3453 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3455 | // Create the on-disk hash table representation. We walk through every |
| 3456 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3457 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3458 | for (auto &SelectorAndID : SelectorIDs) { |
| 3459 | Selector S = SelectorAndID.first; |
| 3460 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3461 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3462 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3463 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3464 | ObjCMethodList(), |
| 3465 | ObjCMethodList() |
| 3466 | }; |
| 3467 | if (F != SemaRef.MethodPool.end()) { |
| 3468 | Data.Instance = F->second.first; |
| 3469 | Data.Factory = F->second.second; |
| 3470 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3471 | // 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] | 3472 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3473 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3474 | // Selector already exists. Did it change? |
| 3475 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3476 | for (ObjCMethodList *M = &Data.Instance; |
| 3477 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 3478 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3479 | changed = true; |
| 3480 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3481 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3482 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3483 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3484 | changed = true; |
| 3485 | } |
| 3486 | if (!changed) |
| 3487 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3488 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3489 | // A new method pool entry. |
| 3490 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3491 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3492 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3493 | } |
| 3494 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3495 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3496 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3497 | uint32_t BucketOffset; |
| 3498 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3499 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3500 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3501 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3502 | llvm::raw_svector_ostream Out(MethodPool); |
| 3503 | // Make sure that no bucket is at offset 0 |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3504 | endian::write<uint32_t>(Out, 0, little); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3505 | BucketOffset = Generator.Emit(Out, Trait); |
| 3506 | } |
| 3507 | |
| 3508 | // Create a blob abbreviation |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3509 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3510 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3511 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3512 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3513 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3514 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3515 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3516 | // Write the method pool |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3517 | { |
| 3518 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, |
| 3519 | NumTableEntries}; |
| 3520 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
| 3521 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3522 | |
| 3523 | // Create a blob abbreviation for the selector table offsets. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3524 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3525 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3526 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3527 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3528 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3529 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3530 | |
| 3531 | // Write the selector offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3532 | { |
| 3533 | RecordData::value_type Record[] = { |
| 3534 | SELECTOR_OFFSETS, SelectorOffsets.size(), |
| 3535 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; |
| 3536 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 3537 | bytes(SelectorOffsets)); |
| 3538 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3539 | } |
| 3540 | } |
| 3541 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3542 | /// Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3543 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3544 | using namespace llvm; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3545 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3546 | if (SemaRef.ReferencedSelectors.empty()) |
| 3547 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3548 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3549 | RecordData Record; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3550 | ASTRecordWriter Writer(*this, Record); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3551 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3552 | // 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] | 3553 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3554 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3555 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3556 | Selector Sel = SelectorAndLocation.first; |
| 3557 | SourceLocation Loc = SelectorAndLocation.second; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3558 | Writer.AddSelectorRef(Sel); |
| 3559 | Writer.AddSourceLocation(Loc); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3560 | } |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3561 | Writer.Emit(REFERENCED_SELECTOR_POOL); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3562 | } |
| 3563 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3564 | //===----------------------------------------------------------------------===// |
| 3565 | // Identifier Table Serialization |
| 3566 | //===----------------------------------------------------------------------===// |
| 3567 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3568 | /// Determine the declaration that should be put into the name lookup table to |
| 3569 | /// represent the given declaration in this module. This is usually D itself, |
| 3570 | /// but if D was imported and merged into a local declaration, we want the most |
| 3571 | /// recent local declaration instead. The chosen declaration will be the most |
| 3572 | /// recent declaration in any module that imports this one. |
| 3573 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3574 | NamedDecl *D) { |
| 3575 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3576 | return D; |
| 3577 | |
| 3578 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3579 | // For Redeclarable decls, a prior declaration might be local. |
| 3580 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3581 | // If we find a local decl, we're done. |
| 3582 | if (!Redecl->isFromASTFile()) { |
| 3583 | // Exception: in very rare cases (for injected-class-names), not all |
| 3584 | // redeclarations are in the same semantic context. Skip ones in a |
| 3585 | // different context. They don't go in this lookup table at all. |
| 3586 | if (!Redecl->getDeclContext()->getRedeclContext()->Equals( |
| 3587 | D->getDeclContext()->getRedeclContext())) |
| 3588 | continue; |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3589 | return cast<NamedDecl>(Redecl); |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3592 | // 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] | 3593 | // local one. |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3594 | if (Redecl->getOwningModuleID() == 0) |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | } |
| 3597 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3598 | // For Mergeable decls, the first decl might be local. |
| 3599 | if (!First->isFromASTFile()) |
| 3600 | return cast<NamedDecl>(First); |
| 3601 | } |
| 3602 | |
| 3603 | // All declarations are imported. Our most recent declaration will also be |
| 3604 | // the most recent one in anyone who imports us. |
| 3605 | return D; |
| 3606 | } |
| 3607 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3608 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3609 | |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3610 | class ASTIdentifierTableTrait { |
| 3611 | ASTWriter &Writer; |
| 3612 | Preprocessor &PP; |
| 3613 | IdentifierResolver &IdResolver; |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3614 | bool IsModule; |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3615 | bool NeedDecls; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3616 | ASTWriter::RecordData *InterestingIdentifierOffsets; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3617 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3618 | /// Determines whether this is an "interesting" identifier that needs a |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3619 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3620 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3621 | /// to check that. |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3622 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3623 | if (MacroOffset || |
| 3624 | II->isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3625 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3626 | II->hasRevertedTokenIDToIdentifier() || |
Bruno Ricci | 366ba73 | 2018-09-21 12:53:22 +0000 | [diff] [blame] | 3627 | (NeedDecls && II->getFETokenInfo())) |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3628 | return true; |
| 3629 | |
| 3630 | return false; |
| 3631 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3632 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3633 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3634 | using key_type = IdentifierInfo *; |
| 3635 | using key_type_ref = key_type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3636 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3637 | using data_type = IdentID; |
| 3638 | using data_type_ref = data_type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3639 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3640 | using hash_value_type = unsigned; |
| 3641 | using offset_type = unsigned; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3642 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3643 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3644 | IdentifierResolver &IdResolver, bool IsModule, |
| 3645 | ASTWriter::RecordData *InterestingIdentifierOffsets) |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3646 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3647 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), |
| 3648 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3649 | |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3650 | bool needDecls() const { return NeedDecls; } |
| 3651 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3652 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3653 | return llvm::djbHash(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3654 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3655 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3656 | bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 3657 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3658 | return isInterestingIdentifier(II, MacroOffset); |
| 3659 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3660 | |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3661 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { |
| 3662 | return isInterestingIdentifier(II, 0); |
| 3663 | } |
| 3664 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3665 | std::pair<unsigned, unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3666 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3667 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3668 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3669 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3670 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3671 | DataLen += 2; // 2 bytes for builtin ID |
| 3672 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3673 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3674 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3675 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3676 | if (NeedDecls) { |
| 3677 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3678 | DEnd = IdResolver.end(); |
| 3679 | D != DEnd; ++D) |
| 3680 | DataLen += 4; |
| 3681 | } |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3682 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3683 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3684 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3685 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3686 | endian::Writer LE(Out, little); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3687 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3688 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3689 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3690 | // We emit the key length after the data length so that every |
| 3691 | // string is preceded by a 16-bit length. This matches the PTH |
| 3692 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3693 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3694 | return std::make_pair(KeyLen, DataLen); |
| 3695 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3696 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3697 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3698 | unsigned KeyLen) { |
| 3699 | // Record the location of the key data. This is used when generating |
| 3700 | // the mapping from persistent IDs to strings. |
| 3701 | Writer.SetIdentifierOffset(II, Out.tell()); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3702 | |
| 3703 | // Emit the offset of the key/data length information to the interesting |
| 3704 | // identifiers table if necessary. |
| 3705 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) |
| 3706 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); |
| 3707 | |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3708 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3710 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3711 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3712 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3713 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3714 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3715 | endian::Writer LE(Out, little); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3716 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3717 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3718 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3719 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3720 | return; |
| 3721 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3722 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3723 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3724 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3725 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3726 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3727 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3728 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3729 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3730 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3731 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3732 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3733 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3734 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3735 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3736 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3737 | if (HadMacroDefinition) |
| 3738 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3739 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3740 | if (NeedDecls) { |
| 3741 | // Emit the declaration IDs in reverse order, because the |
| 3742 | // IdentifierResolver provides the declarations as they would be |
| 3743 | // visible (e.g., the function "stat" would come before the struct |
| 3744 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3745 | // (so we need to see the struct "stat" before the function "stat"). |
| 3746 | // Only emit declarations that aren't from a chained PCH, though. |
| 3747 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), |
| 3748 | IdResolver.end()); |
| 3749 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3750 | DEnd = Decls.rend(); |
| 3751 | D != DEnd; ++D) |
| 3752 | LE.write<uint32_t>( |
| 3753 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
| 3754 | } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3755 | } |
| 3756 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3757 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3758 | } // namespace |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3759 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3760 | /// Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3761 | /// |
| 3762 | /// The identifier table consists of a blob containing string data |
| 3763 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3764 | /// that maps identifier IDs to locations within the blob. |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3765 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3766 | IdentifierResolver &IdResolver, |
| 3767 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3768 | using namespace llvm; |
| 3769 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3770 | RecordData InterestingIdents; |
| 3771 | |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3772 | // Create and write out the blob that contains the identifier |
| 3773 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3774 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3775 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3776 | ASTIdentifierTableTrait Trait( |
| 3777 | *this, PP, IdResolver, IsModule, |
| 3778 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3779 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3780 | // Look for any identifiers that were named while processing the |
| 3781 | // headers, but are otherwise not needed. We add these to the hash |
| 3782 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3783 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3784 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3785 | SmallVector<const IdentifierInfo *, 128> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3786 | for (const auto &ID : PP.getIdentifierTable()) |
| 3787 | IIs.push_back(ID.second); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3788 | // Sort the identifiers lexicographically before getting them references so |
| 3789 | // that their order is stable. |
Benjamin Kramer | cd2bae3 | 2019-08-22 17:32:16 +0000 | [diff] [blame] | 3790 | llvm::sort(IIs, llvm::deref<std::less<>>()); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3791 | for (const IdentifierInfo *II : IIs) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3792 | if (Trait.isInterestingNonMacroIdentifier(II)) |
| 3793 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3794 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3795 | // Create the on-disk hash table representation. We only store offsets |
| 3796 | // for identifiers that appear here for the first time. |
| 3797 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3798 | for (auto IdentIDPair : IdentifierIDs) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3799 | auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3800 | IdentID ID = IdentIDPair.second; |
| 3801 | assert(II && "NULL identifier in identifier table"); |
Vassil Vassilev | 262f41e | 2016-03-30 20:16:03 +0000 | [diff] [blame] | 3802 | // Write out identifiers if either the ID is local or the identifier has |
| 3803 | // changed since it was loaded. |
| 3804 | if (ID >= FirstIdentID || !Chain || !II->isFromAST() |
| 3805 | || II->hasChangedSinceDeserialization() || |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3806 | (Trait.needDecls() && |
| 3807 | II->hasFETokenInfoChangedSinceDeserialization())) |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3808 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3809 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3810 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3811 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3812 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3813 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3814 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3815 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3816 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3817 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3818 | // Make sure that no bucket is at offset 0 |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3819 | endian::write<uint32_t>(Out, 0, little); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3820 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | // Create a blob abbreviation |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3824 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3825 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3826 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3827 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3828 | unsigned IDTableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3829 | |
| 3830 | // Write the identifier table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3831 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3832 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | // Write the offsets table for identifier IDs. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3836 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3837 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3838 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3839 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3840 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3841 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3842 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3843 | #ifndef NDEBUG |
| 3844 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3845 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3846 | #endif |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3847 | |
| 3848 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, |
| 3849 | IdentifierOffsets.size(), |
| 3850 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3851 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3852 | bytes(IdentifierOffsets)); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3853 | |
| 3854 | // In C++, write the list of interesting identifiers (those that are |
| 3855 | // defined as macros, poisoned, or similar unusual things). |
| 3856 | if (!InterestingIdents.empty()) |
| 3857 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3858 | } |
| 3859 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3860 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3861 | // DeclContext's Name Lookup Table Serialization |
| 3862 | //===----------------------------------------------------------------------===// |
| 3863 | |
| 3864 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3865 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3866 | // Trait used for the on-disk hash table used in the method pool. |
| 3867 | class ASTDeclContextNameLookupTrait { |
| 3868 | ASTWriter &Writer; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3869 | llvm::SmallVector<DeclID, 64> DeclIDs; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3870 | |
| 3871 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3872 | using key_type = DeclarationNameKey; |
| 3873 | using key_type_ref = key_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3874 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3875 | /// A start and end index into DeclIDs, representing a sequence of decls. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3876 | using data_type = std::pair<unsigned, unsigned>; |
| 3877 | using data_type_ref = const data_type &; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3878 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3879 | using hash_value_type = unsigned; |
| 3880 | using offset_type = unsigned; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3881 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3882 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) {} |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3883 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3884 | template<typename Coll> |
| 3885 | data_type getData(const Coll &Decls) { |
| 3886 | unsigned Start = DeclIDs.size(); |
| 3887 | for (NamedDecl *D : Decls) { |
| 3888 | DeclIDs.push_back( |
| 3889 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); |
| 3890 | } |
| 3891 | return std::make_pair(Start, DeclIDs.size()); |
| 3892 | } |
| 3893 | |
| 3894 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { |
| 3895 | unsigned Start = DeclIDs.size(); |
| 3896 | for (auto ID : FromReader) |
| 3897 | DeclIDs.push_back(ID); |
| 3898 | return std::make_pair(Start, DeclIDs.size()); |
| 3899 | } |
| 3900 | |
| 3901 | static bool EqualKey(key_type_ref a, key_type_ref b) { |
| 3902 | return a == b; |
| 3903 | } |
| 3904 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3905 | hash_value_type ComputeHash(DeclarationNameKey Name) { |
| 3906 | return Name.getHash(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3909 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { |
| 3910 | assert(Writer.hasChain() && |
| 3911 | "have reference to loaded module file but no chain?"); |
| 3912 | |
| 3913 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3914 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3915 | endian::write<uint32_t>(Out, Writer.getChain()->getModuleFileID(F), little); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3916 | } |
| 3917 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3918 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, |
| 3919 | DeclarationNameKey Name, |
| 3920 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3921 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3922 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3923 | endian::Writer LE(Out, little); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3924 | unsigned KeyLen = 1; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3925 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3926 | case DeclarationName::Identifier: |
| 3927 | case DeclarationName::ObjCZeroArgSelector: |
| 3928 | case DeclarationName::ObjCOneArgSelector: |
| 3929 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3930 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3931 | case DeclarationName::CXXDeductionGuideName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3932 | KeyLen += 4; |
| 3933 | break; |
| 3934 | case DeclarationName::CXXOperatorName: |
| 3935 | KeyLen += 1; |
| 3936 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3937 | case DeclarationName::CXXConstructorName: |
| 3938 | case DeclarationName::CXXDestructorName: |
| 3939 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3940 | case DeclarationName::CXXUsingDirective: |
| 3941 | break; |
| 3942 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3943 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3944 | |
Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3945 | // 4 bytes for each DeclID. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3946 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); |
| 3947 | assert(uint16_t(DataLen) == DataLen && |
| 3948 | "too many decls for serialized lookup result"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3949 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3950 | |
| 3951 | return std::make_pair(KeyLen, DataLen); |
| 3952 | } |
| 3953 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3954 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3955 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3956 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3957 | endian::Writer LE(Out, little); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3958 | LE.write<uint8_t>(Name.getKind()); |
| 3959 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3960 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3961 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3962 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3963 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3964 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3965 | case DeclarationName::ObjCZeroArgSelector: |
| 3966 | case DeclarationName::ObjCOneArgSelector: |
| 3967 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3968 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3969 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3970 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3971 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3972 | "Invalid operator?"); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3973 | LE.write<uint8_t>(Name.getOperatorKind()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3974 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3975 | case DeclarationName::CXXConstructorName: |
| 3976 | case DeclarationName::CXXDestructorName: |
| 3977 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3978 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3979 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3980 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3981 | |
| 3982 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3983 | } |
| 3984 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3985 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, |
| 3986 | unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3987 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3988 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3989 | endian::Writer LE(Out, little); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3990 | uint64_t Start = Out.tell(); (void)Start; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3991 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) |
| 3992 | LE.write<uint32_t>(DeclIDs[I]); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3993 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3994 | } |
| 3995 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3996 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3997 | } // namespace |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3998 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3999 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 4000 | DeclContext *DC) { |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 4001 | return Result.hasExternalDecls() && |
| 4002 | DC->hasNeedToReconcileExternalVisibleStorage(); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 4006 | DeclContext *DC) { |
| 4007 | for (auto *D : Result.getLookupResult()) |
| 4008 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 4009 | return false; |
| 4010 | |
| 4011 | return true; |
| 4012 | } |
| 4013 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4014 | void |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4015 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4016 | llvm::SmallVectorImpl<char> &LookupTable) { |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 4017 | assert(!ConstDC->hasLazyLocalLexicalLookups() && |
| 4018 | !ConstDC->hasLazyExternalLexicalLookups() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 4019 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4020 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4021 | // FIXME: We need to build the lookups table, which is logically const. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4022 | auto *DC = const_cast<DeclContext*>(ConstDC); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4023 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 4024 | |
| 4025 | // Create the on-disk hash table representation. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4026 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, |
| 4027 | ASTDeclContextNameLookupTrait> Generator; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4028 | ASTDeclContextNameLookupTrait Trait(*this); |
| 4029 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4030 | // The first step is to collect the declaration names which we need to |
| 4031 | // serialize into the name lookup table, and to collect them in a stable |
| 4032 | // order. |
| 4033 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4034 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4035 | // We also build up small sets of the constructor and conversion function |
| 4036 | // names which are visible. |
| 4037 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4038 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4039 | for (auto &Lookup : *DC->buildLookup()) { |
| 4040 | auto &Name = Lookup.first; |
| 4041 | auto &Result = Lookup.second; |
| 4042 | |
Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 4043 | // If there are no local declarations in our lookup result, we |
| 4044 | // don't need to write an entry for the name at all. If we can't |
| 4045 | // write out a lookup set without performing more deserialization, |
| 4046 | // just skip this entry. |
| 4047 | if (isLookupResultExternal(Result, DC) && |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4048 | isLookupResultEntirelyExternal(Result, DC)) |
| 4049 | continue; |
| 4050 | |
| 4051 | // We also skip empty results. If any of the results could be external and |
| 4052 | // the currently available results are empty, then all of the results are |
| 4053 | // external and we skip it above. So the only way we get here with an empty |
| 4054 | // results is when no results could have been external *and* we have |
| 4055 | // external results. |
| 4056 | // |
| 4057 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 4058 | // lookups into a decl context as an optimization, today we *have* to skip |
| 4059 | // them because there are names with empty lookup results in decl contexts |
| 4060 | // which we can't emit in any stable ordering: we lookup constructors and |
| 4061 | // conversion functions in the enclosing namespace scope creating empty |
| 4062 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 4063 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 4064 | // here by omitting lookups with empty results. |
| 4065 | if (Lookup.second.getLookupResult().empty()) |
| 4066 | continue; |
| 4067 | |
| 4068 | switch (Lookup.first.getNameKind()) { |
| 4069 | default: |
| 4070 | Names.push_back(Lookup.first); |
| 4071 | break; |
| 4072 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4073 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4074 | assert(isa<CXXRecordDecl>(DC) && |
| 4075 | "Cannot have a constructor name outside of a class!"); |
| 4076 | ConstructorNameSet.insert(Name); |
| 4077 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4078 | |
| 4079 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4080 | assert(isa<CXXRecordDecl>(DC) && |
| 4081 | "Cannot have a conversion function name outside of a class!"); |
| 4082 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 4083 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4084 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 4085 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 4086 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4087 | // Sort the names into a stable order. |
Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 4088 | llvm::sort(Names); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4089 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 4090 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4091 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 4092 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4093 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 4094 | // First we try the easy case by forming the current context's constructor |
| 4095 | // name and adding that name first. This is a very useful optimization to |
| 4096 | // avoid walking the lexical declarations in many cases, and it also |
| 4097 | // handles the only case where a constructor name can come from some other |
| 4098 | // lexical context -- when that name is an implicit constructor merged from |
| 4099 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 4100 | // conversion function which doesn't occur in all the lexical contexts |
| 4101 | // would be an ODR violation. |
| 4102 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 4103 | Context->getCanonicalType(Context->getRecordType(D))); |
| 4104 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 4105 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4106 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 4107 | // If we still have constructors or conversion functions, we walk all the |
| 4108 | // names in the decl and add the constructors and conversion functions |
| 4109 | // which are visible in the order they lexically occur within the context. |
| 4110 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 4111 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 4112 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 4113 | auto Name = ChildND->getDeclName(); |
| 4114 | switch (Name.getNameKind()) { |
| 4115 | default: |
| 4116 | continue; |
| 4117 | |
| 4118 | case DeclarationName::CXXConstructorName: |
| 4119 | if (ConstructorNameSet.erase(Name)) |
| 4120 | Names.push_back(Name); |
| 4121 | break; |
| 4122 | |
| 4123 | case DeclarationName::CXXConversionFunctionName: |
| 4124 | if (ConversionNameSet.erase(Name)) |
| 4125 | Names.push_back(Name); |
| 4126 | break; |
| 4127 | } |
| 4128 | |
| 4129 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 4130 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4131 | } |
| 4132 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4133 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 4134 | "constructors by walking all the " |
| 4135 | "lexical members of the context."); |
| 4136 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 4137 | "conversion functions by walking all " |
| 4138 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 4139 | } |
| 4140 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4141 | // Next we need to do a lookup with each name into this decl context to fully |
| 4142 | // populate any results from external sources. We don't actually use the |
| 4143 | // results of these lookups because we only want to use the results after all |
| 4144 | // results have been loaded and the pointers into them will be stable. |
| 4145 | for (auto &Name : Names) |
| 4146 | DC->lookup(Name); |
| 4147 | |
| 4148 | // Now we need to insert the results for each name into the hash table. For |
| 4149 | // constructor names and conversion function names, we actually need to merge |
| 4150 | // all of the results for them into one list of results each and insert |
| 4151 | // those. |
| 4152 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 4153 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 4154 | |
| 4155 | // Now loop over the names, either inserting them or appending for the two |
| 4156 | // special cases. |
| 4157 | for (auto &Name : Names) { |
| 4158 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 4159 | |
| 4160 | switch (Name.getNameKind()) { |
| 4161 | default: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4162 | Generator.insert(Name, Trait.getData(Result), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4163 | break; |
| 4164 | |
| 4165 | case DeclarationName::CXXConstructorName: |
| 4166 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 4167 | break; |
| 4168 | |
| 4169 | case DeclarationName::CXXConversionFunctionName: |
| 4170 | ConversionDecls.append(Result.begin(), Result.end()); |
| 4171 | break; |
| 4172 | } |
| 4173 | } |
| 4174 | |
| 4175 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 4176 | // the first declaration's name here because the name itself isn't part of |
| 4177 | // the key, only the kind of name is used. |
| 4178 | if (!ConstructorDecls.empty()) |
| 4179 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4180 | Trait.getData(ConstructorDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4181 | if (!ConversionDecls.empty()) |
| 4182 | Generator.insert(ConversionDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4183 | Trait.getData(ConversionDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4184 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4185 | // Create the on-disk hash table. Also emit the existing imported and |
| 4186 | // merged table if there is one. |
| 4187 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; |
| 4188 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4191 | /// Write the block containing all of the declaration IDs |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4192 | /// visible from the given DeclContext. |
| 4193 | /// |
| 4194 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4195 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4196 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 4197 | DeclContext *DC) { |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4198 | // If we imported a key declaration of this namespace, write the visible |
| 4199 | // lookup results as an update record for it rather than including them |
| 4200 | // on this declaration. We will only look at key declarations on reload. |
| 4201 | if (isa<NamespaceDecl>(DC) && Chain && |
| 4202 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { |
| 4203 | // Only do this once, for the first local declaration of the namespace. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4204 | for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4205 | Prev = Prev->getPreviousDecl()) |
| 4206 | if (!Prev->isFromASTFile()) |
| 4207 | return 0; |
| 4208 | |
| 4209 | // Note that we need to emit an update record for the primary context. |
| 4210 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); |
| 4211 | |
| 4212 | // Make sure all visible decls are written. They will be recorded later. We |
| 4213 | // do this using a side data structure so we can sort the names into |
| 4214 | // a deterministic order. |
| 4215 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); |
| 4216 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> |
| 4217 | LookupResults; |
| 4218 | if (Map) { |
| 4219 | LookupResults.reserve(Map->size()); |
| 4220 | for (auto &Entry : *Map) |
| 4221 | LookupResults.push_back( |
| 4222 | std::make_pair(Entry.first, Entry.second.getLookupResult())); |
| 4223 | } |
| 4224 | |
Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 4225 | llvm::sort(LookupResults, llvm::less_first()); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4226 | for (auto &NameAndResult : LookupResults) { |
| 4227 | DeclarationName Name = NameAndResult.first; |
| 4228 | DeclContext::lookup_result Result = NameAndResult.second; |
| 4229 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || |
| 4230 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 4231 | // We have to work around a name lookup bug here where negative lookup |
| 4232 | // results for these names get cached in namespace lookup tables (these |
| 4233 | // names should never be looked up in a namespace). |
| 4234 | assert(Result.empty() && "Cannot have a constructor or conversion " |
| 4235 | "function name in a namespace!"); |
| 4236 | continue; |
| 4237 | } |
| 4238 | |
| 4239 | for (NamedDecl *ND : Result) |
| 4240 | if (!ND->isFromASTFile()) |
| 4241 | GetDeclRef(ND); |
| 4242 | } |
| 4243 | |
| 4244 | return 0; |
| 4245 | } |
| 4246 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4247 | if (DC->getPrimaryContext() != DC) |
| 4248 | return 0; |
| 4249 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 4250 | // Skip contexts which don't support name lookup. |
| 4251 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4252 | return 0; |
| 4253 | |
| 4254 | // If not in C++, we perform name lookup for the translation unit via the |
| 4255 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 4256 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4257 | return 0; |
| 4258 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4259 | // Serialize the contents of the mapping used for lookup. Note that, |
| 4260 | // although we have two very different code paths, the serialized |
| 4261 | // representation is the same for both cases: a declaration name, |
| 4262 | // followed by a size, followed by references to the visible |
| 4263 | // declarations that have that name. |
| 4264 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 4265 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4266 | if (!Map || Map->empty()) |
| 4267 | return 0; |
| 4268 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4269 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4270 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4271 | GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4272 | |
| 4273 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4274 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4275 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 4276 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4277 | ++NumVisibleDeclContexts; |
| 4278 | return Offset; |
| 4279 | } |
| 4280 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4281 | /// Write an UPDATE_VISIBLE block for the given context. |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4282 | /// |
| 4283 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 4284 | /// 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] | 4285 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 4286 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4287 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 4288 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4289 | if (!Map || Map->empty()) |
| 4290 | return; |
| 4291 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4292 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4293 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 4294 | GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4295 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4296 | // If we're updating a namespace, select a key declaration as the key for the |
| 4297 | // update record; those are the only ones that will be checked on reload. |
| 4298 | if (isa<NamespaceDecl>(DC)) |
| 4299 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); |
| 4300 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4301 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4302 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 4303 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 4304 | } |
| 4305 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4306 | /// Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4307 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 4308 | RecordData::value_type Record[] = {Opts.getInt()}; |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4309 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 4310 | } |
| 4311 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4312 | /// Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4313 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 4314 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4315 | return; |
| 4316 | |
| 4317 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 4318 | RecordData Record; |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4319 | for (const auto &I:Opts.OptMap) { |
| 4320 | AddString(I.getKey(), Record); |
| 4321 | auto V = I.getValue(); |
Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 4322 | Record.push_back(V.Supported ? 1 : 0); |
| 4323 | Record.push_back(V.Enabled ? 1 : 0); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4324 | Record.push_back(V.Avail); |
| 4325 | Record.push_back(V.Core); |
| 4326 | } |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4327 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 4328 | } |
| 4329 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4330 | void ASTWriter::WriteOpenCLExtensionTypes(Sema &SemaRef) { |
| 4331 | if (!SemaRef.Context.getLangOpts().OpenCL) |
| 4332 | return; |
| 4333 | |
Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4334 | // Sort the elements of the map OpenCLTypeExtMap by TypeIDs, |
| 4335 | // without copying them. |
| 4336 | const llvm::DenseMap<const Type *, std::set<std::string>> &OpenCLTypeExtMap = |
| 4337 | SemaRef.OpenCLTypeExtMap; |
| 4338 | using ElementTy = std::pair<TypeID, const std::set<std::string> *>; |
| 4339 | llvm::SmallVector<ElementTy, 8> StableOpenCLTypeExtMap; |
| 4340 | StableOpenCLTypeExtMap.reserve(OpenCLTypeExtMap.size()); |
| 4341 | |
| 4342 | for (const auto &I : OpenCLTypeExtMap) |
| 4343 | StableOpenCLTypeExtMap.emplace_back( |
| 4344 | getTypeID(I.first->getCanonicalTypeInternal()), &I.second); |
| 4345 | |
| 4346 | auto CompareByTypeID = [](const ElementTy &E1, const ElementTy &E2) -> bool { |
| 4347 | return E1.first < E2.first; |
| 4348 | }; |
| 4349 | llvm::sort(StableOpenCLTypeExtMap, CompareByTypeID); |
| 4350 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4351 | RecordData Record; |
Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4352 | for (const ElementTy &E : StableOpenCLTypeExtMap) { |
| 4353 | Record.push_back(E.first); // TypeID |
| 4354 | const std::set<std::string> *ExtSet = E.second; |
| 4355 | Record.push_back(static_cast<unsigned>(ExtSet->size())); |
| 4356 | for (const std::string &Ext : *ExtSet) |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4357 | AddString(Ext, Record); |
| 4358 | } |
Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4359 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4360 | Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record); |
| 4361 | } |
| 4362 | |
| 4363 | void ASTWriter::WriteOpenCLExtensionDecls(Sema &SemaRef) { |
| 4364 | if (!SemaRef.Context.getLangOpts().OpenCL) |
| 4365 | return; |
| 4366 | |
Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4367 | // Sort the elements of the map OpenCLDeclExtMap by DeclIDs, |
| 4368 | // without copying them. |
| 4369 | const llvm::DenseMap<const Decl *, std::set<std::string>> &OpenCLDeclExtMap = |
| 4370 | SemaRef.OpenCLDeclExtMap; |
| 4371 | using ElementTy = std::pair<DeclID, const std::set<std::string> *>; |
| 4372 | llvm::SmallVector<ElementTy, 8> StableOpenCLDeclExtMap; |
| 4373 | StableOpenCLDeclExtMap.reserve(OpenCLDeclExtMap.size()); |
| 4374 | |
| 4375 | for (const auto &I : OpenCLDeclExtMap) |
| 4376 | StableOpenCLDeclExtMap.emplace_back(getDeclID(I.first), &I.second); |
| 4377 | |
| 4378 | auto CompareByDeclID = [](const ElementTy &E1, const ElementTy &E2) -> bool { |
| 4379 | return E1.first < E2.first; |
| 4380 | }; |
| 4381 | llvm::sort(StableOpenCLDeclExtMap, CompareByDeclID); |
| 4382 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4383 | RecordData Record; |
Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4384 | for (const ElementTy &E : StableOpenCLDeclExtMap) { |
| 4385 | Record.push_back(E.first); // DeclID |
| 4386 | const std::set<std::string> *ExtSet = E.second; |
| 4387 | Record.push_back(static_cast<unsigned>(ExtSet->size())); |
| 4388 | for (const std::string &Ext : *ExtSet) |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4389 | AddString(Ext, Record); |
| 4390 | } |
Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4391 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4392 | Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record); |
| 4393 | } |
| 4394 | |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 4395 | void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) { |
| 4396 | if (SemaRef.ForceCUDAHostDeviceDepth > 0) { |
| 4397 | RecordData::value_type Record[] = {SemaRef.ForceCUDAHostDeviceDepth}; |
| 4398 | Stream.EmitRecord(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH, Record); |
| 4399 | } |
| 4400 | } |
| 4401 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4402 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4403 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4404 | RecordData Categories; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4405 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4406 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 4407 | unsigned Size = 0; |
| 4408 | unsigned StartIndex = Categories.size(); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4409 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4410 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4411 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4412 | // Allocate space for the size. |
| 4413 | Categories.push_back(0); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4414 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4415 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 4416 | for (ObjCInterfaceDecl::known_categories_iterator |
| 4417 | Cat = Class->known_categories_begin(), |
| 4418 | CatEnd = Class->known_categories_end(); |
| 4419 | Cat != CatEnd; ++Cat, ++Size) { |
| 4420 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 4421 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4422 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4423 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4424 | // Update the size. |
| 4425 | Categories[StartIndex] = Size; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4426 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4427 | // Record this interface -> category map. |
| 4428 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 4429 | CategoriesMap.push_back(CatInfo); |
| 4430 | } |
| 4431 | |
| 4432 | // Sort the categories map by the definition ID, since the reader will be |
| 4433 | // performing binary searches on this information. |
| 4434 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 4435 | |
| 4436 | // Emit the categories map. |
| 4437 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4438 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4439 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4440 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 4441 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 4442 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4443 | unsigned AbbrevID = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4444 | |
| 4445 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; |
| 4446 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 4447 | reinterpret_cast<char *>(CategoriesMap.data()), |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4448 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4449 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4450 | // Emit the category lists. |
| 4451 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 4452 | } |
| 4453 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4454 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 4455 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 4456 | |
| 4457 | if (LPTMap.empty()) |
| 4458 | return; |
| 4459 | |
| 4460 | RecordData Record; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4461 | for (auto &LPTMapEntry : LPTMap) { |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4462 | const FunctionDecl *FD = LPTMapEntry.first; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4463 | LateParsedTemplate &LPT = *LPTMapEntry.second; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4464 | AddDeclRef(FD, Record); |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4465 | AddDeclRef(LPT.D, Record); |
| 4466 | Record.push_back(LPT.Toks.size()); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4467 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4468 | for (const auto &Tok : LPT.Toks) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4469 | AddToken(Tok, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4470 | } |
| 4471 | } |
| 4472 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 4473 | } |
| 4474 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4475 | /// 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] | 4476 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 4477 | RecordData Record; |
| 4478 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 4479 | AddSourceLocation(PragmaLoc, Record); |
| 4480 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 4481 | } |
| 4482 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4483 | /// 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] | 4484 | void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) { |
| 4485 | RecordData Record; |
| 4486 | Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF); |
| 4487 | Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record); |
| 4488 | } |
| 4489 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4490 | /// 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] | 4491 | //module. |
| 4492 | void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) { |
| 4493 | RecordData Record; |
| 4494 | Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod); |
| 4495 | AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record); |
| 4496 | Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record); |
| 4497 | } |
| 4498 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4499 | /// Write the state of 'pragma pack' at the end of the module. |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4500 | void ASTWriter::WritePackPragmaOptions(Sema &SemaRef) { |
Duncan P. N. Exon Smith | 03df14c | 2017-04-15 00:07:57 +0000 | [diff] [blame] | 4501 | // Don't serialize pragma pack state for modules, since it should only take |
| 4502 | // effect on a per-submodule basis. |
| 4503 | if (WritingModule) |
| 4504 | return; |
| 4505 | |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4506 | RecordData Record; |
| 4507 | Record.push_back(SemaRef.PackStack.CurrentValue); |
| 4508 | AddSourceLocation(SemaRef.PackStack.CurrentPragmaLocation, Record); |
| 4509 | Record.push_back(SemaRef.PackStack.Stack.size()); |
| 4510 | for (const auto &StackEntry : SemaRef.PackStack.Stack) { |
| 4511 | Record.push_back(StackEntry.Value); |
| 4512 | AddSourceLocation(StackEntry.PragmaLocation, Record); |
Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 4513 | AddSourceLocation(StackEntry.PragmaPushLocation, Record); |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4514 | AddString(StackEntry.StackSlotLabel, Record); |
| 4515 | } |
| 4516 | Stream.EmitRecord(PACK_PRAGMA_OPTIONS, Record); |
| 4517 | } |
| 4518 | |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4519 | void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, |
| 4520 | ModuleFileExtensionWriter &Writer) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4521 | // Enter the extension block. |
| 4522 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); |
| 4523 | |
| 4524 | // Emit the metadata record abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4525 | auto Abv = std::make_shared<llvm::BitCodeAbbrev>(); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4526 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); |
| 4527 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4528 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4529 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4530 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4531 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4532 | unsigned Abbrev = Stream.EmitAbbrev(std::move(Abv)); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4533 | |
| 4534 | // Emit the metadata record. |
| 4535 | RecordData Record; |
| 4536 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); |
| 4537 | Record.push_back(EXTENSION_METADATA); |
| 4538 | Record.push_back(Metadata.MajorVersion); |
| 4539 | Record.push_back(Metadata.MinorVersion); |
| 4540 | Record.push_back(Metadata.BlockName.size()); |
| 4541 | Record.push_back(Metadata.UserInfo.size()); |
| 4542 | SmallString<64> Buffer; |
| 4543 | Buffer += Metadata.BlockName; |
| 4544 | Buffer += Metadata.UserInfo; |
| 4545 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); |
| 4546 | |
| 4547 | // Emit the contents of the extension block. |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4548 | Writer.writeExtensionContents(SemaRef, Stream); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4549 | |
| 4550 | // Exit the extension block. |
| 4551 | Stream.ExitBlock(); |
| 4552 | } |
| 4553 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4554 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4555 | // General Serialization Routines |
| 4556 | //===----------------------------------------------------------------------===// |
| 4557 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4558 | void ASTRecordWriter::AddAttr(const Attr *A) { |
Reid Kleckner | 11f9f8a | 2018-08-14 01:55:37 +0000 | [diff] [blame] | 4559 | auto &Record = *this; |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4560 | if (!A) |
| 4561 | return Record.push_back(0); |
| 4562 | Record.push_back(A->getKind() + 1); // FIXME: stable encoding, target attrs |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4563 | |
| 4564 | Record.AddIdentifierRef(A->getAttrName()); |
| 4565 | Record.AddIdentifierRef(A->getScopeName()); |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4566 | Record.AddSourceRange(A->getRange()); |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4567 | Record.AddSourceLocation(A->getScopeLoc()); |
| 4568 | Record.push_back(A->getParsedKind()); |
| 4569 | Record.push_back(A->getSyntax()); |
| 4570 | Record.push_back(A->getAttributeSpellingListIndexRaw()); |
Reid Kleckner | 11f9f8a | 2018-08-14 01:55:37 +0000 | [diff] [blame] | 4571 | |
| 4572 | #include "clang/Serialization/AttrPCHWrite.inc" |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4573 | } |
| 4574 | |
| 4575 | /// Emit the list of attributes to the specified record. |
| 4576 | void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) { |
| 4577 | push_back(Attrs.size()); |
| 4578 | for (const auto *A : Attrs) |
| 4579 | AddAttr(A); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4580 | } |
| 4581 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 4582 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 4583 | AddSourceLocation(Tok.getLocation(), Record); |
| 4584 | Record.push_back(Tok.getLength()); |
| 4585 | |
| 4586 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 4587 | // if it is needed. |
| 4588 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 4589 | // FIXME: Should translate token kind to a stable encoding. |
| 4590 | Record.push_back(Tok.getKind()); |
| 4591 | // FIXME: Should translate token flags to a stable encoding. |
| 4592 | Record.push_back(Tok.getFlags()); |
| 4593 | } |
| 4594 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4595 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4596 | Record.push_back(Str.size()); |
| 4597 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 4598 | } |
| 4599 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4600 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4601 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4602 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4603 | bool Changed = |
| 4604 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4605 | |
| 4606 | // Remove a prefix to make the path relative, if relevant. |
| 4607 | const char *PathBegin = Path.data(); |
| 4608 | const char *PathPtr = |
| 4609 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 4610 | if (PathPtr != PathBegin) { |
| 4611 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 4612 | Changed = true; |
| 4613 | } |
| 4614 | |
| 4615 | return Changed; |
| 4616 | } |
| 4617 | |
| 4618 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 4619 | SmallString<128> FilePath(Path); |
| 4620 | PreparePathForOutput(FilePath); |
| 4621 | AddString(FilePath, Record); |
| 4622 | } |
| 4623 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4624 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4625 | StringRef Path) { |
| 4626 | SmallString<128> FilePath(Path); |
| 4627 | PreparePathForOutput(FilePath); |
| 4628 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 4629 | } |
| 4630 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4631 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 4632 | RecordDataImpl &Record) { |
| 4633 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4634 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4635 | Record.push_back(*Minor + 1); |
| 4636 | else |
| 4637 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4638 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4639 | Record.push_back(*Subminor + 1); |
| 4640 | else |
| 4641 | Record.push_back(0); |
| 4642 | } |
| 4643 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4644 | /// Note that the identifier II occurs at the given offset |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4645 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4646 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4647 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4648 | // 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] | 4649 | // up earlier in the chain and thus don't need an offset. |
| 4650 | if (ID >= FirstIdentID) |
| 4651 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4652 | } |
| 4653 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4654 | /// Note that the selector Sel occurs at the given offset |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4655 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4656 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4657 | unsigned ID = SelectorIDs[Sel]; |
| 4658 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4659 | // Don't record offsets for selectors that are also available in a different |
| 4660 | // file. |
| 4661 | if (ID < FirstSelectorID) |
| 4662 | return; |
| 4663 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4664 | } |
| 4665 | |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 4666 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream, |
Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 4667 | SmallVectorImpl<char> &Buffer, |
| 4668 | InMemoryModuleCache &ModuleCache, |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 4669 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 4670 | bool IncludeTimestamps) |
Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 4671 | : Stream(Stream), Buffer(Buffer), ModuleCache(ModuleCache), |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4672 | IncludeTimestamps(IncludeTimestamps) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4673 | for (const auto &Ext : Extensions) { |
| 4674 | if (auto Writer = Ext->createExtensionWriter(*this)) |
| 4675 | ModuleFileExtensionWriters.push_back(std::move(Writer)); |
| 4676 | } |
| 4677 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4678 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4679 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 4680 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4681 | } |
| 4682 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4683 | const LangOptions &ASTWriter::getLangOpts() const { |
| 4684 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 4685 | return Context->getLangOpts(); |
| 4686 | } |
| 4687 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4688 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { |
| 4689 | return IncludeTimestamps ? E->getModificationTime() : 0; |
| 4690 | } |
| 4691 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4692 | ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, |
| 4693 | const std::string &OutputFile, |
| 4694 | Module *WritingModule, StringRef isysroot, |
Duncan P. N. Exon Smith | 70d759b | 2019-03-12 18:38:04 +0000 | [diff] [blame] | 4695 | bool hasErrors, |
| 4696 | bool ShouldCacheASTInMemory) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4697 | WritingAST = true; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4698 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4699 | ASTHasCompilerErrors = hasErrors; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4700 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4701 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4702 | Stream.Emit((unsigned)'C', 8); |
| 4703 | Stream.Emit((unsigned)'P', 8); |
| 4704 | Stream.Emit((unsigned)'C', 8); |
| 4705 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4706 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4707 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4708 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4709 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4710 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4711 | this->WritingModule = WritingModule; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4712 | ASTFileSignature Signature = |
| 4713 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4714 | Context = nullptr; |
| 4715 | PP = nullptr; |
| 4716 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4717 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4719 | WritingAST = false; |
Duncan P. N. Exon Smith | 70d759b | 2019-03-12 18:38:04 +0000 | [diff] [blame] | 4720 | if (ShouldCacheASTInMemory) { |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4721 | // Construct MemoryBuffer and update buffer manager. |
Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 4722 | ModuleCache.addBuiltPCM(OutputFile, |
| 4723 | llvm::MemoryBuffer::getMemBufferCopy( |
| 4724 | StringRef(Buffer.begin(), Buffer.size()))); |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4725 | } |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4726 | return Signature; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4727 | } |
| 4728 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4729 | template<typename Vector> |
| 4730 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4731 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4732 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4733 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4734 | Writer.AddDeclRef(*I, Record); |
| 4735 | } |
| 4736 | } |
| 4737 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4738 | ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, |
| 4739 | const std::string &OutputFile, |
| 4740 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4741 | using namespace llvm; |
| 4742 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4743 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4744 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4745 | // Make sure that the AST reader knows to finalize itself. |
| 4746 | if (Chain) |
| 4747 | Chain->finalizeForWriting(); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4748 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4749 | ASTContext &Context = SemaRef.Context; |
| 4750 | Preprocessor &PP = SemaRef.PP; |
| 4751 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4752 | // Set up predefined declaration IDs. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4753 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { |
| 4754 | if (D) { |
| 4755 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); |
| 4756 | DeclIDs[D] = ID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4757 | } |
| 4758 | }; |
| 4759 | RegisterPredefDecl(Context.getTranslationUnitDecl(), |
| 4760 | PREDEF_DECL_TRANSLATION_UNIT_ID); |
| 4761 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); |
| 4762 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); |
| 4763 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); |
| 4764 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, |
| 4765 | PREDEF_DECL_OBJC_PROTOCOL_ID); |
| 4766 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); |
| 4767 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); |
| 4768 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, |
| 4769 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); |
| 4770 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4771 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4772 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, |
| 4773 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4774 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4775 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, |
| 4776 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 4777 | RegisterPredefDecl(Context.CFConstantStringTypeDecl, |
| 4778 | PREDEF_DECL_CF_CONSTANT_STRING_ID); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 4779 | RegisterPredefDecl(Context.CFConstantStringTagDecl, |
| 4780 | PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 4781 | RegisterPredefDecl(Context.TypePackElementDecl, |
| 4782 | PREDEF_DECL_TYPE_PACK_ELEMENT_ID); |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4783 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4784 | // 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] | 4785 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4786 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4787 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4788 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4789 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4790 | // Build a record containing all of the file scoped decls in this file. |
| 4791 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4792 | if (!isModule) |
| 4793 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4794 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4795 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4796 | // Build a record containing all of the delegating constructors we still need |
| 4797 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4798 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4799 | if (!isModule) |
| 4800 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4801 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4802 | // Write the set of weak, undeclared identifiers. We always write the |
| 4803 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4804 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4805 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4806 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4807 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4808 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4809 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4810 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4811 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4812 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4813 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4814 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4815 | // Build a record containing all of the ext_vector declarations. |
| 4816 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4817 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4818 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4819 | // Build a record containing all of the VTable uses information. |
| 4820 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4821 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4822 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4823 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4824 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4825 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4826 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4827 | } |
| 4828 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4829 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4830 | RecordData UnusedLocalTypedefNameCandidates; |
| 4831 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4832 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4833 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4834 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4835 | RecordData PendingInstantiations; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4836 | for (const auto &I : SemaRef.PendingInstantiations) { |
| 4837 | AddDeclRef(I.first, PendingInstantiations); |
| 4838 | AddSourceLocation(I.second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4839 | } |
| 4840 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4841 | "There are local ones at end of translation unit!"); |
| 4842 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4843 | // Build a record containing some declaration references. |
| 4844 | RecordData SemaDeclRefs; |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4845 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) { |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4846 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4847 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4848 | AddDeclRef(SemaRef.getStdAlignValT(), SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4849 | } |
| 4850 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4851 | RecordData CUDASpecialDeclRefs; |
| 4852 | if (Context.getcudaConfigureCallDecl()) { |
| 4853 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4854 | } |
| 4855 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4856 | // Build a record containing all of the known namespaces. |
| 4857 | RecordData KnownNamespaces; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4858 | for (const auto &I : SemaRef.KnownNamespaces) { |
| 4859 | if (!I.second) |
| 4860 | AddDeclRef(I.first, KnownNamespaces); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4861 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4862 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4863 | // Build a record of all used, undefined objects that require definitions. |
| 4864 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4865 | |
| 4866 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4867 | SemaRef.getUndefinedButUsed(Undefined); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4868 | for (const auto &I : Undefined) { |
| 4869 | AddDeclRef(I.first, UndefinedButUsed); |
| 4870 | AddSourceLocation(I.second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4873 | // Build a record containing all delete-expressions that we would like to |
| 4874 | // analyze later in AST. |
| 4875 | RecordData DeleteExprsToAnalyze; |
| 4876 | |
Richard Smith | f5262c6 | 2018-06-28 01:57:04 +0000 | [diff] [blame] | 4877 | if (!isModule) { |
| 4878 | for (const auto &DeleteExprsInfo : |
| 4879 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4880 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4881 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4882 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4883 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4884 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4885 | } |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4886 | } |
| 4887 | } |
| 4888 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4889 | // Write the control block |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4890 | WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4891 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4892 | // Write the remaining AST contents. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4893 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4894 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4895 | // This is so that older clang versions, before the introduction |
| 4896 | // of the control block, can read and reject the newer PCH format. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4897 | { |
| 4898 | RecordData Record = {VERSION_MAJOR}; |
| 4899 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4900 | } |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4901 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4902 | // Create a lexical update block containing all of the declarations in the |
| 4903 | // translation unit that do not come from other AST files. |
| 4904 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4905 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; |
| 4906 | for (const auto *D : TU->noload_decls()) { |
| 4907 | if (!D->isFromASTFile()) { |
| 4908 | NewGlobalKindDeclPairs.push_back(D->getKind()); |
| 4909 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); |
| 4910 | } |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4911 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4912 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4913 | auto Abv = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4914 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4915 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4916 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4917 | { |
| 4918 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; |
| 4919 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 4920 | bytes(NewGlobalKindDeclPairs)); |
| 4921 | } |
| 4922 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4923 | // And a visible updates block for the translation unit. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4924 | Abv = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4925 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4926 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4927 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4928 | UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4929 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4930 | |
| 4931 | // If we have any extern "C" names, write out a visible update for them. |
| 4932 | if (Context.ExternCContext) |
| 4933 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4934 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4935 | // If the translation unit has an anonymous namespace, and we don't already |
| 4936 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4937 | // 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] | 4938 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4939 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4940 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4941 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4942 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4943 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4944 | // Add update records for all mangling numbers and static local numbers. |
| 4945 | // These aren't really update records, but this is a convenient way of |
| 4946 | // tagging this rare extra data onto the declarations. |
| 4947 | for (const auto &Number : Context.MangleNumbers) |
| 4948 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4949 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4950 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4951 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4952 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4953 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4954 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4955 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4956 | // Make sure visible decls, added to DeclContexts previously loaded from |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 4957 | // an AST file, are registered for serialization. Likewise for template |
| 4958 | // specializations added to imported templates. |
| 4959 | for (const auto *I : DeclsToEmitEvenIfUnreferenced) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4960 | GetDeclRef(I); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4961 | } |
| 4962 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4963 | // Make sure all decls associated with an identifier are registered for |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4964 | // serialization, if we're storing decls with identifiers. |
| 4965 | if (!WritingModule || !getLangOpts().CPlusPlus) { |
| 4966 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4967 | for (const auto &ID : PP.getIdentifierTable()) { |
| 4968 | const IdentifierInfo *II = ID.second; |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4969 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 4970 | IIs.push_back(II); |
| 4971 | } |
| 4972 | // Sort the identifiers to visit based on their name. |
Benjamin Kramer | cd2bae3 | 2019-08-22 17:32:16 +0000 | [diff] [blame] | 4973 | llvm::sort(IIs, llvm::deref<std::less<>>()); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4974 | for (const IdentifierInfo *II : IIs) { |
| 4975 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4976 | DEnd = SemaRef.IdResolver.end(); |
| 4977 | D != DEnd; ++D) { |
| 4978 | GetDeclRef(*D); |
| 4979 | } |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4980 | } |
| 4981 | } |
| 4982 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 4983 | // For method pool in the module, if it contains an entry for a selector, |
| 4984 | // the entry should be complete, containing everything introduced by that |
| 4985 | // module and all modules it imports. It's possible that the entry is out of |
| 4986 | // date, so we need to pull in the new content here. |
| 4987 | |
| 4988 | // It's possible that updateOutOfDateSelector can update SelectorIDs. To be |
| 4989 | // safe, we copy all selectors out. |
| 4990 | llvm::SmallVector<Selector, 256> AllSelectors; |
| 4991 | for (auto &SelectorAndID : SelectorIDs) |
| 4992 | AllSelectors.push_back(SelectorAndID.first); |
| 4993 | for (auto &Selector : AllSelectors) |
| 4994 | SemaRef.updateOutOfDateSelector(Selector); |
| 4995 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4996 | // Form the record of special types. |
| 4997 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4998 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4999 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 5000 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 5001 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 5002 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 5003 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 5004 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 5005 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 5006 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5007 | if (Chain) { |
| 5008 | // Write the mapping information describing our module dependencies and how |
| 5009 | // each of those modules were mapped into our own offset/ID space, so that |
| 5010 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 5011 | // The map consists solely of a blob with the following format: |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 5012 | // *(module-kind:i8 |
| 5013 | // module-name-len:i16 module-name:len*i8 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5014 | // source-location-offset:i32 |
| 5015 | // identifier-id:i32 |
| 5016 | // preprocessed-entity-id:i32 |
| 5017 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5018 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5019 | // selector-id:i32 |
| 5020 | // declaration-id:i32 |
| 5021 | // c++-base-specifiers-id:i32 |
| 5022 | // type-id:i32) |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5023 | // |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 5024 | // module-kind is the ModuleKind enum value. If it is MK_PrebuiltModule or |
| 5025 | // MK_ExplicitModule, then the module-name is the module name. Otherwise, |
| 5026 | // it is the module file name. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 5027 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5028 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 5029 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 5030 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 5031 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5032 | { |
| 5033 | llvm::raw_svector_ostream Out(Buffer); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 5034 | for (ModuleFile &M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 5035 | using namespace llvm::support; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 5036 | |
Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 5037 | endian::Writer LE(Out, little); |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 5038 | LE.write<uint8_t>(static_cast<uint8_t>(M.Kind)); |
| 5039 | StringRef Name = |
| 5040 | M.Kind == MK_PrebuiltModule || M.Kind == MK_ExplicitModule |
| 5041 | ? M.ModuleName |
| 5042 | : M.FileName; |
| 5043 | LE.write<uint16_t>(Name.size()); |
| 5044 | Out.write(Name.data(), Name.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 5045 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 5046 | // Note: if a base ID was uint max, it would not be possible to load |
| 5047 | // another module after it or have more than one entity inside it. |
| 5048 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 5049 | |
| 5050 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 5051 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 5052 | if (ShouldWrite) |
| 5053 | LE.write<uint32_t>(BaseID); |
| 5054 | else |
| 5055 | LE.write<uint32_t>(None); |
| 5056 | }; |
| 5057 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 5058 | // These values should be unique within a chain, since they will be read |
| 5059 | // as keys into ContinuousRangeMaps. |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 5060 | writeBaseIDOrNone(M.SLocEntryBaseOffset, M.LocalNumSLocEntries); |
| 5061 | writeBaseIDOrNone(M.BaseIdentifierID, M.LocalNumIdentifiers); |
| 5062 | writeBaseIDOrNone(M.BaseMacroID, M.LocalNumMacros); |
| 5063 | writeBaseIDOrNone(M.BasePreprocessedEntityID, |
| 5064 | M.NumPreprocessedEntities); |
| 5065 | writeBaseIDOrNone(M.BaseSubmoduleID, M.LocalNumSubmodules); |
| 5066 | writeBaseIDOrNone(M.BaseSelectorID, M.LocalNumSelectors); |
| 5067 | writeBaseIDOrNone(M.BaseDeclID, M.LocalNumDecls); |
| 5068 | writeBaseIDOrNone(M.BaseTypeIndex, M.LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5069 | } |
| 5070 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 5071 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5072 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 5073 | Buffer.data(), Buffer.size()); |
| 5074 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5075 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5076 | RecordData DeclUpdatesOffsetsRecord; |
| 5077 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 5078 | // Keep writing types, declarations, and declaration update records |
| 5079 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 5080 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 5081 | WriteTypeAbbrevs(); |
| 5082 | WriteDeclAbbrevs(); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 5083 | do { |
| 5084 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 5085 | while (!DeclTypesToEmit.empty()) { |
| 5086 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 5087 | DeclTypesToEmit.pop(); |
| 5088 | if (DOT.isType()) |
| 5089 | WriteType(DOT.getType()); |
| 5090 | else |
| 5091 | WriteDecl(Context, DOT.getDecl()); |
| 5092 | } |
| 5093 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5094 | Stream.ExitBlock(); |
| 5095 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5096 | DoneWritingDeclsAndTypes = true; |
| 5097 | |
| 5098 | // These things can only be done once we've written out decls and types. |
| 5099 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 5100 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 5101 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5102 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 5103 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5104 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 5105 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 5106 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 5107 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 5108 | WriteReferencedSelectorsPool(SemaRef); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 5109 | WriteLateParsedTemplates(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 5110 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 5111 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 5112 | WriteOpenCLExtensions(SemaRef); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 5113 | WriteOpenCLExtensionTypes(SemaRef); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 5114 | WriteCUDAPragmas(SemaRef); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 5115 | |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5116 | // If we're emitting a module, write out the submodule information. |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 5117 | if (WritingModule) |
| 5118 | WriteSubmodules(WritingModule); |
| 5119 | |
Andrew Savonichev | 52d674d | 2018-10-29 11:14:01 +0000 | [diff] [blame] | 5120 | // We need to have information about submodules to correctly deserialize |
| 5121 | // decls from OpenCLExtensionDecls block |
| 5122 | WriteOpenCLExtensionDecls(SemaRef); |
| 5123 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 5124 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 5125 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5126 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 5127 | if (!EagerlyDeserializedDecls.empty()) |
| 5128 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5129 | |
David Blaikie | f63556d | 2017-04-12 20:58:33 +0000 | [diff] [blame] | 5130 | if (!ModularCodegenDecls.empty()) |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 5131 | Stream.EmitRecord(MODULAR_CODEGEN_DECLS, ModularCodegenDecls); |
| 5132 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5133 | // Write the record containing tentative definitions. |
| 5134 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5135 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 5136 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 5137 | // Write the record containing unused file scoped decls. |
| 5138 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5139 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 5140 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 5141 | // Write the record containing weak undeclared identifiers. |
| 5142 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5143 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 5144 | WeakUndeclaredIdentifiers); |
| 5145 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 5146 | // Write the record containing ext_vector type names. |
| 5147 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5148 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5149 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 5150 | // Write the record containing VTable uses information. |
| 5151 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5152 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 5153 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 5154 | // Write the record containing potentially unused local typedefs. |
| 5155 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 5156 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 5157 | UnusedLocalTypedefNameCandidates); |
| 5158 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 5159 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 5160 | if (!PendingInstantiations.empty()) |
| 5161 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 5162 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5163 | // Write the record containing declaration references of Sema. |
| 5164 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5165 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5166 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 5167 | // Write the record containing CUDA-specific declaration references. |
| 5168 | if (!CUDASpecialDeclRefs.empty()) |
| 5169 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5170 | |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 5171 | // Write the delegating constructors. |
| 5172 | if (!DelegatingCtorDecls.empty()) |
| 5173 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 5174 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5175 | // Write the known namespaces. |
| 5176 | if (!KnownNamespaces.empty()) |
| 5177 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 5178 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 5179 | // Write the undefined internal functions and variables, and inline functions. |
| 5180 | if (!UndefinedButUsed.empty()) |
| 5181 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 5182 | |
| 5183 | if (!DeleteExprsToAnalyze.empty()) |
| 5184 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 5185 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 5186 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5187 | for (auto *DC : UpdatedDeclContexts) |
| 5188 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 5189 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 5190 | if (!WritingModule) { |
| 5191 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5192 | struct ModuleInfo { |
| 5193 | uint64_t ID; |
| 5194 | Module *M; |
| 5195 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 5196 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5197 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 5198 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 5199 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5200 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 5201 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 5202 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5203 | |
| 5204 | if (!Imports.empty()) { |
| 5205 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 5206 | return A.ID < B.ID; |
| 5207 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 5208 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 5209 | return A.ID == B.ID; |
| 5210 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5211 | |
| 5212 | // Sort and deduplicate module IDs. |
Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 5213 | llvm::sort(Imports, Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 5214 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5215 | Imports.end()); |
| 5216 | |
| 5217 | RecordData ImportedModules; |
| 5218 | for (const auto &Import : Imports) { |
| 5219 | ImportedModules.push_back(Import.ID); |
| 5220 | // FIXME: If the module has macros imported then later has declarations |
| 5221 | // imported, this location won't be the right one as a location for the |
| 5222 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 5223 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 5224 | } |
| 5225 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 5226 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 5227 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 5228 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5229 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5230 | WriteObjCCategories(); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 5231 | if(!WritingModule) { |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 5232 | WriteOptimizePragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 5233 | WriteMSStructPragmaOptions(SemaRef); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 5234 | WriteMSPointersToMembersPragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 5235 | } |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 5236 | WritePackPragmaOptions(SemaRef); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 5237 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 5238 | // Some simple statistics |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 5239 | RecordData::value_type Record[] = { |
| 5240 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5241 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 5242 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 5243 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 5244 | // Write the module file extension blocks. |
| 5245 | for (const auto &ExtWriter : ModuleFileExtensionWriters) |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 5246 | WriteModuleFileExtension(SemaRef, *ExtWriter); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 5247 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 5248 | return writeUnhashedControlBlock(PP, Context); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5249 | } |
| 5250 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 5251 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5252 | if (DeclUpdates.empty()) |
| 5253 | return; |
| 5254 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 5255 | DeclUpdateMap LocalUpdates; |
| 5256 | LocalUpdates.swap(DeclUpdates); |
| 5257 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5258 | for (auto &DeclUpdate : LocalUpdates) { |
| 5259 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 5260 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5261 | bool HasUpdatedBody = false; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5262 | RecordData RecordData; |
| 5263 | ASTRecordWriter Record(*this, RecordData); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5264 | for (auto &Update : DeclUpdate.second) { |
| 5265 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 5266 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5267 | // An updated body is emitted last, so that the reader doesn't need |
| 5268 | // to skip over the lazy body to reach statements for other records. |
| 5269 | if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION) |
| 5270 | HasUpdatedBody = true; |
| 5271 | else |
| 5272 | Record.push_back(Kind); |
| 5273 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5274 | switch (Kind) { |
| 5275 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 5276 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 5277 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5278 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5279 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 5280 | break; |
| 5281 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5282 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5283 | break; |
| 5284 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 5285 | case UPD_CXX_POINT_OF_INSTANTIATION: |
| 5286 | // FIXME: Do we need to also save the template specialization kind here? |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5287 | Record.AddSourceLocation(Update.getLoc()); |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 5288 | break; |
| 5289 | |
| 5290 | case UPD_CXX_ADDED_VAR_DEFINITION: { |
| 5291 | const VarDecl *VD = cast<VarDecl>(D); |
Richard Smith | f501759 | 2017-11-02 01:06:00 +0000 | [diff] [blame] | 5292 | Record.push_back(VD->isInline()); |
| 5293 | Record.push_back(VD->isInlineSpecified()); |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 5294 | if (VD->getInit()) { |
| 5295 | Record.push_back(!VD->isInitKnownICE() ? 1 |
| 5296 | : (VD->isInitICE() ? 3 : 2)); |
| 5297 | Record.AddStmt(const_cast<Expr*>(VD->getInit())); |
| 5298 | } else { |
| 5299 | Record.push_back(0); |
| 5300 | } |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5301 | break; |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 5302 | } |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5303 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5304 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5305 | Record.AddStmt(const_cast<Expr *>( |
| 5306 | cast<ParmVarDecl>(Update.getDecl())->getDefaultArg())); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5307 | break; |
| 5308 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 5309 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: |
| 5310 | Record.AddStmt( |
| 5311 | cast<FieldDecl>(Update.getDecl())->getInClassInitializer()); |
| 5312 | break; |
| 5313 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5314 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 5315 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 5316 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Akira Hatanaka | fcbe17c | 2018-03-28 21:13:14 +0000 | [diff] [blame] | 5317 | Record.push_back(RD->isParamDestroyedInCallee()); |
Akira Hatanaka | e6313ac | 2018-04-09 22:48:22 +0000 | [diff] [blame] | 5318 | Record.push_back(RD->getArgPassingRestrictions()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5319 | Record.AddCXXDefinitionData(RD); |
Richard Smith | 72e50fe | 2016-04-14 00:50:18 +0000 | [diff] [blame] | 5320 | Record.AddOffset(WriteDeclContextLexicalBlock( |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5321 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 5322 | |
| 5323 | // This state is sometimes updated by template instantiation, when we |
| 5324 | // switch from the specialization referring to the template declaration |
| 5325 | // to it referring to the template definition. |
| 5326 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 5327 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5328 | Record.AddSourceLocation(MSInfo->getPointOfInstantiation()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5329 | } else { |
| 5330 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 5331 | Record.push_back(Spec->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5332 | Record.AddSourceLocation(Spec->getPointOfInstantiation()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 5333 | |
| 5334 | // The instantiation might have been resolved to a partial |
| 5335 | // specialization. If so, record which one. |
| 5336 | auto From = Spec->getInstantiatedFrom(); |
| 5337 | if (auto PartialSpec = |
| 5338 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 5339 | Record.push_back(true); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5340 | Record.AddDeclRef(PartialSpec); |
| 5341 | Record.AddTemplateArgumentList( |
| 5342 | &Spec->getTemplateInstantiationArgs()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 5343 | } else { |
| 5344 | Record.push_back(false); |
| 5345 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5346 | } |
| 5347 | Record.push_back(RD->getTagKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5348 | Record.AddSourceLocation(RD->getLocation()); |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5349 | Record.AddSourceLocation(RD->getBeginLoc()); |
Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 5350 | Record.AddSourceRange(RD->getBraceRange()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5351 | |
| 5352 | // Instantiation may change attributes; write them all out afresh. |
| 5353 | Record.push_back(D->hasAttrs()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5354 | if (D->hasAttrs()) |
| 5355 | Record.AddAttributes(D->getAttrs()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5356 | |
| 5357 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 5358 | break; |
| 5359 | } |
| 5360 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5361 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5362 | Record.AddDeclRef(Update.getDecl()); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 5363 | Record.AddStmt(cast<CXXDestructorDecl>(D)->getOperatorDeleteThisArg()); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5364 | break; |
| 5365 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5366 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 5367 | addExceptionSpec( |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5368 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 5369 | Record); |
| 5370 | break; |
| 5371 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5372 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 5373 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 5374 | break; |
| 5375 | |
| 5376 | case UPD_DECL_MARKED_USED: |
| 5377 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 5378 | |
| 5379 | case UPD_MANGLING_NUMBER: |
| 5380 | case UPD_STATIC_LOCAL_NUMBER: |
| 5381 | Record.push_back(Update.getNumber()); |
| 5382 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5383 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5384 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5385 | Record.AddSourceRange( |
| 5386 | D->getAttr<OMPThreadPrivateDeclAttr>()->getRange()); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5387 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5388 | |
Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 5389 | case UPD_DECL_MARKED_OPENMP_ALLOCATE: { |
| 5390 | auto *A = D->getAttr<OMPAllocateDeclAttr>(); |
| 5391 | Record.push_back(A->getAllocatorType()); |
| 5392 | Record.AddStmt(A->getAllocator()); |
| 5393 | Record.AddSourceRange(A->getRange()); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 5394 | break; |
Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 5395 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 5396 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5397 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 5398 | Record.push_back(D->getAttr<OMPDeclareTargetDeclAttr>()->getMapType()); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5399 | Record.AddSourceRange( |
| 5400 | D->getAttr<OMPDeclareTargetDeclAttr>()->getRange()); |
| 5401 | break; |
| 5402 | |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5403 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5404 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5405 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5406 | |
| 5407 | case UPD_ADDED_ATTR_TO_RECORD: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5408 | Record.AddAttributes(llvm::makeArrayRef(Update.getAttr())); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5409 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5410 | } |
| 5411 | } |
| 5412 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5413 | if (HasUpdatedBody) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5414 | const auto *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5415 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5416 | Record.push_back(Def->isInlined()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5417 | Record.AddSourceLocation(Def->getInnerLocStart()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5418 | Record.AddFunctionDefinition(Def); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5419 | } |
| 5420 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5421 | OffsetsRecord.push_back(GetDeclRef(D)); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5422 | OffsetsRecord.push_back(Record.Emit(DECL_UPDATES)); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5423 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5424 | } |
| 5425 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5426 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5427 | uint32_t Raw = Loc.getRawEncoding(); |
| 5428 | Record.push_back((Raw << 1) | (Raw >> 31)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5431 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5432 | AddSourceLocation(Range.getBegin(), Record); |
| 5433 | AddSourceLocation(Range.getEnd(), Record); |
| 5434 | } |
| 5435 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5436 | void ASTRecordWriter::AddAPInt(const llvm::APInt &Value) { |
| 5437 | Record->push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 5438 | const uint64_t *Words = Value.getRawData(); |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5439 | Record->append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5440 | } |
| 5441 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5442 | void ASTRecordWriter::AddAPSInt(const llvm::APSInt &Value) { |
| 5443 | Record->push_back(Value.isUnsigned()); |
| 5444 | AddAPInt(Value); |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5445 | } |
| 5446 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5447 | void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) { |
| 5448 | AddAPInt(Value.bitcastToAPInt()); |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 5451 | static void WriteFixedPointSemantics(ASTRecordWriter &Record, |
| 5452 | FixedPointSemantics FPSema) { |
| 5453 | Record.push_back(FPSema.getWidth()); |
| 5454 | Record.push_back(FPSema.getScale()); |
| 5455 | Record.push_back(FPSema.isSigned() | FPSema.isSaturated() << 1 | |
| 5456 | FPSema.hasUnsignedPadding() << 2); |
| 5457 | } |
| 5458 | |
| 5459 | void ASTRecordWriter::AddAPValue(const APValue &Value) { |
| 5460 | APValue::ValueKind Kind = Value.getKind(); |
| 5461 | push_back(static_cast<uint64_t>(Kind)); |
| 5462 | switch (Kind) { |
| 5463 | case APValue::None: |
| 5464 | case APValue::Indeterminate: |
| 5465 | return; |
| 5466 | case APValue::Int: |
| 5467 | AddAPSInt(Value.getInt()); |
| 5468 | return; |
| 5469 | case APValue::Float: |
| 5470 | push_back(static_cast<uint64_t>( |
| 5471 | llvm::APFloatBase::SemanticsToEnum(Value.getFloat().getSemantics()))); |
| 5472 | AddAPFloat(Value.getFloat()); |
| 5473 | return; |
| 5474 | case APValue::FixedPoint: { |
| 5475 | WriteFixedPointSemantics(*this, Value.getFixedPoint().getSemantics()); |
| 5476 | AddAPSInt(Value.getFixedPoint().getValue()); |
| 5477 | return; |
| 5478 | } |
| 5479 | case APValue::ComplexInt: { |
| 5480 | AddAPSInt(Value.getComplexIntReal()); |
| 5481 | AddAPSInt(Value.getComplexIntImag()); |
| 5482 | return; |
| 5483 | } |
| 5484 | case APValue::ComplexFloat: { |
| 5485 | push_back(static_cast<uint64_t>(llvm::APFloatBase::SemanticsToEnum( |
| 5486 | Value.getComplexFloatReal().getSemantics()))); |
| 5487 | AddAPFloat(Value.getComplexFloatReal()); |
| 5488 | push_back(static_cast<uint64_t>(llvm::APFloatBase::SemanticsToEnum( |
| 5489 | Value.getComplexFloatImag().getSemantics()))); |
| 5490 | AddAPFloat(Value.getComplexFloatImag()); |
| 5491 | return; |
| 5492 | } |
| 5493 | case APValue::LValue: |
| 5494 | case APValue::Vector: |
| 5495 | case APValue::Array: |
| 5496 | case APValue::Struct: |
| 5497 | case APValue::Union: |
| 5498 | case APValue::MemberPointer: |
| 5499 | case APValue::AddrLabelDiff: |
| 5500 | // TODO : Handle all these APValue::ValueKind. |
| 5501 | return; |
| 5502 | } |
| 5503 | llvm_unreachable("Invalid APValue::ValueKind"); |
| 5504 | } |
| 5505 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5506 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5507 | Record.push_back(getIdentifierRef(II)); |
| 5508 | } |
| 5509 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5510 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5511 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5512 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5513 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5514 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5515 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5516 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5517 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5518 | } |
| 5519 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5520 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5521 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 5522 | // have been redefined by the header (in which case they are not |
| 5523 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5524 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5525 | return 0; |
| 5526 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5527 | MacroID &ID = MacroIDs[MI]; |
| 5528 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5529 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5530 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 5531 | MacroInfosToEmit.push_back(Info); |
| 5532 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5533 | return ID; |
| 5534 | } |
| 5535 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5536 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5537 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5538 | return 0; |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5539 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5540 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 5541 | return MacroIDs[MI]; |
| 5542 | } |
| 5543 | |
| 5544 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 5545 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5546 | } |
| 5547 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5548 | void ASTRecordWriter::AddSelectorRef(const Selector SelRef) { |
| 5549 | Record->push_back(Writer->getSelectorRef(SelRef)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5550 | } |
| 5551 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5552 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5553 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5554 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5555 | } |
| 5556 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5557 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5558 | if (SID == 0 && Chain) { |
| 5559 | // This might trigger a ReadSelector callback, which will set the ID for |
| 5560 | // this selector. |
| 5561 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5562 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5563 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5564 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5565 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5566 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5567 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5568 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5569 | } |
| 5570 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5571 | void ASTRecordWriter::AddCXXTemporary(const CXXTemporary *Temp) { |
| 5572 | AddDeclRef(Temp->getDestructor()); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5573 | } |
| 5574 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5575 | void ASTRecordWriter::AddTemplateArgumentLocInfo( |
| 5576 | TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5577 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5578 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5579 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5580 | break; |
| 5581 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5582 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5583 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5584 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5585 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5586 | AddSourceLocation(Arg.getTemplateNameLoc()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5587 | break; |
| 5588 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5589 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5590 | AddSourceLocation(Arg.getTemplateNameLoc()); |
| 5591 | AddSourceLocation(Arg.getTemplateEllipsisLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5592 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5593 | case TemplateArgument::Null: |
| 5594 | case TemplateArgument::Integral: |
| 5595 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5596 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5597 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5598 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5599 | break; |
| 5600 | } |
| 5601 | } |
| 5602 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5603 | void ASTRecordWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg) { |
| 5604 | AddTemplateArgument(Arg.getArgument()); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5605 | |
| 5606 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 5607 | bool InfoHasSameExpr |
| 5608 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5609 | Record->push_back(InfoHasSameExpr); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5610 | if (InfoHasSameExpr) |
| 5611 | return; // Avoid storing the same expr twice. |
| 5612 | } |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5613 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo()); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5614 | } |
| 5615 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5616 | void ASTRecordWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5617 | if (!TInfo) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5618 | AddTypeRef(QualType()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5619 | return; |
| 5620 | } |
| 5621 | |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 5622 | AddTypeRef(TInfo->getType()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5623 | AddTypeLoc(TInfo->getTypeLoc()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5624 | } |
| 5625 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5626 | void ASTRecordWriter::AddTypeLoc(TypeLoc TL) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5627 | TypeLocWriter TLW(*this); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5628 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 5629 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5630 | } |
| 5631 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5632 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 5633 | Record.push_back(GetOrCreateTypeID(T)); |
| 5634 | } |
| 5635 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5636 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5637 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5638 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5639 | if (T.isNull()) |
| 5640 | return TypeIdx(); |
| 5641 | assert(!T.getLocalFastQualifiers()); |
| 5642 | |
| 5643 | TypeIdx &Idx = TypeIdxs[T]; |
| 5644 | if (Idx.getIndex() == 0) { |
| 5645 | if (DoneWritingDeclsAndTypes) { |
| 5646 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 5647 | return TypeIdx(); |
| 5648 | } |
| 5649 | |
| 5650 | // We haven't seen this type before. Assign it a new ID and put it |
| 5651 | // into the queue of types to emit. |
| 5652 | Idx = TypeIdx(NextTypeID++); |
| 5653 | DeclTypesToEmit.push(T); |
| 5654 | } |
| 5655 | return Idx; |
| 5656 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 5657 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5658 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 5659 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5660 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5661 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5662 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5663 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5664 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5665 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5666 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 5667 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 5668 | return I->second; |
| 5669 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5670 | } |
| 5671 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5672 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5673 | Record.push_back(GetDeclRef(D)); |
| 5674 | } |
| 5675 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5676 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5677 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5678 | |
| 5679 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5680 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5681 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5682 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5683 | // If D comes from an AST file, its declaration ID is already known and |
| 5684 | // fixed. |
| 5685 | if (D->isFromASTFile()) |
| 5686 | return D->getGlobalID(); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5687 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5688 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5689 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5690 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5691 | if (DoneWritingDeclsAndTypes) { |
| 5692 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 5693 | return 0; |
| 5694 | } |
| 5695 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5696 | // We haven't seen this declaration before. Give it a new ID and |
| 5697 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5698 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5699 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5700 | } |
| 5701 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5702 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5703 | } |
| 5704 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5705 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5706 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5707 | return 0; |
| 5708 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5709 | // If D comes from an AST file, its declaration ID is already known and |
| 5710 | // fixed. |
| 5711 | if (D->isFromASTFile()) |
| 5712 | return D->getGlobalID(); |
| 5713 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5714 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 5715 | return DeclIDs[D]; |
| 5716 | } |
| 5717 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5718 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5719 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5720 | assert(D); |
| 5721 | |
| 5722 | SourceLocation Loc = D->getLocation(); |
| 5723 | if (Loc.isInvalid()) |
| 5724 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5725 | |
| 5726 | // We only keep track of the file-level declarations of each file. |
| 5727 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 5728 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5729 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 5730 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | 71b74eb | 2018-01-26 19:26:12 +0000 | [diff] [blame] | 5731 | // TemplateTemplateParmDecls that are part of an alias template, should not |
| 5732 | // have TU as lexical context. |
| 5733 | if (isa<ParmVarDecl>(D) || isa<TemplateTemplateParmDecl>(D)) |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5734 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5735 | |
| 5736 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5737 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5738 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5739 | FileID FID; |
| 5740 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5741 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5742 | if (FID.isInvalid()) |
| 5743 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5744 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5745 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5746 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5747 | if (!Info) |
| 5748 | Info = new DeclIDInFileInfo(); |
| 5749 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5750 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5751 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 5752 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5753 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5754 | Decls.push_back(LocDecl); |
| 5755 | return; |
| 5756 | } |
| 5757 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5758 | LocDeclIDsTy::iterator I = |
Fangrui Song | 7264a47 | 2019-07-03 08:13:17 +0000 | [diff] [blame] | 5759 | llvm::upper_bound(Decls, LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5760 | |
| 5761 | Decls.insert(I, LocDecl); |
| 5762 | } |
| 5763 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5764 | void ASTRecordWriter::AddDeclarationName(DeclarationName Name) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 5765 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5766 | Record->push_back(Name.getNameKind()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5767 | switch (Name.getNameKind()) { |
| 5768 | case DeclarationName::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5769 | AddIdentifierRef(Name.getAsIdentifierInfo()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5770 | break; |
| 5771 | |
| 5772 | case DeclarationName::ObjCZeroArgSelector: |
| 5773 | case DeclarationName::ObjCOneArgSelector: |
| 5774 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5775 | AddSelectorRef(Name.getObjCSelector()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5776 | break; |
| 5777 | |
| 5778 | case DeclarationName::CXXConstructorName: |
| 5779 | case DeclarationName::CXXDestructorName: |
| 5780 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5781 | AddTypeRef(Name.getCXXNameType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5782 | break; |
| 5783 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 5784 | case DeclarationName::CXXDeductionGuideName: |
| 5785 | AddDeclRef(Name.getCXXDeductionGuideTemplate()); |
| 5786 | break; |
| 5787 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5788 | case DeclarationName::CXXOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5789 | Record->push_back(Name.getCXXOverloadedOperator()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5790 | break; |
| 5791 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5792 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5793 | AddIdentifierRef(Name.getCXXLiteralIdentifier()); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5794 | break; |
| 5795 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5796 | case DeclarationName::CXXUsingDirective: |
| 5797 | // No extra data to emit |
| 5798 | break; |
| 5799 | } |
| 5800 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5801 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5802 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5803 | assert(needsAnonymousDeclarationNumber(D) && |
| 5804 | "expected an anonymous declaration"); |
| 5805 | |
| 5806 | // Number the anonymous declarations within this context, if we've not |
| 5807 | // already done so. |
| 5808 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5809 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5810 | auto *DC = D->getLexicalDeclContext(); |
| 5811 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5812 | AnonymousDeclarationNumbers[ND] = Number; |
| 5813 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5814 | |
| 5815 | It = AnonymousDeclarationNumbers.find(D); |
| 5816 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5817 | "declaration not found within its lexical context"); |
| 5818 | } |
| 5819 | |
| 5820 | return It->second; |
| 5821 | } |
| 5822 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5823 | void ASTRecordWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
| 5824 | DeclarationName Name) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5825 | switch (Name.getNameKind()) { |
| 5826 | case DeclarationName::CXXConstructorName: |
| 5827 | case DeclarationName::CXXDestructorName: |
| 5828 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5829 | AddTypeSourceInfo(DNLoc.NamedType.TInfo); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5830 | break; |
| 5831 | |
| 5832 | case DeclarationName::CXXOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5833 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5834 | DNLoc.CXXOperatorName.BeginOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5835 | AddSourceLocation( |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5836 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5837 | break; |
| 5838 | |
| 5839 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5840 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5841 | DNLoc.CXXLiteralOperatorName.OpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5842 | break; |
| 5843 | |
| 5844 | case DeclarationName::Identifier: |
| 5845 | case DeclarationName::ObjCZeroArgSelector: |
| 5846 | case DeclarationName::ObjCOneArgSelector: |
| 5847 | case DeclarationName::ObjCMultiArgSelector: |
| 5848 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 5849 | case DeclarationName::CXXDeductionGuideName: |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5850 | break; |
| 5851 | } |
| 5852 | } |
| 5853 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5854 | void ASTRecordWriter::AddDeclarationNameInfo( |
| 5855 | const DeclarationNameInfo &NameInfo) { |
| 5856 | AddDeclarationName(NameInfo.getName()); |
| 5857 | AddSourceLocation(NameInfo.getLoc()); |
| 5858 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName()); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5859 | } |
| 5860 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5861 | void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { |
| 5862 | AddNestedNameSpecifierLoc(Info.QualifierLoc); |
| 5863 | Record->push_back(Info.NumTemplParamLists); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5864 | for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5865 | AddTemplateParameterList(Info.TemplParamLists[i]); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5866 | } |
| 5867 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5868 | void ASTRecordWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5869 | // 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] | 5870 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5871 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5872 | |
| 5873 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5874 | while (NNS) { |
| 5875 | NestedNames.push_back(NNS); |
| 5876 | NNS = NNS->getPrefix(); |
| 5877 | } |
| 5878 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5879 | Record->push_back(NestedNames.size()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5880 | while(!NestedNames.empty()) { |
| 5881 | NNS = NestedNames.pop_back_val(); |
| 5882 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5883 | Record->push_back(Kind); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5884 | switch (Kind) { |
| 5885 | case NestedNameSpecifier::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5886 | AddIdentifierRef(NNS->getAsIdentifier()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5887 | break; |
| 5888 | |
| 5889 | case NestedNameSpecifier::Namespace: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5890 | AddDeclRef(NNS->getAsNamespace()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5891 | break; |
| 5892 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5893 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5894 | AddDeclRef(NNS->getAsNamespaceAlias()); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5895 | break; |
| 5896 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5897 | case NestedNameSpecifier::TypeSpec: |
| 5898 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5899 | AddTypeRef(QualType(NNS->getAsType(), 0)); |
| 5900 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5901 | break; |
| 5902 | |
| 5903 | case NestedNameSpecifier::Global: |
| 5904 | // Don't need to write an associated value. |
| 5905 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5906 | |
| 5907 | case NestedNameSpecifier::Super: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5908 | AddDeclRef(NNS->getAsRecordDecl()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5909 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5910 | } |
| 5911 | } |
| 5912 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5913 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5914 | void ASTRecordWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5915 | // 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] | 5916 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5917 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5918 | |
| 5919 | // Push each of the nested-name-specifiers's onto a stack for |
| 5920 | // serialization in reverse order. |
| 5921 | while (NNS) { |
| 5922 | NestedNames.push_back(NNS); |
| 5923 | NNS = NNS.getPrefix(); |
| 5924 | } |
| 5925 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5926 | Record->push_back(NestedNames.size()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5927 | while(!NestedNames.empty()) { |
| 5928 | NNS = NestedNames.pop_back_val(); |
| 5929 | NestedNameSpecifier::SpecifierKind Kind |
| 5930 | = NNS.getNestedNameSpecifier()->getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5931 | Record->push_back(Kind); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5932 | switch (Kind) { |
| 5933 | case NestedNameSpecifier::Identifier: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5934 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier()); |
| 5935 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5936 | break; |
| 5937 | |
| 5938 | case NestedNameSpecifier::Namespace: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5939 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace()); |
| 5940 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5941 | break; |
| 5942 | |
| 5943 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5944 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias()); |
| 5945 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5946 | break; |
| 5947 | |
| 5948 | case NestedNameSpecifier::TypeSpec: |
| 5949 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5950 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 5951 | AddTypeRef(NNS.getTypeLoc().getType()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5952 | AddTypeLoc(NNS.getTypeLoc()); |
| 5953 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5954 | break; |
| 5955 | |
| 5956 | case NestedNameSpecifier::Global: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5957 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5958 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5959 | |
| 5960 | case NestedNameSpecifier::Super: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5961 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl()); |
| 5962 | AddSourceRange(NNS.getLocalSourceRange()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5963 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5964 | } |
| 5965 | } |
| 5966 | } |
| 5967 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5968 | void ASTRecordWriter::AddTemplateName(TemplateName Name) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5969 | TemplateName::NameKind Kind = Name.getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5970 | Record->push_back(Kind); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5971 | switch (Kind) { |
| 5972 | case TemplateName::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5973 | AddDeclRef(Name.getAsTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5974 | break; |
| 5975 | |
| 5976 | case TemplateName::OverloadedTemplate: { |
| 5977 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5978 | Record->push_back(OvT->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5979 | for (const auto &I : *OvT) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5980 | AddDeclRef(I); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5981 | break; |
| 5982 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5983 | |
Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 5984 | case TemplateName::AssumedTemplate: { |
| 5985 | AssumedTemplateStorage *ADLT = Name.getAsAssumedTemplateName(); |
| 5986 | AddDeclarationName(ADLT->getDeclName()); |
| 5987 | break; |
| 5988 | } |
| 5989 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5990 | case TemplateName::QualifiedTemplate: { |
| 5991 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5992 | AddNestedNameSpecifier(QualT->getQualifier()); |
| 5993 | Record->push_back(QualT->hasTemplateKeyword()); |
| 5994 | AddDeclRef(QualT->getTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5995 | break; |
| 5996 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5997 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5998 | case TemplateName::DependentTemplate: { |
| 5999 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6000 | AddNestedNameSpecifier(DepT->getQualifier()); |
| 6001 | Record->push_back(DepT->isIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6002 | if (DepT->isIdentifier()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6003 | AddIdentifierRef(DepT->getIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6004 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6005 | Record->push_back(DepT->getOperator()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6006 | break; |
| 6007 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6008 | |
| 6009 | case TemplateName::SubstTemplateTemplateParm: { |
| 6010 | SubstTemplateTemplateParmStorage *subst |
| 6011 | = Name.getAsSubstTemplateTemplateParm(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6012 | AddDeclRef(subst->getParameter()); |
| 6013 | AddTemplateName(subst->getReplacement()); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6014 | break; |
| 6015 | } |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 6016 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6017 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 6018 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 6019 | = Name.getAsSubstTemplateTemplateParmPack(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6020 | AddDeclRef(SubstPack->getParameterPack()); |
| 6021 | AddTemplateArgument(SubstPack->getArgumentPack()); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6022 | break; |
| 6023 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6024 | } |
| 6025 | } |
| 6026 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6027 | void ASTRecordWriter::AddTemplateArgument(const TemplateArgument &Arg) { |
| 6028 | Record->push_back(Arg.getKind()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6029 | switch (Arg.getKind()) { |
| 6030 | case TemplateArgument::Null: |
| 6031 | break; |
| 6032 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6033 | AddTypeRef(Arg.getAsType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6034 | break; |
| 6035 | case TemplateArgument::Declaration: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6036 | AddDeclRef(Arg.getAsDecl()); |
| 6037 | AddTypeRef(Arg.getParamTypeForDecl()); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 6038 | break; |
| 6039 | case TemplateArgument::NullPtr: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6040 | AddTypeRef(Arg.getNullPtrType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6041 | break; |
| 6042 | case TemplateArgument::Integral: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6043 | AddAPSInt(Arg.getAsIntegral()); |
| 6044 | AddTypeRef(Arg.getIntegralType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6045 | break; |
| 6046 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6047 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 6048 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6049 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6050 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 6051 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6052 | Record->push_back(*NumExpansions + 1); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 6053 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6054 | Record->push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6055 | break; |
| 6056 | case TemplateArgument::Expression: |
| 6057 | AddStmt(Arg.getAsExpr()); |
| 6058 | break; |
| 6059 | case TemplateArgument::Pack: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6060 | Record->push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 6061 | for (const auto &P : Arg.pack_elements()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6062 | AddTemplateArgument(P); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 6063 | break; |
| 6064 | } |
| 6065 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6066 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 6067 | void ASTRecordWriter::AddTemplateParameterList( |
| 6068 | const TemplateParameterList *TemplateParams) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6069 | assert(TemplateParams && "No TemplateParams!"); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 6070 | AddSourceLocation(TemplateParams->getTemplateLoc()); |
| 6071 | AddSourceLocation(TemplateParams->getLAngleLoc()); |
| 6072 | AddSourceLocation(TemplateParams->getRAngleLoc()); |
Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame] | 6073 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 6074 | Record->push_back(TemplateParams->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 6075 | for (const auto &P : *TemplateParams) |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 6076 | AddDeclRef(P); |
Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame] | 6077 | if (const Expr *RequiresClause = TemplateParams->getRequiresClause()) { |
| 6078 | Record->push_back(true); |
| 6079 | AddStmt(const_cast<Expr*>(RequiresClause)); |
| 6080 | } else { |
| 6081 | Record->push_back(false); |
| 6082 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6083 | } |
| 6084 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6085 | /// Emit a template argument list. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6086 | void ASTRecordWriter::AddTemplateArgumentList( |
| 6087 | const TemplateArgumentList *TemplateArgs) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6088 | assert(TemplateArgs && "No TemplateArgs!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6089 | Record->push_back(TemplateArgs->size()); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6090 | for (int i = 0, e = TemplateArgs->size(); i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6091 | AddTemplateArgument(TemplateArgs->get(i)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6092 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6093 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6094 | void ASTRecordWriter::AddASTTemplateArgumentListInfo( |
| 6095 | const ASTTemplateArgumentListInfo *ASTTemplArgList) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 6096 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6097 | AddSourceLocation(ASTTemplArgList->LAngleLoc); |
| 6098 | AddSourceLocation(ASTTemplArgList->RAngleLoc); |
| 6099 | Record->push_back(ASTTemplArgList->NumTemplateArgs); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 6100 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6101 | for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6102 | AddTemplateArgumentLoc(TemplArgs[i]); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 6103 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6104 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 6105 | void ASTRecordWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set) { |
| 6106 | Record->push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 6107 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6108 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 6109 | AddDeclRef(I.getDecl()); |
| 6110 | Record->push_back(I.getAccess()); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6111 | } |
| 6112 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6113 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6114 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 6115 | void ASTRecordWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base) { |
| 6116 | Record->push_back(Base.isVirtual()); |
| 6117 | Record->push_back(Base.isBaseOfClass()); |
| 6118 | Record->push_back(Base.getAccessSpecifierAsWritten()); |
| 6119 | Record->push_back(Base.getInheritConstructors()); |
| 6120 | AddTypeSourceInfo(Base.getTypeSourceInfo()); |
| 6121 | AddSourceRange(Base.getSourceRange()); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 6122 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6123 | : SourceLocation()); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6124 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 6125 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 6126 | static uint64_t EmitCXXBaseSpecifiers(ASTWriter &W, |
| 6127 | ArrayRef<CXXBaseSpecifier> Bases) { |
| 6128 | ASTWriter::RecordData Record; |
| 6129 | ASTRecordWriter Writer(W, Record); |
| 6130 | Writer.push_back(Bases.size()); |
Dmitry Polukhin | 790b540 | 2016-04-06 10:01:46 +0000 | [diff] [blame] | 6131 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 6132 | for (auto &Base : Bases) |
| 6133 | Writer.AddCXXBaseSpecifier(Base); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6134 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 6135 | return Writer.Emit(serialization::DECL_CXX_BASE_SPECIFIERS); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 6136 | } |
| 6137 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6138 | // FIXME: Move this out of the main ASTRecordWriter interface. |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 6139 | void ASTRecordWriter::AddCXXBaseSpecifiers(ArrayRef<CXXBaseSpecifier> Bases) { |
| 6140 | AddOffset(EmitCXXBaseSpecifiers(*Writer, Bases)); |
| 6141 | } |
| 6142 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6143 | static uint64_t |
| 6144 | EmitCXXCtorInitializers(ASTWriter &W, |
| 6145 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 6146 | ASTWriter::RecordData Record; |
| 6147 | ASTRecordWriter Writer(W, Record); |
| 6148 | Writer.push_back(CtorInits.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6149 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6150 | for (auto *Init : CtorInits) { |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6151 | if (Init->isBaseInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6152 | Writer.push_back(CTOR_INITIALIZER_BASE); |
| 6153 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
| 6154 | Writer.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6155 | } else if (Init->isDelegatingInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6156 | Writer.push_back(CTOR_INITIALIZER_DELEGATING); |
| 6157 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6158 | } else if (Init->isMemberInitializer()){ |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6159 | Writer.push_back(CTOR_INITIALIZER_MEMBER); |
| 6160 | Writer.AddDeclRef(Init->getMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6161 | } else { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6162 | Writer.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 6163 | Writer.AddDeclRef(Init->getIndirectMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6164 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6165 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6166 | Writer.AddSourceLocation(Init->getMemberLocation()); |
| 6167 | Writer.AddStmt(Init->getInit()); |
| 6168 | Writer.AddSourceLocation(Init->getLParenLoc()); |
| 6169 | Writer.AddSourceLocation(Init->getRParenLoc()); |
| 6170 | Writer.push_back(Init->isWritten()); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 6171 | if (Init->isWritten()) |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6172 | Writer.push_back(Init->getSourceOrder()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6173 | } |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6174 | |
| 6175 | return Writer.Emit(serialization::DECL_CXX_CTOR_INITIALIZERS); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6176 | } |
| 6177 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 6178 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 6179 | void ASTRecordWriter::AddCXXCtorInitializers( |
| 6180 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 6181 | AddOffset(EmitCXXCtorInitializers(*Writer, CtorInits)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 6182 | } |
| 6183 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6184 | void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6185 | auto &Data = D->data(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6186 | Record->push_back(Data.IsLambda); |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 6187 | |
| 6188 | #define FIELD(Name, Width, Merge) \ |
| 6189 | Record->push_back(Data.Name); |
| 6190 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 6191 | |
| 6192 | // getODRHash will compute the ODRHash if it has not been previously computed. |
| 6193 | Record->push_back(D->getODRHash()); |
David Blaikie | f63556d | 2017-04-12 20:58:33 +0000 | [diff] [blame] | 6194 | bool ModulesDebugInfo = Writer->Context->getLangOpts().ModulesDebugInfo && |
| 6195 | Writer->WritingModule && !D->isDependentType(); |
| 6196 | Record->push_back(ModulesDebugInfo); |
| 6197 | if (ModulesDebugInfo) |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 6198 | Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(D)); |
| 6199 | |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 6200 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 6201 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6202 | Record->push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 6203 | if (Data.NumBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 6204 | AddCXXBaseSpecifiers(Data.bases()); |
| 6205 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 6206 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6207 | Record->push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 6208 | if (Data.NumVBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 6209 | AddCXXBaseSpecifiers(Data.vbases()); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 6210 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6211 | AddUnresolvedSet(Data.Conversions.get(*Writer->Context)); |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 6212 | Record->push_back(Data.ComputedVisibleConversions); |
| 6213 | if (Data.ComputedVisibleConversions) |
| 6214 | AddUnresolvedSet(Data.VisibleConversions.get(*Writer->Context)); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 6215 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6216 | AddDeclRef(D->getFirstFriend()); |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 6217 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 6218 | // Add lambda-specific data. |
| 6219 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6220 | auto &Lambda = D->getLambdaData(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6221 | Record->push_back(Lambda.Dependent); |
| 6222 | Record->push_back(Lambda.IsGenericLambda); |
| 6223 | Record->push_back(Lambda.CaptureDefault); |
| 6224 | Record->push_back(Lambda.NumCaptures); |
| 6225 | Record->push_back(Lambda.NumExplicitCaptures); |
| 6226 | Record->push_back(Lambda.ManglingNumber); |
Richard Smith | 0bae624 | 2016-08-25 00:34:00 +0000 | [diff] [blame] | 6227 | AddDeclRef(D->getLambdaContextDecl()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6228 | AddTypeSourceInfo(Lambda.MethodTyInfo); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 6229 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 6230 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6231 | AddSourceLocation(Capture.getLocation()); |
| 6232 | Record->push_back(Capture.isImplicit()); |
| 6233 | Record->push_back(Capture.getCaptureKind()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6234 | switch (Capture.getCaptureKind()) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 6235 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6236 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 6237 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6238 | break; |
| 6239 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 6240 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6241 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6242 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6243 | AddDeclRef(Var); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6244 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 6245 | : SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 6246 | break; |
| 6247 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 6248 | } |
| 6249 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 6250 | } |
| 6251 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 6252 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6253 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 6254 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6255 | assert(FirstDeclID == NextDeclID && |
| 6256 | FirstTypeID == NextTypeID && |
| 6257 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6258 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6259 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 6260 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6261 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6262 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6263 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 6264 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 6265 | // Note, this will get called multiple times, once one the reader starts up |
| 6266 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 6267 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 6268 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 6269 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6270 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6271 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 6272 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 6273 | NextDeclID = FirstDeclID; |
| 6274 | NextTypeID = FirstTypeID; |
| 6275 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6276 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 6277 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 6278 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 6279 | } |
| 6280 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 6281 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 6282 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 6283 | IdentID &StoredID = IdentifierIDs[II]; |
| 6284 | if (ID > StoredID) |
| 6285 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 6288 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 6289 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 6290 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 6291 | if (ID > StoredID) |
| 6292 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6293 | } |
| 6294 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 6295 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 6296 | // Always take the highest-numbered type index. This copes with an interesting |
| 6297 | // 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] | 6298 | // 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] | 6299 | // keep the higher-numbered entry so that we can properly write it out to |
| 6300 | // the AST file. |
| 6301 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 6302 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 6303 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 6304 | } |
| 6305 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 6306 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 6307 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 6308 | SelectorID &StoredID = SelectorIDs[S]; |
| 6309 | if (ID > StoredID) |
| 6310 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 6311 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 6312 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 6313 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 6314 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 6315 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 6316 | MacroDefinitions[MD] = ID; |
| 6317 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6318 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 6319 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 6320 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 6321 | SubmoduleIDs[Mod] = ID; |
| 6322 | } |
| 6323 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6324 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6325 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 6326 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6327 | assert(!WritingAST && "Already writing the AST!"); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 6328 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6329 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6330 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6331 | // A forward reference was mutated into a definition. Rewrite it. |
| 6332 | // FIXME: This happens during template instantiation, should we |
| 6333 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6334 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 6335 | "completed a tag from another module but not by instantiation?"); |
| 6336 | DeclUpdates[RD].push_back( |
| 6337 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6338 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 6339 | } |
| 6340 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 6341 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6342 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { |
| 6343 | if (D->isFromASTFile()) |
| 6344 | return true; |
| 6345 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6346 | // The predefined __va_list_tag struct is imported if we imported any decls. |
| 6347 | // FIXME: This is a gross hack. |
| 6348 | return D == D->getASTContext().getVaListTagDecl(); |
| 6349 | } |
| 6350 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6351 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6352 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
| 6353 | assert(DC->isLookupContext() && |
Vassil Vassilev | 71eafde | 2016-04-06 20:56:03 +0000 | [diff] [blame] | 6354 | "Should not add lookup results to non-lookup contexts!"); |
| 6355 | |
Vassil Vassilev | 632eac3 | 2016-03-16 11:17:04 +0000 | [diff] [blame] | 6356 | // TU is handled elsewhere. |
| 6357 | if (isa<TranslationUnitDecl>(DC)) |
| 6358 | return; |
| 6359 | |
| 6360 | // Namespaces are handled elsewhere, except for template instantiations of |
| 6361 | // FunctionTemplateDecls in namespaces. We are interested in cases where the |
| 6362 | // local instantiations are added to an imported context. Only happens when |
| 6363 | // adding ADL lookup candidates, for example templated friends. |
| 6364 | if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && |
| 6365 | !isa<FunctionTemplateDecl>(D)) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6366 | return; |
| 6367 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6368 | // We're only interested in cases where a local declaration is added to an |
| 6369 | // imported context. |
| 6370 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) |
| 6371 | return; |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6372 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 6373 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 6374 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 6375 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6376 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { |
| 6377 | // We're adding a visible declaration to a predefined decl context. Ensure |
| 6378 | // that we write out all of its lookup results so we don't get a nasty |
| 6379 | // surprise when we try to emit its lookup table. |
| 6380 | for (auto *Child : DC->decls()) |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6381 | DeclsToEmitEvenIfUnreferenced.push_back(Child); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6382 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6383 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 6384 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6385 | |
| 6386 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6387 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6388 | assert(D->isImplicit()); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6389 | |
| 6390 | // We're only interested in cases where a local declaration is added to an |
| 6391 | // imported context. |
| 6392 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) |
| 6393 | return; |
| 6394 | |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6395 | if (!isa<CXXMethodDecl>(D)) |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 6396 | return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6397 | |
| 6398 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 6399 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 6400 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 6401 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 6402 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 6403 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6404 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6405 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6406 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 6407 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6408 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6409 | // If we don't already know the exception specification for this redecl |
| 6410 | // chain, add an update record for it. |
| 6411 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 6412 | ->getType() |
| 6413 | ->castAs<FunctionProtoType>() |
| 6414 | ->getExceptionSpecType())) |
| 6415 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 6416 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6417 | } |
| 6418 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 6419 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6420 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 6421 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6422 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6423 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6424 | DeclUpdates[D].push_back( |
| 6425 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 6426 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 6427 | } |
| 6428 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 6429 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 6430 | const FunctionDecl *Delete, |
| 6431 | Expr *ThisArg) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6432 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 6433 | assert(!WritingAST && "Already writing the AST!"); |
| 6434 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6435 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6436 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6437 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 6438 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 6439 | } |
| 6440 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 6441 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6442 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6443 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6444 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 6445 | return; // Declaration not imported from PCH. |
| 6446 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 6447 | // Implicit function decl from a PCH was defined. |
| 6448 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 6449 | } |
| 6450 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 6451 | void ASTWriter::VariableDefinitionInstantiated(const VarDecl *D) { |
| 6452 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
| 6453 | assert(!WritingAST && "Already writing the AST!"); |
| 6454 | if (!D->isFromASTFile()) |
| 6455 | return; |
| 6456 | |
| 6457 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_VAR_DEFINITION)); |
| 6458 | } |
| 6459 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 6460 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6461 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 6462 | assert(!WritingAST && "Already writing the AST!"); |
| 6463 | if (!D->isFromASTFile()) |
| 6464 | return; |
| 6465 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 6466 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 6467 | } |
| 6468 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 6469 | void ASTWriter::InstantiationRequested(const ValueDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6470 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6471 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6472 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 6473 | return; |
| 6474 | |
| 6475 | // Since the actual instantiation is delayed, this really means that we need |
| 6476 | // to update the instantiation location. |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 6477 | SourceLocation POI; |
| 6478 | if (auto *VD = dyn_cast<VarDecl>(D)) |
| 6479 | POI = VD->getPointOfInstantiation(); |
| 6480 | else |
| 6481 | POI = cast<FunctionDecl>(D)->getPointOfInstantiation(); |
| 6482 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_POINT_OF_INSTANTIATION, POI)); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 6483 | } |
| 6484 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 6485 | void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6486 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 6487 | assert(!WritingAST && "Already writing the AST!"); |
| 6488 | if (!D->isFromASTFile()) |
| 6489 | return; |
| 6490 | |
| 6491 | DeclUpdates[D].push_back( |
| 6492 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D)); |
| 6493 | } |
| 6494 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 6495 | void ASTWriter::DefaultMemberInitializerInstantiated(const FieldDecl *D) { |
| 6496 | assert(!WritingAST && "Already writing the AST!"); |
| 6497 | if (!D->isFromASTFile()) |
| 6498 | return; |
| 6499 | |
| 6500 | DeclUpdates[D].push_back( |
| 6501 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER, D)); |
| 6502 | } |
| 6503 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 6504 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 6505 | const ObjCInterfaceDecl *IFD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6506 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 6507 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 6508 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 6509 | return; // Declaration not imported from PCH. |
Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 6510 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 6511 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 6512 | ObjCClassesWithCategories.insert( |
| 6513 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 6514 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 6515 | |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6516 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6517 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6518 | assert(!WritingAST && "Already writing the AST!"); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 6519 | |
| 6520 | // If there is *any* declaration of the entity that's not from an AST file, |
| 6521 | // we can skip writing the update record. We make sure that isUsed() triggers |
| 6522 | // completion of the redeclaration chain of the entity. |
| 6523 | for (auto Prev = D->getMostRecentDecl(); Prev; Prev = Prev->getPreviousDecl()) |
| 6524 | if (IsLocalDecl(Prev)) |
| 6525 | return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6526 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 6527 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6528 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 6529 | |
| 6530 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6531 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 6532 | assert(!WritingAST && "Already writing the AST!"); |
| 6533 | if (!D->isFromASTFile()) |
| 6534 | return; |
| 6535 | |
| 6536 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 6537 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6538 | |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 6539 | void ASTWriter::DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) { |
| 6540 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
| 6541 | assert(!WritingAST && "Already writing the AST!"); |
| 6542 | if (!D->isFromASTFile()) |
| 6543 | return; |
| 6544 | |
| 6545 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_ALLOCATE, A)); |
| 6546 | } |
| 6547 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 6548 | void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, |
| 6549 | const Attr *Attr) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6550 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 6551 | assert(!WritingAST && "Already writing the AST!"); |
| 6552 | if (!D->isFromASTFile()) |
| 6553 | return; |
| 6554 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 6555 | DeclUpdates[D].push_back( |
| 6556 | DeclUpdate(UPD_DECL_MARKED_OPENMP_DECLARETARGET, Attr)); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 6557 | } |
| 6558 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6559 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6560 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6561 | assert(!WritingAST && "Already writing the AST!"); |
| 6562 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6563 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6564 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6565 | |
| 6566 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 6567 | const RecordDecl *Record) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6568 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6569 | assert(!WritingAST && "Already writing the AST!"); |
| 6570 | if (!Record->isFromASTFile()) |
| 6571 | return; |
| 6572 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 6573 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6574 | |
| 6575 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6576 | const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) { |
| 6577 | assert(!WritingAST && "Already writing the AST!"); |
| 6578 | |
| 6579 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6580 | return; |
| 6581 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6582 | return; |
| 6583 | |
| 6584 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6585 | } |
| 6586 | |
| 6587 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6588 | const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) { |
| 6589 | assert(!WritingAST && "Already writing the AST!"); |
| 6590 | |
| 6591 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6592 | return; |
| 6593 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6594 | return; |
| 6595 | |
| 6596 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6597 | } |
| 6598 | |
| 6599 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 6600 | const FunctionDecl *D) { |
| 6601 | assert(!WritingAST && "Already writing the AST!"); |
| 6602 | |
| 6603 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6604 | return; |
| 6605 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6606 | return; |
| 6607 | |
| 6608 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6609 | } |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6610 | |
| 6611 | //===----------------------------------------------------------------------===// |
| 6612 | //// OMPClause Serialization |
| 6613 | ////===----------------------------------------------------------------------===// |
| 6614 | |
| 6615 | void OMPClauseWriter::writeClause(OMPClause *C) { |
| 6616 | Record.push_back(C->getClauseKind()); |
| 6617 | Visit(C); |
| 6618 | Record.AddSourceLocation(C->getBeginLoc()); |
| 6619 | Record.AddSourceLocation(C->getEndLoc()); |
| 6620 | } |
| 6621 | |
| 6622 | void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) { |
| 6623 | Record.push_back(C->getCaptureRegion()); |
| 6624 | Record.AddStmt(C->getPreInitStmt()); |
| 6625 | } |
| 6626 | |
| 6627 | void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) { |
| 6628 | VisitOMPClauseWithPreInit(C); |
| 6629 | Record.AddStmt(C->getPostUpdateExpr()); |
| 6630 | } |
| 6631 | |
| 6632 | void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) { |
| 6633 | VisitOMPClauseWithPreInit(C); |
| 6634 | Record.push_back(C->getNameModifier()); |
| 6635 | Record.AddSourceLocation(C->getNameModifierLoc()); |
| 6636 | Record.AddSourceLocation(C->getColonLoc()); |
| 6637 | Record.AddStmt(C->getCondition()); |
| 6638 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6639 | } |
| 6640 | |
| 6641 | void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) { |
Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame^] | 6642 | VisitOMPClauseWithPreInit(C); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6643 | Record.AddStmt(C->getCondition()); |
| 6644 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6645 | } |
| 6646 | |
| 6647 | void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 6648 | VisitOMPClauseWithPreInit(C); |
| 6649 | Record.AddStmt(C->getNumThreads()); |
| 6650 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6651 | } |
| 6652 | |
| 6653 | void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) { |
| 6654 | Record.AddStmt(C->getSafelen()); |
| 6655 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6656 | } |
| 6657 | |
| 6658 | void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) { |
| 6659 | Record.AddStmt(C->getSimdlen()); |
| 6660 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6661 | } |
| 6662 | |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 6663 | void OMPClauseWriter::VisitOMPAllocatorClause(OMPAllocatorClause *C) { |
| 6664 | Record.AddStmt(C->getAllocator()); |
| 6665 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6666 | } |
| 6667 | |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6668 | void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) { |
| 6669 | Record.AddStmt(C->getNumForLoops()); |
| 6670 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6671 | } |
| 6672 | |
| 6673 | void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) { |
| 6674 | Record.push_back(C->getDefaultKind()); |
| 6675 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6676 | Record.AddSourceLocation(C->getDefaultKindKwLoc()); |
| 6677 | } |
| 6678 | |
| 6679 | void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) { |
| 6680 | Record.push_back(C->getProcBindKind()); |
| 6681 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6682 | Record.AddSourceLocation(C->getProcBindKindKwLoc()); |
| 6683 | } |
| 6684 | |
| 6685 | void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) { |
| 6686 | VisitOMPClauseWithPreInit(C); |
| 6687 | Record.push_back(C->getScheduleKind()); |
| 6688 | Record.push_back(C->getFirstScheduleModifier()); |
| 6689 | Record.push_back(C->getSecondScheduleModifier()); |
| 6690 | Record.AddStmt(C->getChunkSize()); |
| 6691 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6692 | Record.AddSourceLocation(C->getFirstScheduleModifierLoc()); |
| 6693 | Record.AddSourceLocation(C->getSecondScheduleModifierLoc()); |
| 6694 | Record.AddSourceLocation(C->getScheduleKindLoc()); |
| 6695 | Record.AddSourceLocation(C->getCommaLoc()); |
| 6696 | } |
| 6697 | |
| 6698 | void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) { |
| 6699 | Record.push_back(C->getLoopNumIterations().size()); |
| 6700 | Record.AddStmt(C->getNumForLoops()); |
| 6701 | for (Expr *NumIter : C->getLoopNumIterations()) |
| 6702 | Record.AddStmt(NumIter); |
| 6703 | for (unsigned I = 0, E = C->getLoopNumIterations().size(); I <E; ++I) |
Mike Rice | 0ed4666 | 2018-09-20 17:19:41 +0000 | [diff] [blame] | 6704 | Record.AddStmt(C->getLoopCounter(I)); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6705 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6706 | } |
| 6707 | |
| 6708 | void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {} |
| 6709 | |
| 6710 | void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {} |
| 6711 | |
| 6712 | void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {} |
| 6713 | |
| 6714 | void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {} |
| 6715 | |
| 6716 | void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {} |
| 6717 | |
| 6718 | void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {} |
| 6719 | |
| 6720 | void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {} |
| 6721 | |
| 6722 | void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {} |
| 6723 | |
| 6724 | void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {} |
| 6725 | |
| 6726 | void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {} |
| 6727 | |
| 6728 | void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {} |
| 6729 | |
| 6730 | void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) { |
| 6731 | Record.push_back(C->varlist_size()); |
| 6732 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6733 | for (auto *VE : C->varlists()) { |
| 6734 | Record.AddStmt(VE); |
| 6735 | } |
| 6736 | for (auto *VE : C->private_copies()) { |
| 6737 | Record.AddStmt(VE); |
| 6738 | } |
| 6739 | } |
| 6740 | |
| 6741 | void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) { |
| 6742 | Record.push_back(C->varlist_size()); |
| 6743 | VisitOMPClauseWithPreInit(C); |
| 6744 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6745 | for (auto *VE : C->varlists()) { |
| 6746 | Record.AddStmt(VE); |
| 6747 | } |
| 6748 | for (auto *VE : C->private_copies()) { |
| 6749 | Record.AddStmt(VE); |
| 6750 | } |
| 6751 | for (auto *VE : C->inits()) { |
| 6752 | Record.AddStmt(VE); |
| 6753 | } |
| 6754 | } |
| 6755 | |
| 6756 | void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) { |
| 6757 | Record.push_back(C->varlist_size()); |
| 6758 | VisitOMPClauseWithPostUpdate(C); |
| 6759 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6760 | for (auto *VE : C->varlists()) |
| 6761 | Record.AddStmt(VE); |
| 6762 | for (auto *E : C->private_copies()) |
| 6763 | Record.AddStmt(E); |
| 6764 | for (auto *E : C->source_exprs()) |
| 6765 | Record.AddStmt(E); |
| 6766 | for (auto *E : C->destination_exprs()) |
| 6767 | Record.AddStmt(E); |
| 6768 | for (auto *E : C->assignment_ops()) |
| 6769 | Record.AddStmt(E); |
| 6770 | } |
| 6771 | |
| 6772 | void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) { |
| 6773 | Record.push_back(C->varlist_size()); |
| 6774 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6775 | for (auto *VE : C->varlists()) |
| 6776 | Record.AddStmt(VE); |
| 6777 | } |
| 6778 | |
| 6779 | void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) { |
| 6780 | Record.push_back(C->varlist_size()); |
| 6781 | VisitOMPClauseWithPostUpdate(C); |
| 6782 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6783 | Record.AddSourceLocation(C->getColonLoc()); |
| 6784 | Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); |
| 6785 | Record.AddDeclarationNameInfo(C->getNameInfo()); |
| 6786 | for (auto *VE : C->varlists()) |
| 6787 | Record.AddStmt(VE); |
| 6788 | for (auto *VE : C->privates()) |
| 6789 | Record.AddStmt(VE); |
| 6790 | for (auto *E : C->lhs_exprs()) |
| 6791 | Record.AddStmt(E); |
| 6792 | for (auto *E : C->rhs_exprs()) |
| 6793 | Record.AddStmt(E); |
| 6794 | for (auto *E : C->reduction_ops()) |
| 6795 | Record.AddStmt(E); |
| 6796 | } |
| 6797 | |
| 6798 | void OMPClauseWriter::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) { |
| 6799 | Record.push_back(C->varlist_size()); |
| 6800 | VisitOMPClauseWithPostUpdate(C); |
| 6801 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6802 | Record.AddSourceLocation(C->getColonLoc()); |
| 6803 | Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); |
| 6804 | Record.AddDeclarationNameInfo(C->getNameInfo()); |
| 6805 | for (auto *VE : C->varlists()) |
| 6806 | Record.AddStmt(VE); |
| 6807 | for (auto *VE : C->privates()) |
| 6808 | Record.AddStmt(VE); |
| 6809 | for (auto *E : C->lhs_exprs()) |
| 6810 | Record.AddStmt(E); |
| 6811 | for (auto *E : C->rhs_exprs()) |
| 6812 | Record.AddStmt(E); |
| 6813 | for (auto *E : C->reduction_ops()) |
| 6814 | Record.AddStmt(E); |
| 6815 | } |
| 6816 | |
| 6817 | void OMPClauseWriter::VisitOMPInReductionClause(OMPInReductionClause *C) { |
| 6818 | Record.push_back(C->varlist_size()); |
| 6819 | VisitOMPClauseWithPostUpdate(C); |
| 6820 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6821 | Record.AddSourceLocation(C->getColonLoc()); |
| 6822 | Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); |
| 6823 | Record.AddDeclarationNameInfo(C->getNameInfo()); |
| 6824 | for (auto *VE : C->varlists()) |
| 6825 | Record.AddStmt(VE); |
| 6826 | for (auto *VE : C->privates()) |
| 6827 | Record.AddStmt(VE); |
| 6828 | for (auto *E : C->lhs_exprs()) |
| 6829 | Record.AddStmt(E); |
| 6830 | for (auto *E : C->rhs_exprs()) |
| 6831 | Record.AddStmt(E); |
| 6832 | for (auto *E : C->reduction_ops()) |
| 6833 | Record.AddStmt(E); |
| 6834 | for (auto *E : C->taskgroup_descriptors()) |
| 6835 | Record.AddStmt(E); |
| 6836 | } |
| 6837 | |
| 6838 | void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) { |
| 6839 | Record.push_back(C->varlist_size()); |
| 6840 | VisitOMPClauseWithPostUpdate(C); |
| 6841 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6842 | Record.AddSourceLocation(C->getColonLoc()); |
| 6843 | Record.push_back(C->getModifier()); |
| 6844 | Record.AddSourceLocation(C->getModifierLoc()); |
| 6845 | for (auto *VE : C->varlists()) { |
| 6846 | Record.AddStmt(VE); |
| 6847 | } |
| 6848 | for (auto *VE : C->privates()) { |
| 6849 | Record.AddStmt(VE); |
| 6850 | } |
| 6851 | for (auto *VE : C->inits()) { |
| 6852 | Record.AddStmt(VE); |
| 6853 | } |
| 6854 | for (auto *VE : C->updates()) { |
| 6855 | Record.AddStmt(VE); |
| 6856 | } |
| 6857 | for (auto *VE : C->finals()) { |
| 6858 | Record.AddStmt(VE); |
| 6859 | } |
| 6860 | Record.AddStmt(C->getStep()); |
| 6861 | Record.AddStmt(C->getCalcStep()); |
Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 6862 | for (auto *VE : C->used_expressions()) |
| 6863 | Record.AddStmt(VE); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6864 | } |
| 6865 | |
| 6866 | void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) { |
| 6867 | Record.push_back(C->varlist_size()); |
| 6868 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6869 | Record.AddSourceLocation(C->getColonLoc()); |
| 6870 | for (auto *VE : C->varlists()) |
| 6871 | Record.AddStmt(VE); |
| 6872 | Record.AddStmt(C->getAlignment()); |
| 6873 | } |
| 6874 | |
| 6875 | void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) { |
| 6876 | Record.push_back(C->varlist_size()); |
| 6877 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6878 | for (auto *VE : C->varlists()) |
| 6879 | Record.AddStmt(VE); |
| 6880 | for (auto *E : C->source_exprs()) |
| 6881 | Record.AddStmt(E); |
| 6882 | for (auto *E : C->destination_exprs()) |
| 6883 | Record.AddStmt(E); |
| 6884 | for (auto *E : C->assignment_ops()) |
| 6885 | Record.AddStmt(E); |
| 6886 | } |
| 6887 | |
| 6888 | void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 6889 | Record.push_back(C->varlist_size()); |
| 6890 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6891 | for (auto *VE : C->varlists()) |
| 6892 | Record.AddStmt(VE); |
| 6893 | for (auto *E : C->source_exprs()) |
| 6894 | Record.AddStmt(E); |
| 6895 | for (auto *E : C->destination_exprs()) |
| 6896 | Record.AddStmt(E); |
| 6897 | for (auto *E : C->assignment_ops()) |
| 6898 | Record.AddStmt(E); |
| 6899 | } |
| 6900 | |
| 6901 | void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) { |
| 6902 | Record.push_back(C->varlist_size()); |
| 6903 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6904 | for (auto *VE : C->varlists()) |
| 6905 | Record.AddStmt(VE); |
| 6906 | } |
| 6907 | |
| 6908 | void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) { |
| 6909 | Record.push_back(C->varlist_size()); |
| 6910 | Record.push_back(C->getNumLoops()); |
| 6911 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6912 | Record.push_back(C->getDependencyKind()); |
| 6913 | Record.AddSourceLocation(C->getDependencyLoc()); |
| 6914 | Record.AddSourceLocation(C->getColonLoc()); |
| 6915 | for (auto *VE : C->varlists()) |
| 6916 | Record.AddStmt(VE); |
| 6917 | for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I) |
| 6918 | Record.AddStmt(C->getLoopData(I)); |
| 6919 | } |
| 6920 | |
| 6921 | void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) { |
| 6922 | VisitOMPClauseWithPreInit(C); |
| 6923 | Record.AddStmt(C->getDevice()); |
| 6924 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6925 | } |
| 6926 | |
| 6927 | void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) { |
| 6928 | Record.push_back(C->varlist_size()); |
| 6929 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 6930 | Record.push_back(C->getTotalComponentListNum()); |
| 6931 | Record.push_back(C->getTotalComponentsNum()); |
| 6932 | Record.AddSourceLocation(C->getLParenLoc()); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 6933 | for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) { |
| 6934 | Record.push_back(C->getMapTypeModifier(I)); |
| 6935 | Record.AddSourceLocation(C->getMapTypeModifierLoc(I)); |
| 6936 | } |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 6937 | Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc()); |
| 6938 | Record.AddDeclarationNameInfo(C->getMapperIdInfo()); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6939 | Record.push_back(C->getMapType()); |
| 6940 | Record.AddSourceLocation(C->getMapLoc()); |
| 6941 | Record.AddSourceLocation(C->getColonLoc()); |
| 6942 | for (auto *E : C->varlists()) |
| 6943 | Record.AddStmt(E); |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 6944 | for (auto *E : C->mapperlists()) |
| 6945 | Record.AddStmt(E); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6946 | for (auto *D : C->all_decls()) |
| 6947 | Record.AddDeclRef(D); |
| 6948 | for (auto N : C->all_num_lists()) |
| 6949 | Record.push_back(N); |
| 6950 | for (auto N : C->all_lists_sizes()) |
| 6951 | Record.push_back(N); |
| 6952 | for (auto &M : C->all_components()) { |
| 6953 | Record.AddStmt(M.getAssociatedExpression()); |
| 6954 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 6955 | } |
| 6956 | } |
| 6957 | |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 6958 | void OMPClauseWriter::VisitOMPAllocateClause(OMPAllocateClause *C) { |
| 6959 | Record.push_back(C->varlist_size()); |
| 6960 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6961 | Record.AddSourceLocation(C->getColonLoc()); |
| 6962 | Record.AddStmt(C->getAllocator()); |
| 6963 | for (auto *VE : C->varlists()) |
| 6964 | Record.AddStmt(VE); |
| 6965 | } |
| 6966 | |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6967 | void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 6968 | VisitOMPClauseWithPreInit(C); |
| 6969 | Record.AddStmt(C->getNumTeams()); |
| 6970 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6971 | } |
| 6972 | |
| 6973 | void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 6974 | VisitOMPClauseWithPreInit(C); |
| 6975 | Record.AddStmt(C->getThreadLimit()); |
| 6976 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6977 | } |
| 6978 | |
| 6979 | void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) { |
| 6980 | Record.AddStmt(C->getPriority()); |
| 6981 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6982 | } |
| 6983 | |
| 6984 | void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) { |
Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 6985 | VisitOMPClauseWithPreInit(C); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6986 | Record.AddStmt(C->getGrainsize()); |
| 6987 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6988 | } |
| 6989 | |
| 6990 | void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) { |
Alexey Bataev | d88c7de | 2019-10-14 20:44:34 +0000 | [diff] [blame] | 6991 | VisitOMPClauseWithPreInit(C); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6992 | Record.AddStmt(C->getNumTasks()); |
| 6993 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6994 | } |
| 6995 | |
| 6996 | void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) { |
| 6997 | Record.AddStmt(C->getHint()); |
| 6998 | Record.AddSourceLocation(C->getLParenLoc()); |
| 6999 | } |
| 7000 | |
| 7001 | void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) { |
| 7002 | VisitOMPClauseWithPreInit(C); |
| 7003 | Record.push_back(C->getDistScheduleKind()); |
| 7004 | Record.AddStmt(C->getChunkSize()); |
| 7005 | Record.AddSourceLocation(C->getLParenLoc()); |
| 7006 | Record.AddSourceLocation(C->getDistScheduleKindLoc()); |
| 7007 | Record.AddSourceLocation(C->getCommaLoc()); |
| 7008 | } |
| 7009 | |
| 7010 | void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 7011 | Record.push_back(C->getDefaultmapKind()); |
| 7012 | Record.push_back(C->getDefaultmapModifier()); |
| 7013 | Record.AddSourceLocation(C->getLParenLoc()); |
| 7014 | Record.AddSourceLocation(C->getDefaultmapModifierLoc()); |
| 7015 | Record.AddSourceLocation(C->getDefaultmapKindLoc()); |
| 7016 | } |
| 7017 | |
| 7018 | void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) { |
| 7019 | Record.push_back(C->varlist_size()); |
| 7020 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 7021 | Record.push_back(C->getTotalComponentListNum()); |
| 7022 | Record.push_back(C->getTotalComponentsNum()); |
| 7023 | Record.AddSourceLocation(C->getLParenLoc()); |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 7024 | Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc()); |
| 7025 | Record.AddDeclarationNameInfo(C->getMapperIdInfo()); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 7026 | for (auto *E : C->varlists()) |
| 7027 | Record.AddStmt(E); |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 7028 | for (auto *E : C->mapperlists()) |
| 7029 | Record.AddStmt(E); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 7030 | for (auto *D : C->all_decls()) |
| 7031 | Record.AddDeclRef(D); |
| 7032 | for (auto N : C->all_num_lists()) |
| 7033 | Record.push_back(N); |
| 7034 | for (auto N : C->all_lists_sizes()) |
| 7035 | Record.push_back(N); |
| 7036 | for (auto &M : C->all_components()) { |
| 7037 | Record.AddStmt(M.getAssociatedExpression()); |
| 7038 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 7039 | } |
| 7040 | } |
| 7041 | |
| 7042 | void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) { |
| 7043 | Record.push_back(C->varlist_size()); |
| 7044 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 7045 | Record.push_back(C->getTotalComponentListNum()); |
| 7046 | Record.push_back(C->getTotalComponentsNum()); |
| 7047 | Record.AddSourceLocation(C->getLParenLoc()); |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 7048 | Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc()); |
| 7049 | Record.AddDeclarationNameInfo(C->getMapperIdInfo()); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 7050 | for (auto *E : C->varlists()) |
| 7051 | Record.AddStmt(E); |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 7052 | for (auto *E : C->mapperlists()) |
| 7053 | Record.AddStmt(E); |
Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 7054 | for (auto *D : C->all_decls()) |
| 7055 | Record.AddDeclRef(D); |
| 7056 | for (auto N : C->all_num_lists()) |
| 7057 | Record.push_back(N); |
| 7058 | for (auto N : C->all_lists_sizes()) |
| 7059 | Record.push_back(N); |
| 7060 | for (auto &M : C->all_components()) { |
| 7061 | Record.AddStmt(M.getAssociatedExpression()); |
| 7062 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 7063 | } |
| 7064 | } |
| 7065 | |
| 7066 | void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) { |
| 7067 | Record.push_back(C->varlist_size()); |
| 7068 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 7069 | Record.push_back(C->getTotalComponentListNum()); |
| 7070 | Record.push_back(C->getTotalComponentsNum()); |
| 7071 | Record.AddSourceLocation(C->getLParenLoc()); |
| 7072 | for (auto *E : C->varlists()) |
| 7073 | Record.AddStmt(E); |
| 7074 | for (auto *VE : C->private_copies()) |
| 7075 | Record.AddStmt(VE); |
| 7076 | for (auto *VE : C->inits()) |
| 7077 | Record.AddStmt(VE); |
| 7078 | for (auto *D : C->all_decls()) |
| 7079 | Record.AddDeclRef(D); |
| 7080 | for (auto N : C->all_num_lists()) |
| 7081 | Record.push_back(N); |
| 7082 | for (auto N : C->all_lists_sizes()) |
| 7083 | Record.push_back(N); |
| 7084 | for (auto &M : C->all_components()) { |
| 7085 | Record.AddStmt(M.getAssociatedExpression()); |
| 7086 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 7087 | } |
| 7088 | } |
| 7089 | |
| 7090 | void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { |
| 7091 | Record.push_back(C->varlist_size()); |
| 7092 | Record.push_back(C->getUniqueDeclarationsNum()); |
| 7093 | Record.push_back(C->getTotalComponentListNum()); |
| 7094 | Record.push_back(C->getTotalComponentsNum()); |
| 7095 | Record.AddSourceLocation(C->getLParenLoc()); |
| 7096 | for (auto *E : C->varlists()) |
| 7097 | Record.AddStmt(E); |
| 7098 | for (auto *D : C->all_decls()) |
| 7099 | Record.AddDeclRef(D); |
| 7100 | for (auto N : C->all_num_lists()) |
| 7101 | Record.push_back(N); |
| 7102 | for (auto N : C->all_lists_sizes()) |
| 7103 | Record.push_back(N); |
| 7104 | for (auto &M : C->all_components()) { |
| 7105 | Record.AddStmt(M.getAssociatedExpression()); |
| 7106 | Record.AddDeclRef(M.getAssociatedDeclaration()); |
| 7107 | } |
| 7108 | } |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 7109 | |
| 7110 | void OMPClauseWriter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {} |
Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 7111 | |
| 7112 | void OMPClauseWriter::VisitOMPUnifiedSharedMemoryClause( |
| 7113 | OMPUnifiedSharedMemoryClause *) {} |
Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 7114 | |
| 7115 | void OMPClauseWriter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {} |
Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 7116 | |
| 7117 | void |
| 7118 | OMPClauseWriter::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) { |
| 7119 | } |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 7120 | |
| 7121 | void OMPClauseWriter::VisitOMPAtomicDefaultMemOrderClause( |
| 7122 | OMPAtomicDefaultMemOrderClause *C) { |
| 7123 | Record.push_back(C->getAtomicDefaultMemOrderKind()); |
| 7124 | Record.AddSourceLocation(C->getLParenLoc()); |
| 7125 | Record.AddSourceLocation(C->getAtomicDefaultMemOrderKindKwLoc()); |
| 7126 | } |