Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1 | //===--- ASTWriter.cpp - AST File Writer ------------------------*- C++ -*-===// |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 10 | // This file defines the ASTWriter class, which writes AST files. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sebastian Redl | 1914c6f | 2010-08-18 23:56:37 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTWriter.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 16 | #include "ASTReaderInternals.h" |
| 17 | #include "MultiOnDiskHashTable.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTUnresolvedSet.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclContextInternals.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclCXX.h" |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclFriend.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 25 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprCXX.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 27 | #include "clang/AST/LambdaCapture.h" |
| 28 | #include "clang/AST/NestedNameSpecifier.h" |
| 29 | #include "clang/AST/RawCommentList.h" |
| 30 | #include "clang/AST/TemplateName.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 31 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 32 | #include "clang/AST/TypeLocVisitor.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 33 | #include "clang/Basic/DiagnosticOptions.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 34 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 35 | #include "clang/Basic/FileSystemOptions.h" |
| 36 | #include "clang/Basic/LangOptions.h" |
| 37 | #include "clang/Basic/LLVM.h" |
| 38 | #include "clang/Basic/Module.h" |
| 39 | #include "clang/Basic/ObjCRuntime.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 40 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 41 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 42 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | cb177f1 | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 43 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 44 | #include "clang/Basic/Version.h" |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 45 | #include "clang/Basic/VersionTuple.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 46 | #include "clang/Lex/HeaderSearch.h" |
| 47 | #include "clang/Lex/HeaderSearchOptions.h" |
| 48 | #include "clang/Lex/MacroInfo.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 49 | #include "clang/Lex/ModuleMap.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 50 | #include "clang/Lex/PreprocessingRecord.h" |
| 51 | #include "clang/Lex/Preprocessor.h" |
| 52 | #include "clang/Lex/PreprocessorOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 53 | #include "clang/Lex/Token.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 54 | #include "clang/Sema/IdentifierResolver.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 55 | #include "clang/Sema/ObjCMethodList.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 56 | #include "clang/Sema/Sema.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 57 | #include "clang/Sema/Weak.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 58 | #include "clang/Serialization/ASTReader.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 59 | #include "clang/Serialization/Module.h" |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 60 | #include "clang/Serialization/ModuleFileExtension.h" |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 61 | #include "clang/Serialization/SerializationDiagnostic.h" |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 62 | #include "llvm/ADT/APFloat.h" |
| 63 | #include "llvm/ADT/APInt.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 64 | #include "llvm/ADT/Hashing.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 65 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 66 | #include "llvm/ADT/Optional.h" |
| 67 | #include "llvm/ADT/SmallSet.h" |
| 68 | #include "llvm/ADT/SmallString.h" |
| 69 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 70 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 71 | #include "llvm/Bitcode/BitCodes.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 72 | #include "llvm/Bitcode/BitstreamWriter.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 73 | #include "llvm/Support/Casting.h" |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 74 | #include "llvm/Support/Compression.h" |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 75 | #include "llvm/Support/EndianStream.h" |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame^] | 76 | #include "llvm/Support/Error.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 77 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 78 | #include "llvm/Support/MemoryBuffer.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 79 | #include "llvm/Support/OnDiskHashTable.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 80 | #include "llvm/Support/Path.h" |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 81 | #include "llvm/Support/Process.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 82 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 83 | #include <algorithm> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 84 | #include <cassert> |
| 85 | #include <cstdint> |
| 86 | #include <cstdlib> |
| 87 | #include <cstring> |
| 88 | #include <deque> |
| 89 | #include <limits> |
| 90 | #include <new> |
| 91 | #include <tuple> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 92 | #include <utility> |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 93 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 94 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 95 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 96 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 97 | template <typename T, typename Allocator> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 98 | static StringRef bytes(const std::vector<T, Allocator> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 99 | if (v.empty()) return StringRef(); |
| 100 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 101 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 102 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 103 | |
| 104 | template <typename T> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 105 | static StringRef bytes(const SmallVectorImpl<T> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 106 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 107 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 110 | //===----------------------------------------------------------------------===// |
| 111 | // Type serialization |
| 112 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 113 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 114 | namespace clang { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 115 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 116 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 117 | ASTWriter &Writer; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 118 | ASTRecordWriter Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 119 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 120 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 121 | TypeCode Code; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 122 | /// \brief Abbreviation to use for the record, if any. |
| 123 | unsigned AbbrevToUse; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 124 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 125 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 126 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 127 | : Writer(Writer), Record(Writer, Record), Code((TypeCode)0), AbbrevToUse(0) { } |
| 128 | |
| 129 | uint64_t Emit() { |
| 130 | return Record.Emit(Code, AbbrevToUse); |
| 131 | } |
| 132 | |
| 133 | void Visit(QualType T) { |
| 134 | if (T.hasLocalNonFastQualifiers()) { |
| 135 | Qualifiers Qs = T.getLocalQualifiers(); |
| 136 | Record.AddTypeRef(T.getLocalUnqualifiedType()); |
| 137 | Record.push_back(Qs.getAsOpaqueValue()); |
| 138 | Code = TYPE_EXT_QUAL; |
| 139 | AbbrevToUse = Writer.TypeExtQualAbbrev; |
| 140 | } else { |
| 141 | switch (T->getTypeClass()) { |
| 142 | // For all of the concrete, non-dependent types, call the |
| 143 | // appropriate visitor function. |
| 144 | #define TYPE(Class, Base) \ |
| 145 | case Type::Class: Visit##Class##Type(cast<Class##Type>(T)); break; |
| 146 | #define ABSTRACT_TYPE(Class, Base) |
| 147 | #include "clang/AST/TypeNodes.def" |
| 148 | } |
| 149 | } |
| 150 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 151 | |
| 152 | void VisitArrayType(const ArrayType *T); |
| 153 | void VisitFunctionType(const FunctionType *T); |
| 154 | void VisitTagType(const TagType *T); |
| 155 | |
| 156 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 157 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 158 | #include "clang/AST/TypeNodes.def" |
| 159 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 160 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 161 | } // end namespace clang |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 162 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 163 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 164 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 167 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 168 | Record.AddTypeRef(T->getElementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 169 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 172 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 173 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 174 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 177 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 178 | Record.AddTypeRef(T->getOriginalType()); |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 179 | Code = TYPE_DECAYED; |
| 180 | } |
| 181 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 182 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 183 | Record.AddTypeRef(T->getOriginalType()); |
| 184 | Record.AddTypeRef(T->getAdjustedType()); |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 185 | Code = TYPE_ADJUSTED; |
| 186 | } |
| 187 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 188 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 189 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 190 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 193 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 194 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 195 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 196 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 199 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 200 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 201 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 204 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 205 | Record.AddTypeRef(T->getPointeeType()); |
| 206 | Record.AddTypeRef(QualType(T->getClass(), 0)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 207 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 210 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 211 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 212 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 213 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 216 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 217 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 218 | Record.AddAPInt(T->getSize()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 219 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 222 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 223 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 224 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 227 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 228 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 229 | Record.AddSourceLocation(T->getLBracketLoc()); |
| 230 | Record.AddSourceLocation(T->getRBracketLoc()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 231 | Record.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 232 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 235 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 236 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 237 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 238 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 239 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 242 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 243 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 244 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 247 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 248 | Record.AddTypeRef(T->getReturnType()); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 249 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 250 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 251 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 252 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 253 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 254 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 255 | Record.push_back(C.getProducesResult()); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 256 | |
| 257 | if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult()) |
| 258 | AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 261 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 262 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 263 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 266 | static void addExceptionSpec(const FunctionProtoType *T, |
| 267 | ASTRecordWriter &Record) { |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 268 | Record.push_back(T->getExceptionSpecType()); |
| 269 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 270 | Record.push_back(T->getNumExceptions()); |
| 271 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 272 | Record.AddTypeRef(T->getExceptionType(I)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 273 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 274 | Record.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 275 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 276 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
| 277 | Record.AddDeclRef(T->getExceptionSpecTemplate()); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 278 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 279 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 280 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 284 | VisitFunctionType(T); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 285 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 286 | Record.push_back(T->isVariadic()); |
| 287 | Record.push_back(T->hasTrailingReturn()); |
| 288 | Record.push_back(T->getTypeQuals()); |
| 289 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 290 | addExceptionSpec(T, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 291 | |
| 292 | Record.push_back(T->getNumParams()); |
| 293 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 294 | Record.AddTypeRef(T->getParamType(I)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 295 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 296 | if (T->hasExtParameterInfos()) { |
| 297 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 298 | Record.push_back(T->getExtParameterInfo(I).getOpaqueValue()); |
| 299 | } |
| 300 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 301 | if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 302 | T->getRefQualifier() || T->getExceptionSpecType() != EST_None || |
| 303 | T->hasExtParameterInfos()) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 304 | AbbrevToUse = 0; |
| 305 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 306 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 309 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 310 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 311 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 312 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 313 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 314 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 315 | Record.AddDeclRef(T->getDecl()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 316 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 317 | Record.AddTypeRef(T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 318 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 321 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 322 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 323 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 326 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 327 | Record.AddTypeRef(T->getUnderlyingType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 328 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 331 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 332 | Record.AddTypeRef(T->getUnderlyingType()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 333 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 334 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 337 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 338 | Record.AddTypeRef(T->getBaseType()); |
| 339 | Record.AddTypeRef(T->getUnderlyingType()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 340 | Record.push_back(T->getUTTKind()); |
| 341 | Code = TYPE_UNARY_TRANSFORM; |
| 342 | } |
| 343 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 344 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 345 | Record.AddTypeRef(T->getDeducedType()); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 346 | Record.push_back((unsigned)T->getKeyword()); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 347 | if (T->getDeducedType().isNull()) |
| 348 | Record.push_back(T->isDependentType()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 349 | Code = TYPE_AUTO; |
| 350 | } |
| 351 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 352 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 353 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 354 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 356 | "Cannot serialize in the middle of a type definition"); |
| 357 | } |
| 358 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 359 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 360 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 361 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 364 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 365 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 366 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 367 | } |
| 368 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 369 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 370 | Record.AddTypeRef(T->getModifiedType()); |
| 371 | Record.AddTypeRef(T->getEquivalentType()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 372 | Record.push_back(T->getAttrKind()); |
| 373 | Code = TYPE_ATTRIBUTED; |
| 374 | } |
| 375 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 376 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 377 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 378 | const SubstTemplateTypeParmType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 379 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 380 | Record.AddTypeRef(T->getReplacementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 381 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 385 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 386 | const SubstTemplateTypeParmPackType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 387 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 388 | Record.AddTemplateArgument(T->getArgumentPack()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 389 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 390 | } |
| 391 | |
| 392 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 393 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 394 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 395 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 396 | Record.AddTemplateName(T->getTemplateName()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 397 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 398 | for (const auto &ArgI : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 399 | Record.AddTemplateArgument(ArgI); |
| 400 | Record.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() |
| 401 | : T->isCanonicalUnqualified() |
| 402 | ? QualType() |
| 403 | : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 404 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 408 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 409 | VisitArrayType(T); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 410 | Record.AddStmt(T->getSizeExpr()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 411 | Record.AddSourceRange(T->getBracketsRange()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 412 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 416 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 417 | const DependentSizedExtVectorType *T) { |
| 418 | // FIXME: Serialize this type (C++ only) |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 419 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 423 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 424 | Record.push_back(T->getDepth()); |
| 425 | Record.push_back(T->getIndex()); |
| 426 | Record.push_back(T->isParameterPack()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 427 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 428 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 432 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 433 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 434 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 435 | Record.AddIdentifierRef(T->getIdentifier()); |
| 436 | Record.AddTypeRef( |
| 437 | T->isCanonicalUnqualified() ? QualType() : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 438 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 442 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 443 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 444 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 445 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 446 | Record.AddIdentifierRef(T->getIdentifier()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 447 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 448 | for (const auto &I : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 449 | Record.AddTemplateArgument(I); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 450 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 453 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 454 | Record.AddTypeRef(T->getPattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 455 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 456 | Record.push_back(*NumExpansions + 1); |
| 457 | else |
| 458 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 459 | Code = TYPE_PACK_EXPANSION; |
| 460 | } |
| 461 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 462 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 463 | Record.AddTypeRef(T->getInnerType()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 464 | Code = TYPE_PAREN; |
| 465 | } |
| 466 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 467 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 468 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 469 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 470 | Record.AddTypeRef(T->getNamedType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 471 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 474 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 475 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
| 476 | Record.AddTypeRef(T->getInjectedSpecializationType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 477 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 480 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 481 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 482 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 485 | void ASTTypeWriter::VisitObjCTypeParamType(const ObjCTypeParamType *T) { |
| 486 | Record.AddDeclRef(T->getDecl()); |
| 487 | Record.push_back(T->getNumProtocols()); |
| 488 | for (const auto *I : T->quals()) |
| 489 | Record.AddDeclRef(I); |
| 490 | Code = TYPE_OBJC_TYPE_PARAM; |
| 491 | } |
| 492 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 493 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 494 | Record.AddTypeRef(T->getBaseType()); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 495 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 496 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 497 | Record.AddTypeRef(TypeArg); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 498 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 499 | for (const auto *I : T->quals()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 500 | Record.AddDeclRef(I); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 501 | Record.push_back(T->isKindOfTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 502 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 505 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 506 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 507 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 508 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 511 | void |
| 512 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 513 | Record.AddTypeRef(T->getValueType()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 514 | Code = TYPE_ATOMIC; |
| 515 | } |
| 516 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 517 | void |
| 518 | ASTTypeWriter::VisitPipeType(const PipeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 519 | Record.AddTypeRef(T->getElementType()); |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 520 | Record.push_back(T->isReadOnly()); |
| 521 | Code = TYPE_PIPE; |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 522 | } |
| 523 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 524 | namespace { |
| 525 | |
| 526 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 527 | ASTRecordWriter &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 528 | |
| 529 | public: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 530 | TypeLocWriter(ASTRecordWriter &Record) |
| 531 | : Record(Record) { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 532 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 533 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 534 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 535 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 536 | #include "clang/AST/TypeLocNodes.def" |
| 537 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 538 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 539 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 540 | }; |
| 541 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 542 | } // end anonymous namespace |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 543 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 544 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 545 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 546 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 547 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 548 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 549 | Record.AddSourceLocation(TL.getBuiltinLoc()); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 550 | if (TL.needsExtraLocalData()) { |
| 551 | Record.push_back(TL.getWrittenTypeSpec()); |
| 552 | Record.push_back(TL.getWrittenSignSpec()); |
| 553 | Record.push_back(TL.getWrittenWidthSpec()); |
| 554 | Record.push_back(TL.hasModeAttr()); |
| 555 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 556 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 557 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 558 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 559 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 560 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 561 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 562 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 563 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 564 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 565 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 566 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 567 | // nothing to do |
| 568 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 569 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 570 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 571 | // nothing to do |
| 572 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 573 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 574 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 575 | Record.AddSourceLocation(TL.getCaretLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 576 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 577 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 578 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 579 | Record.AddSourceLocation(TL.getAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 580 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 581 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 582 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 583 | Record.AddSourceLocation(TL.getAmpAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 584 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 585 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 586 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 587 | Record.AddSourceLocation(TL.getStarLoc()); |
| 588 | Record.AddTypeSourceInfo(TL.getClassTInfo()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 589 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 590 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 591 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 592 | Record.AddSourceLocation(TL.getLBracketLoc()); |
| 593 | Record.AddSourceLocation(TL.getRBracketLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 594 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 595 | if (TL.getSizeExpr()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 596 | Record.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 597 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 598 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 599 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 600 | VisitArrayTypeLoc(TL); |
| 601 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 602 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 603 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 604 | VisitArrayTypeLoc(TL); |
| 605 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 606 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 607 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 608 | VisitArrayTypeLoc(TL); |
| 609 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 610 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 611 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 612 | DependentSizedArrayTypeLoc TL) { |
| 613 | VisitArrayTypeLoc(TL); |
| 614 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 615 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 616 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 617 | DependentSizedExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 618 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 619 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 620 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 621 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 622 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 623 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 624 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 625 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 626 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 627 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 628 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 629 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 630 | Record.AddSourceLocation(TL.getLocalRangeBegin()); |
| 631 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 632 | Record.AddSourceLocation(TL.getRParenLoc()); |
Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 633 | Record.AddSourceRange(TL.getExceptionSpecRange()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 634 | Record.AddSourceLocation(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 635 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 636 | Record.AddDeclRef(TL.getParam(i)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 637 | } |
| 638 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 639 | VisitFunctionTypeLoc(TL); |
| 640 | } |
| 641 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 642 | VisitFunctionTypeLoc(TL); |
| 643 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 644 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 645 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 646 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 647 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 648 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 649 | } |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 650 | void TypeLocWriter::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 651 | if (TL.getNumProtocols()) { |
| 652 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 653 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
| 654 | } |
| 655 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 656 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
| 657 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 658 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 659 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 660 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 661 | Record.AddSourceLocation(TL.getRParenLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 662 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 663 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 664 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 665 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 666 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 667 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 668 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 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::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 672 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 673 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 674 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 675 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 676 | Record.AddSourceLocation(TL.getKWLoc()); |
| 677 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 678 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 679 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 680 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 681 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 682 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 683 | Record.AddSourceLocation(TL.getNameLoc()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 684 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 685 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 686 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc 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::VisitEnumTypeLoc(EnumTypeLoc 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 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 694 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 695 | Record.AddSourceLocation(TL.getAttrNameLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 696 | if (TL.hasAttrOperand()) { |
| 697 | SourceRange range = TL.getAttrOperandParensRange(); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 698 | Record.AddSourceLocation(range.getBegin()); |
| 699 | Record.AddSourceLocation(range.getEnd()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 700 | } |
| 701 | if (TL.hasAttrExprOperand()) { |
| 702 | Expr *operand = TL.getAttrExprOperand(); |
| 703 | Record.push_back(operand ? 1 : 0); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 704 | if (operand) Record.AddStmt(operand); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 705 | } else if (TL.hasAttrEnumOperand()) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 706 | Record.AddSourceLocation(TL.getAttrEnumOperandLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 707 | } |
| 708 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 709 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 710 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 711 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 712 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 713 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 714 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 715 | SubstTemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 716 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 717 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 718 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 719 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 720 | SubstTemplateTypeParmPackTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 721 | Record.AddSourceLocation(TL.getNameLoc()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 722 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 723 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 724 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 725 | TemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 726 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 727 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 728 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 729 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 730 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 731 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 732 | TL.getArgLoc(i).getLocInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 733 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 734 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 735 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 736 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 737 | Record.AddSourceLocation(TL.getRParenLoc()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 738 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 739 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 740 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 741 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 742 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 743 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 744 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 745 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 746 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 747 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 748 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 749 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 750 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 751 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 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 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 755 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 756 | DependentTemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 757 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 758 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 759 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 760 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 761 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 762 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 763 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 764 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 765 | TL.getArgLoc(I).getLocInfo()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 766 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 767 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 768 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 769 | Record.AddSourceLocation(TL.getEllipsisLoc()); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 770 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 771 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 772 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 773 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 774 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 775 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 776 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 777 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 778 | Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); |
| 779 | Record.AddSourceLocation(TL.getTypeArgsRAngleLoc()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 780 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 781 | Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i)); |
| 782 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 783 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 784 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 785 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 786 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 787 | |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 788 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 789 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 790 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 791 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 792 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 793 | Record.AddSourceLocation(TL.getKWLoc()); |
| 794 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 795 | Record.AddSourceLocation(TL.getRParenLoc()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 796 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 797 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 798 | void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 799 | Record.AddSourceLocation(TL.getKWLoc()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 800 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 801 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 802 | void ASTWriter::WriteTypeAbbrevs() { |
| 803 | using namespace llvm; |
| 804 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 805 | std::shared_ptr<BitCodeAbbrev> Abv; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 806 | |
| 807 | // Abbreviation for TYPE_EXT_QUAL |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 808 | Abv = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 809 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 810 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 811 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 812 | TypeExtQualAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 813 | |
| 814 | // Abbreviation for TYPE_FUNCTION_PROTO |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 815 | Abv = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 816 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 817 | // FunctionType |
| 818 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 819 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 820 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 821 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 822 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 823 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
| 824 | // FunctionProtoType |
| 825 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 826 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 827 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 828 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 829 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 830 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 831 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 832 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 833 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 836 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 837 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 838 | //===----------------------------------------------------------------------===// |
| 839 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 840 | static void EmitBlockID(unsigned ID, const char *Name, |
| 841 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 842 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 843 | Record.clear(); |
| 844 | Record.push_back(ID); |
| 845 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 846 | |
| 847 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 848 | if (!Name || Name[0] == 0) |
| 849 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 850 | Record.clear(); |
| 851 | while (*Name) |
| 852 | Record.push_back(*Name++); |
| 853 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 854 | } |
| 855 | |
| 856 | static void EmitRecordID(unsigned ID, const char *Name, |
| 857 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 858 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 859 | Record.clear(); |
| 860 | Record.push_back(ID); |
| 861 | while (*Name) |
| 862 | Record.push_back(*Name++); |
| 863 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 867 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 868 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 869 | RECORD(STMT_STOP); |
| 870 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 871 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 872 | RECORD(STMT_NULL); |
| 873 | RECORD(STMT_COMPOUND); |
| 874 | RECORD(STMT_CASE); |
| 875 | RECORD(STMT_DEFAULT); |
| 876 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 877 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 878 | RECORD(STMT_IF); |
| 879 | RECORD(STMT_SWITCH); |
| 880 | RECORD(STMT_WHILE); |
| 881 | RECORD(STMT_DO); |
| 882 | RECORD(STMT_FOR); |
| 883 | RECORD(STMT_GOTO); |
| 884 | RECORD(STMT_INDIRECT_GOTO); |
| 885 | RECORD(STMT_CONTINUE); |
| 886 | RECORD(STMT_BREAK); |
| 887 | RECORD(STMT_RETURN); |
| 888 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 889 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 890 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 891 | RECORD(EXPR_PREDEFINED); |
| 892 | RECORD(EXPR_DECL_REF); |
| 893 | RECORD(EXPR_INTEGER_LITERAL); |
| 894 | RECORD(EXPR_FLOATING_LITERAL); |
| 895 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 896 | RECORD(EXPR_STRING_LITERAL); |
| 897 | RECORD(EXPR_CHARACTER_LITERAL); |
| 898 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 899 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 900 | RECORD(EXPR_UNARY_OPERATOR); |
| 901 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 902 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 903 | RECORD(EXPR_CALL); |
| 904 | RECORD(EXPR_MEMBER); |
| 905 | RECORD(EXPR_BINARY_OPERATOR); |
| 906 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 907 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 908 | RECORD(EXPR_IMPLICIT_CAST); |
| 909 | RECORD(EXPR_CSTYLE_CAST); |
| 910 | RECORD(EXPR_COMPOUND_LITERAL); |
| 911 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 912 | RECORD(EXPR_INIT_LIST); |
| 913 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 914 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 915 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 916 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 917 | RECORD(EXPR_VA_ARG); |
| 918 | RECORD(EXPR_ADDR_LABEL); |
| 919 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 920 | RECORD(EXPR_CHOOSE); |
| 921 | RECORD(EXPR_GNU_NULL); |
| 922 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 923 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 924 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 925 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 926 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 927 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 928 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 929 | RECORD(EXPR_OBJC_ENCODE); |
| 930 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 931 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 932 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 933 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 934 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 935 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 936 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 937 | RECORD(STMT_OBJC_CATCH); |
| 938 | RECORD(STMT_OBJC_FINALLY); |
| 939 | RECORD(STMT_OBJC_AT_TRY); |
| 940 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 941 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 942 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 943 | RECORD(STMT_CXX_CATCH); |
| 944 | RECORD(STMT_CXX_TRY); |
| 945 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 946 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 947 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 948 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 949 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 950 | RECORD(EXPR_CXX_STATIC_CAST); |
| 951 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 952 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 953 | RECORD(EXPR_CXX_CONST_CAST); |
| 954 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 955 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 956 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 957 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 958 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 959 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 960 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 961 | RECORD(EXPR_CXX_THIS); |
| 962 | RECORD(EXPR_CXX_THROW); |
| 963 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 964 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 965 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 966 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 967 | RECORD(EXPR_CXX_NEW); |
| 968 | RECORD(EXPR_CXX_DELETE); |
| 969 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 970 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 971 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 972 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 973 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 974 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 975 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 976 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 977 | RECORD(EXPR_CXX_NOEXCEPT); |
| 978 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 979 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 980 | RECORD(EXPR_TYPE_TRAIT); |
| 981 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 982 | RECORD(EXPR_PACK_EXPANSION); |
| 983 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 984 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 985 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 986 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 987 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 988 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 989 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 990 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 991 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 992 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 993 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 995 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 996 | RecordData Record; |
Peter Collingbourne | d3a6c70 | 2016-11-01 01:18:57 +0000 | [diff] [blame] | 997 | Stream.EnterBlockInfoBlock(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 999 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 1000 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1002 | // Control Block. |
| 1003 | BLOCK(CONTROL_BLOCK); |
| 1004 | RECORD(METADATA); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1005 | RECORD(SIGNATURE); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1006 | RECORD(MODULE_NAME); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1007 | RECORD(MODULE_DIRECTORY); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1008 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1009 | RECORD(IMPORTS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1010 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1011 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1012 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1013 | RECORD(INPUT_FILE_OFFSETS); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1014 | |
| 1015 | BLOCK(OPTIONS_BLOCK); |
| 1016 | RECORD(LANGUAGE_OPTIONS); |
| 1017 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1018 | RECORD(DIAGNOSTIC_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1019 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1020 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1021 | RECORD(PREPROCESSOR_OPTIONS); |
| 1022 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 1023 | BLOCK(INPUT_FILES_BLOCK); |
| 1024 | RECORD(INPUT_FILE); |
| 1025 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1026 | // AST Top-Level Block. |
| 1027 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1028 | RECORD(TYPE_OFFSET); |
| 1029 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1030 | RECORD(IDENTIFIER_OFFSET); |
| 1031 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 1032 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1033 | RECORD(SPECIAL_TYPES); |
| 1034 | RECORD(STATISTICS); |
| 1035 | RECORD(TENTATIVE_DEFINITIONS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1036 | RECORD(SELECTOR_OFFSETS); |
| 1037 | RECORD(METHOD_POOL); |
| 1038 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1039 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 1040 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1041 | RECORD(EXT_VECTOR_DECLS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1042 | RECORD(UNUSED_FILESCOPED_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1043 | RECORD(PPD_ENTITIES_OFFSETS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1044 | RECORD(VTABLE_USES); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 1045 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1046 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1047 | RECORD(SEMA_DECL_REFS); |
| 1048 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 1049 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1050 | RECORD(UPDATE_VISIBLE); |
| 1051 | RECORD(DECL_UPDATE_OFFSETS); |
| 1052 | RECORD(DECL_UPDATES); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1053 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1054 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1055 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1056 | RECORD(FP_PRAGMA_OPTIONS); |
| 1057 | RECORD(OPENCL_EXTENSIONS); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 1058 | RECORD(OPENCL_EXTENSION_TYPES); |
| 1059 | RECORD(OPENCL_EXTENSION_DECLS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1060 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 1061 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 1062 | RECORD(MODULE_OFFSET_MAP); |
| 1063 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1064 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 1065 | RECORD(FILE_SORTED_DECLS); |
| 1066 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1067 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1068 | RECORD(MACRO_OFFSET); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1069 | RECORD(INTERESTING_IDENTIFIERS); |
| 1070 | RECORD(UNDEFINED_BUT_USED); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1071 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 1072 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 1073 | RECORD(MSSTRUCT_PRAGMA_OPTIONS); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 1074 | RECORD(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1075 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1076 | RECORD(DELETE_EXPRS_TO_ANALYZE); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 1077 | RECORD(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 1078 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1079 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1080 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1081 | RECORD(SM_SLOC_FILE_ENTRY); |
| 1082 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 1083 | RECORD(SM_SLOC_BUFFER_BLOB); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1084 | RECORD(SM_SLOC_BUFFER_BLOB_COMPRESSED); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1085 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1087 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1088 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1089 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1090 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1091 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 1092 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1093 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1094 | |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1095 | // Submodule Block. |
| 1096 | BLOCK(SUBMODULE_BLOCK); |
| 1097 | RECORD(SUBMODULE_METADATA); |
| 1098 | RECORD(SUBMODULE_DEFINITION); |
| 1099 | RECORD(SUBMODULE_UMBRELLA_HEADER); |
| 1100 | RECORD(SUBMODULE_HEADER); |
| 1101 | RECORD(SUBMODULE_TOPHEADER); |
| 1102 | RECORD(SUBMODULE_UMBRELLA_DIR); |
| 1103 | RECORD(SUBMODULE_IMPORTS); |
| 1104 | RECORD(SUBMODULE_EXPORTS); |
| 1105 | RECORD(SUBMODULE_REQUIRES); |
| 1106 | RECORD(SUBMODULE_EXCLUDED_HEADER); |
| 1107 | RECORD(SUBMODULE_LINK_LIBRARY); |
| 1108 | RECORD(SUBMODULE_CONFIG_MACRO); |
| 1109 | RECORD(SUBMODULE_CONFLICT); |
| 1110 | RECORD(SUBMODULE_PRIVATE_HEADER); |
| 1111 | RECORD(SUBMODULE_TEXTUAL_HEADER); |
| 1112 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 1113 | RECORD(SUBMODULE_INITIALIZERS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1114 | |
| 1115 | // Comments Block. |
| 1116 | BLOCK(COMMENTS_BLOCK); |
| 1117 | RECORD(COMMENTS_RAW_COMMENT); |
| 1118 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1119 | // Decls and Types block. |
| 1120 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1121 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1122 | RECORD(TYPE_COMPLEX); |
| 1123 | RECORD(TYPE_POINTER); |
| 1124 | RECORD(TYPE_BLOCK_POINTER); |
| 1125 | RECORD(TYPE_LVALUE_REFERENCE); |
| 1126 | RECORD(TYPE_RVALUE_REFERENCE); |
| 1127 | RECORD(TYPE_MEMBER_POINTER); |
| 1128 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1129 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1130 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1131 | RECORD(TYPE_VECTOR); |
| 1132 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1133 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1134 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1135 | RECORD(TYPE_TYPEDEF); |
| 1136 | RECORD(TYPE_TYPEOF_EXPR); |
| 1137 | RECORD(TYPE_TYPEOF); |
| 1138 | RECORD(TYPE_RECORD); |
| 1139 | RECORD(TYPE_ENUM); |
| 1140 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1141 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1142 | RECORD(TYPE_DECLTYPE); |
| 1143 | RECORD(TYPE_ELABORATED); |
| 1144 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 1145 | RECORD(TYPE_UNRESOLVED_USING); |
| 1146 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 1147 | RECORD(TYPE_OBJC_OBJECT); |
| 1148 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 1149 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 1150 | RECORD(TYPE_DEPENDENT_NAME); |
| 1151 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 1152 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 1153 | RECORD(TYPE_PAREN); |
| 1154 | RECORD(TYPE_PACK_EXPANSION); |
| 1155 | RECORD(TYPE_ATTRIBUTED); |
| 1156 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1157 | RECORD(TYPE_AUTO); |
| 1158 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1159 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1160 | RECORD(TYPE_DECAYED); |
| 1161 | RECORD(TYPE_ADJUSTED); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 1162 | RECORD(TYPE_OBJC_TYPE_PARAM); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 1163 | RECORD(LOCAL_REDECLARATIONS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1164 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1165 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1166 | RECORD(DECL_ENUM); |
| 1167 | RECORD(DECL_RECORD); |
| 1168 | RECORD(DECL_ENUM_CONSTANT); |
| 1169 | RECORD(DECL_FUNCTION); |
| 1170 | RECORD(DECL_OBJC_METHOD); |
| 1171 | RECORD(DECL_OBJC_INTERFACE); |
| 1172 | RECORD(DECL_OBJC_PROTOCOL); |
| 1173 | RECORD(DECL_OBJC_IVAR); |
| 1174 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1175 | RECORD(DECL_OBJC_CATEGORY); |
| 1176 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1177 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1178 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1179 | RECORD(DECL_OBJC_PROPERTY); |
| 1180 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1181 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1182 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1183 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1184 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1185 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1186 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1187 | RECORD(DECL_BLOCK); |
| 1188 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1189 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1190 | RECORD(DECL_NAMESPACE); |
| 1191 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1192 | RECORD(DECL_USING); |
| 1193 | RECORD(DECL_USING_SHADOW); |
| 1194 | RECORD(DECL_USING_DIRECTIVE); |
| 1195 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1196 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1197 | RECORD(DECL_LINKAGE_SPEC); |
| 1198 | RECORD(DECL_CXX_RECORD); |
| 1199 | RECORD(DECL_CXX_METHOD); |
| 1200 | RECORD(DECL_CXX_CONSTRUCTOR); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1201 | RECORD(DECL_CXX_INHERITED_CONSTRUCTOR); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1202 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1203 | RECORD(DECL_CXX_CONVERSION); |
| 1204 | RECORD(DECL_ACCESS_SPEC); |
| 1205 | RECORD(DECL_FRIEND); |
| 1206 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1207 | RECORD(DECL_CLASS_TEMPLATE); |
| 1208 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1209 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1210 | RECORD(DECL_VAR_TEMPLATE); |
| 1211 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1212 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1213 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1214 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1215 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1216 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1217 | RECORD(DECL_TYPE_ALIAS_TEMPLATE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1218 | RECORD(DECL_STATIC_ASSERT); |
| 1219 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1220 | RECORD(DECL_CXX_CTOR_INITIALIZERS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1221 | RECORD(DECL_INDIRECTFIELD); |
| 1222 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1223 | RECORD(DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK); |
| 1224 | RECORD(DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION); |
| 1225 | RECORD(DECL_IMPORT); |
| 1226 | RECORD(DECL_OMP_THREADPRIVATE); |
| 1227 | RECORD(DECL_EMPTY); |
| 1228 | RECORD(DECL_OBJC_TYPE_PARAM); |
| 1229 | RECORD(DECL_OMP_CAPTUREDEXPR); |
| 1230 | RECORD(DECL_PRAGMA_COMMENT); |
| 1231 | RECORD(DECL_PRAGMA_DETECT_MISMATCH); |
| 1232 | RECORD(DECL_OMP_DECLARE_REDUCTION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1233 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1234 | // Statements and Exprs can occur in the Decls and Types block. |
| 1235 | AddStmtsExprs(Stream, Record); |
| 1236 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1237 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1238 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1239 | RECORD(PPD_MACRO_DEFINITION); |
| 1240 | RECORD(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 1241 | |
| 1242 | // Decls and Types block. |
| 1243 | BLOCK(EXTENSION_BLOCK); |
| 1244 | RECORD(EXTENSION_METADATA); |
| 1245 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1246 | #undef RECORD |
| 1247 | #undef BLOCK |
| 1248 | Stream.ExitBlock(); |
| 1249 | } |
| 1250 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1251 | /// \brief Prepares a path for being written to an AST file by converting it |
| 1252 | /// to an absolute path and removing nested './'s. |
| 1253 | /// |
| 1254 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1255 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1256 | SmallVectorImpl<char> &Path) { |
Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 1257 | bool Changed = FileMgr.makeAbsolutePath(Path); |
Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame] | 1258 | return Changed | llvm::sys::path::remove_dots(Path); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1261 | /// \brief Adjusts the given filename to only write out the portion of the |
| 1262 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1264 | /// \param Filename the file name to adjust. |
| 1265 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1266 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1267 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1268 | /// |
| 1269 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1270 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1271 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1272 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1273 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1274 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1275 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1276 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1277 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1278 | // Verify that the filename and the system root have the same prefix. |
| 1279 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1280 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1281 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1282 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1283 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1284 | // We hit the end of the filename before we hit the end of the system root. |
| 1285 | if (!Filename[Pos]) |
| 1286 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1287 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1288 | // If there's not a path separator at the end of the base directory nor |
| 1289 | // immediately after it, then this isn't within the base directory. |
| 1290 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1291 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1292 | return Filename; |
| 1293 | } else { |
| 1294 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1295 | // We distinguish relative paths from absolute paths by the |
| 1296 | // absence of '/' at the beginning of relative paths. |
| 1297 | // |
| 1298 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1299 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1300 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1301 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1302 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1303 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1305 | return Filename + Pos; |
| 1306 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1307 | |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1308 | static ASTFileSignature getSignature() { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1309 | while (true) { |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1310 | if (ASTFileSignature S = llvm::sys::Process::GetRandomNumber()) |
| 1311 | return S; |
| 1312 | // Rely on GetRandomNumber to eventually return non-zero... |
| 1313 | } |
| 1314 | } |
| 1315 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1316 | /// \brief Write the control block. |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1317 | uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP, |
| 1318 | ASTContext &Context, |
| 1319 | StringRef isysroot, |
| 1320 | const std::string &OutputFile) { |
| 1321 | ASTFileSignature Signature = 0; |
| 1322 | |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1323 | using namespace llvm; |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1324 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1325 | RecordData Record; |
| 1326 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1327 | // Metadata |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1328 | auto MetadataAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1329 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1330 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1331 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1332 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1333 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1334 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1335 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1336 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1337 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1338 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(std::move(MetadataAbbrev)); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1339 | assert((!WritingModule || isysroot.empty()) && |
| 1340 | "writing module as a relocatable PCH?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1341 | { |
| 1342 | RecordData::value_type Record[] = {METADATA, VERSION_MAJOR, VERSION_MINOR, |
| 1343 | CLANG_VERSION_MAJOR, CLANG_VERSION_MINOR, |
| 1344 | !isysroot.empty(), IncludeTimestamps, |
| 1345 | ASTHasCompilerErrors}; |
| 1346 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1347 | getClangFullRepositoryVersion()); |
| 1348 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1349 | if (WritingModule) { |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1350 | // For implicit modules we output a signature that we can use to ensure |
| 1351 | // duplicate module builds don't collide in the cache as their output order |
| 1352 | // is non-deterministic. |
| 1353 | // FIXME: Remove this when output is deterministic. |
| 1354 | if (Context.getLangOpts().ImplicitModules) { |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1355 | Signature = getSignature(); |
| 1356 | RecordData::value_type Record[] = {Signature}; |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1357 | Stream.EmitRecord(SIGNATURE, Record); |
| 1358 | } |
| 1359 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1360 | // Module name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1361 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1362 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1363 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1364 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1365 | RecordData::value_type Record[] = {MODULE_NAME}; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1366 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1367 | } |
| 1368 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1369 | if (WritingModule && WritingModule->Directory) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1370 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1371 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1372 | |
| 1373 | // If the home of the module is the current working directory, then we |
| 1374 | // want to pick up the cwd of the build process loading the module, not |
| 1375 | // our cwd, when we load this module. |
| 1376 | if (!PP.getHeaderSearchInfo() |
| 1377 | .getHeaderSearchOpts() |
| 1378 | .ModuleMapFileHomeIsCwd || |
| 1379 | WritingModule->Directory->getName() != StringRef(".")) { |
| 1380 | // Module directory. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1381 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1382 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1383 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1384 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1385 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1386 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1387 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1388 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1389 | |
| 1390 | // Write out all other paths relative to the base directory if possible. |
| 1391 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1392 | } else if (!isysroot.empty()) { |
| 1393 | // Write out paths relative to the sysroot if possible. |
| 1394 | BaseDirectory = isysroot; |
| 1395 | } |
| 1396 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1397 | // Module map file |
| 1398 | if (WritingModule) { |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1399 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1400 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1401 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 1402 | |
| 1403 | // Primary module map file. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1404 | AddPath(Map.getModuleMapFileForUniquing(WritingModule)->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1405 | |
| 1406 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1407 | if (auto *AdditionalModMaps = |
| 1408 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1409 | Record.push_back(AdditionalModMaps->size()); |
| 1410 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1411 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1412 | } else { |
| 1413 | Record.push_back(0); |
| 1414 | } |
| 1415 | |
| 1416 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1419 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1420 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1421 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1422 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1423 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1424 | for (auto *M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1425 | // Skip modules that weren't directly imported. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1426 | if (!M->isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1427 | continue; |
| 1428 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1429 | Record.push_back((unsigned)M->Kind); // FIXME: Stable encoding |
| 1430 | AddSourceLocation(M->ImportLoc, Record); |
| 1431 | Record.push_back(M->File->getSize()); |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1432 | Record.push_back(getTimestampForOutput(M->File)); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1433 | Record.push_back(M->Signature); |
| 1434 | AddPath(M->FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1435 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1436 | Stream.EmitRecord(IMPORTS, Record); |
| 1437 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1438 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1439 | // Write the options block. |
| 1440 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); |
| 1441 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1442 | // Language options. |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1443 | Record.clear(); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1444 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1445 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1446 | Record.push_back(LangOpts.Name); |
| 1447 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1448 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1449 | #include "clang/Basic/LangOptions.def" |
| 1450 | #define SANITIZER(NAME, ID) \ |
| 1451 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1452 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1453 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1454 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1455 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1456 | AddString(Feature, Record); |
| 1457 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1458 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1459 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1460 | |
| 1461 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1462 | |
| 1463 | // Comment options. |
| 1464 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1465 | for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) { |
| 1466 | AddString(I, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1467 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1468 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1469 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1470 | // OpenMP offloading options. |
| 1471 | Record.push_back(LangOpts.OMPTargetTriples.size()); |
| 1472 | for (auto &T : LangOpts.OMPTargetTriples) |
| 1473 | AddString(T.getTriple(), Record); |
| 1474 | |
| 1475 | AddString(LangOpts.OMPHostIRFile, Record); |
| 1476 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1477 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1478 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1479 | // Target options. |
| 1480 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1481 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1482 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1483 | AddString(TargetOpts.Triple, Record); |
| 1484 | AddString(TargetOpts.CPU, Record); |
| 1485 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1486 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1487 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1488 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1489 | } |
| 1490 | Record.push_back(TargetOpts.Features.size()); |
| 1491 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1492 | AddString(TargetOpts.Features[I], Record); |
| 1493 | } |
| 1494 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1495 | |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1496 | // Diagnostic options. |
| 1497 | Record.clear(); |
| 1498 | const DiagnosticOptions &DiagOpts |
| 1499 | = Context.getDiagnostics().getDiagnosticOptions(); |
| 1500 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1501 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1502 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1503 | #include "clang/Basic/DiagnosticOptions.def" |
| 1504 | Record.push_back(DiagOpts.Warnings.size()); |
| 1505 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1506 | AddString(DiagOpts.Warnings[I], Record); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 1507 | Record.push_back(DiagOpts.Remarks.size()); |
| 1508 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1509 | AddString(DiagOpts.Remarks[I], Record); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1510 | // Note: we don't serialize the log or serialization file names, because they |
| 1511 | // are generally transient files and will almost always be overridden. |
| 1512 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1513 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1514 | // File system options. |
| 1515 | Record.clear(); |
Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1516 | const FileSystemOptions &FSOpts = |
| 1517 | Context.getSourceManager().getFileManager().getFileSystemOpts(); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1518 | AddString(FSOpts.WorkingDir, Record); |
| 1519 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1520 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1521 | // Header search options. |
| 1522 | Record.clear(); |
| 1523 | const HeaderSearchOptions &HSOpts |
| 1524 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1525 | AddString(HSOpts.Sysroot, Record); |
| 1526 | |
| 1527 | // Include entries. |
| 1528 | Record.push_back(HSOpts.UserEntries.size()); |
| 1529 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1530 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1531 | AddString(Entry.Path, Record); |
| 1532 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1533 | Record.push_back(Entry.IsFramework); |
| 1534 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | // System header prefixes. |
| 1538 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1539 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1540 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1541 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1542 | } |
| 1543 | |
| 1544 | AddString(HSOpts.ResourceDir, Record); |
| 1545 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1546 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1547 | Record.push_back(HSOpts.DisableModuleHash); |
| 1548 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1549 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1550 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1551 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1552 | // Write out the specific module cache path that contains the module files. |
| 1553 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1554 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1555 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1556 | // Preprocessor options. |
| 1557 | Record.clear(); |
| 1558 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1559 | |
| 1560 | // Macro definitions. |
| 1561 | Record.push_back(PPOpts.Macros.size()); |
| 1562 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1563 | AddString(PPOpts.Macros[I].first, Record); |
| 1564 | Record.push_back(PPOpts.Macros[I].second); |
| 1565 | } |
| 1566 | |
| 1567 | // Includes |
| 1568 | Record.push_back(PPOpts.Includes.size()); |
| 1569 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1570 | AddString(PPOpts.Includes[I], Record); |
| 1571 | |
| 1572 | // Macro includes |
| 1573 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1574 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1575 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1576 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1577 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1578 | // Detailed record is important since it is used for the module cache hash. |
| 1579 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1580 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1581 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1582 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1583 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1584 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1585 | // Leave the options block. |
| 1586 | Stream.ExitBlock(); |
| 1587 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1588 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1589 | SourceManager &SM = Context.getSourceManager(); |
| 1590 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1591 | auto FileAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1592 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1593 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1594 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1595 | unsigned FileAbbrevCode = Stream.EmitAbbrev(std::move(FileAbbrev)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1596 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1597 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1598 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1599 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1600 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1601 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1602 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1603 | Record.clear(); |
| 1604 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1605 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1606 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1607 | // Original PCH directory |
| 1608 | if (!OutputFile.empty() && OutputFile != "-") { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1609 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1610 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1611 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1612 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1613 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1614 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1615 | |
Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1616 | SM.getFileManager().makeAbsolutePath(OutputPath); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1617 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1618 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1619 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1620 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1621 | } |
| 1622 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1623 | WriteInputFiles(Context.SourceMgr, |
| 1624 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1625 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1626 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1627 | return Signature; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1630 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1631 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1632 | /// \brief An input file. |
| 1633 | struct InputFileEntry { |
| 1634 | const FileEntry *File; |
| 1635 | bool IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1636 | bool IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1637 | bool BufferOverridden; |
| 1638 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1639 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1640 | } // end anonymous namespace |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1641 | |
| 1642 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1643 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1644 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1645 | using namespace llvm; |
| 1646 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1647 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1648 | // Create input-file abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1649 | auto IFAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1650 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1651 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1652 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1653 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1654 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1655 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1656 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1657 | unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev)); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1658 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1659 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1660 | // 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] | 1661 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1662 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1663 | // Get this source location entry. |
| 1664 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1665 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1666 | |
| 1667 | // We only care about file entries that were not overridden. |
| 1668 | if (!SLoc->isFile()) |
| 1669 | continue; |
| 1670 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1671 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1672 | continue; |
| 1673 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1674 | InputFileEntry Entry; |
| 1675 | Entry.File = Cache->OrigEntry; |
| 1676 | Entry.IsSystemFile = Cache->IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1677 | Entry.IsTransient = Cache->IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1678 | Entry.BufferOverridden = Cache->BufferOverridden; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1679 | if (Cache->IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1680 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1681 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1682 | SortedFiles.push_front(Entry); |
| 1683 | } |
| 1684 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1685 | unsigned UserFilesNum = 0; |
| 1686 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1687 | std::vector<uint64_t> InputFileOffsets; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1688 | for (const auto &Entry : SortedFiles) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1689 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1690 | if (InputFileID != 0) |
| 1691 | continue; // already recorded this file. |
| 1692 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1693 | // Record this entry's offset. |
| 1694 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1695 | |
| 1696 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1697 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1698 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1699 | ++UserFilesNum; |
| 1700 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1701 | // Emit size/modification time for this file. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1702 | // And whether this file was overridden. |
| 1703 | RecordData::value_type Record[] = { |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1704 | INPUT_FILE, |
| 1705 | InputFileOffsets.size(), |
| 1706 | (uint64_t)Entry.File->getSize(), |
| 1707 | (uint64_t)getTimestampForOutput(Entry.File), |
| 1708 | Entry.BufferOverridden, |
| 1709 | Entry.IsTransient}; |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1710 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1711 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1712 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1713 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1714 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1715 | |
| 1716 | // Create input file offsets abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1717 | auto OffsetsAbbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1718 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1719 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1720 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1721 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1722 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1723 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(std::move(OffsetsAbbrev)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1724 | |
| 1725 | // Write input file offsets. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1726 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, |
| 1727 | InputFileOffsets.size(), UserFilesNum}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1728 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1731 | //===----------------------------------------------------------------------===// |
| 1732 | // Source Manager Serialization |
| 1733 | //===----------------------------------------------------------------------===// |
| 1734 | |
| 1735 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1736 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1737 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1738 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1739 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1740 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1741 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1742 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1743 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1744 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1745 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1746 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1747 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1748 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1749 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1750 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1751 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1755 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1756 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1757 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1758 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1759 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1760 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1761 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1762 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1763 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1764 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1765 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1766 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1770 | /// buffer's blob. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1771 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, |
| 1772 | bool Compressed) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1773 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1774 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1775 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1776 | Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED |
| 1777 | : SM_SLOC_BUFFER_BLOB)); |
| 1778 | if (Compressed) |
| 1779 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1780 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1781 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1784 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1785 | /// expansion. |
| 1786 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1787 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1788 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1789 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1790 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1791 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1792 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1793 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1794 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1795 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1796 | return Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1799 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1800 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1801 | // Trait used for the on-disk hash table of header search information. |
| 1802 | class HeaderFileInfoTrait { |
| 1803 | ASTWriter &Writer; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1804 | const HeaderSearch &HS; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1805 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1806 | // Keep track of the framework names we've used during serialization. |
| 1807 | SmallVector<char, 128> FrameworkStringData; |
| 1808 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1809 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1810 | public: |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1811 | HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) |
| 1812 | : Writer(Writer), HS(HS) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1813 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1814 | struct key_type { |
| 1815 | const FileEntry *FE; |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1816 | StringRef Filename; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1817 | }; |
| 1818 | typedef const key_type &key_type_ref; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1819 | |
| 1820 | typedef HeaderFileInfo data_type; |
| 1821 | typedef const data_type &data_type_ref; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 1822 | typedef unsigned hash_value_type; |
| 1823 | typedef unsigned offset_type; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1824 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1825 | hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1826 | // The hash is based only on size/time of the file, so that the reader can |
| 1827 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1828 | // change the form of the name. However, complete path is still the key. |
| 1829 | return llvm::hash_combine(key.FE->getSize(), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1830 | Writer.getTimestampForOutput(key.FE)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | std::pair<unsigned,unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1834 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1835 | using namespace llvm::support; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1836 | endian::Writer<little> LE(Out); |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1837 | unsigned KeyLen = key.Filename.size() + 1 + 8 + 8; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1838 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1839 | unsigned DataLen = 1 + 2 + 4 + 4; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1840 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) |
| 1841 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) |
| 1842 | DataLen += 4; |
| 1843 | LE.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1844 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1845 | } |
| 1846 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1847 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1848 | using namespace llvm::support; |
| 1849 | endian::Writer<little> LE(Out); |
| 1850 | LE.write<uint64_t>(key.FE->getSize()); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1851 | KeyLen -= 8; |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1852 | LE.write<uint64_t>(Writer.getTimestampForOutput(key.FE)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1853 | KeyLen -= 8; |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1854 | Out.write(key.Filename.data(), KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1857 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1858 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1859 | using namespace llvm::support; |
| 1860 | endian::Writer<little> LE(Out); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1861 | uint64_t Start = Out.tell(); (void)Start; |
| 1862 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1863 | unsigned char Flags = (Data.isImport << 4) |
| 1864 | | (Data.isPragmaOnce << 3) |
| 1865 | | (Data.DirInfo << 1) |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1866 | | Data.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1867 | LE.write<uint8_t>(Flags); |
| 1868 | LE.write<uint16_t>(Data.NumIncludes); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1869 | |
| 1870 | if (!Data.ControllingMacro) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1871 | LE.write<uint32_t>(Data.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1872 | else |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1873 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1874 | |
| 1875 | unsigned Offset = 0; |
| 1876 | if (!Data.Framework.empty()) { |
| 1877 | // If this header refers into a framework, save the framework name. |
| 1878 | llvm::StringMap<unsigned>::iterator Pos |
| 1879 | = FrameworkNameOffset.find(Data.Framework); |
| 1880 | if (Pos == FrameworkNameOffset.end()) { |
| 1881 | Offset = FrameworkStringData.size() + 1; |
| 1882 | FrameworkStringData.append(Data.Framework.begin(), |
| 1883 | Data.Framework.end()); |
| 1884 | FrameworkStringData.push_back(0); |
| 1885 | |
| 1886 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1887 | } else |
| 1888 | Offset = Pos->second; |
| 1889 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1890 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1891 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1892 | // FIXME: If the header is excluded, we should write out some |
| 1893 | // record of that fact. |
| 1894 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) { |
| 1895 | if (uint32_t ModID = |
| 1896 | Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) { |
| 1897 | uint32_t Value = (ModID << 2) | (unsigned)ModInfo.getRole(); |
| 1898 | assert((Value >> 2) == ModID && "overflow in header module info"); |
| 1899 | LE.write<uint32_t>(Value); |
| 1900 | } |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1903 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1904 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1905 | |
| 1906 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1907 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1908 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1909 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1910 | } // end anonymous namespace |
| 1911 | |
| 1912 | /// \brief Write the header search block for the list of files that |
| 1913 | /// |
| 1914 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1915 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1916 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1917 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1918 | |
| 1919 | if (FilesByUID.size() > HS.header_file_size()) |
| 1920 | FilesByUID.resize(HS.header_file_size()); |
| 1921 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1922 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 1923 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1924 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1925 | unsigned NumHeaderSearchEntries = 0; |
| 1926 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1927 | const FileEntry *File = FilesByUID[UID]; |
| 1928 | if (!File) |
| 1929 | continue; |
| 1930 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1931 | // Get the file info. This will load info from the external source if |
| 1932 | // necessary. Skip emitting this file if we have no information on it |
| 1933 | // as a header file (in which case HFI will be null) or if it hasn't |
| 1934 | // changed since it was loaded. Also skip it if it's for a modular header |
| 1935 | // from a different module; in that case, we rely on the module(s) |
| 1936 | // containing the header to provide this information. |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1937 | const HeaderFileInfo *HFI = |
| 1938 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); |
| 1939 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 1940 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1941 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1942 | // Massage the file path into an appropriate form. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1943 | StringRef Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1944 | SmallString<128> FilenameTmp(Filename); |
| 1945 | if (PreparePathForOutput(FilenameTmp)) { |
| 1946 | // If we performed any translation on the file name at all, we need to |
| 1947 | // save this string, since the generator will refer to it later. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1948 | Filename = StringRef(strdup(FilenameTmp.c_str())); |
| 1949 | SavedStrings.push_back(Filename.data()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1950 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1951 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1952 | HeaderFileInfoTrait::key_type key = { File, Filename }; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1953 | Generator.insert(key, *HFI, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1954 | ++NumHeaderSearchEntries; |
| 1955 | } |
| 1956 | |
| 1957 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1958 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1959 | uint32_t BucketOffset; |
| 1960 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1961 | using namespace llvm::support; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1962 | llvm::raw_svector_ostream Out(TableData); |
| 1963 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1964 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1965 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1966 | } |
| 1967 | |
| 1968 | // Create a blob abbreviation |
| 1969 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1970 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1971 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1972 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1973 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1974 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1975 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1976 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1977 | unsigned TableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1978 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1979 | // Write the header search table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1980 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, |
| 1981 | NumHeaderSearchEntries, TableData.size()}; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1982 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 1983 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1984 | |
| 1985 | // Free all of the strings we had to duplicate. |
| 1986 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1987 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame^] | 1990 | static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob, |
| 1991 | unsigned SLocBufferBlobCompressedAbbrv, |
| 1992 | unsigned SLocBufferBlobAbbrv) { |
| 1993 | typedef ASTWriter::RecordData::value_type RecordDataType; |
| 1994 | |
| 1995 | // Compress the buffer if possible. We expect that almost all PCM |
| 1996 | // consumers will not want its contents. |
| 1997 | SmallString<0> CompressedBuffer; |
| 1998 | if (llvm::zlib::isAvailable()) { |
| 1999 | llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer); |
| 2000 | if (!E) { |
| 2001 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, |
| 2002 | Blob.size() - 1}; |
| 2003 | Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, |
| 2004 | CompressedBuffer); |
| 2005 | return; |
| 2006 | } |
| 2007 | llvm::consumeError(std::move(E)); |
| 2008 | } |
| 2009 | |
| 2010 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB}; |
| 2011 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob); |
| 2012 | } |
| 2013 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2014 | /// \brief Writes the block containing the serialized form of the |
| 2015 | /// source manager. |
| 2016 | /// |
| 2017 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 2018 | /// blob), indexed based on the file name, so that we only create |
| 2019 | /// entries for files that we actually need. In the common case (no |
| 2020 | /// errors), we probably won't have to create file entries for any of |
| 2021 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2022 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2023 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2024 | RecordData Record; |
| 2025 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2026 | // Enter the source manager block. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2027 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2028 | |
| 2029 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 2030 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 2031 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2032 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false); |
| 2033 | unsigned SLocBufferBlobCompressedAbbrv = |
| 2034 | CreateSLocBufferBlobAbbrev(Stream, true); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2035 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2036 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2037 | // Write out the source location entry table. We skip the first |
| 2038 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 2039 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2040 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2041 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 2042 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2043 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2044 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2045 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2046 | FileID FID = FileID::get(I); |
| 2047 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2048 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2049 | // Record the offset of this source-location entry. |
| 2050 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2051 | |
| 2052 | // Figure out which record code to use. |
| 2053 | unsigned Code; |
| 2054 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2055 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 2056 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2057 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2058 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2059 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2060 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2061 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2062 | Record.clear(); |
| 2063 | Record.push_back(Code); |
| 2064 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2065 | // Starting offset of this entry within this module, so skip the dummy. |
| 2066 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2067 | if (SLoc->isFile()) { |
| 2068 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2069 | AddSourceLocation(File.getIncludeLoc(), Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2070 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 2071 | Record.push_back(File.hasLineDirectives()); |
| 2072 | |
| 2073 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2074 | bool EmitBlob = false; |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2075 | if (Content->OrigEntry) { |
| 2076 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2077 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2078 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2079 | // The source location entry is a file. Emit input file ID. |
| 2080 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 2081 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2082 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 2083 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2084 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2085 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2086 | if (FDI != FileDeclIDs.end()) { |
| 2087 | Record.push_back(FDI->second->FirstDeclIndex); |
| 2088 | Record.push_back(FDI->second->DeclIDs.size()); |
| 2089 | } else { |
| 2090 | Record.push_back(0); |
| 2091 | Record.push_back(0); |
| 2092 | } |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2093 | |
| 2094 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
| 2095 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2096 | if (Content->BufferOverridden || Content->IsTransient) |
| 2097 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2098 | } else { |
| 2099 | // The source location entry is a buffer. The blob associated |
| 2100 | // with this entry contains the contents of the buffer. |
| 2101 | |
| 2102 | // We add one to the size so that we capture the trailing NULL |
| 2103 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 2104 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 2105 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 2106 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2107 | StringRef Name = Buffer->getBufferIdentifier(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2108 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2109 | StringRef(Name.data(), Name.size() + 1)); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2110 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2111 | |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2112 | if (Name == "<built-in>") |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2113 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2114 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2115 | |
| 2116 | if (EmitBlob) { |
| 2117 | // Include the implicit terminating null character in the on-disk buffer |
| 2118 | // if we're writing it uncompressed. |
| 2119 | const llvm::MemoryBuffer *Buffer = |
| 2120 | Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 2121 | StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1); |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame^] | 2122 | emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv, |
| 2123 | SLocBufferBlobAbbrv); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2124 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2125 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2126 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 2127 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2128 | AddSourceLocation(Expansion.getSpellingLoc(), Record); |
| 2129 | AddSourceLocation(Expansion.getExpansionLocStart(), Record); |
| 2130 | AddSourceLocation(Expansion.isMacroArgExpansion() |
| 2131 | ? SourceLocation() |
| 2132 | : Expansion.getExpansionLocEnd(), |
| 2133 | Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2134 | |
| 2135 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2136 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2137 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2138 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2139 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2140 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2141 | } |
| 2142 | } |
| 2143 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2144 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2145 | |
| 2146 | if (SLocEntryOffsets.empty()) |
| 2147 | return; |
| 2148 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2149 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2150 | // table is used for lazily loading source-location information. |
| 2151 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2152 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2153 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2154 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2155 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2156 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2157 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2158 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2159 | { |
| 2160 | RecordData::value_type Record[] = { |
| 2161 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), |
| 2162 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */}; |
| 2163 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
| 2164 | bytes(SLocEntryOffsets)); |
| 2165 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2166 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2167 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2168 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2169 | |
| 2170 | // Write the line table. It depends on remapping working, so it must come |
| 2171 | // after the source location offsets. |
| 2172 | if (SourceMgr.hasLineTable()) { |
| 2173 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 2174 | |
| 2175 | Record.clear(); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2176 | |
| 2177 | // Emit the needed file names. |
| 2178 | llvm::DenseMap<int, int> FilenameMap; |
| 2179 | for (const auto &L : LineTable) { |
| 2180 | if (L.first.ID < 0) |
| 2181 | continue; |
| 2182 | for (auto &LE : L.second) { |
| 2183 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, |
| 2184 | FilenameMap.size())).second) |
| 2185 | AddPath(LineTable.getFilename(LE.FilenameID), Record); |
| 2186 | } |
| 2187 | } |
| 2188 | Record.push_back(0); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2189 | |
| 2190 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2191 | for (const auto &L : LineTable) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2192 | // Only emit entries for local files. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2193 | if (L.first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2194 | continue; |
| 2195 | |
| 2196 | // Emit the file ID |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2197 | Record.push_back(L.first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2198 | |
| 2199 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2200 | Record.push_back(L.second.size()); |
| 2201 | for (const auto &LE : L.second) { |
| 2202 | Record.push_back(LE.FileOffset); |
| 2203 | Record.push_back(LE.LineNo); |
| 2204 | Record.push_back(FilenameMap[LE.FilenameID]); |
| 2205 | Record.push_back((unsigned)LE.FileKind); |
| 2206 | Record.push_back(LE.IncludeOffset); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2207 | } |
| 2208 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2209 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2210 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 2211 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2214 | //===----------------------------------------------------------------------===// |
| 2215 | // Preprocessor Serialization |
| 2216 | //===----------------------------------------------------------------------===// |
| 2217 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2218 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 2219 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2220 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 2221 | if (MI->isBuiltinMacro()) |
| 2222 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2223 | |
| 2224 | if (IsModule) { |
| 2225 | SourceLocation Loc = MD->getLocation(); |
| 2226 | if (Loc.isInvalid()) |
| 2227 | return true; |
| 2228 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 2229 | return true; |
| 2230 | } |
| 2231 | |
| 2232 | return false; |
| 2233 | } |
| 2234 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2235 | /// \brief Writes the block containing the serialized form of the |
| 2236 | /// preprocessor. |
| 2237 | /// |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2238 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2239 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2240 | if (PPRec) |
| 2241 | WritePreprocessorDetail(*PPRec); |
| 2242 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2243 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2244 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2245 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2246 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2247 | if (PP.getCounterValue() != 0) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2248 | RecordData::value_type Record[] = {PP.getCounterValue()}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2249 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2253 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2254 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2255 | // 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] | 2256 | // 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] | 2257 | if (PP.SawDateOrTime()) |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2258 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2259 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2260 | // 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] | 2261 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2262 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2263 | // Construct the list of identifiers with macro directives that need to be |
| 2264 | // serialized. |
| 2265 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2266 | for (auto &Id : PP.getIdentifierTable()) |
| 2267 | if (Id.second->hadMacroDefinition() && |
| 2268 | (!Id.second->isFromAST() || |
| 2269 | Id.second->hasChangedSinceDeserialization())) |
| 2270 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2271 | // Sort the set of macro definitions that need to be serialized by the |
| 2272 | // name of the macro, to provide a stable ordering. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2273 | std::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(), |
| 2274 | llvm::less_ptr<IdentifierInfo>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2275 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2276 | // Emit the macro directives as a list and associate the offset with the |
| 2277 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2278 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2279 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2280 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2281 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2282 | // Emit the macro directives in reverse source order. |
| 2283 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2284 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2285 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2286 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2287 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2288 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2289 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2290 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2291 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2292 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2293 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2294 | Record.push_back(VisMD->isPublic()); |
| 2295 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2296 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2297 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2298 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2299 | bool EmittedModuleMacros = false; |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2300 | // We write out exported module macros for PCH as well. |
| 2301 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2302 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2303 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2304 | while (!Worklist.empty()) { |
| 2305 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2306 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2307 | // Emit a record indicating this submodule exports this macro. |
| 2308 | ModuleMacroRecord.push_back( |
| 2309 | getSubmoduleID(Macro->getOwningModule())); |
| 2310 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
| 2311 | for (auto *M : Macro->overrides()) |
| 2312 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2313 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2314 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2315 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2316 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2317 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2318 | for (auto *M : Macro->overrides()) |
| 2319 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2320 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2321 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2322 | EmittedModuleMacros = true; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2323 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2324 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2325 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2326 | continue; |
| 2327 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2328 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2329 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2330 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2331 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2332 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2333 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 2334 | /// the local macro ID |
| 2335 | /// |
| 2336 | /// For each identifier that is associated with a macro, this map |
| 2337 | /// provides the offset into the bitstream where that macro is |
| 2338 | /// defined. |
| 2339 | std::vector<uint32_t> MacroOffsets; |
| 2340 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2341 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2342 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2343 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2344 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2345 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2346 | if (ID < FirstMacroID) { |
| 2347 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2348 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2349 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2350 | |
| 2351 | // Record the local offset of this macro. |
| 2352 | unsigned Index = ID - FirstMacroID; |
| 2353 | if (Index == MacroOffsets.size()) |
| 2354 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2355 | else { |
| 2356 | if (Index > MacroOffsets.size()) |
| 2357 | MacroOffsets.resize(Index + 1); |
| 2358 | |
| 2359 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2360 | } |
| 2361 | |
| 2362 | AddIdentifierRef(Name, Record); |
| 2363 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
| 2364 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2365 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2366 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2367 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2368 | unsigned Code; |
| 2369 | if (MI->isObjectLike()) { |
| 2370 | Code = PP_MACRO_OBJECT_LIKE; |
| 2371 | } else { |
| 2372 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2373 | |
| 2374 | Record.push_back(MI->isC99Varargs()); |
| 2375 | Record.push_back(MI->isGNUVarargs()); |
| 2376 | Record.push_back(MI->hasCommaPasting()); |
| 2377 | Record.push_back(MI->getNumArgs()); |
Daniel Marjamaki | e4770da | 2015-05-29 09:15:24 +0000 | [diff] [blame] | 2378 | for (const IdentifierInfo *Arg : MI->args()) |
| 2379 | AddIdentifierRef(Arg, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | // If we have a detailed preprocessing record, record the macro definition |
| 2383 | // ID that corresponds to this macro. |
| 2384 | if (PPRec) |
| 2385 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2386 | |
| 2387 | Stream.EmitRecord(Code, Record); |
| 2388 | Record.clear(); |
| 2389 | |
| 2390 | // Emit the tokens array. |
| 2391 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2392 | // Note that we know that the preprocessor does not have any annotation |
| 2393 | // tokens in it because they are created by the parser, and thus can't |
| 2394 | // be in a macro definition. |
| 2395 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2396 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2397 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2398 | Record.clear(); |
| 2399 | } |
| 2400 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2401 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2402 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2403 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2404 | |
| 2405 | // Write the offsets table for macro IDs. |
| 2406 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2407 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2408 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2409 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2410 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2411 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2412 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2413 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2414 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2415 | { |
| 2416 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), |
| 2417 | FirstMacroID - NUM_PREDEF_MACRO_IDS}; |
| 2418 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); |
| 2419 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2423 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2424 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2425 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2426 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2427 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2428 | // Enter the preprocessor block. |
| 2429 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2430 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2431 | // If the preprocessor has a preprocessing record, emit it. |
| 2432 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2433 | using namespace llvm; |
| 2434 | |
| 2435 | // Set up the abbreviation for |
| 2436 | unsigned InclusionAbbrev = 0; |
| 2437 | { |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2438 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2439 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2440 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2441 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2442 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2443 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2444 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2445 | InclusionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2448 | unsigned FirstPreprocessorEntityID |
| 2449 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 2450 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2451 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2452 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2453 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2454 | EEnd = PPRec.local_end(); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2455 | E != EEnd; |
| 2456 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2457 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2458 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2459 | PreprocessedEntityOffsets.push_back( |
| 2460 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2461 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2462 | if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2463 | // Record this macro definition's ID. |
| 2464 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2465 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2466 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2467 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2468 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2469 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2470 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2471 | if (auto *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2472 | Record.push_back(ME->isBuiltinMacro()); |
| 2473 | if (ME->isBuiltinMacro()) |
| 2474 | AddIdentifierRef(ME->getName(), Record); |
| 2475 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2476 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2477 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2478 | continue; |
| 2479 | } |
| 2480 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2481 | if (auto *ID = dyn_cast<InclusionDirective>(*E)) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2482 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2483 | Record.push_back(ID->getFileName().size()); |
| 2484 | Record.push_back(ID->wasInQuotes()); |
| 2485 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2486 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2487 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2488 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2489 | // Check that the FileEntry is not null because it was not resolved and |
| 2490 | // we create a PCH even with compiler errors. |
| 2491 | if (ID->getFile()) |
| 2492 | Buffer += ID->getFile()->getName(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2493 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2494 | continue; |
| 2495 | } |
| 2496 | |
| 2497 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2498 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2499 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2500 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2501 | // Write the offsets table for the preprocessing record. |
| 2502 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2503 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2504 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2505 | // Write the offsets table for identifier IDs. |
| 2506 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2507 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2508 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2509 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2510 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2511 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2512 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2513 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2514 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, |
| 2515 | FirstPreprocessorEntityID - |
| 2516 | NUM_PREDEF_PP_ENTITY_IDS}; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2517 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2518 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2519 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2520 | } |
| 2521 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2522 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2523 | if (!Mod) |
| 2524 | return 0; |
| 2525 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2526 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2527 | if (Known != SubmoduleIDs.end()) |
| 2528 | return Known->second; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2529 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2530 | auto *Top = Mod->getTopLevelModule(); |
| 2531 | if (Top != WritingModule && |
| 2532 | !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule))) |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2533 | return 0; |
| 2534 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2535 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2536 | } |
| 2537 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2538 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2539 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2540 | // did not result in us loading a module file for that submodule. For |
| 2541 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2542 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); |
| 2543 | assert((ID || !Mod) && |
| 2544 | "asked for module ID for non-local, non-imported module"); |
| 2545 | return ID; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2546 | } |
| 2547 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2548 | /// \brief Compute the number of modules within the given tree (including the |
| 2549 | /// given module). |
| 2550 | static unsigned getNumberOfModules(Module *Mod) { |
| 2551 | unsigned ChildModules = 0; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2552 | for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2553 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2554 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2555 | |
| 2556 | return ChildModules + 1; |
| 2557 | } |
| 2558 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2559 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2560 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2561 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2562 | |
| 2563 | // Write the abbreviations needed for the submodules block. |
| 2564 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2565 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2566 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2567 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2568 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2569 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2570 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2571 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2572 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2573 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2574 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2575 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2576 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2577 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2578 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2579 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2580 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2581 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2582 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2583 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2584 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2585 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2586 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2587 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2588 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2589 | unsigned HeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2590 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2591 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2592 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2593 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2594 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2595 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2596 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2597 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2598 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2599 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2600 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2601 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2602 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2603 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2604 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2605 | unsigned RequiresAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2606 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2607 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2608 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2609 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2610 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2611 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2612 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2613 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2614 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2615 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2616 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2617 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2618 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2619 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2620 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2621 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2622 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2623 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2624 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2625 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2626 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2627 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2628 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2629 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2630 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2631 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2632 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2633 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2634 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2635 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2636 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2637 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2638 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2639 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2640 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2641 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2642 | unsigned ConflictAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2643 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2644 | // Write the submodule metadata block. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2645 | RecordData::value_type Record[] = {getNumberOfModules(WritingModule), |
| 2646 | FirstSubmoduleID - |
| 2647 | NUM_PREDEF_SUBMODULE_IDS}; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2648 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2649 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2650 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2651 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2652 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2653 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2654 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2655 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2656 | unsigned ID = getSubmoduleID(Mod); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2657 | |
| 2658 | uint64_t ParentID = 0; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2659 | if (Mod->Parent) { |
| 2660 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2661 | ParentID = SubmoduleIDs[Mod->Parent]; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2662 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2663 | |
| 2664 | // Emit the definition of the block. |
| 2665 | { |
| 2666 | RecordData::value_type Record[] = { |
| 2667 | SUBMODULE_DEFINITION, ID, ParentID, Mod->IsFramework, Mod->IsExplicit, |
| 2668 | Mod->IsSystem, Mod->IsExternC, Mod->InferSubmodules, |
| 2669 | Mod->InferExplicitSubmodules, Mod->InferExportWildcard, |
| 2670 | Mod->ConfigMacrosExhaustive}; |
| 2671 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2672 | } |
| 2673 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2674 | // Emit the requirements. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2675 | for (const auto &R : Mod->Requirements) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2676 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2677 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2678 | } |
| 2679 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2680 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2681 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2682 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2683 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2684 | UmbrellaHeader.NameAsWritten); |
| 2685 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2686 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; |
| 2687 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2688 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2689 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2690 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2691 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2692 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2693 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2694 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2695 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2696 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2697 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 2698 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 2699 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2700 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2701 | Module::HK_PrivateTextual}, |
| 2702 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2703 | }; |
| 2704 | for (auto &HL : HeaderLists) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2705 | RecordData::value_type Record[] = {HL.RecordKind}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2706 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 2707 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 2708 | } |
| 2709 | |
| 2710 | // Emit the top headers. |
| 2711 | { |
| 2712 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2713 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2714 | for (auto *H : TopHeaders) |
| 2715 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2716 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2717 | |
| 2718 | // Emit the imports. |
| 2719 | if (!Mod->Imports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2720 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2721 | for (auto *I : Mod->Imports) |
| 2722 | Record.push_back(getSubmoduleID(I)); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2723 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2724 | } |
| 2725 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2726 | // Emit the exports. |
| 2727 | if (!Mod->Exports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2728 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2729 | for (const auto &E : Mod->Exports) { |
| 2730 | // FIXME: This may fail; we don't require that all exported modules |
| 2731 | // are local or imported. |
| 2732 | Record.push_back(getSubmoduleID(E.getPointer())); |
| 2733 | Record.push_back(E.getInt()); |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2734 | } |
| 2735 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2736 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2737 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2738 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 2739 | // Might be unnecessary as use declarations are only used to build the |
| 2740 | // module itself. |
| 2741 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2742 | // Emit the link libraries. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2743 | for (const auto &LL : Mod->LinkLibraries) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2744 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, |
| 2745 | LL.IsFramework}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2746 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2747 | } |
| 2748 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2749 | // Emit the conflicts. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2750 | for (const auto &C : Mod->Conflicts) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2751 | // FIXME: This may fail; we don't require that all conflicting modules |
| 2752 | // are local or imported. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2753 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, |
| 2754 | getSubmoduleID(C.Other)}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2755 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2756 | } |
| 2757 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2758 | // Emit the configuration macros. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2759 | for (const auto &CM : Mod->ConfigMacros) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2760 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2761 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2762 | } |
| 2763 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2764 | // Emit the initializers, if any. |
| 2765 | RecordData Inits; |
| 2766 | for (Decl *D : Context->getModuleInitializers(Mod)) |
| 2767 | Inits.push_back(GetDeclRef(D)); |
| 2768 | if (!Inits.empty()) |
| 2769 | Stream.EmitRecord(SUBMODULE_INITIALIZERS, Inits); |
| 2770 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2771 | // Queue up the submodules of this module. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2772 | for (auto *M : Mod->submodules()) |
| 2773 | Q.push(M); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2777 | |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2778 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 2779 | getNumberOfModules(WritingModule)) && |
| 2780 | "Wrong # of submodules; found a reference to a non-local, " |
| 2781 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2784 | serialization::SubmoduleID |
| 2785 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2786 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2787 | return 0; // No submodule |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2788 | |
| 2789 | // Find the module that owns this location. |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2790 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2791 | Module *OwningMod |
| 2792 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2793 | if (!OwningMod) |
| 2794 | return 0; |
| 2795 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2796 | // Check whether this submodule is part of our own module. |
| 2797 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2798 | return 0; |
| 2799 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2800 | return getSubmoduleID(OwningMod); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 2803 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 2804 | bool isModule) { |
| 2805 | // Make sure set diagnostic pragmas don't affect the translation unit that |
| 2806 | // imports the module. |
| 2807 | // FIXME: Make diagnostic pragma sections work properly with modules. |
| 2808 | if (isModule) |
| 2809 | return; |
| 2810 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2811 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2812 | DiagStateIDMap; |
| 2813 | unsigned CurrID = 0; |
| 2814 | DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2815 | RecordData Record; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2816 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2817 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2818 | I != E; ++I) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2819 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2820 | if (point.Loc.isInvalid()) |
| 2821 | continue; |
| 2822 | |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2823 | AddSourceLocation(point.Loc, Record); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2824 | unsigned &DiagStateID = DiagStateIDMap[point.State]; |
| 2825 | Record.push_back(DiagStateID); |
| 2826 | |
| 2827 | if (DiagStateID == 0) { |
| 2828 | DiagStateID = ++CurrID; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2829 | for (const auto &I : *(point.State)) { |
| 2830 | if (I.second.isPragma()) { |
| 2831 | Record.push_back(I.first); |
| 2832 | Record.push_back((unsigned)I.second.getSeverity()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2833 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2834 | } |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2835 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2836 | // location. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2837 | } |
| 2838 | } |
| 2839 | |
Argyrios Kyrtzidis | b0ca9eb | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2840 | if (!Record.empty()) |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2841 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2842 | } |
| 2843 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2844 | //===----------------------------------------------------------------------===// |
| 2845 | // Type Serialization |
| 2846 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2847 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2848 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2849 | void ASTWriter::WriteType(QualType T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2850 | TypeIdx &IdxRef = TypeIdxs[T]; |
| 2851 | if (IdxRef.getIndex() == 0) // we haven't seen this type before. |
| 2852 | IdxRef = TypeIdx(NextTypeID++); |
| 2853 | TypeIdx Idx = IdxRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2854 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2855 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2856 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2857 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2858 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2859 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2860 | ASTTypeWriter W(*this, Record); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2861 | W.Visit(T); |
| 2862 | uint64_t Offset = W.Emit(); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2863 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2864 | // Record the offset for this type. |
| 2865 | unsigned Index = Idx.getIndex() - FirstTypeID; |
| 2866 | if (TypeOffsets.size() == Index) |
| 2867 | TypeOffsets.push_back(Offset); |
| 2868 | else if (TypeOffsets.size() < Index) { |
| 2869 | TypeOffsets.resize(Index + 1); |
| 2870 | TypeOffsets[Index] = Offset; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2871 | } else { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2872 | llvm_unreachable("Types emitted in wrong order"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2873 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2874 | } |
| 2875 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2876 | //===----------------------------------------------------------------------===// |
| 2877 | // Declaration Serialization |
| 2878 | //===----------------------------------------------------------------------===// |
| 2879 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2880 | /// \brief Write the block containing all of the declaration IDs |
| 2881 | /// lexically declared within the given DeclContext. |
| 2882 | /// |
| 2883 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2884 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2885 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2886 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2887 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2888 | return 0; |
| 2889 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2890 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2891 | SmallVector<uint32_t, 128> KindDeclPairs; |
| 2892 | for (const auto *D : DC->decls()) { |
| 2893 | KindDeclPairs.push_back(D->getKind()); |
| 2894 | KindDeclPairs.push_back(GetDeclRef(D)); |
| 2895 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2896 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2897 | ++NumLexicalDeclContexts; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2898 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2899 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, |
| 2900 | bytes(KindDeclPairs)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2901 | return Offset; |
| 2902 | } |
| 2903 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2904 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2905 | using namespace llvm; |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2906 | |
| 2907 | // Write the type offsets array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2908 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2909 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2910 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2911 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2912 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2913 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2914 | { |
| 2915 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), |
| 2916 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; |
| 2917 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
| 2918 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2919 | |
| 2920 | // Write the declaration offsets array |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2921 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2922 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2923 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2924 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2925 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2926 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2927 | { |
| 2928 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), |
| 2929 | FirstDeclID - NUM_PREDEF_DECL_IDS}; |
| 2930 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
| 2931 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2934 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2935 | using namespace llvm; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2936 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2937 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 2938 | FileDeclIDs.begin(), FileDeclIDs.end()); |
| 2939 | std::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), |
| 2940 | llvm::less_first()); |
| 2941 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2942 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2943 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 2944 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 2945 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 2946 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 2947 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 2948 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2949 | } |
| 2950 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2951 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2952 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2953 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2954 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2955 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2956 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, |
| 2957 | FileGroupedDeclIDs.size()}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2958 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2961 | void ASTWriter::WriteComments() { |
| 2962 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2963 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2964 | RecordData Record; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2965 | for (const auto *I : RawComments) { |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2966 | Record.clear(); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2967 | AddSourceRange(I->getSourceRange(), Record); |
| 2968 | Record.push_back(I->getKind()); |
| 2969 | Record.push_back(I->isTrailingComment()); |
| 2970 | Record.push_back(I->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2971 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2972 | } |
| 2973 | Stream.ExitBlock(); |
| 2974 | } |
| 2975 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2976 | //===----------------------------------------------------------------------===// |
| 2977 | // Global Method Pool and Selector Serialization |
| 2978 | //===----------------------------------------------------------------------===// |
| 2979 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2980 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2981 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2982 | // 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] | 2983 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2984 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2985 | |
| 2986 | public: |
| 2987 | typedef Selector key_type; |
| 2988 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2989 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2990 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2991 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2992 | ObjCMethodList Instance, Factory; |
| 2993 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2994 | typedef const data_type& data_type_ref; |
| 2995 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2996 | typedef unsigned hash_value_type; |
| 2997 | typedef unsigned offset_type; |
| 2998 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2999 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3000 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3001 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 3002 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3003 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3004 | |
| 3005 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3006 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3007 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3008 | using namespace llvm::support; |
| 3009 | endian::Writer<little> LE(Out); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3010 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3011 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3012 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 3013 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3014 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3015 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3016 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3017 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3018 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3019 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3020 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3021 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3022 | return std::make_pair(KeyLen, DataLen); |
| 3023 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3024 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3025 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3026 | using namespace llvm::support; |
| 3027 | endian::Writer<little> LE(Out); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3028 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3029 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 3030 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3031 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3032 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3033 | if (N == 0) |
| 3034 | N = 1; |
| 3035 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3036 | LE.write<uint32_t>( |
| 3037 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3038 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3040 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3041 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3042 | using namespace llvm::support; |
| 3043 | endian::Writer<little> LE(Out); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3044 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3045 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3046 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3047 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3048 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3049 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3050 | ++NumInstanceMethods; |
| 3051 | |
| 3052 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3053 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3054 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3055 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3056 | ++NumFactoryMethods; |
| 3057 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3058 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 3059 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3060 | unsigned InstanceHasMoreThanOneDeclBit = |
| 3061 | Methods.Instance.hasMoreThanOneDecl(); |
| 3062 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 3063 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 3064 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3065 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 3066 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3067 | unsigned FactoryHasMoreThanOneDeclBit = |
| 3068 | Methods.Factory.hasMoreThanOneDecl(); |
| 3069 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 3070 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 3071 | FactoryBits; |
| 3072 | LE.write<uint16_t>(FullInstanceBits); |
| 3073 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3074 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3075 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3076 | if (Method->getMethod()) |
| 3077 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3078 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3079 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3080 | if (Method->getMethod()) |
| 3081 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3082 | |
| 3083 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3084 | } |
| 3085 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3086 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3087 | } // end anonymous namespace |
| 3088 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3089 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3090 | /// |
| 3091 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3092 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 3093 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3094 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3095 | using namespace llvm; |
| 3096 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3097 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3098 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3099 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3100 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3101 | // 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] | 3102 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3103 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3104 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3105 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3106 | // Create the on-disk hash table representation. We walk through every |
| 3107 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3108 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3109 | for (auto &SelectorAndID : SelectorIDs) { |
| 3110 | Selector S = SelectorAndID.first; |
| 3111 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3112 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3113 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3114 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3115 | ObjCMethodList(), |
| 3116 | ObjCMethodList() |
| 3117 | }; |
| 3118 | if (F != SemaRef.MethodPool.end()) { |
| 3119 | Data.Instance = F->second.first; |
| 3120 | Data.Factory = F->second.second; |
| 3121 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3122 | // 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] | 3123 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3124 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3125 | // Selector already exists. Did it change? |
| 3126 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3127 | for (ObjCMethodList *M = &Data.Instance; |
| 3128 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 3129 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3130 | changed = true; |
| 3131 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3132 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3133 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3134 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3135 | changed = true; |
| 3136 | } |
| 3137 | if (!changed) |
| 3138 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3139 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3140 | // A new method pool entry. |
| 3141 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3142 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3143 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3144 | } |
| 3145 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3146 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3147 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3148 | uint32_t BucketOffset; |
| 3149 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3150 | using namespace llvm::support; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3151 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3152 | llvm::raw_svector_ostream Out(MethodPool); |
| 3153 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3154 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3155 | BucketOffset = Generator.Emit(Out, Trait); |
| 3156 | } |
| 3157 | |
| 3158 | // Create a blob abbreviation |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3159 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3160 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3161 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3162 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3163 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3164 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3165 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3166 | // Write the method pool |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3167 | { |
| 3168 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, |
| 3169 | NumTableEntries}; |
| 3170 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
| 3171 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3172 | |
| 3173 | // Create a blob abbreviation for the selector table offsets. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3174 | Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3175 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3176 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3177 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3178 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3179 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3180 | |
| 3181 | // Write the selector offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3182 | { |
| 3183 | RecordData::value_type Record[] = { |
| 3184 | SELECTOR_OFFSETS, SelectorOffsets.size(), |
| 3185 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; |
| 3186 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 3187 | bytes(SelectorOffsets)); |
| 3188 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3192 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3193 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3194 | using namespace llvm; |
| 3195 | if (SemaRef.ReferencedSelectors.empty()) |
| 3196 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3197 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3198 | RecordData Record; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3199 | ASTRecordWriter Writer(*this, Record); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3200 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3201 | // 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] | 3202 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3203 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3204 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3205 | Selector Sel = SelectorAndLocation.first; |
| 3206 | SourceLocation Loc = SelectorAndLocation.second; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3207 | Writer.AddSelectorRef(Sel); |
| 3208 | Writer.AddSourceLocation(Loc); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3209 | } |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3210 | Writer.Emit(REFERENCED_SELECTOR_POOL); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3211 | } |
| 3212 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3213 | //===----------------------------------------------------------------------===// |
| 3214 | // Identifier Table Serialization |
| 3215 | //===----------------------------------------------------------------------===// |
| 3216 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3217 | /// Determine the declaration that should be put into the name lookup table to |
| 3218 | /// represent the given declaration in this module. This is usually D itself, |
| 3219 | /// but if D was imported and merged into a local declaration, we want the most |
| 3220 | /// recent local declaration instead. The chosen declaration will be the most |
| 3221 | /// recent declaration in any module that imports this one. |
| 3222 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3223 | NamedDecl *D) { |
| 3224 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3225 | return D; |
| 3226 | |
| 3227 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3228 | // For Redeclarable decls, a prior declaration might be local. |
| 3229 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3230 | // If we find a local decl, we're done. |
| 3231 | if (!Redecl->isFromASTFile()) { |
| 3232 | // Exception: in very rare cases (for injected-class-names), not all |
| 3233 | // redeclarations are in the same semantic context. Skip ones in a |
| 3234 | // different context. They don't go in this lookup table at all. |
| 3235 | if (!Redecl->getDeclContext()->getRedeclContext()->Equals( |
| 3236 | D->getDeclContext()->getRedeclContext())) |
| 3237 | continue; |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3238 | return cast<NamedDecl>(Redecl); |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3239 | } |
| 3240 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3241 | // 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] | 3242 | // local one. |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3243 | if (Redecl->getOwningModuleID() == 0) |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3244 | break; |
| 3245 | } |
| 3246 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3247 | // For Mergeable decls, the first decl might be local. |
| 3248 | if (!First->isFromASTFile()) |
| 3249 | return cast<NamedDecl>(First); |
| 3250 | } |
| 3251 | |
| 3252 | // All declarations are imported. Our most recent declaration will also be |
| 3253 | // the most recent one in anyone who imports us. |
| 3254 | return D; |
| 3255 | } |
| 3256 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3257 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3258 | |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3259 | class ASTIdentifierTableTrait { |
| 3260 | ASTWriter &Writer; |
| 3261 | Preprocessor &PP; |
| 3262 | IdentifierResolver &IdResolver; |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3263 | bool IsModule; |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3264 | bool NeedDecls; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3265 | ASTWriter::RecordData *InterestingIdentifierOffsets; |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3266 | |
| 3267 | /// \brief Determines whether this is an "interesting" identifier that needs a |
| 3268 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3269 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3270 | /// to check that. |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3271 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3272 | if (MacroOffset || |
| 3273 | II->isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3274 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3275 | II->hasRevertedTokenIDToIdentifier() || |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3276 | (NeedDecls && II->getFETokenInfo<void>())) |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3277 | return true; |
| 3278 | |
| 3279 | return false; |
| 3280 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3281 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3282 | public: |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3283 | typedef IdentifierInfo* key_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3284 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3285 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3286 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3287 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3288 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3289 | typedef unsigned hash_value_type; |
| 3290 | typedef unsigned offset_type; |
| 3291 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3292 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3293 | IdentifierResolver &IdResolver, bool IsModule, |
| 3294 | ASTWriter::RecordData *InterestingIdentifierOffsets) |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3295 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3296 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), |
| 3297 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3298 | |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3299 | bool needDecls() const { return NeedDecls; } |
| 3300 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3301 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 3302 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3303 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3304 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3305 | bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 3306 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3307 | return isInterestingIdentifier(II, MacroOffset); |
| 3308 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3309 | |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3310 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { |
| 3311 | return isInterestingIdentifier(II, 0); |
| 3312 | } |
| 3313 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3314 | std::pair<unsigned,unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3315 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3316 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3317 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3318 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3319 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3320 | DataLen += 2; // 2 bytes for builtin ID |
| 3321 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3322 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3323 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3324 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3325 | if (NeedDecls) { |
| 3326 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3327 | DEnd = IdResolver.end(); |
| 3328 | D != DEnd; ++D) |
| 3329 | DataLen += 4; |
| 3330 | } |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3331 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3332 | using namespace llvm::support; |
| 3333 | endian::Writer<little> LE(Out); |
| 3334 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3335 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3336 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3337 | // We emit the key length after the data length so that every |
| 3338 | // string is preceded by a 16-bit length. This matches the PTH |
| 3339 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3340 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3341 | return std::make_pair(KeyLen, DataLen); |
| 3342 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3343 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3344 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3345 | unsigned KeyLen) { |
| 3346 | // Record the location of the key data. This is used when generating |
| 3347 | // the mapping from persistent IDs to strings. |
| 3348 | Writer.SetIdentifierOffset(II, Out.tell()); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3349 | |
| 3350 | // Emit the offset of the key/data length information to the interesting |
| 3351 | // identifiers table if necessary. |
| 3352 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) |
| 3353 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); |
| 3354 | |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3355 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3356 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3357 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3358 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3359 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3360 | using namespace llvm::support; |
| 3361 | endian::Writer<little> LE(Out); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3362 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3363 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3364 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3365 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3366 | return; |
| 3367 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3368 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3369 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3370 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3371 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3372 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3373 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3374 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3375 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3376 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3377 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3378 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3379 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3380 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3381 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3382 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3383 | if (HadMacroDefinition) |
| 3384 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3385 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3386 | if (NeedDecls) { |
| 3387 | // Emit the declaration IDs in reverse order, because the |
| 3388 | // IdentifierResolver provides the declarations as they would be |
| 3389 | // visible (e.g., the function "stat" would come before the struct |
| 3390 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3391 | // (so we need to see the struct "stat" before the function "stat"). |
| 3392 | // Only emit declarations that aren't from a chained PCH, though. |
| 3393 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), |
| 3394 | IdResolver.end()); |
| 3395 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3396 | DEnd = Decls.rend(); |
| 3397 | D != DEnd; ++D) |
| 3398 | LE.write<uint32_t>( |
| 3399 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
| 3400 | } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3401 | } |
| 3402 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3403 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3404 | } // end anonymous namespace |
| 3405 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3406 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3407 | /// |
| 3408 | /// The identifier table consists of a blob containing string data |
| 3409 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3410 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3411 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 3412 | IdentifierResolver &IdResolver, |
| 3413 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3414 | using namespace llvm; |
| 3415 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3416 | RecordData InterestingIdents; |
| 3417 | |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3418 | // Create and write out the blob that contains the identifier |
| 3419 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3420 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3421 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3422 | ASTIdentifierTableTrait Trait( |
| 3423 | *this, PP, IdResolver, IsModule, |
| 3424 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3425 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3426 | // Look for any identifiers that were named while processing the |
| 3427 | // headers, but are otherwise not needed. We add these to the hash |
| 3428 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3429 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3430 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3431 | SmallVector<const IdentifierInfo *, 128> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3432 | for (const auto &ID : PP.getIdentifierTable()) |
| 3433 | IIs.push_back(ID.second); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3434 | // Sort the identifiers lexicographically before getting them references so |
| 3435 | // that their order is stable. |
| 3436 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 3437 | for (const IdentifierInfo *II : IIs) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3438 | if (Trait.isInterestingNonMacroIdentifier(II)) |
| 3439 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3440 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3441 | // Create the on-disk hash table representation. We only store offsets |
| 3442 | // for identifiers that appear here for the first time. |
| 3443 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3444 | for (auto IdentIDPair : IdentifierIDs) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3445 | auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3446 | IdentID ID = IdentIDPair.second; |
| 3447 | assert(II && "NULL identifier in identifier table"); |
Vassil Vassilev | 262f41e | 2016-03-30 20:16:03 +0000 | [diff] [blame] | 3448 | // Write out identifiers if either the ID is local or the identifier has |
| 3449 | // changed since it was loaded. |
| 3450 | if (ID >= FirstIdentID || !Chain || !II->isFromAST() |
| 3451 | || II->hasChangedSinceDeserialization() || |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3452 | (Trait.needDecls() && |
| 3453 | II->hasFETokenInfoChangedSinceDeserialization())) |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3454 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3455 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3456 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3457 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3458 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3459 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3460 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3461 | using namespace llvm::support; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3462 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3463 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3464 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3465 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | // Create a blob abbreviation |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3469 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3470 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3471 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3472 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3473 | unsigned IDTableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3474 | |
| 3475 | // Write the identifier table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3476 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3477 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | // Write the offsets table for identifier IDs. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3481 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3482 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3483 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3484 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3485 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3486 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3487 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3488 | #ifndef NDEBUG |
| 3489 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3490 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3491 | #endif |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3492 | |
| 3493 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, |
| 3494 | IdentifierOffsets.size(), |
| 3495 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3496 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3497 | bytes(IdentifierOffsets)); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3498 | |
| 3499 | // In C++, write the list of interesting identifiers (those that are |
| 3500 | // defined as macros, poisoned, or similar unusual things). |
| 3501 | if (!InterestingIdents.empty()) |
| 3502 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3505 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3506 | // DeclContext's Name Lookup Table Serialization |
| 3507 | //===----------------------------------------------------------------------===// |
| 3508 | |
| 3509 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3510 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3511 | // Trait used for the on-disk hash table used in the method pool. |
| 3512 | class ASTDeclContextNameLookupTrait { |
| 3513 | ASTWriter &Writer; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3514 | llvm::SmallVector<DeclID, 64> DeclIDs; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3515 | |
| 3516 | public: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3517 | typedef DeclarationNameKey key_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3518 | typedef key_type key_type_ref; |
| 3519 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3520 | /// A start and end index into DeclIDs, representing a sequence of decls. |
| 3521 | typedef std::pair<unsigned, unsigned> data_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3522 | typedef const data_type& data_type_ref; |
| 3523 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3524 | typedef unsigned hash_value_type; |
| 3525 | typedef unsigned offset_type; |
| 3526 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3527 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 3528 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3529 | template<typename Coll> |
| 3530 | data_type getData(const Coll &Decls) { |
| 3531 | unsigned Start = DeclIDs.size(); |
| 3532 | for (NamedDecl *D : Decls) { |
| 3533 | DeclIDs.push_back( |
| 3534 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); |
| 3535 | } |
| 3536 | return std::make_pair(Start, DeclIDs.size()); |
| 3537 | } |
| 3538 | |
| 3539 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { |
| 3540 | unsigned Start = DeclIDs.size(); |
| 3541 | for (auto ID : FromReader) |
| 3542 | DeclIDs.push_back(ID); |
| 3543 | return std::make_pair(Start, DeclIDs.size()); |
| 3544 | } |
| 3545 | |
| 3546 | static bool EqualKey(key_type_ref a, key_type_ref b) { |
| 3547 | return a == b; |
| 3548 | } |
| 3549 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3550 | hash_value_type ComputeHash(DeclarationNameKey Name) { |
| 3551 | return Name.getHash(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3552 | } |
| 3553 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3554 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { |
| 3555 | assert(Writer.hasChain() && |
| 3556 | "have reference to loaded module file but no chain?"); |
| 3557 | |
| 3558 | using namespace llvm::support; |
| 3559 | endian::Writer<little>(Out) |
| 3560 | .write<uint32_t>(Writer.getChain()->getModuleFileID(F)); |
| 3561 | } |
| 3562 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3563 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, |
| 3564 | DeclarationNameKey Name, |
| 3565 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3566 | using namespace llvm::support; |
| 3567 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3568 | unsigned KeyLen = 1; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3569 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3570 | case DeclarationName::Identifier: |
| 3571 | case DeclarationName::ObjCZeroArgSelector: |
| 3572 | case DeclarationName::ObjCOneArgSelector: |
| 3573 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3574 | case DeclarationName::CXXLiteralOperatorName: |
| 3575 | KeyLen += 4; |
| 3576 | break; |
| 3577 | case DeclarationName::CXXOperatorName: |
| 3578 | KeyLen += 1; |
| 3579 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3580 | case DeclarationName::CXXConstructorName: |
| 3581 | case DeclarationName::CXXDestructorName: |
| 3582 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3583 | case DeclarationName::CXXUsingDirective: |
| 3584 | break; |
| 3585 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3586 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3587 | |
Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3588 | // 4 bytes for each DeclID. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3589 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); |
| 3590 | assert(uint16_t(DataLen) == DataLen && |
| 3591 | "too many decls for serialized lookup result"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3592 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3593 | |
| 3594 | return std::make_pair(KeyLen, DataLen); |
| 3595 | } |
| 3596 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3597 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3598 | using namespace llvm::support; |
| 3599 | endian::Writer<little> LE(Out); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3600 | LE.write<uint8_t>(Name.getKind()); |
| 3601 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3602 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3603 | case DeclarationName::CXXLiteralOperatorName: |
| 3604 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3605 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3606 | case DeclarationName::ObjCZeroArgSelector: |
| 3607 | case DeclarationName::ObjCOneArgSelector: |
| 3608 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3609 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3610 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3611 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3612 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3613 | "Invalid operator?"); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3614 | LE.write<uint8_t>(Name.getOperatorKind()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3615 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3616 | case DeclarationName::CXXConstructorName: |
| 3617 | case DeclarationName::CXXDestructorName: |
| 3618 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3619 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3620 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3621 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3622 | |
| 3623 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3624 | } |
| 3625 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3626 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, |
| 3627 | unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3628 | using namespace llvm::support; |
| 3629 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3630 | uint64_t Start = Out.tell(); (void)Start; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3631 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) |
| 3632 | LE.write<uint32_t>(DeclIDs[I]); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3633 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3634 | } |
| 3635 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3636 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3637 | } // end anonymous namespace |
| 3638 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3639 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 3640 | DeclContext *DC) { |
| 3641 | return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage; |
| 3642 | } |
| 3643 | |
| 3644 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 3645 | DeclContext *DC) { |
| 3646 | for (auto *D : Result.getLookupResult()) |
| 3647 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 3648 | return false; |
| 3649 | |
| 3650 | return true; |
| 3651 | } |
| 3652 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3653 | void |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3654 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3655 | llvm::SmallVectorImpl<char> &LookupTable) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3656 | assert(!ConstDC->HasLazyLocalLexicalLookups && |
| 3657 | !ConstDC->HasLazyExternalLexicalLookups && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3658 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3659 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3660 | // FIXME: We need to build the lookups table, which is logically const. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3661 | auto *DC = const_cast<DeclContext*>(ConstDC); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3662 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 3663 | |
| 3664 | // Create the on-disk hash table representation. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3665 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, |
| 3666 | ASTDeclContextNameLookupTrait> Generator; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3667 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3668 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3669 | // The first step is to collect the declaration names which we need to |
| 3670 | // serialize into the name lookup table, and to collect them in a stable |
| 3671 | // order. |
| 3672 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3673 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3674 | // We also build up small sets of the constructor and conversion function |
| 3675 | // names which are visible. |
| 3676 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3677 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3678 | for (auto &Lookup : *DC->buildLookup()) { |
| 3679 | auto &Name = Lookup.first; |
| 3680 | auto &Result = Lookup.second; |
| 3681 | |
Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 3682 | // If there are no local declarations in our lookup result, we |
| 3683 | // don't need to write an entry for the name at all. If we can't |
| 3684 | // write out a lookup set without performing more deserialization, |
| 3685 | // just skip this entry. |
| 3686 | if (isLookupResultExternal(Result, DC) && |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3687 | isLookupResultEntirelyExternal(Result, DC)) |
| 3688 | continue; |
| 3689 | |
| 3690 | // We also skip empty results. If any of the results could be external and |
| 3691 | // the currently available results are empty, then all of the results are |
| 3692 | // external and we skip it above. So the only way we get here with an empty |
| 3693 | // results is when no results could have been external *and* we have |
| 3694 | // external results. |
| 3695 | // |
| 3696 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 3697 | // lookups into a decl context as an optimization, today we *have* to skip |
| 3698 | // them because there are names with empty lookup results in decl contexts |
| 3699 | // which we can't emit in any stable ordering: we lookup constructors and |
| 3700 | // conversion functions in the enclosing namespace scope creating empty |
| 3701 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 3702 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 3703 | // here by omitting lookups with empty results. |
| 3704 | if (Lookup.second.getLookupResult().empty()) |
| 3705 | continue; |
| 3706 | |
| 3707 | switch (Lookup.first.getNameKind()) { |
| 3708 | default: |
| 3709 | Names.push_back(Lookup.first); |
| 3710 | break; |
| 3711 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3712 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3713 | assert(isa<CXXRecordDecl>(DC) && |
| 3714 | "Cannot have a constructor name outside of a class!"); |
| 3715 | ConstructorNameSet.insert(Name); |
| 3716 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3717 | |
| 3718 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3719 | assert(isa<CXXRecordDecl>(DC) && |
| 3720 | "Cannot have a conversion function name outside of a class!"); |
| 3721 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 3722 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3723 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3724 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3725 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3726 | // Sort the names into a stable order. |
| 3727 | std::sort(Names.begin(), Names.end()); |
| 3728 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3729 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3730 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3731 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3732 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3733 | // First we try the easy case by forming the current context's constructor |
| 3734 | // name and adding that name first. This is a very useful optimization to |
| 3735 | // avoid walking the lexical declarations in many cases, and it also |
| 3736 | // handles the only case where a constructor name can come from some other |
| 3737 | // lexical context -- when that name is an implicit constructor merged from |
| 3738 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 3739 | // conversion function which doesn't occur in all the lexical contexts |
| 3740 | // would be an ODR violation. |
| 3741 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 3742 | Context->getCanonicalType(Context->getRecordType(D))); |
| 3743 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 3744 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3745 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3746 | // If we still have constructors or conversion functions, we walk all the |
| 3747 | // names in the decl and add the constructors and conversion functions |
| 3748 | // which are visible in the order they lexically occur within the context. |
| 3749 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 3750 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 3751 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 3752 | auto Name = ChildND->getDeclName(); |
| 3753 | switch (Name.getNameKind()) { |
| 3754 | default: |
| 3755 | continue; |
| 3756 | |
| 3757 | case DeclarationName::CXXConstructorName: |
| 3758 | if (ConstructorNameSet.erase(Name)) |
| 3759 | Names.push_back(Name); |
| 3760 | break; |
| 3761 | |
| 3762 | case DeclarationName::CXXConversionFunctionName: |
| 3763 | if (ConversionNameSet.erase(Name)) |
| 3764 | Names.push_back(Name); |
| 3765 | break; |
| 3766 | } |
| 3767 | |
| 3768 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 3769 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3770 | } |
| 3771 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3772 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 3773 | "constructors by walking all the " |
| 3774 | "lexical members of the context."); |
| 3775 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 3776 | "conversion functions by walking all " |
| 3777 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3778 | } |
| 3779 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3780 | // Next we need to do a lookup with each name into this decl context to fully |
| 3781 | // populate any results from external sources. We don't actually use the |
| 3782 | // results of these lookups because we only want to use the results after all |
| 3783 | // results have been loaded and the pointers into them will be stable. |
| 3784 | for (auto &Name : Names) |
| 3785 | DC->lookup(Name); |
| 3786 | |
| 3787 | // Now we need to insert the results for each name into the hash table. For |
| 3788 | // constructor names and conversion function names, we actually need to merge |
| 3789 | // all of the results for them into one list of results each and insert |
| 3790 | // those. |
| 3791 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 3792 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 3793 | |
| 3794 | // Now loop over the names, either inserting them or appending for the two |
| 3795 | // special cases. |
| 3796 | for (auto &Name : Names) { |
| 3797 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 3798 | |
| 3799 | switch (Name.getNameKind()) { |
| 3800 | default: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3801 | Generator.insert(Name, Trait.getData(Result), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3802 | break; |
| 3803 | |
| 3804 | case DeclarationName::CXXConstructorName: |
| 3805 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 3806 | break; |
| 3807 | |
| 3808 | case DeclarationName::CXXConversionFunctionName: |
| 3809 | ConversionDecls.append(Result.begin(), Result.end()); |
| 3810 | break; |
| 3811 | } |
| 3812 | } |
| 3813 | |
| 3814 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 3815 | // the first declaration's name here because the name itself isn't part of |
| 3816 | // the key, only the kind of name is used. |
| 3817 | if (!ConstructorDecls.empty()) |
| 3818 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3819 | Trait.getData(ConstructorDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3820 | if (!ConversionDecls.empty()) |
| 3821 | Generator.insert(ConversionDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3822 | Trait.getData(ConversionDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3823 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3824 | // Create the on-disk hash table. Also emit the existing imported and |
| 3825 | // merged table if there is one. |
| 3826 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; |
| 3827 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3828 | } |
| 3829 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3830 | /// \brief Write the block containing all of the declaration IDs |
| 3831 | /// visible from the given DeclContext. |
| 3832 | /// |
| 3833 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3834 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3835 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 3836 | DeclContext *DC) { |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3837 | // If we imported a key declaration of this namespace, write the visible |
| 3838 | // lookup results as an update record for it rather than including them |
| 3839 | // on this declaration. We will only look at key declarations on reload. |
| 3840 | if (isa<NamespaceDecl>(DC) && Chain && |
| 3841 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { |
| 3842 | // Only do this once, for the first local declaration of the namespace. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3843 | for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3844 | Prev = Prev->getPreviousDecl()) |
| 3845 | if (!Prev->isFromASTFile()) |
| 3846 | return 0; |
| 3847 | |
| 3848 | // Note that we need to emit an update record for the primary context. |
| 3849 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); |
| 3850 | |
| 3851 | // Make sure all visible decls are written. They will be recorded later. We |
| 3852 | // do this using a side data structure so we can sort the names into |
| 3853 | // a deterministic order. |
| 3854 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); |
| 3855 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> |
| 3856 | LookupResults; |
| 3857 | if (Map) { |
| 3858 | LookupResults.reserve(Map->size()); |
| 3859 | for (auto &Entry : *Map) |
| 3860 | LookupResults.push_back( |
| 3861 | std::make_pair(Entry.first, Entry.second.getLookupResult())); |
| 3862 | } |
| 3863 | |
| 3864 | std::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); |
| 3865 | for (auto &NameAndResult : LookupResults) { |
| 3866 | DeclarationName Name = NameAndResult.first; |
| 3867 | DeclContext::lookup_result Result = NameAndResult.second; |
| 3868 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || |
| 3869 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 3870 | // We have to work around a name lookup bug here where negative lookup |
| 3871 | // results for these names get cached in namespace lookup tables (these |
| 3872 | // names should never be looked up in a namespace). |
| 3873 | assert(Result.empty() && "Cannot have a constructor or conversion " |
| 3874 | "function name in a namespace!"); |
| 3875 | continue; |
| 3876 | } |
| 3877 | |
| 3878 | for (NamedDecl *ND : Result) |
| 3879 | if (!ND->isFromASTFile()) |
| 3880 | GetDeclRef(ND); |
| 3881 | } |
| 3882 | |
| 3883 | return 0; |
| 3884 | } |
| 3885 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3886 | if (DC->getPrimaryContext() != DC) |
| 3887 | return 0; |
| 3888 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3889 | // Skip contexts which don't support name lookup. |
| 3890 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3891 | return 0; |
| 3892 | |
| 3893 | // If not in C++, we perform name lookup for the translation unit via the |
| 3894 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3895 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3896 | return 0; |
| 3897 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3898 | // Serialize the contents of the mapping used for lookup. Note that, |
| 3899 | // although we have two very different code paths, the serialized |
| 3900 | // representation is the same for both cases: a declaration name, |
| 3901 | // followed by a size, followed by references to the visible |
| 3902 | // declarations that have that name. |
| 3903 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3904 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3905 | if (!Map || Map->empty()) |
| 3906 | return 0; |
| 3907 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3908 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3909 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3910 | GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3911 | |
| 3912 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3913 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3914 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3915 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3916 | ++NumVisibleDeclContexts; |
| 3917 | return Offset; |
| 3918 | } |
| 3919 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3920 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3921 | /// |
| 3922 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3923 | /// 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] | 3924 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3925 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3926 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3927 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3928 | if (!Map || Map->empty()) |
| 3929 | return; |
| 3930 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3931 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3932 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3933 | GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3934 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3935 | // If we're updating a namespace, select a key declaration as the key for the |
| 3936 | // update record; those are the only ones that will be checked on reload. |
| 3937 | if (isa<NamespaceDecl>(DC)) |
| 3938 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); |
| 3939 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3940 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3941 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3942 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3943 | } |
| 3944 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3945 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3946 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3947 | RecordData::value_type Record[] = {Opts.fp_contract}; |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3948 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3949 | } |
| 3950 | |
| 3951 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3952 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3953 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3954 | return; |
| 3955 | |
| 3956 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3957 | RecordData Record; |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3958 | for (const auto &I:Opts.OptMap) { |
| 3959 | AddString(I.getKey(), Record); |
| 3960 | auto V = I.getValue(); |
Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 3961 | Record.push_back(V.Supported ? 1 : 0); |
| 3962 | Record.push_back(V.Enabled ? 1 : 0); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3963 | Record.push_back(V.Avail); |
| 3964 | Record.push_back(V.Core); |
| 3965 | } |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3966 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3967 | } |
| 3968 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3969 | void ASTWriter::WriteOpenCLExtensionTypes(Sema &SemaRef) { |
| 3970 | if (!SemaRef.Context.getLangOpts().OpenCL) |
| 3971 | return; |
| 3972 | |
| 3973 | RecordData Record; |
| 3974 | for (const auto &I : SemaRef.OpenCLTypeExtMap) { |
| 3975 | Record.push_back( |
| 3976 | static_cast<unsigned>(getTypeID(I.first->getCanonicalTypeInternal()))); |
| 3977 | Record.push_back(I.second.size()); |
| 3978 | for (auto Ext : I.second) |
| 3979 | AddString(Ext, Record); |
| 3980 | } |
| 3981 | Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record); |
| 3982 | } |
| 3983 | |
| 3984 | void ASTWriter::WriteOpenCLExtensionDecls(Sema &SemaRef) { |
| 3985 | if (!SemaRef.Context.getLangOpts().OpenCL) |
| 3986 | return; |
| 3987 | |
| 3988 | RecordData Record; |
| 3989 | for (const auto &I : SemaRef.OpenCLDeclExtMap) { |
| 3990 | Record.push_back(getDeclID(I.first)); |
| 3991 | Record.push_back(static_cast<unsigned>(I.second.size())); |
| 3992 | for (auto Ext : I.second) |
| 3993 | AddString(Ext, Record); |
| 3994 | } |
| 3995 | Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record); |
| 3996 | } |
| 3997 | |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 3998 | void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) { |
| 3999 | if (SemaRef.ForceCUDAHostDeviceDepth > 0) { |
| 4000 | RecordData::value_type Record[] = {SemaRef.ForceCUDAHostDeviceDepth}; |
| 4001 | Stream.EmitRecord(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH, Record); |
| 4002 | } |
| 4003 | } |
| 4004 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4005 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4006 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4007 | RecordData Categories; |
| 4008 | |
| 4009 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 4010 | unsigned Size = 0; |
| 4011 | unsigned StartIndex = Categories.size(); |
| 4012 | |
| 4013 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 4014 | |
| 4015 | // Allocate space for the size. |
| 4016 | Categories.push_back(0); |
| 4017 | |
| 4018 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 4019 | for (ObjCInterfaceDecl::known_categories_iterator |
| 4020 | Cat = Class->known_categories_begin(), |
| 4021 | CatEnd = Class->known_categories_end(); |
| 4022 | Cat != CatEnd; ++Cat, ++Size) { |
| 4023 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 4024 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4025 | } |
| 4026 | |
| 4027 | // Update the size. |
| 4028 | Categories[StartIndex] = Size; |
| 4029 | |
| 4030 | // Record this interface -> category map. |
| 4031 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 4032 | CategoriesMap.push_back(CatInfo); |
| 4033 | } |
| 4034 | |
| 4035 | // Sort the categories map by the definition ID, since the reader will be |
| 4036 | // performing binary searches on this information. |
| 4037 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 4038 | |
| 4039 | // Emit the categories map. |
| 4040 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4041 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4042 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4043 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 4044 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 4045 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4046 | unsigned AbbrevID = Stream.EmitAbbrev(std::move(Abbrev)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4047 | |
| 4048 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; |
| 4049 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 4050 | reinterpret_cast<char *>(CategoriesMap.data()), |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4051 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4052 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4053 | // Emit the category lists. |
| 4054 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 4055 | } |
| 4056 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4057 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 4058 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 4059 | |
| 4060 | if (LPTMap.empty()) |
| 4061 | return; |
| 4062 | |
| 4063 | RecordData Record; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4064 | for (auto &LPTMapEntry : LPTMap) { |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4065 | const FunctionDecl *FD = LPTMapEntry.first; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4066 | LateParsedTemplate &LPT = *LPTMapEntry.second; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4067 | AddDeclRef(FD, Record); |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4068 | AddDeclRef(LPT.D, Record); |
| 4069 | Record.push_back(LPT.Toks.size()); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4070 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4071 | for (const auto &Tok : LPT.Toks) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4072 | AddToken(Tok, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4073 | } |
| 4074 | } |
| 4075 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 4076 | } |
| 4077 | |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4078 | /// \brief Write the state of 'pragma clang optimize' at the end of the module. |
| 4079 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 4080 | RecordData Record; |
| 4081 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 4082 | AddSourceLocation(PragmaLoc, Record); |
| 4083 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 4084 | } |
| 4085 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4086 | /// \brief Write the state of 'pragma ms_struct' at the end of the module. |
| 4087 | void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) { |
| 4088 | RecordData Record; |
| 4089 | Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF); |
| 4090 | Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record); |
| 4091 | } |
| 4092 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4093 | /// \brief Write the state of 'pragma pointers_to_members' at the end of the |
| 4094 | //module. |
| 4095 | void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) { |
| 4096 | RecordData Record; |
| 4097 | Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod); |
| 4098 | AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record); |
| 4099 | Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record); |
| 4100 | } |
| 4101 | |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4102 | void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, |
| 4103 | ModuleFileExtensionWriter &Writer) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4104 | // Enter the extension block. |
| 4105 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); |
| 4106 | |
| 4107 | // Emit the metadata record abbreviation. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4108 | auto Abv = std::make_shared<llvm::BitCodeAbbrev>(); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4109 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); |
| 4110 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4111 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4112 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4113 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4114 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4115 | unsigned Abbrev = Stream.EmitAbbrev(std::move(Abv)); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4116 | |
| 4117 | // Emit the metadata record. |
| 4118 | RecordData Record; |
| 4119 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); |
| 4120 | Record.push_back(EXTENSION_METADATA); |
| 4121 | Record.push_back(Metadata.MajorVersion); |
| 4122 | Record.push_back(Metadata.MinorVersion); |
| 4123 | Record.push_back(Metadata.BlockName.size()); |
| 4124 | Record.push_back(Metadata.UserInfo.size()); |
| 4125 | SmallString<64> Buffer; |
| 4126 | Buffer += Metadata.BlockName; |
| 4127 | Buffer += Metadata.UserInfo; |
| 4128 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); |
| 4129 | |
| 4130 | // Emit the contents of the extension block. |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4131 | Writer.writeExtensionContents(SemaRef, Stream); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4132 | |
| 4133 | // Exit the extension block. |
| 4134 | Stream.ExitBlock(); |
| 4135 | } |
| 4136 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4137 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4138 | // General Serialization Routines |
| 4139 | //===----------------------------------------------------------------------===// |
| 4140 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4141 | /// \brief Emit the list of attributes to the specified record. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4142 | void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) { |
| 4143 | auto &Record = *this; |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 4144 | Record.push_back(Attrs.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4145 | for (const auto *A : Attrs) { |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 4146 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4147 | Record.AddSourceRange(A->getRange()); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4148 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 4149 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 4150 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4151 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4152 | } |
| 4153 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 4154 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 4155 | AddSourceLocation(Tok.getLocation(), Record); |
| 4156 | Record.push_back(Tok.getLength()); |
| 4157 | |
| 4158 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 4159 | // if it is needed. |
| 4160 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 4161 | // FIXME: Should translate token kind to a stable encoding. |
| 4162 | Record.push_back(Tok.getKind()); |
| 4163 | // FIXME: Should translate token flags to a stable encoding. |
| 4164 | Record.push_back(Tok.getFlags()); |
| 4165 | } |
| 4166 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4167 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4168 | Record.push_back(Str.size()); |
| 4169 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 4170 | } |
| 4171 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4172 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4173 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4174 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4175 | bool Changed = |
| 4176 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4177 | |
| 4178 | // Remove a prefix to make the path relative, if relevant. |
| 4179 | const char *PathBegin = Path.data(); |
| 4180 | const char *PathPtr = |
| 4181 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 4182 | if (PathPtr != PathBegin) { |
| 4183 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 4184 | Changed = true; |
| 4185 | } |
| 4186 | |
| 4187 | return Changed; |
| 4188 | } |
| 4189 | |
| 4190 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 4191 | SmallString<128> FilePath(Path); |
| 4192 | PreparePathForOutput(FilePath); |
| 4193 | AddString(FilePath, Record); |
| 4194 | } |
| 4195 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4196 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4197 | StringRef Path) { |
| 4198 | SmallString<128> FilePath(Path); |
| 4199 | PreparePathForOutput(FilePath); |
| 4200 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 4201 | } |
| 4202 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4203 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 4204 | RecordDataImpl &Record) { |
| 4205 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4206 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4207 | Record.push_back(*Minor + 1); |
| 4208 | else |
| 4209 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4210 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4211 | Record.push_back(*Subminor + 1); |
| 4212 | else |
| 4213 | Record.push_back(0); |
| 4214 | } |
| 4215 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4216 | /// \brief Note that the identifier II occurs at the given offset |
| 4217 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4218 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4219 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4220 | // 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] | 4221 | // up earlier in the chain and thus don't need an offset. |
| 4222 | if (ID >= FirstIdentID) |
| 4223 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4224 | } |
| 4225 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4226 | /// \brief Note that the selector Sel occurs at the given offset |
| 4227 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4228 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4229 | unsigned ID = SelectorIDs[Sel]; |
| 4230 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4231 | // Don't record offsets for selectors that are also available in a different |
| 4232 | // file. |
| 4233 | if (ID < FirstSelectorID) |
| 4234 | return; |
| 4235 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4236 | } |
| 4237 | |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 4238 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream, |
| 4239 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 4240 | bool IncludeTimestamps) |
David Blaikie | 95dd362 | 2017-01-05 18:45:45 +0000 | [diff] [blame] | 4241 | : Stream(Stream), IncludeTimestamps(IncludeTimestamps) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4242 | for (const auto &Ext : Extensions) { |
| 4243 | if (auto Writer = Ext->createExtensionWriter(*this)) |
| 4244 | ModuleFileExtensionWriters.push_back(std::move(Writer)); |
| 4245 | } |
| 4246 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4247 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4248 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 4249 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4250 | } |
| 4251 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4252 | const LangOptions &ASTWriter::getLangOpts() const { |
| 4253 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 4254 | return Context->getLangOpts(); |
| 4255 | } |
| 4256 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4257 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { |
| 4258 | return IncludeTimestamps ? E->getModificationTime() : 0; |
| 4259 | } |
| 4260 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4261 | uint64_t ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile, |
| 4262 | Module *WritingModule, StringRef isysroot, |
| 4263 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4264 | WritingAST = true; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4265 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4266 | ASTHasCompilerErrors = hasErrors; |
| 4267 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4268 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4269 | Stream.Emit((unsigned)'C', 8); |
| 4270 | Stream.Emit((unsigned)'P', 8); |
| 4271 | Stream.Emit((unsigned)'C', 8); |
| 4272 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4273 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4274 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4275 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4276 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4277 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4278 | this->WritingModule = WritingModule; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4279 | ASTFileSignature Signature = |
| 4280 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4281 | Context = nullptr; |
| 4282 | PP = nullptr; |
| 4283 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4284 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4285 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4286 | WritingAST = false; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4287 | return Signature; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4288 | } |
| 4289 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4290 | template<typename Vector> |
| 4291 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4292 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4293 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4294 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4295 | Writer.AddDeclRef(*I, Record); |
| 4296 | } |
| 4297 | } |
| 4298 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4299 | uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, |
| 4300 | const std::string &OutputFile, |
| 4301 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4302 | using namespace llvm; |
| 4303 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4304 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4305 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4306 | // Make sure that the AST reader knows to finalize itself. |
| 4307 | if (Chain) |
| 4308 | Chain->finalizeForWriting(); |
| 4309 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4310 | ASTContext &Context = SemaRef.Context; |
| 4311 | Preprocessor &PP = SemaRef.PP; |
| 4312 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4313 | // Set up predefined declaration IDs. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4314 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { |
| 4315 | if (D) { |
| 4316 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); |
| 4317 | DeclIDs[D] = ID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4318 | } |
| 4319 | }; |
| 4320 | RegisterPredefDecl(Context.getTranslationUnitDecl(), |
| 4321 | PREDEF_DECL_TRANSLATION_UNIT_ID); |
| 4322 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); |
| 4323 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); |
| 4324 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); |
| 4325 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, |
| 4326 | PREDEF_DECL_OBJC_PROTOCOL_ID); |
| 4327 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); |
| 4328 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); |
| 4329 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, |
| 4330 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); |
| 4331 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4332 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4333 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, |
| 4334 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4335 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4336 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, |
| 4337 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 4338 | RegisterPredefDecl(Context.CFConstantStringTypeDecl, |
| 4339 | PREDEF_DECL_CF_CONSTANT_STRING_ID); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 4340 | RegisterPredefDecl(Context.CFConstantStringTagDecl, |
| 4341 | PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 4342 | RegisterPredefDecl(Context.TypePackElementDecl, |
| 4343 | PREDEF_DECL_TYPE_PACK_ELEMENT_ID); |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4344 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4345 | // 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] | 4346 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4347 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4348 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4349 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4350 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4351 | // Build a record containing all of the file scoped decls in this file. |
| 4352 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4353 | if (!isModule) |
| 4354 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4355 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4356 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4357 | // Build a record containing all of the delegating constructors we still need |
| 4358 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4359 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4360 | if (!isModule) |
| 4361 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4362 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4363 | // Write the set of weak, undeclared identifiers. We always write the |
| 4364 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4365 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4366 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4367 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4368 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4369 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4370 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4371 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4372 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4373 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4374 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4375 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4376 | // Build a record containing all of the ext_vector declarations. |
| 4377 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4378 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4379 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4380 | // Build a record containing all of the VTable uses information. |
| 4381 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4382 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4383 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4384 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4385 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4386 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4387 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4390 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4391 | RecordData UnusedLocalTypedefNameCandidates; |
| 4392 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4393 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4394 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4395 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4396 | RecordData PendingInstantiations; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4397 | for (const auto &I : SemaRef.PendingInstantiations) { |
| 4398 | AddDeclRef(I.first, PendingInstantiations); |
| 4399 | AddSourceLocation(I.second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4400 | } |
| 4401 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4402 | "There are local ones at end of translation unit!"); |
| 4403 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4404 | // Build a record containing some declaration references. |
| 4405 | RecordData SemaDeclRefs; |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4406 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) { |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4407 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4408 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4409 | AddDeclRef(SemaRef.getStdAlignValT(), SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4412 | RecordData CUDASpecialDeclRefs; |
| 4413 | if (Context.getcudaConfigureCallDecl()) { |
| 4414 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4415 | } |
| 4416 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4417 | // Build a record containing all of the known namespaces. |
| 4418 | RecordData KnownNamespaces; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4419 | for (const auto &I : SemaRef.KnownNamespaces) { |
| 4420 | if (!I.second) |
| 4421 | AddDeclRef(I.first, KnownNamespaces); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4422 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4423 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4424 | // Build a record of all used, undefined objects that require definitions. |
| 4425 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4426 | |
| 4427 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4428 | SemaRef.getUndefinedButUsed(Undefined); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4429 | for (const auto &I : Undefined) { |
| 4430 | AddDeclRef(I.first, UndefinedButUsed); |
| 4431 | AddSourceLocation(I.second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4432 | } |
| 4433 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4434 | // Build a record containing all delete-expressions that we would like to |
| 4435 | // analyze later in AST. |
| 4436 | RecordData DeleteExprsToAnalyze; |
| 4437 | |
| 4438 | for (const auto &DeleteExprsInfo : |
| 4439 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4440 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4441 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4442 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4443 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4444 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4445 | } |
| 4446 | } |
| 4447 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4448 | // Write the control block |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4449 | uint64_t Signature = WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4450 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4451 | // Write the remaining AST contents. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4452 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4453 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4454 | // This is so that older clang versions, before the introduction |
| 4455 | // of the control block, can read and reject the newer PCH format. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4456 | { |
| 4457 | RecordData Record = {VERSION_MAJOR}; |
| 4458 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4459 | } |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4460 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4461 | // Create a lexical update block containing all of the declarations in the |
| 4462 | // translation unit that do not come from other AST files. |
| 4463 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4464 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; |
| 4465 | for (const auto *D : TU->noload_decls()) { |
| 4466 | if (!D->isFromASTFile()) { |
| 4467 | NewGlobalKindDeclPairs.push_back(D->getKind()); |
| 4468 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); |
| 4469 | } |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4470 | } |
| 4471 | |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4472 | auto Abv = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4473 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4474 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4475 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4476 | { |
| 4477 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; |
| 4478 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 4479 | bytes(NewGlobalKindDeclPairs)); |
| 4480 | } |
| 4481 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4482 | // And a visible updates block for the translation unit. |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4483 | Abv = std::make_shared<BitCodeAbbrev>(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4484 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4485 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4486 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4487 | UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4488 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4489 | |
| 4490 | // If we have any extern "C" names, write out a visible update for them. |
| 4491 | if (Context.ExternCContext) |
| 4492 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4493 | |
| 4494 | // If the translation unit has an anonymous namespace, and we don't already |
| 4495 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4496 | // 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] | 4497 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4498 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4499 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4500 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4501 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4502 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4503 | // Add update records for all mangling numbers and static local numbers. |
| 4504 | // These aren't really update records, but this is a convenient way of |
| 4505 | // tagging this rare extra data onto the declarations. |
| 4506 | for (const auto &Number : Context.MangleNumbers) |
| 4507 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4508 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4509 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4510 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4511 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4512 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4513 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4514 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4515 | // Make sure visible decls, added to DeclContexts previously loaded from |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 4516 | // an AST file, are registered for serialization. Likewise for template |
| 4517 | // specializations added to imported templates. |
| 4518 | for (const auto *I : DeclsToEmitEvenIfUnreferenced) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4519 | GetDeclRef(I); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4520 | } |
| 4521 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4522 | // Make sure all decls associated with an identifier are registered for |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4523 | // serialization, if we're storing decls with identifiers. |
| 4524 | if (!WritingModule || !getLangOpts().CPlusPlus) { |
| 4525 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4526 | for (const auto &ID : PP.getIdentifierTable()) { |
| 4527 | const IdentifierInfo *II = ID.second; |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4528 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 4529 | IIs.push_back(II); |
| 4530 | } |
| 4531 | // Sort the identifiers to visit based on their name. |
| 4532 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 4533 | for (const IdentifierInfo *II : IIs) { |
| 4534 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4535 | DEnd = SemaRef.IdResolver.end(); |
| 4536 | D != DEnd; ++D) { |
| 4537 | GetDeclRef(*D); |
| 4538 | } |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4539 | } |
| 4540 | } |
| 4541 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 4542 | // For method pool in the module, if it contains an entry for a selector, |
| 4543 | // the entry should be complete, containing everything introduced by that |
| 4544 | // module and all modules it imports. It's possible that the entry is out of |
| 4545 | // date, so we need to pull in the new content here. |
| 4546 | |
| 4547 | // It's possible that updateOutOfDateSelector can update SelectorIDs. To be |
| 4548 | // safe, we copy all selectors out. |
| 4549 | llvm::SmallVector<Selector, 256> AllSelectors; |
| 4550 | for (auto &SelectorAndID : SelectorIDs) |
| 4551 | AllSelectors.push_back(SelectorAndID.first); |
| 4552 | for (auto &Selector : AllSelectors) |
| 4553 | SemaRef.updateOutOfDateSelector(Selector); |
| 4554 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4555 | // Form the record of special types. |
| 4556 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4557 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4558 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 4559 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 4560 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 4561 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 4562 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4563 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4564 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4565 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4566 | if (Chain) { |
| 4567 | // Write the mapping information describing our module dependencies and how |
| 4568 | // each of those modules were mapped into our own offset/ID space, so that |
| 4569 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4570 | // The map consists solely of a blob with the following format: |
| 4571 | // *(module-name-len:i16 module-name:len*i8 |
| 4572 | // source-location-offset:i32 |
| 4573 | // identifier-id:i32 |
| 4574 | // preprocessed-entity-id:i32 |
| 4575 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4576 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4577 | // selector-id:i32 |
| 4578 | // declaration-id:i32 |
| 4579 | // c++-base-specifiers-id:i32 |
| 4580 | // type-id:i32) |
| 4581 | // |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4582 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4583 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4584 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4585 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4586 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4587 | { |
| 4588 | llvm::raw_svector_ostream Out(Buffer); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4589 | for (ModuleFile *M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4590 | using namespace llvm::support; |
| 4591 | endian::Writer<little> LE(Out); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4592 | StringRef FileName = M->FileName; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4593 | LE.write<uint16_t>(FileName.size()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4594 | Out.write(FileName.data(), FileName.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4595 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4596 | // Note: if a base ID was uint max, it would not be possible to load |
| 4597 | // another module after it or have more than one entity inside it. |
| 4598 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 4599 | |
| 4600 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 4601 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 4602 | if (ShouldWrite) |
| 4603 | LE.write<uint32_t>(BaseID); |
| 4604 | else |
| 4605 | LE.write<uint32_t>(None); |
| 4606 | }; |
| 4607 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4608 | // These values should be unique within a chain, since they will be read |
| 4609 | // as keys into ContinuousRangeMaps. |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4610 | writeBaseIDOrNone(M->SLocEntryBaseOffset, M->LocalNumSLocEntries); |
| 4611 | writeBaseIDOrNone(M->BaseIdentifierID, M->LocalNumIdentifiers); |
| 4612 | writeBaseIDOrNone(M->BaseMacroID, M->LocalNumMacros); |
| 4613 | writeBaseIDOrNone(M->BasePreprocessedEntityID, |
| 4614 | M->NumPreprocessedEntities); |
| 4615 | writeBaseIDOrNone(M->BaseSubmoduleID, M->LocalNumSubmodules); |
| 4616 | writeBaseIDOrNone(M->BaseSelectorID, M->LocalNumSelectors); |
| 4617 | writeBaseIDOrNone(M->BaseDeclID, M->LocalNumDecls); |
| 4618 | writeBaseIDOrNone(M->BaseTypeIndex, M->LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4619 | } |
| 4620 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4621 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4622 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4623 | Buffer.data(), Buffer.size()); |
| 4624 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4625 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4626 | RecordData DeclUpdatesOffsetsRecord; |
| 4627 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4628 | // Keep writing types, declarations, and declaration update records |
| 4629 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4630 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 4631 | WriteTypeAbbrevs(); |
| 4632 | WriteDeclAbbrevs(); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4633 | do { |
| 4634 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 4635 | while (!DeclTypesToEmit.empty()) { |
| 4636 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 4637 | DeclTypesToEmit.pop(); |
| 4638 | if (DOT.isType()) |
| 4639 | WriteType(DOT.getType()); |
| 4640 | else |
| 4641 | WriteDecl(Context, DOT.getDecl()); |
| 4642 | } |
| 4643 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4644 | Stream.ExitBlock(); |
| 4645 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4646 | DoneWritingDeclsAndTypes = true; |
| 4647 | |
| 4648 | // These things can only be done once we've written out decls and types. |
| 4649 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4650 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 4651 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4652 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4653 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4654 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4655 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4656 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4657 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4658 | WriteReferencedSelectorsPool(SemaRef); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 4659 | WriteLateParsedTemplates(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4660 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4661 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 4662 | WriteOpenCLExtensions(SemaRef); |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4663 | WriteOpenCLExtensionTypes(SemaRef); |
| 4664 | WriteOpenCLExtensionDecls(SemaRef); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 4665 | WriteCUDAPragmas(SemaRef); |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 4666 | WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4667 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4668 | // If we're emitting a module, write out the submodule information. |
| 4669 | if (WritingModule) |
| 4670 | WriteSubmodules(WritingModule); |
| 4671 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4672 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 4673 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4674 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 4675 | if (!EagerlyDeserializedDecls.empty()) |
| 4676 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4677 | |
| 4678 | // Write the record containing tentative definitions. |
| 4679 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4680 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4681 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4682 | // Write the record containing unused file scoped decls. |
| 4683 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4684 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4685 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4686 | // Write the record containing weak undeclared identifiers. |
| 4687 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4688 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4689 | WeakUndeclaredIdentifiers); |
| 4690 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4691 | // Write the record containing ext_vector type names. |
| 4692 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4693 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4694 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4695 | // Write the record containing VTable uses information. |
| 4696 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4697 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4698 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4699 | // Write the record containing potentially unused local typedefs. |
| 4700 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 4701 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 4702 | UnusedLocalTypedefNameCandidates); |
| 4703 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4704 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4705 | if (!PendingInstantiations.empty()) |
| 4706 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4707 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4708 | // Write the record containing declaration references of Sema. |
| 4709 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4710 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4711 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4712 | // Write the record containing CUDA-specific declaration references. |
| 4713 | if (!CUDASpecialDeclRefs.empty()) |
| 4714 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4715 | |
| 4716 | // Write the delegating constructors. |
| 4717 | if (!DelegatingCtorDecls.empty()) |
| 4718 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4719 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4720 | // Write the known namespaces. |
| 4721 | if (!KnownNamespaces.empty()) |
| 4722 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4723 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4724 | // Write the undefined internal functions and variables, and inline functions. |
| 4725 | if (!UndefinedButUsed.empty()) |
| 4726 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4727 | |
| 4728 | if (!DeleteExprsToAnalyze.empty()) |
| 4729 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 4730 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4731 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4732 | for (auto *DC : UpdatedDeclContexts) |
| 4733 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4734 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4735 | if (!WritingModule) { |
| 4736 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4737 | struct ModuleInfo { |
| 4738 | uint64_t ID; |
| 4739 | Module *M; |
| 4740 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 4741 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4742 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 4743 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4744 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4745 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 4746 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4747 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4748 | |
| 4749 | if (!Imports.empty()) { |
| 4750 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4751 | return A.ID < B.ID; |
| 4752 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4753 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4754 | return A.ID == B.ID; |
| 4755 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4756 | |
| 4757 | // Sort and deduplicate module IDs. |
| 4758 | std::sort(Imports.begin(), Imports.end(), Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4759 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4760 | Imports.end()); |
| 4761 | |
| 4762 | RecordData ImportedModules; |
| 4763 | for (const auto &Import : Imports) { |
| 4764 | ImportedModules.push_back(Import.ID); |
| 4765 | // FIXME: If the module has macros imported then later has declarations |
| 4766 | // imported, this location won't be the right one as a location for the |
| 4767 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 4768 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4769 | } |
| 4770 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4771 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 4772 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4773 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4774 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4775 | WriteObjCCategories(); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4776 | if(!WritingModule) { |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4777 | WriteOptimizePragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4778 | WriteMSStructPragmaOptions(SemaRef); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4779 | WriteMSPointersToMembersPragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4780 | } |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4781 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4782 | // Some simple statistics |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4783 | RecordData::value_type Record[] = { |
| 4784 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4785 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4786 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4787 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4788 | // Write the module file extension blocks. |
| 4789 | for (const auto &ExtWriter : ModuleFileExtensionWriters) |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4790 | WriteModuleFileExtension(SemaRef, *ExtWriter); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4791 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4792 | return Signature; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4793 | } |
| 4794 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4795 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4796 | if (DeclUpdates.empty()) |
| 4797 | return; |
| 4798 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4799 | DeclUpdateMap LocalUpdates; |
| 4800 | LocalUpdates.swap(DeclUpdates); |
| 4801 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4802 | for (auto &DeclUpdate : LocalUpdates) { |
| 4803 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 4804 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4805 | bool HasUpdatedBody = false; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4806 | RecordData RecordData; |
| 4807 | ASTRecordWriter Record(*this, RecordData); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4808 | for (auto &Update : DeclUpdate.second) { |
| 4809 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 4810 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4811 | // An updated body is emitted last, so that the reader doesn't need |
| 4812 | // to skip over the lazy body to reach statements for other records. |
| 4813 | if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION) |
| 4814 | HasUpdatedBody = true; |
| 4815 | else |
| 4816 | Record.push_back(Kind); |
| 4817 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4818 | switch (Kind) { |
| 4819 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 4820 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 4821 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4822 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4823 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 4824 | break; |
| 4825 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4826 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4827 | break; |
| 4828 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4829 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4830 | Record.AddSourceLocation(Update.getLoc()); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4831 | break; |
| 4832 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4833 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4834 | Record.AddStmt(const_cast<Expr *>( |
| 4835 | cast<ParmVarDecl>(Update.getDecl())->getDefaultArg())); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4836 | break; |
| 4837 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4838 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: |
| 4839 | Record.AddStmt( |
| 4840 | cast<FieldDecl>(Update.getDecl())->getInClassInitializer()); |
| 4841 | break; |
| 4842 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4843 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4844 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 4845 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4846 | Record.AddCXXDefinitionData(RD); |
Richard Smith | 72e50fe | 2016-04-14 00:50:18 +0000 | [diff] [blame] | 4847 | Record.AddOffset(WriteDeclContextLexicalBlock( |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4848 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 4849 | |
| 4850 | // This state is sometimes updated by template instantiation, when we |
| 4851 | // switch from the specialization referring to the template declaration |
| 4852 | // to it referring to the template definition. |
| 4853 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 4854 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4855 | Record.AddSourceLocation(MSInfo->getPointOfInstantiation()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4856 | } else { |
| 4857 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 4858 | Record.push_back(Spec->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4859 | Record.AddSourceLocation(Spec->getPointOfInstantiation()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4860 | |
| 4861 | // The instantiation might have been resolved to a partial |
| 4862 | // specialization. If so, record which one. |
| 4863 | auto From = Spec->getInstantiatedFrom(); |
| 4864 | if (auto PartialSpec = |
| 4865 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 4866 | Record.push_back(true); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4867 | Record.AddDeclRef(PartialSpec); |
| 4868 | Record.AddTemplateArgumentList( |
| 4869 | &Spec->getTemplateInstantiationArgs()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4870 | } else { |
| 4871 | Record.push_back(false); |
| 4872 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4873 | } |
| 4874 | Record.push_back(RD->getTagKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4875 | Record.AddSourceLocation(RD->getLocation()); |
| 4876 | Record.AddSourceLocation(RD->getLocStart()); |
Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 4877 | Record.AddSourceRange(RD->getBraceRange()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4878 | |
| 4879 | // Instantiation may change attributes; write them all out afresh. |
| 4880 | Record.push_back(D->hasAttrs()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4881 | if (D->hasAttrs()) |
| 4882 | Record.AddAttributes(D->getAttrs()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4883 | |
| 4884 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 4885 | break; |
| 4886 | } |
| 4887 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4888 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4889 | Record.AddDeclRef(Update.getDecl()); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4890 | break; |
| 4891 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4892 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 4893 | addExceptionSpec( |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4894 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 4895 | Record); |
| 4896 | break; |
| 4897 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4898 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 4899 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 4900 | break; |
| 4901 | |
| 4902 | case UPD_DECL_MARKED_USED: |
| 4903 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4904 | |
| 4905 | case UPD_MANGLING_NUMBER: |
| 4906 | case UPD_STATIC_LOCAL_NUMBER: |
| 4907 | Record.push_back(Update.getNumber()); |
| 4908 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4909 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4910 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4911 | Record.AddSourceRange( |
| 4912 | D->getAttr<OMPThreadPrivateDeclAttr>()->getRange()); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4913 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4914 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 4915 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: |
| 4916 | Record.AddSourceRange( |
| 4917 | D->getAttr<OMPDeclareTargetDeclAttr>()->getRange()); |
| 4918 | break; |
| 4919 | |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4920 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 4921 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4922 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4923 | |
| 4924 | case UPD_ADDED_ATTR_TO_RECORD: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4925 | Record.AddAttributes(llvm::makeArrayRef(Update.getAttr())); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4926 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4927 | } |
| 4928 | } |
| 4929 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4930 | if (HasUpdatedBody) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4931 | const auto *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4932 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4933 | Record.push_back(Def->isInlined()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4934 | Record.AddSourceLocation(Def->getInnerLocStart()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4935 | Record.AddFunctionDefinition(Def); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4936 | } |
| 4937 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4938 | OffsetsRecord.push_back(GetDeclRef(D)); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4939 | OffsetsRecord.push_back(Record.Emit(DECL_UPDATES)); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4940 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4941 | } |
| 4942 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4943 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 4944 | uint32_t Raw = Loc.getRawEncoding(); |
| 4945 | Record.push_back((Raw << 1) | (Raw >> 31)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4946 | } |
| 4947 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4948 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4949 | AddSourceLocation(Range.getBegin(), Record); |
| 4950 | AddSourceLocation(Range.getEnd(), Record); |
| 4951 | } |
| 4952 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4953 | void ASTRecordWriter::AddAPInt(const llvm::APInt &Value) { |
| 4954 | Record->push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4955 | const uint64_t *Words = Value.getRawData(); |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4956 | Record->append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4957 | } |
| 4958 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4959 | void ASTRecordWriter::AddAPSInt(const llvm::APSInt &Value) { |
| 4960 | Record->push_back(Value.isUnsigned()); |
| 4961 | AddAPInt(Value); |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4962 | } |
| 4963 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4964 | void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) { |
| 4965 | AddAPInt(Value.bitcastToAPInt()); |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4966 | } |
| 4967 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4968 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4969 | Record.push_back(getIdentifierRef(II)); |
| 4970 | } |
| 4971 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4972 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4973 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4974 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4975 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4976 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4977 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4978 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4979 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4980 | } |
| 4981 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4982 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4983 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 4984 | // have been redefined by the header (in which case they are not |
| 4985 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4986 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4987 | return 0; |
| 4988 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4989 | MacroID &ID = MacroIDs[MI]; |
| 4990 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4991 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4992 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 4993 | MacroInfosToEmit.push_back(Info); |
| 4994 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4995 | return ID; |
| 4996 | } |
| 4997 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4998 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4999 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5000 | return 0; |
| 5001 | |
| 5002 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 5003 | return MacroIDs[MI]; |
| 5004 | } |
| 5005 | |
| 5006 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 5007 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5010 | void ASTRecordWriter::AddSelectorRef(const Selector SelRef) { |
| 5011 | Record->push_back(Writer->getSelectorRef(SelRef)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5014 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5015 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5016 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5017 | } |
| 5018 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5019 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5020 | if (SID == 0 && Chain) { |
| 5021 | // This might trigger a ReadSelector callback, which will set the ID for |
| 5022 | // this selector. |
| 5023 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5024 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5025 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5026 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5027 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5028 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5029 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5030 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5031 | } |
| 5032 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5033 | void ASTRecordWriter::AddCXXTemporary(const CXXTemporary *Temp) { |
| 5034 | AddDeclRef(Temp->getDestructor()); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5035 | } |
| 5036 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5037 | void ASTRecordWriter::AddTemplateArgumentLocInfo( |
| 5038 | TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5039 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5040 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5041 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5042 | break; |
| 5043 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5044 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5045 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5046 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5047 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5048 | AddSourceLocation(Arg.getTemplateNameLoc()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5049 | break; |
| 5050 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5051 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5052 | AddSourceLocation(Arg.getTemplateNameLoc()); |
| 5053 | AddSourceLocation(Arg.getTemplateEllipsisLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5054 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5055 | case TemplateArgument::Null: |
| 5056 | case TemplateArgument::Integral: |
| 5057 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5058 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5059 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5060 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5061 | break; |
| 5062 | } |
| 5063 | } |
| 5064 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5065 | void ASTRecordWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg) { |
| 5066 | AddTemplateArgument(Arg.getArgument()); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5067 | |
| 5068 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 5069 | bool InfoHasSameExpr |
| 5070 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5071 | Record->push_back(InfoHasSameExpr); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5072 | if (InfoHasSameExpr) |
| 5073 | return; // Avoid storing the same expr twice. |
| 5074 | } |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5075 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo()); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5076 | } |
| 5077 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5078 | void ASTRecordWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5079 | if (!TInfo) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5080 | AddTypeRef(QualType()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5081 | return; |
| 5082 | } |
| 5083 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5084 | AddTypeLoc(TInfo->getTypeLoc()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5085 | } |
| 5086 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5087 | void ASTRecordWriter::AddTypeLoc(TypeLoc TL) { |
| 5088 | AddTypeRef(TL.getType()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5089 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5090 | TypeLocWriter TLW(*this); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5091 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 5092 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5093 | } |
| 5094 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5095 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 5096 | Record.push_back(GetOrCreateTypeID(T)); |
| 5097 | } |
| 5098 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5099 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5100 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5101 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5102 | if (T.isNull()) |
| 5103 | return TypeIdx(); |
| 5104 | assert(!T.getLocalFastQualifiers()); |
| 5105 | |
| 5106 | TypeIdx &Idx = TypeIdxs[T]; |
| 5107 | if (Idx.getIndex() == 0) { |
| 5108 | if (DoneWritingDeclsAndTypes) { |
| 5109 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 5110 | return TypeIdx(); |
| 5111 | } |
| 5112 | |
| 5113 | // We haven't seen this type before. Assign it a new ID and put it |
| 5114 | // into the queue of types to emit. |
| 5115 | Idx = TypeIdx(NextTypeID++); |
| 5116 | DeclTypesToEmit.push(T); |
| 5117 | } |
| 5118 | return Idx; |
| 5119 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 5120 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5121 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 5122 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5123 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5124 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5125 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5126 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5127 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5128 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5129 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 5130 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 5131 | return I->second; |
| 5132 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5133 | } |
| 5134 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5135 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5136 | Record.push_back(GetDeclRef(D)); |
| 5137 | } |
| 5138 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5139 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5140 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5141 | |
| 5142 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5143 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5144 | } |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5145 | |
| 5146 | // If D comes from an AST file, its declaration ID is already known and |
| 5147 | // fixed. |
| 5148 | if (D->isFromASTFile()) |
| 5149 | return D->getGlobalID(); |
| 5150 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5151 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5152 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5153 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5154 | if (DoneWritingDeclsAndTypes) { |
| 5155 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 5156 | return 0; |
| 5157 | } |
| 5158 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5159 | // We haven't seen this declaration before. Give it a new ID and |
| 5160 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5161 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5162 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5163 | } |
| 5164 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5165 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5168 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5169 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5170 | return 0; |
| 5171 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5172 | // If D comes from an AST file, its declaration ID is already known and |
| 5173 | // fixed. |
| 5174 | if (D->isFromASTFile()) |
| 5175 | return D->getGlobalID(); |
| 5176 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5177 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 5178 | return DeclIDs[D]; |
| 5179 | } |
| 5180 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5181 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5182 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5183 | assert(D); |
| 5184 | |
| 5185 | SourceLocation Loc = D->getLocation(); |
| 5186 | if (Loc.isInvalid()) |
| 5187 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5188 | |
| 5189 | // We only keep track of the file-level declarations of each file. |
| 5190 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 5191 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5192 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 5193 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5194 | if (isa<ParmVarDecl>(D)) |
| 5195 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5196 | |
| 5197 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5198 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5199 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5200 | FileID FID; |
| 5201 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5202 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5203 | if (FID.isInvalid()) |
| 5204 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5205 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5206 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5207 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5208 | if (!Info) |
| 5209 | Info = new DeclIDInFileInfo(); |
| 5210 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5211 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5212 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 5213 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5214 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5215 | Decls.push_back(LocDecl); |
| 5216 | return; |
| 5217 | } |
| 5218 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5219 | LocDeclIDsTy::iterator I = |
| 5220 | std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5221 | |
| 5222 | Decls.insert(I, LocDecl); |
| 5223 | } |
| 5224 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5225 | void ASTRecordWriter::AddDeclarationName(DeclarationName Name) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 5226 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5227 | Record->push_back(Name.getNameKind()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5228 | switch (Name.getNameKind()) { |
| 5229 | case DeclarationName::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5230 | AddIdentifierRef(Name.getAsIdentifierInfo()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5231 | break; |
| 5232 | |
| 5233 | case DeclarationName::ObjCZeroArgSelector: |
| 5234 | case DeclarationName::ObjCOneArgSelector: |
| 5235 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5236 | AddSelectorRef(Name.getObjCSelector()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5237 | break; |
| 5238 | |
| 5239 | case DeclarationName::CXXConstructorName: |
| 5240 | case DeclarationName::CXXDestructorName: |
| 5241 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5242 | AddTypeRef(Name.getCXXNameType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5243 | break; |
| 5244 | |
| 5245 | case DeclarationName::CXXOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5246 | Record->push_back(Name.getCXXOverloadedOperator()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5247 | break; |
| 5248 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5249 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5250 | AddIdentifierRef(Name.getCXXLiteralIdentifier()); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5251 | break; |
| 5252 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5253 | case DeclarationName::CXXUsingDirective: |
| 5254 | // No extra data to emit |
| 5255 | break; |
| 5256 | } |
| 5257 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5258 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5259 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5260 | assert(needsAnonymousDeclarationNumber(D) && |
| 5261 | "expected an anonymous declaration"); |
| 5262 | |
| 5263 | // Number the anonymous declarations within this context, if we've not |
| 5264 | // already done so. |
| 5265 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5266 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5267 | auto *DC = D->getLexicalDeclContext(); |
| 5268 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5269 | AnonymousDeclarationNumbers[ND] = Number; |
| 5270 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5271 | |
| 5272 | It = AnonymousDeclarationNumbers.find(D); |
| 5273 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5274 | "declaration not found within its lexical context"); |
| 5275 | } |
| 5276 | |
| 5277 | return It->second; |
| 5278 | } |
| 5279 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5280 | void ASTRecordWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
| 5281 | DeclarationName Name) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5282 | switch (Name.getNameKind()) { |
| 5283 | case DeclarationName::CXXConstructorName: |
| 5284 | case DeclarationName::CXXDestructorName: |
| 5285 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5286 | AddTypeSourceInfo(DNLoc.NamedType.TInfo); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5287 | break; |
| 5288 | |
| 5289 | case DeclarationName::CXXOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5290 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5291 | DNLoc.CXXOperatorName.BeginOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5292 | AddSourceLocation( |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5293 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5294 | break; |
| 5295 | |
| 5296 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5297 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5298 | DNLoc.CXXLiteralOperatorName.OpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5299 | break; |
| 5300 | |
| 5301 | case DeclarationName::Identifier: |
| 5302 | case DeclarationName::ObjCZeroArgSelector: |
| 5303 | case DeclarationName::ObjCOneArgSelector: |
| 5304 | case DeclarationName::ObjCMultiArgSelector: |
| 5305 | case DeclarationName::CXXUsingDirective: |
| 5306 | break; |
| 5307 | } |
| 5308 | } |
| 5309 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5310 | void ASTRecordWriter::AddDeclarationNameInfo( |
| 5311 | const DeclarationNameInfo &NameInfo) { |
| 5312 | AddDeclarationName(NameInfo.getName()); |
| 5313 | AddSourceLocation(NameInfo.getLoc()); |
| 5314 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName()); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5315 | } |
| 5316 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5317 | void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { |
| 5318 | AddNestedNameSpecifierLoc(Info.QualifierLoc); |
| 5319 | Record->push_back(Info.NumTemplParamLists); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5320 | for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5321 | AddTemplateParameterList(Info.TemplParamLists[i]); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5322 | } |
| 5323 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5324 | void ASTRecordWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5325 | // 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] | 5326 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5327 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5328 | |
| 5329 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5330 | while (NNS) { |
| 5331 | NestedNames.push_back(NNS); |
| 5332 | NNS = NNS->getPrefix(); |
| 5333 | } |
| 5334 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5335 | Record->push_back(NestedNames.size()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5336 | while(!NestedNames.empty()) { |
| 5337 | NNS = NestedNames.pop_back_val(); |
| 5338 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5339 | Record->push_back(Kind); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5340 | switch (Kind) { |
| 5341 | case NestedNameSpecifier::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5342 | AddIdentifierRef(NNS->getAsIdentifier()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5343 | break; |
| 5344 | |
| 5345 | case NestedNameSpecifier::Namespace: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5346 | AddDeclRef(NNS->getAsNamespace()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5347 | break; |
| 5348 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5349 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5350 | AddDeclRef(NNS->getAsNamespaceAlias()); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5351 | break; |
| 5352 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5353 | case NestedNameSpecifier::TypeSpec: |
| 5354 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5355 | AddTypeRef(QualType(NNS->getAsType(), 0)); |
| 5356 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5357 | break; |
| 5358 | |
| 5359 | case NestedNameSpecifier::Global: |
| 5360 | // Don't need to write an associated value. |
| 5361 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5362 | |
| 5363 | case NestedNameSpecifier::Super: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5364 | AddDeclRef(NNS->getAsRecordDecl()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5365 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5366 | } |
| 5367 | } |
| 5368 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5369 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5370 | void ASTRecordWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5371 | // 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] | 5372 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5373 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5374 | |
| 5375 | // Push each of the nested-name-specifiers's onto a stack for |
| 5376 | // serialization in reverse order. |
| 5377 | while (NNS) { |
| 5378 | NestedNames.push_back(NNS); |
| 5379 | NNS = NNS.getPrefix(); |
| 5380 | } |
| 5381 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5382 | Record->push_back(NestedNames.size()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5383 | while(!NestedNames.empty()) { |
| 5384 | NNS = NestedNames.pop_back_val(); |
| 5385 | NestedNameSpecifier::SpecifierKind Kind |
| 5386 | = NNS.getNestedNameSpecifier()->getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5387 | Record->push_back(Kind); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5388 | switch (Kind) { |
| 5389 | case NestedNameSpecifier::Identifier: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5390 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier()); |
| 5391 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5392 | break; |
| 5393 | |
| 5394 | case NestedNameSpecifier::Namespace: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5395 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace()); |
| 5396 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5397 | break; |
| 5398 | |
| 5399 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5400 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias()); |
| 5401 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5402 | break; |
| 5403 | |
| 5404 | case NestedNameSpecifier::TypeSpec: |
| 5405 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5406 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5407 | AddTypeLoc(NNS.getTypeLoc()); |
| 5408 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5409 | break; |
| 5410 | |
| 5411 | case NestedNameSpecifier::Global: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5412 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5413 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5414 | |
| 5415 | case NestedNameSpecifier::Super: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5416 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl()); |
| 5417 | AddSourceRange(NNS.getLocalSourceRange()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5418 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5419 | } |
| 5420 | } |
| 5421 | } |
| 5422 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5423 | void ASTRecordWriter::AddTemplateName(TemplateName Name) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5424 | TemplateName::NameKind Kind = Name.getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5425 | Record->push_back(Kind); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5426 | switch (Kind) { |
| 5427 | case TemplateName::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5428 | AddDeclRef(Name.getAsTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5429 | break; |
| 5430 | |
| 5431 | case TemplateName::OverloadedTemplate: { |
| 5432 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5433 | Record->push_back(OvT->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5434 | for (const auto &I : *OvT) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5435 | AddDeclRef(I); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5436 | break; |
| 5437 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5438 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5439 | case TemplateName::QualifiedTemplate: { |
| 5440 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5441 | AddNestedNameSpecifier(QualT->getQualifier()); |
| 5442 | Record->push_back(QualT->hasTemplateKeyword()); |
| 5443 | AddDeclRef(QualT->getTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5444 | break; |
| 5445 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5446 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5447 | case TemplateName::DependentTemplate: { |
| 5448 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5449 | AddNestedNameSpecifier(DepT->getQualifier()); |
| 5450 | Record->push_back(DepT->isIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5451 | if (DepT->isIdentifier()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5452 | AddIdentifierRef(DepT->getIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5453 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5454 | Record->push_back(DepT->getOperator()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5455 | break; |
| 5456 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5457 | |
| 5458 | case TemplateName::SubstTemplateTemplateParm: { |
| 5459 | SubstTemplateTemplateParmStorage *subst |
| 5460 | = Name.getAsSubstTemplateTemplateParm(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5461 | AddDeclRef(subst->getParameter()); |
| 5462 | AddTemplateName(subst->getReplacement()); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5463 | break; |
| 5464 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5465 | |
| 5466 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5467 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5468 | = Name.getAsSubstTemplateTemplateParmPack(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5469 | AddDeclRef(SubstPack->getParameterPack()); |
| 5470 | AddTemplateArgument(SubstPack->getArgumentPack()); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5471 | break; |
| 5472 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5473 | } |
| 5474 | } |
| 5475 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5476 | void ASTRecordWriter::AddTemplateArgument(const TemplateArgument &Arg) { |
| 5477 | Record->push_back(Arg.getKind()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5478 | switch (Arg.getKind()) { |
| 5479 | case TemplateArgument::Null: |
| 5480 | break; |
| 5481 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5482 | AddTypeRef(Arg.getAsType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5483 | break; |
| 5484 | case TemplateArgument::Declaration: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5485 | AddDeclRef(Arg.getAsDecl()); |
| 5486 | AddTypeRef(Arg.getParamTypeForDecl()); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5487 | break; |
| 5488 | case TemplateArgument::NullPtr: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5489 | AddTypeRef(Arg.getNullPtrType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5490 | break; |
| 5491 | case TemplateArgument::Integral: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5492 | AddAPSInt(Arg.getAsIntegral()); |
| 5493 | AddTypeRef(Arg.getIntegralType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5494 | break; |
| 5495 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5496 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5497 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5498 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5499 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5500 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5501 | Record->push_back(*NumExpansions + 1); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5502 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5503 | Record->push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5504 | break; |
| 5505 | case TemplateArgument::Expression: |
| 5506 | AddStmt(Arg.getAsExpr()); |
| 5507 | break; |
| 5508 | case TemplateArgument::Pack: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5509 | Record->push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 5510 | for (const auto &P : Arg.pack_elements()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5511 | AddTemplateArgument(P); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5512 | break; |
| 5513 | } |
| 5514 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5515 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5516 | void ASTRecordWriter::AddTemplateParameterList( |
| 5517 | const TemplateParameterList *TemplateParams) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5518 | assert(TemplateParams && "No TemplateParams!"); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5519 | AddSourceLocation(TemplateParams->getTemplateLoc()); |
| 5520 | AddSourceLocation(TemplateParams->getLAngleLoc()); |
| 5521 | AddSourceLocation(TemplateParams->getRAngleLoc()); |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 5522 | // TODO: Concepts |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5523 | Record->push_back(TemplateParams->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5524 | for (const auto &P : *TemplateParams) |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5525 | AddDeclRef(P); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | /// \brief Emit a template argument list. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5529 | void ASTRecordWriter::AddTemplateArgumentList( |
| 5530 | const TemplateArgumentList *TemplateArgs) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5531 | assert(TemplateArgs && "No TemplateArgs!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5532 | Record->push_back(TemplateArgs->size()); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5533 | for (int i = 0, e = TemplateArgs->size(); i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5534 | AddTemplateArgument(TemplateArgs->get(i)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5535 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5536 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5537 | void ASTRecordWriter::AddASTTemplateArgumentListInfo( |
| 5538 | const ASTTemplateArgumentListInfo *ASTTemplArgList) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5539 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5540 | AddSourceLocation(ASTTemplArgList->LAngleLoc); |
| 5541 | AddSourceLocation(ASTTemplArgList->RAngleLoc); |
| 5542 | Record->push_back(ASTTemplArgList->NumTemplateArgs); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5543 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5544 | for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5545 | AddTemplateArgumentLoc(TemplArgs[i]); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5546 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5547 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5548 | void ASTRecordWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set) { |
| 5549 | Record->push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5550 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5551 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5552 | AddDeclRef(I.getDecl()); |
| 5553 | Record->push_back(I.getAccess()); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5554 | } |
| 5555 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5556 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5557 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5558 | void ASTRecordWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base) { |
| 5559 | Record->push_back(Base.isVirtual()); |
| 5560 | Record->push_back(Base.isBaseOfClass()); |
| 5561 | Record->push_back(Base.getAccessSpecifierAsWritten()); |
| 5562 | Record->push_back(Base.getInheritConstructors()); |
| 5563 | AddTypeSourceInfo(Base.getTypeSourceInfo()); |
| 5564 | AddSourceRange(Base.getSourceRange()); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5565 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5566 | : SourceLocation()); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5567 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5568 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5569 | static uint64_t EmitCXXBaseSpecifiers(ASTWriter &W, |
| 5570 | ArrayRef<CXXBaseSpecifier> Bases) { |
| 5571 | ASTWriter::RecordData Record; |
| 5572 | ASTRecordWriter Writer(W, Record); |
| 5573 | Writer.push_back(Bases.size()); |
Dmitry Polukhin | 790b540 | 2016-04-06 10:01:46 +0000 | [diff] [blame] | 5574 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5575 | for (auto &Base : Bases) |
| 5576 | Writer.AddCXXBaseSpecifier(Base); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5577 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5578 | return Writer.Emit(serialization::DECL_CXX_BASE_SPECIFIERS); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5579 | } |
| 5580 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5581 | // FIXME: Move this out of the main ASTRecordWriter interface. |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5582 | void ASTRecordWriter::AddCXXBaseSpecifiers(ArrayRef<CXXBaseSpecifier> Bases) { |
| 5583 | AddOffset(EmitCXXBaseSpecifiers(*Writer, Bases)); |
| 5584 | } |
| 5585 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5586 | static uint64_t |
| 5587 | EmitCXXCtorInitializers(ASTWriter &W, |
| 5588 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 5589 | ASTWriter::RecordData Record; |
| 5590 | ASTRecordWriter Writer(W, Record); |
| 5591 | Writer.push_back(CtorInits.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5592 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5593 | for (auto *Init : CtorInits) { |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5594 | if (Init->isBaseInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5595 | Writer.push_back(CTOR_INITIALIZER_BASE); |
| 5596 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
| 5597 | Writer.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5598 | } else if (Init->isDelegatingInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5599 | Writer.push_back(CTOR_INITIALIZER_DELEGATING); |
| 5600 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5601 | } else if (Init->isMemberInitializer()){ |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5602 | Writer.push_back(CTOR_INITIALIZER_MEMBER); |
| 5603 | Writer.AddDeclRef(Init->getMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5604 | } else { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5605 | Writer.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 5606 | Writer.AddDeclRef(Init->getIndirectMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5607 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5608 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5609 | Writer.AddSourceLocation(Init->getMemberLocation()); |
| 5610 | Writer.AddStmt(Init->getInit()); |
| 5611 | Writer.AddSourceLocation(Init->getLParenLoc()); |
| 5612 | Writer.AddSourceLocation(Init->getRParenLoc()); |
| 5613 | Writer.push_back(Init->isWritten()); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 5614 | if (Init->isWritten()) |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5615 | Writer.push_back(Init->getSourceOrder()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5616 | } |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5617 | |
| 5618 | return Writer.Emit(serialization::DECL_CXX_CTOR_INITIALIZERS); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5619 | } |
| 5620 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5621 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5622 | void ASTRecordWriter::AddCXXCtorInitializers( |
| 5623 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 5624 | AddOffset(EmitCXXCtorInitializers(*Writer, CtorInits)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5625 | } |
| 5626 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5627 | void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5628 | auto &Data = D->data(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5629 | Record->push_back(Data.IsLambda); |
| 5630 | Record->push_back(Data.UserDeclaredConstructor); |
| 5631 | Record->push_back(Data.UserDeclaredSpecialMembers); |
| 5632 | Record->push_back(Data.Aggregate); |
| 5633 | Record->push_back(Data.PlainOldData); |
| 5634 | Record->push_back(Data.Empty); |
| 5635 | Record->push_back(Data.Polymorphic); |
| 5636 | Record->push_back(Data.Abstract); |
| 5637 | Record->push_back(Data.IsStandardLayout); |
| 5638 | Record->push_back(Data.HasNoNonEmptyBases); |
| 5639 | Record->push_back(Data.HasPrivateFields); |
| 5640 | Record->push_back(Data.HasProtectedFields); |
| 5641 | Record->push_back(Data.HasPublicFields); |
| 5642 | Record->push_back(Data.HasMutableFields); |
| 5643 | Record->push_back(Data.HasVariantMembers); |
| 5644 | Record->push_back(Data.HasOnlyCMembers); |
| 5645 | Record->push_back(Data.HasInClassInitializer); |
| 5646 | Record->push_back(Data.HasUninitializedReferenceMember); |
| 5647 | Record->push_back(Data.HasUninitializedFields); |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 5648 | Record->push_back(Data.HasInheritedConstructor); |
| 5649 | Record->push_back(Data.HasInheritedAssignment); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5650 | Record->push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 5651 | Record->push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 5652 | Record->push_back(Data.NeedOverloadResolutionForDestructor); |
| 5653 | Record->push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 5654 | Record->push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 5655 | Record->push_back(Data.DefaultedDestructorIsDeleted); |
| 5656 | Record->push_back(Data.HasTrivialSpecialMembers); |
| 5657 | Record->push_back(Data.DeclaredNonTrivialSpecialMembers); |
| 5658 | Record->push_back(Data.HasIrrelevantDestructor); |
| 5659 | Record->push_back(Data.HasConstexprNonCopyMoveConstructor); |
| 5660 | Record->push_back(Data.HasDefaultedDefaultConstructor); |
| 5661 | Record->push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
| 5662 | Record->push_back(Data.HasConstexprDefaultConstructor); |
| 5663 | Record->push_back(Data.HasNonLiteralTypeFieldsOrBases); |
| 5664 | Record->push_back(Data.ComputedVisibleConversions); |
| 5665 | Record->push_back(Data.UserProvidedDefaultConstructor); |
| 5666 | Record->push_back(Data.DeclaredSpecialMembers); |
| 5667 | Record->push_back(Data.ImplicitCopyConstructorHasConstParam); |
| 5668 | Record->push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 5669 | Record->push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 5670 | Record->push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5671 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5672 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5673 | Record->push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5674 | if (Data.NumBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5675 | AddCXXBaseSpecifiers(Data.bases()); |
| 5676 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5677 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5678 | Record->push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5679 | if (Data.NumVBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5680 | AddCXXBaseSpecifiers(Data.vbases()); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5681 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5682 | AddUnresolvedSet(Data.Conversions.get(*Writer->Context)); |
| 5683 | AddUnresolvedSet(Data.VisibleConversions.get(*Writer->Context)); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5684 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5685 | AddDeclRef(D->getFirstFriend()); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5686 | |
| 5687 | // Add lambda-specific data. |
| 5688 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5689 | auto &Lambda = D->getLambdaData(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5690 | Record->push_back(Lambda.Dependent); |
| 5691 | Record->push_back(Lambda.IsGenericLambda); |
| 5692 | Record->push_back(Lambda.CaptureDefault); |
| 5693 | Record->push_back(Lambda.NumCaptures); |
| 5694 | Record->push_back(Lambda.NumExplicitCaptures); |
| 5695 | Record->push_back(Lambda.ManglingNumber); |
Richard Smith | 0bae624 | 2016-08-25 00:34:00 +0000 | [diff] [blame] | 5696 | AddDeclRef(D->getLambdaContextDecl()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5697 | AddTypeSourceInfo(Lambda.MethodTyInfo); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5698 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 5699 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5700 | AddSourceLocation(Capture.getLocation()); |
| 5701 | Record->push_back(Capture.isImplicit()); |
| 5702 | Record->push_back(Capture.getCaptureKind()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5703 | switch (Capture.getCaptureKind()) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 5704 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5705 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 5706 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5707 | break; |
| 5708 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 5709 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5710 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5711 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5712 | AddDeclRef(Var); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5713 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5714 | : SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5715 | break; |
| 5716 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5717 | } |
| 5718 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5719 | } |
| 5720 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5721 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5722 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5723 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5724 | assert(FirstDeclID == NextDeclID && |
| 5725 | FirstTypeID == NextTypeID && |
| 5726 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5727 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5728 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5729 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5730 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5731 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5732 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5733 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 5734 | // Note, this will get called multiple times, once one the reader starts up |
| 5735 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5736 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 5737 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 5738 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5739 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5740 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5741 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5742 | NextDeclID = FirstDeclID; |
| 5743 | NextTypeID = FirstTypeID; |
| 5744 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5745 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5746 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5747 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5748 | } |
| 5749 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5750 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5751 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5752 | IdentID &StoredID = IdentifierIDs[II]; |
| 5753 | if (ID > StoredID) |
| 5754 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5755 | } |
| 5756 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5757 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5758 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5759 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5760 | if (ID > StoredID) |
| 5761 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5764 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5765 | // Always take the highest-numbered type index. This copes with an interesting |
| 5766 | // 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] | 5767 | // 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] | 5768 | // keep the higher-numbered entry so that we can properly write it out to |
| 5769 | // the AST file. |
| 5770 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 5771 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 5772 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5773 | } |
| 5774 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5775 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5776 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5777 | SelectorID &StoredID = SelectorIDs[S]; |
| 5778 | if (ID > StoredID) |
| 5779 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5780 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5781 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5782 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5783 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5784 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5785 | MacroDefinitions[MD] = ID; |
| 5786 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5787 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 5788 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 5789 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 5790 | SubmoduleIDs[Mod] = ID; |
| 5791 | } |
| 5792 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5793 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5794 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5795 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5796 | assert(!WritingAST && "Already writing the AST!"); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5797 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5798 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5799 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5800 | // A forward reference was mutated into a definition. Rewrite it. |
| 5801 | // FIXME: This happens during template instantiation, should we |
| 5802 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5803 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 5804 | "completed a tag from another module but not by instantiation?"); |
| 5805 | DeclUpdates[RD].push_back( |
| 5806 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5807 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5808 | } |
| 5809 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5810 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5811 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { |
| 5812 | if (D->isFromASTFile()) |
| 5813 | return true; |
| 5814 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5815 | // The predefined __va_list_tag struct is imported if we imported any decls. |
| 5816 | // FIXME: This is a gross hack. |
| 5817 | return D == D->getASTContext().getVaListTagDecl(); |
| 5818 | } |
| 5819 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5820 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5821 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
| 5822 | assert(DC->isLookupContext() && |
Vassil Vassilev | 71eafde | 2016-04-06 20:56:03 +0000 | [diff] [blame] | 5823 | "Should not add lookup results to non-lookup contexts!"); |
| 5824 | |
Vassil Vassilev | 632eac3 | 2016-03-16 11:17:04 +0000 | [diff] [blame] | 5825 | // TU is handled elsewhere. |
| 5826 | if (isa<TranslationUnitDecl>(DC)) |
| 5827 | return; |
| 5828 | |
| 5829 | // Namespaces are handled elsewhere, except for template instantiations of |
| 5830 | // FunctionTemplateDecls in namespaces. We are interested in cases where the |
| 5831 | // local instantiations are added to an imported context. Only happens when |
| 5832 | // adding ADL lookup candidates, for example templated friends. |
| 5833 | if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && |
| 5834 | !isa<FunctionTemplateDecl>(D)) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5835 | return; |
| 5836 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5837 | // We're only interested in cases where a local declaration is added to an |
| 5838 | // imported context. |
| 5839 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) |
| 5840 | return; |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5841 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 5842 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5843 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5844 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5845 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { |
| 5846 | // We're adding a visible declaration to a predefined decl context. Ensure |
| 5847 | // that we write out all of its lookup results so we don't get a nasty |
| 5848 | // surprise when we try to emit its lookup table. |
| 5849 | for (auto *Child : DC->decls()) |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 5850 | DeclsToEmitEvenIfUnreferenced.push_back(Child); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5851 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 5852 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5853 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5854 | |
| 5855 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5856 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5857 | assert(D->isImplicit()); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5858 | |
| 5859 | // We're only interested in cases where a local declaration is added to an |
| 5860 | // imported context. |
| 5861 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) |
| 5862 | return; |
| 5863 | |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5864 | if (!isa<CXXMethodDecl>(D)) |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5865 | return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5866 | |
| 5867 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5868 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5869 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5870 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5871 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5872 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5873 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5874 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5875 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 5876 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5877 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5878 | // If we don't already know the exception specification for this redecl |
| 5879 | // chain, add an update record for it. |
| 5880 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 5881 | ->getType() |
| 5882 | ->castAs<FunctionProtoType>() |
| 5883 | ->getExceptionSpecType())) |
| 5884 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 5885 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5886 | } |
| 5887 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5888 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5889 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5890 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5891 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5892 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5893 | DeclUpdates[D].push_back( |
| 5894 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 5895 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5896 | } |
| 5897 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5898 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
| 5899 | const FunctionDecl *Delete) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5900 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5901 | assert(!WritingAST && "Already writing the AST!"); |
| 5902 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5903 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5904 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5905 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 5906 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5907 | } |
| 5908 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5909 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5910 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5911 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5912 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5913 | return; // Declaration not imported from PCH. |
| 5914 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5915 | // Implicit function decl from a PCH was defined. |
| 5916 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5917 | } |
| 5918 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5919 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5920 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5921 | assert(!WritingAST && "Already writing the AST!"); |
| 5922 | if (!D->isFromASTFile()) |
| 5923 | return; |
| 5924 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5925 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5926 | } |
| 5927 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5928 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5929 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5930 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5931 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5932 | return; |
| 5933 | |
| 5934 | // Since the actual instantiation is delayed, this really means that we need |
| 5935 | // to update the instantiation location. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5936 | DeclUpdates[D].push_back( |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5937 | DeclUpdate(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER, |
| 5938 | D->getMemberSpecializationInfo()->getPointOfInstantiation())); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5941 | void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5942 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5943 | assert(!WritingAST && "Already writing the AST!"); |
| 5944 | if (!D->isFromASTFile()) |
| 5945 | return; |
| 5946 | |
| 5947 | DeclUpdates[D].push_back( |
| 5948 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D)); |
| 5949 | } |
| 5950 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 5951 | void ASTWriter::DefaultMemberInitializerInstantiated(const FieldDecl *D) { |
| 5952 | assert(!WritingAST && "Already writing the AST!"); |
| 5953 | if (!D->isFromASTFile()) |
| 5954 | return; |
| 5955 | |
| 5956 | DeclUpdates[D].push_back( |
| 5957 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER, D)); |
| 5958 | } |
| 5959 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5960 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 5961 | const ObjCInterfaceDecl *IFD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5962 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5963 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5964 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5965 | return; // Declaration not imported from PCH. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5966 | |
| 5967 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 5968 | ObjCClassesWithCategories.insert( |
| 5969 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5970 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 5971 | |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5972 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5973 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5974 | assert(!WritingAST && "Already writing the AST!"); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 5975 | |
| 5976 | // If there is *any* declaration of the entity that's not from an AST file, |
| 5977 | // we can skip writing the update record. We make sure that isUsed() triggers |
| 5978 | // completion of the redeclaration chain of the entity. |
| 5979 | for (auto Prev = D->getMostRecentDecl(); Prev; Prev = Prev->getPreviousDecl()) |
| 5980 | if (IsLocalDecl(Prev)) |
| 5981 | return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5982 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5983 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5984 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5985 | |
| 5986 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5987 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5988 | assert(!WritingAST && "Already writing the AST!"); |
| 5989 | if (!D->isFromASTFile()) |
| 5990 | return; |
| 5991 | |
| 5992 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 5993 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5994 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 5995 | void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, |
| 5996 | const Attr *Attr) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5997 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5998 | assert(!WritingAST && "Already writing the AST!"); |
| 5999 | if (!D->isFromASTFile()) |
| 6000 | return; |
| 6001 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 6002 | DeclUpdates[D].push_back( |
| 6003 | DeclUpdate(UPD_DECL_MARKED_OPENMP_DECLARETARGET, Attr)); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 6004 | } |
| 6005 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6006 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6007 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6008 | assert(!WritingAST && "Already writing the AST!"); |
| 6009 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6010 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6011 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6012 | |
| 6013 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 6014 | const RecordDecl *Record) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6015 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6016 | assert(!WritingAST && "Already writing the AST!"); |
| 6017 | if (!Record->isFromASTFile()) |
| 6018 | return; |
| 6019 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 6020 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6021 | |
| 6022 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6023 | const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) { |
| 6024 | assert(!WritingAST && "Already writing the AST!"); |
| 6025 | |
| 6026 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6027 | return; |
| 6028 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6029 | return; |
| 6030 | |
| 6031 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6032 | } |
| 6033 | |
| 6034 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6035 | const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) { |
| 6036 | assert(!WritingAST && "Already writing the AST!"); |
| 6037 | |
| 6038 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6039 | return; |
| 6040 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6041 | return; |
| 6042 | |
| 6043 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6044 | } |
| 6045 | |
| 6046 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 6047 | const FunctionDecl *D) { |
| 6048 | assert(!WritingAST && "Already writing the AST!"); |
| 6049 | |
| 6050 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6051 | return; |
| 6052 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6053 | return; |
| 6054 | |
| 6055 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6056 | } |