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" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 76 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 77 | #include "llvm/Support/MemoryBuffer.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 78 | #include "llvm/Support/OnDiskHashTable.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 79 | #include "llvm/Support/Path.h" |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 80 | #include "llvm/Support/Process.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 81 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 82 | #include <algorithm> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 83 | #include <cassert> |
| 84 | #include <cstdint> |
| 85 | #include <cstdlib> |
| 86 | #include <cstring> |
| 87 | #include <deque> |
| 88 | #include <limits> |
| 89 | #include <new> |
| 90 | #include <tuple> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 91 | #include <utility> |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 92 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 93 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 94 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 95 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 96 | template <typename T, typename Allocator> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 97 | static StringRef bytes(const std::vector<T, Allocator> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 98 | if (v.empty()) return StringRef(); |
| 99 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 100 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 101 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 102 | |
| 103 | template <typename T> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 104 | static StringRef bytes(const SmallVectorImpl<T> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 105 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 106 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 109 | //===----------------------------------------------------------------------===// |
| 110 | // Type serialization |
| 111 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 112 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 113 | namespace clang { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 114 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 115 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 116 | ASTWriter &Writer; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 117 | ASTRecordWriter Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 118 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 119 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 120 | TypeCode Code; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 121 | /// \brief Abbreviation to use for the record, if any. |
| 122 | unsigned AbbrevToUse; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 123 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 124 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 125 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 126 | : Writer(Writer), Record(Writer, Record), Code((TypeCode)0), AbbrevToUse(0) { } |
| 127 | |
| 128 | uint64_t Emit() { |
| 129 | return Record.Emit(Code, AbbrevToUse); |
| 130 | } |
| 131 | |
| 132 | void Visit(QualType T) { |
| 133 | if (T.hasLocalNonFastQualifiers()) { |
| 134 | Qualifiers Qs = T.getLocalQualifiers(); |
| 135 | Record.AddTypeRef(T.getLocalUnqualifiedType()); |
| 136 | Record.push_back(Qs.getAsOpaqueValue()); |
| 137 | Code = TYPE_EXT_QUAL; |
| 138 | AbbrevToUse = Writer.TypeExtQualAbbrev; |
| 139 | } else { |
| 140 | switch (T->getTypeClass()) { |
| 141 | // For all of the concrete, non-dependent types, call the |
| 142 | // appropriate visitor function. |
| 143 | #define TYPE(Class, Base) \ |
| 144 | case Type::Class: Visit##Class##Type(cast<Class##Type>(T)); break; |
| 145 | #define ABSTRACT_TYPE(Class, Base) |
| 146 | #include "clang/AST/TypeNodes.def" |
| 147 | } |
| 148 | } |
| 149 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 150 | |
| 151 | void VisitArrayType(const ArrayType *T); |
| 152 | void VisitFunctionType(const FunctionType *T); |
| 153 | void VisitTagType(const TagType *T); |
| 154 | |
| 155 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 156 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 157 | #include "clang/AST/TypeNodes.def" |
| 158 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 159 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 160 | } // end namespace clang |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 161 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 162 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 163 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 166 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 167 | Record.AddTypeRef(T->getElementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 168 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 171 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 172 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 173 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 176 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 177 | Record.AddTypeRef(T->getOriginalType()); |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 178 | Code = TYPE_DECAYED; |
| 179 | } |
| 180 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 181 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 182 | Record.AddTypeRef(T->getOriginalType()); |
| 183 | Record.AddTypeRef(T->getAdjustedType()); |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 184 | Code = TYPE_ADJUSTED; |
| 185 | } |
| 186 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 187 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 188 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 189 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 192 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 193 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 194 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 195 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 198 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 199 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 200 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 203 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 204 | Record.AddTypeRef(T->getPointeeType()); |
| 205 | Record.AddTypeRef(QualType(T->getClass(), 0)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 206 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 209 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 210 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 211 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 212 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 215 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 216 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 217 | Record.AddAPInt(T->getSize()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 218 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 221 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 222 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 223 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 226 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 227 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 228 | Record.AddSourceLocation(T->getLBracketLoc()); |
| 229 | Record.AddSourceLocation(T->getRBracketLoc()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 230 | Record.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 231 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 234 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 235 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 236 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 237 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 238 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 241 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 242 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 243 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 246 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 247 | Record.AddTypeRef(T->getReturnType()); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 248 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 249 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 250 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 251 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 252 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 253 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 254 | Record.push_back(C.getProducesResult()); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 255 | |
| 256 | if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult()) |
| 257 | AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 260 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 261 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 262 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 265 | static void addExceptionSpec(const FunctionProtoType *T, |
| 266 | ASTRecordWriter &Record) { |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 267 | Record.push_back(T->getExceptionSpecType()); |
| 268 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 269 | Record.push_back(T->getNumExceptions()); |
| 270 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 271 | Record.AddTypeRef(T->getExceptionType(I)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 272 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 273 | Record.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 274 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 275 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
| 276 | Record.AddDeclRef(T->getExceptionSpecTemplate()); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 277 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 278 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 279 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 283 | VisitFunctionType(T); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 284 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 285 | Record.push_back(T->isVariadic()); |
| 286 | Record.push_back(T->hasTrailingReturn()); |
| 287 | Record.push_back(T->getTypeQuals()); |
| 288 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 289 | addExceptionSpec(T, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 290 | |
| 291 | Record.push_back(T->getNumParams()); |
| 292 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 293 | Record.AddTypeRef(T->getParamType(I)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 294 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 295 | if (T->hasExtParameterInfos()) { |
| 296 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 297 | Record.push_back(T->getExtParameterInfo(I).getOpaqueValue()); |
| 298 | } |
| 299 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 300 | if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 301 | T->getRefQualifier() || T->getExceptionSpecType() != EST_None || |
| 302 | T->hasExtParameterInfos()) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 303 | AbbrevToUse = 0; |
| 304 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 305 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 308 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 309 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 310 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 311 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 312 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 313 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 314 | Record.AddDeclRef(T->getDecl()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 315 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 316 | Record.AddTypeRef(T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 317 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 320 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 321 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 322 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 325 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 326 | Record.AddTypeRef(T->getUnderlyingType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 327 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 330 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 331 | Record.AddTypeRef(T->getUnderlyingType()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 332 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 333 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 336 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 337 | Record.AddTypeRef(T->getBaseType()); |
| 338 | Record.AddTypeRef(T->getUnderlyingType()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 339 | Record.push_back(T->getUTTKind()); |
| 340 | Code = TYPE_UNARY_TRANSFORM; |
| 341 | } |
| 342 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 343 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 344 | Record.AddTypeRef(T->getDeducedType()); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 345 | Record.push_back((unsigned)T->getKeyword()); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 346 | if (T->getDeducedType().isNull()) |
| 347 | Record.push_back(T->isDependentType()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 348 | Code = TYPE_AUTO; |
| 349 | } |
| 350 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 351 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 352 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 353 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 354 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 355 | "Cannot serialize in the middle of a type definition"); |
| 356 | } |
| 357 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 358 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 359 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 360 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 363 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 364 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 365 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 366 | } |
| 367 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 368 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 369 | Record.AddTypeRef(T->getModifiedType()); |
| 370 | Record.AddTypeRef(T->getEquivalentType()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 371 | Record.push_back(T->getAttrKind()); |
| 372 | Code = TYPE_ATTRIBUTED; |
| 373 | } |
| 374 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 376 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 377 | const SubstTemplateTypeParmType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 378 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 379 | Record.AddTypeRef(T->getReplacementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 380 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 384 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 385 | const SubstTemplateTypeParmPackType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 386 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 387 | Record.AddTemplateArgument(T->getArgumentPack()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 388 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 389 | } |
| 390 | |
| 391 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 392 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 393 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 394 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 395 | Record.AddTemplateName(T->getTemplateName()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 396 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 397 | for (const auto &ArgI : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 398 | Record.AddTemplateArgument(ArgI); |
| 399 | Record.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() |
| 400 | : T->isCanonicalUnqualified() |
| 401 | ? QualType() |
| 402 | : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 403 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 407 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 408 | VisitArrayType(T); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 409 | Record.AddStmt(T->getSizeExpr()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 410 | Record.AddSourceRange(T->getBracketsRange()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 411 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 415 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 416 | const DependentSizedExtVectorType *T) { |
| 417 | // FIXME: Serialize this type (C++ only) |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 418 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 422 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 423 | Record.push_back(T->getDepth()); |
| 424 | Record.push_back(T->getIndex()); |
| 425 | Record.push_back(T->isParameterPack()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 426 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 427 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 431 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 432 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 433 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 434 | Record.AddIdentifierRef(T->getIdentifier()); |
| 435 | Record.AddTypeRef( |
| 436 | T->isCanonicalUnqualified() ? QualType() : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 437 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 441 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 442 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 443 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 444 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 445 | Record.AddIdentifierRef(T->getIdentifier()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 446 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 447 | for (const auto &I : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 448 | Record.AddTemplateArgument(I); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 449 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 452 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 453 | Record.AddTypeRef(T->getPattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 454 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 455 | Record.push_back(*NumExpansions + 1); |
| 456 | else |
| 457 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 458 | Code = TYPE_PACK_EXPANSION; |
| 459 | } |
| 460 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 461 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 462 | Record.AddTypeRef(T->getInnerType()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 463 | Code = TYPE_PAREN; |
| 464 | } |
| 465 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 466 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 467 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 468 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 469 | Record.AddTypeRef(T->getNamedType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 470 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 473 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 474 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
| 475 | Record.AddTypeRef(T->getInjectedSpecializationType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 476 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 479 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 480 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 481 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 484 | void ASTTypeWriter::VisitObjCTypeParamType(const ObjCTypeParamType *T) { |
| 485 | Record.AddDeclRef(T->getDecl()); |
| 486 | Record.push_back(T->getNumProtocols()); |
| 487 | for (const auto *I : T->quals()) |
| 488 | Record.AddDeclRef(I); |
| 489 | Code = TYPE_OBJC_TYPE_PARAM; |
| 490 | } |
| 491 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 492 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 493 | Record.AddTypeRef(T->getBaseType()); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 494 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 495 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 496 | Record.AddTypeRef(TypeArg); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 497 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 498 | for (const auto *I : T->quals()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 499 | Record.AddDeclRef(I); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 500 | Record.push_back(T->isKindOfTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 501 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 504 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 505 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 506 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 507 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 510 | void |
| 511 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 512 | Record.AddTypeRef(T->getValueType()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 513 | Code = TYPE_ATOMIC; |
| 514 | } |
| 515 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 516 | void |
| 517 | ASTTypeWriter::VisitPipeType(const PipeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 518 | Record.AddTypeRef(T->getElementType()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 519 | Code = TYPE_PIPE; |
| 520 | } |
| 521 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 522 | namespace { |
| 523 | |
| 524 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 525 | ASTRecordWriter &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 526 | |
| 527 | public: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 528 | TypeLocWriter(ASTRecordWriter &Record) |
| 529 | : Record(Record) { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 530 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 531 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 532 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 533 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 534 | #include "clang/AST/TypeLocNodes.def" |
| 535 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 536 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 537 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 538 | }; |
| 539 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 540 | } // end anonymous namespace |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 541 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 542 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 543 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 544 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 545 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 546 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 547 | Record.AddSourceLocation(TL.getBuiltinLoc()); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 548 | if (TL.needsExtraLocalData()) { |
| 549 | Record.push_back(TL.getWrittenTypeSpec()); |
| 550 | Record.push_back(TL.getWrittenSignSpec()); |
| 551 | Record.push_back(TL.getWrittenWidthSpec()); |
| 552 | Record.push_back(TL.hasModeAttr()); |
| 553 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 554 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 555 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 556 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 557 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 558 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 559 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 560 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 561 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 562 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 563 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 564 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 565 | // nothing to do |
| 566 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 567 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 568 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 569 | // nothing to do |
| 570 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 571 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 572 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 573 | Record.AddSourceLocation(TL.getCaretLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 574 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 575 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 576 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 577 | Record.AddSourceLocation(TL.getAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 578 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 579 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 580 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 581 | Record.AddSourceLocation(TL.getAmpAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 582 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 583 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 584 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 585 | Record.AddSourceLocation(TL.getStarLoc()); |
| 586 | Record.AddTypeSourceInfo(TL.getClassTInfo()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 587 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 588 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 589 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 590 | Record.AddSourceLocation(TL.getLBracketLoc()); |
| 591 | Record.AddSourceLocation(TL.getRBracketLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 592 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 593 | if (TL.getSizeExpr()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 594 | Record.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 595 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 596 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 597 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 598 | VisitArrayTypeLoc(TL); |
| 599 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 600 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 601 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 602 | VisitArrayTypeLoc(TL); |
| 603 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 604 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 605 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 606 | VisitArrayTypeLoc(TL); |
| 607 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 608 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 609 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 610 | DependentSizedArrayTypeLoc TL) { |
| 611 | VisitArrayTypeLoc(TL); |
| 612 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 613 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 614 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 615 | DependentSizedExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 616 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 617 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 618 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 619 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 620 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 621 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 622 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 623 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 624 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 625 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 626 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 627 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 628 | Record.AddSourceLocation(TL.getLocalRangeBegin()); |
| 629 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 630 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 631 | Record.AddSourceLocation(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 632 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 633 | Record.AddDeclRef(TL.getParam(i)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 634 | } |
| 635 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 636 | VisitFunctionTypeLoc(TL); |
| 637 | } |
| 638 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 639 | VisitFunctionTypeLoc(TL); |
| 640 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 641 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 642 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 643 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 644 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 645 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 646 | } |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 647 | void TypeLocWriter::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 648 | if (TL.getNumProtocols()) { |
| 649 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 650 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
| 651 | } |
| 652 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 653 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
| 654 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 655 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 656 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 657 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 658 | Record.AddSourceLocation(TL.getRParenLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 659 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 660 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 661 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 662 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 663 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 664 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 665 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 666 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 667 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 668 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 669 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 670 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 671 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 672 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 673 | Record.AddSourceLocation(TL.getKWLoc()); |
| 674 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 675 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 676 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 677 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 678 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 679 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 680 | Record.AddSourceLocation(TL.getNameLoc()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 681 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 682 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 683 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 684 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 685 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 686 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 687 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 688 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 689 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 690 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 691 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 692 | Record.AddSourceLocation(TL.getAttrNameLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 693 | if (TL.hasAttrOperand()) { |
| 694 | SourceRange range = TL.getAttrOperandParensRange(); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 695 | Record.AddSourceLocation(range.getBegin()); |
| 696 | Record.AddSourceLocation(range.getEnd()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 697 | } |
| 698 | if (TL.hasAttrExprOperand()) { |
| 699 | Expr *operand = TL.getAttrExprOperand(); |
| 700 | Record.push_back(operand ? 1 : 0); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 701 | if (operand) Record.AddStmt(operand); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 702 | } else if (TL.hasAttrEnumOperand()) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 703 | Record.AddSourceLocation(TL.getAttrEnumOperandLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 704 | } |
| 705 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 706 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 707 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 708 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 709 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 710 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 711 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 712 | SubstTemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 713 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 714 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 715 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 716 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 717 | SubstTemplateTypeParmPackTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 718 | Record.AddSourceLocation(TL.getNameLoc()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 719 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 720 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 721 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 722 | TemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 723 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 724 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 725 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 726 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 727 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 728 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 729 | TL.getArgLoc(i).getLocInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 730 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 731 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 732 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 733 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 734 | Record.AddSourceLocation(TL.getRParenLoc()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 735 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 736 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 737 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 738 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 739 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 740 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 741 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 742 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 743 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 744 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 745 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 746 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 747 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 748 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 749 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 750 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 751 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 752 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 753 | DependentTemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 754 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 755 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 756 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 757 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 758 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 759 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 760 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 761 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 762 | TL.getArgLoc(I).getLocInfo()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 763 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 764 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 765 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 766 | Record.AddSourceLocation(TL.getEllipsisLoc()); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 767 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 768 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 769 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 770 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 771 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 772 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 773 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 774 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 775 | Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); |
| 776 | Record.AddSourceLocation(TL.getTypeArgsRAngleLoc()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 777 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 778 | Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i)); |
| 779 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 780 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 781 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 782 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 783 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 784 | |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 785 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 786 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 787 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 788 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 789 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 790 | Record.AddSourceLocation(TL.getKWLoc()); |
| 791 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 792 | Record.AddSourceLocation(TL.getRParenLoc()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 793 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 794 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 795 | void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 796 | Record.AddSourceLocation(TL.getKWLoc()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 797 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 798 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 799 | void ASTWriter::WriteTypeAbbrevs() { |
| 800 | using namespace llvm; |
| 801 | |
| 802 | BitCodeAbbrev *Abv; |
| 803 | |
| 804 | // Abbreviation for TYPE_EXT_QUAL |
| 805 | Abv = new BitCodeAbbrev(); |
| 806 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 807 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 808 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
| 809 | TypeExtQualAbbrev = Stream.EmitAbbrev(Abv); |
| 810 | |
| 811 | // Abbreviation for TYPE_FUNCTION_PROTO |
| 812 | Abv = new BitCodeAbbrev(); |
| 813 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 814 | // FunctionType |
| 815 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 816 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 817 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 818 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 819 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 820 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
| 821 | // FunctionProtoType |
| 822 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 823 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 824 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 825 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 826 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 827 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 828 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 829 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
| 830 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(Abv); |
| 831 | } |
| 832 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 833 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 834 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 835 | //===----------------------------------------------------------------------===// |
| 836 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 837 | static void EmitBlockID(unsigned ID, const char *Name, |
| 838 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 839 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 840 | Record.clear(); |
| 841 | Record.push_back(ID); |
| 842 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 843 | |
| 844 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 845 | if (!Name || Name[0] == 0) |
| 846 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 847 | Record.clear(); |
| 848 | while (*Name) |
| 849 | Record.push_back(*Name++); |
| 850 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 851 | } |
| 852 | |
| 853 | static void EmitRecordID(unsigned ID, const char *Name, |
| 854 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 855 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 856 | Record.clear(); |
| 857 | Record.push_back(ID); |
| 858 | while (*Name) |
| 859 | Record.push_back(*Name++); |
| 860 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 864 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 865 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 866 | RECORD(STMT_STOP); |
| 867 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 868 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 869 | RECORD(STMT_NULL); |
| 870 | RECORD(STMT_COMPOUND); |
| 871 | RECORD(STMT_CASE); |
| 872 | RECORD(STMT_DEFAULT); |
| 873 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 874 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 875 | RECORD(STMT_IF); |
| 876 | RECORD(STMT_SWITCH); |
| 877 | RECORD(STMT_WHILE); |
| 878 | RECORD(STMT_DO); |
| 879 | RECORD(STMT_FOR); |
| 880 | RECORD(STMT_GOTO); |
| 881 | RECORD(STMT_INDIRECT_GOTO); |
| 882 | RECORD(STMT_CONTINUE); |
| 883 | RECORD(STMT_BREAK); |
| 884 | RECORD(STMT_RETURN); |
| 885 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 886 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 887 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 888 | RECORD(EXPR_PREDEFINED); |
| 889 | RECORD(EXPR_DECL_REF); |
| 890 | RECORD(EXPR_INTEGER_LITERAL); |
| 891 | RECORD(EXPR_FLOATING_LITERAL); |
| 892 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 893 | RECORD(EXPR_STRING_LITERAL); |
| 894 | RECORD(EXPR_CHARACTER_LITERAL); |
| 895 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 896 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 897 | RECORD(EXPR_UNARY_OPERATOR); |
| 898 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 899 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 900 | RECORD(EXPR_CALL); |
| 901 | RECORD(EXPR_MEMBER); |
| 902 | RECORD(EXPR_BINARY_OPERATOR); |
| 903 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 904 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 905 | RECORD(EXPR_IMPLICIT_CAST); |
| 906 | RECORD(EXPR_CSTYLE_CAST); |
| 907 | RECORD(EXPR_COMPOUND_LITERAL); |
| 908 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 909 | RECORD(EXPR_INIT_LIST); |
| 910 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 911 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 912 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 913 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 914 | RECORD(EXPR_VA_ARG); |
| 915 | RECORD(EXPR_ADDR_LABEL); |
| 916 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 917 | RECORD(EXPR_CHOOSE); |
| 918 | RECORD(EXPR_GNU_NULL); |
| 919 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 920 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 921 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 922 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 923 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 924 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 925 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 926 | RECORD(EXPR_OBJC_ENCODE); |
| 927 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 928 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 929 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 930 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 931 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 932 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 933 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 934 | RECORD(STMT_OBJC_CATCH); |
| 935 | RECORD(STMT_OBJC_FINALLY); |
| 936 | RECORD(STMT_OBJC_AT_TRY); |
| 937 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 938 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 939 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 940 | RECORD(STMT_CXX_CATCH); |
| 941 | RECORD(STMT_CXX_TRY); |
| 942 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 943 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 944 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 945 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 946 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 947 | RECORD(EXPR_CXX_STATIC_CAST); |
| 948 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 949 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 950 | RECORD(EXPR_CXX_CONST_CAST); |
| 951 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 952 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 953 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 954 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 955 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 956 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 957 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 958 | RECORD(EXPR_CXX_THIS); |
| 959 | RECORD(EXPR_CXX_THROW); |
| 960 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 961 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 962 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 963 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 964 | RECORD(EXPR_CXX_NEW); |
| 965 | RECORD(EXPR_CXX_DELETE); |
| 966 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 967 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 968 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 969 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 970 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 971 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 972 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 973 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 974 | RECORD(EXPR_CXX_NOEXCEPT); |
| 975 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 976 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 977 | RECORD(EXPR_TYPE_TRAIT); |
| 978 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 979 | RECORD(EXPR_PACK_EXPANSION); |
| 980 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 981 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 982 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 983 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 984 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 985 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 986 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 987 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 988 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 989 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 990 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 992 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 993 | RecordData Record; |
Peter Collingbourne | d3a6c70 | 2016-11-01 01:18:57 +0000 | [diff] [blame^] | 994 | Stream.EnterBlockInfoBlock(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 995 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 996 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 997 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 999 | // Control Block. |
| 1000 | BLOCK(CONTROL_BLOCK); |
| 1001 | RECORD(METADATA); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1002 | RECORD(SIGNATURE); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1003 | RECORD(MODULE_NAME); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1004 | RECORD(MODULE_DIRECTORY); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1005 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1006 | RECORD(IMPORTS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1007 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1008 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1009 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1010 | RECORD(INPUT_FILE_OFFSETS); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1011 | |
| 1012 | BLOCK(OPTIONS_BLOCK); |
| 1013 | RECORD(LANGUAGE_OPTIONS); |
| 1014 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1015 | RECORD(DIAGNOSTIC_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1016 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1017 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1018 | RECORD(PREPROCESSOR_OPTIONS); |
| 1019 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 1020 | BLOCK(INPUT_FILES_BLOCK); |
| 1021 | RECORD(INPUT_FILE); |
| 1022 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1023 | // AST Top-Level Block. |
| 1024 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1025 | RECORD(TYPE_OFFSET); |
| 1026 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1027 | RECORD(IDENTIFIER_OFFSET); |
| 1028 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 1029 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1030 | RECORD(SPECIAL_TYPES); |
| 1031 | RECORD(STATISTICS); |
| 1032 | RECORD(TENTATIVE_DEFINITIONS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1033 | RECORD(SELECTOR_OFFSETS); |
| 1034 | RECORD(METHOD_POOL); |
| 1035 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1036 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 1037 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1038 | RECORD(EXT_VECTOR_DECLS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1039 | RECORD(UNUSED_FILESCOPED_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1040 | RECORD(PPD_ENTITIES_OFFSETS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1041 | RECORD(VTABLE_USES); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 1042 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1043 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1044 | RECORD(SEMA_DECL_REFS); |
| 1045 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 1046 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1047 | RECORD(UPDATE_VISIBLE); |
| 1048 | RECORD(DECL_UPDATE_OFFSETS); |
| 1049 | RECORD(DECL_UPDATES); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1050 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1051 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1052 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1053 | RECORD(FP_PRAGMA_OPTIONS); |
| 1054 | RECORD(OPENCL_EXTENSIONS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1055 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 1056 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 1057 | RECORD(MODULE_OFFSET_MAP); |
| 1058 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1059 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 1060 | RECORD(FILE_SORTED_DECLS); |
| 1061 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1062 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1063 | RECORD(MACRO_OFFSET); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1064 | RECORD(INTERESTING_IDENTIFIERS); |
| 1065 | RECORD(UNDEFINED_BUT_USED); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1066 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 1067 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 1068 | RECORD(MSSTRUCT_PRAGMA_OPTIONS); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 1069 | RECORD(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1070 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1071 | RECORD(DELETE_EXPRS_TO_ANALYZE); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 1072 | RECORD(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 1073 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1074 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1075 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1076 | RECORD(SM_SLOC_FILE_ENTRY); |
| 1077 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 1078 | RECORD(SM_SLOC_BUFFER_BLOB); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1079 | RECORD(SM_SLOC_BUFFER_BLOB_COMPRESSED); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1080 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1082 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 1083 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1084 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1085 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1086 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 1087 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1088 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1089 | |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1090 | // Submodule Block. |
| 1091 | BLOCK(SUBMODULE_BLOCK); |
| 1092 | RECORD(SUBMODULE_METADATA); |
| 1093 | RECORD(SUBMODULE_DEFINITION); |
| 1094 | RECORD(SUBMODULE_UMBRELLA_HEADER); |
| 1095 | RECORD(SUBMODULE_HEADER); |
| 1096 | RECORD(SUBMODULE_TOPHEADER); |
| 1097 | RECORD(SUBMODULE_UMBRELLA_DIR); |
| 1098 | RECORD(SUBMODULE_IMPORTS); |
| 1099 | RECORD(SUBMODULE_EXPORTS); |
| 1100 | RECORD(SUBMODULE_REQUIRES); |
| 1101 | RECORD(SUBMODULE_EXCLUDED_HEADER); |
| 1102 | RECORD(SUBMODULE_LINK_LIBRARY); |
| 1103 | RECORD(SUBMODULE_CONFIG_MACRO); |
| 1104 | RECORD(SUBMODULE_CONFLICT); |
| 1105 | RECORD(SUBMODULE_PRIVATE_HEADER); |
| 1106 | RECORD(SUBMODULE_TEXTUAL_HEADER); |
| 1107 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 1108 | RECORD(SUBMODULE_INITIALIZERS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1109 | |
| 1110 | // Comments Block. |
| 1111 | BLOCK(COMMENTS_BLOCK); |
| 1112 | RECORD(COMMENTS_RAW_COMMENT); |
| 1113 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1114 | // Decls and Types block. |
| 1115 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1116 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1117 | RECORD(TYPE_COMPLEX); |
| 1118 | RECORD(TYPE_POINTER); |
| 1119 | RECORD(TYPE_BLOCK_POINTER); |
| 1120 | RECORD(TYPE_LVALUE_REFERENCE); |
| 1121 | RECORD(TYPE_RVALUE_REFERENCE); |
| 1122 | RECORD(TYPE_MEMBER_POINTER); |
| 1123 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1124 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1125 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1126 | RECORD(TYPE_VECTOR); |
| 1127 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1128 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1129 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1130 | RECORD(TYPE_TYPEDEF); |
| 1131 | RECORD(TYPE_TYPEOF_EXPR); |
| 1132 | RECORD(TYPE_TYPEOF); |
| 1133 | RECORD(TYPE_RECORD); |
| 1134 | RECORD(TYPE_ENUM); |
| 1135 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1136 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1137 | RECORD(TYPE_DECLTYPE); |
| 1138 | RECORD(TYPE_ELABORATED); |
| 1139 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 1140 | RECORD(TYPE_UNRESOLVED_USING); |
| 1141 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 1142 | RECORD(TYPE_OBJC_OBJECT); |
| 1143 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 1144 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 1145 | RECORD(TYPE_DEPENDENT_NAME); |
| 1146 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 1147 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 1148 | RECORD(TYPE_PAREN); |
| 1149 | RECORD(TYPE_PACK_EXPANSION); |
| 1150 | RECORD(TYPE_ATTRIBUTED); |
| 1151 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1152 | RECORD(TYPE_AUTO); |
| 1153 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1154 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1155 | RECORD(TYPE_DECAYED); |
| 1156 | RECORD(TYPE_ADJUSTED); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 1157 | RECORD(TYPE_OBJC_TYPE_PARAM); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 1158 | RECORD(LOCAL_REDECLARATIONS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1159 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1160 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1161 | RECORD(DECL_ENUM); |
| 1162 | RECORD(DECL_RECORD); |
| 1163 | RECORD(DECL_ENUM_CONSTANT); |
| 1164 | RECORD(DECL_FUNCTION); |
| 1165 | RECORD(DECL_OBJC_METHOD); |
| 1166 | RECORD(DECL_OBJC_INTERFACE); |
| 1167 | RECORD(DECL_OBJC_PROTOCOL); |
| 1168 | RECORD(DECL_OBJC_IVAR); |
| 1169 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1170 | RECORD(DECL_OBJC_CATEGORY); |
| 1171 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1172 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1173 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1174 | RECORD(DECL_OBJC_PROPERTY); |
| 1175 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1176 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1177 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1178 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1179 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1180 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1181 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1182 | RECORD(DECL_BLOCK); |
| 1183 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1184 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1185 | RECORD(DECL_NAMESPACE); |
| 1186 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1187 | RECORD(DECL_USING); |
| 1188 | RECORD(DECL_USING_SHADOW); |
| 1189 | RECORD(DECL_USING_DIRECTIVE); |
| 1190 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1191 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1192 | RECORD(DECL_LINKAGE_SPEC); |
| 1193 | RECORD(DECL_CXX_RECORD); |
| 1194 | RECORD(DECL_CXX_METHOD); |
| 1195 | RECORD(DECL_CXX_CONSTRUCTOR); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1196 | RECORD(DECL_CXX_INHERITED_CONSTRUCTOR); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1197 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1198 | RECORD(DECL_CXX_CONVERSION); |
| 1199 | RECORD(DECL_ACCESS_SPEC); |
| 1200 | RECORD(DECL_FRIEND); |
| 1201 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1202 | RECORD(DECL_CLASS_TEMPLATE); |
| 1203 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1204 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1205 | RECORD(DECL_VAR_TEMPLATE); |
| 1206 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1207 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1208 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1209 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1210 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1211 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1212 | RECORD(DECL_TYPE_ALIAS_TEMPLATE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1213 | RECORD(DECL_STATIC_ASSERT); |
| 1214 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1215 | RECORD(DECL_CXX_CTOR_INITIALIZERS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1216 | RECORD(DECL_INDIRECTFIELD); |
| 1217 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 1218 | RECORD(DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK); |
| 1219 | RECORD(DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION); |
| 1220 | RECORD(DECL_IMPORT); |
| 1221 | RECORD(DECL_OMP_THREADPRIVATE); |
| 1222 | RECORD(DECL_EMPTY); |
| 1223 | RECORD(DECL_OBJC_TYPE_PARAM); |
| 1224 | RECORD(DECL_OMP_CAPTUREDEXPR); |
| 1225 | RECORD(DECL_PRAGMA_COMMENT); |
| 1226 | RECORD(DECL_PRAGMA_DETECT_MISMATCH); |
| 1227 | RECORD(DECL_OMP_DECLARE_REDUCTION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1228 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1229 | // Statements and Exprs can occur in the Decls and Types block. |
| 1230 | AddStmtsExprs(Stream, Record); |
| 1231 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1232 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1233 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1234 | RECORD(PPD_MACRO_DEFINITION); |
| 1235 | RECORD(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 1236 | |
| 1237 | // Decls and Types block. |
| 1238 | BLOCK(EXTENSION_BLOCK); |
| 1239 | RECORD(EXTENSION_METADATA); |
| 1240 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1241 | #undef RECORD |
| 1242 | #undef BLOCK |
| 1243 | Stream.ExitBlock(); |
| 1244 | } |
| 1245 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1246 | /// \brief Prepares a path for being written to an AST file by converting it |
| 1247 | /// to an absolute path and removing nested './'s. |
| 1248 | /// |
| 1249 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1250 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1251 | SmallVectorImpl<char> &Path) { |
Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 1252 | bool Changed = FileMgr.makeAbsolutePath(Path); |
Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame] | 1253 | return Changed | llvm::sys::path::remove_dots(Path); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1256 | /// \brief Adjusts the given filename to only write out the portion of the |
| 1257 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1258 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1259 | /// \param Filename the file name to adjust. |
| 1260 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1261 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1262 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1263 | /// |
| 1264 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1265 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1266 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1267 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1268 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1269 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1270 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1271 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1272 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1273 | // Verify that the filename and the system root have the same prefix. |
| 1274 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1275 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1276 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1277 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1278 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1279 | // We hit the end of the filename before we hit the end of the system root. |
| 1280 | if (!Filename[Pos]) |
| 1281 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1282 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1283 | // If there's not a path separator at the end of the base directory nor |
| 1284 | // immediately after it, then this isn't within the base directory. |
| 1285 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1286 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1287 | return Filename; |
| 1288 | } else { |
| 1289 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1290 | // We distinguish relative paths from absolute paths by the |
| 1291 | // absence of '/' at the beginning of relative paths. |
| 1292 | // |
| 1293 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1294 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1295 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1296 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1297 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1298 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1299 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1300 | return Filename + Pos; |
| 1301 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1302 | |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1303 | static ASTFileSignature getSignature() { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1304 | while (true) { |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1305 | if (ASTFileSignature S = llvm::sys::Process::GetRandomNumber()) |
| 1306 | return S; |
| 1307 | // Rely on GetRandomNumber to eventually return non-zero... |
| 1308 | } |
| 1309 | } |
| 1310 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1311 | /// \brief Write the control block. |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1312 | uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP, |
| 1313 | ASTContext &Context, |
| 1314 | StringRef isysroot, |
| 1315 | const std::string &OutputFile) { |
| 1316 | ASTFileSignature Signature = 0; |
| 1317 | |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1318 | using namespace llvm; |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1319 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1320 | RecordData Record; |
| 1321 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1322 | // Metadata |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1323 | auto *MetadataAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1324 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1325 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1326 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1327 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1328 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1329 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1330 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1331 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1332 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1333 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1334 | assert((!WritingModule || isysroot.empty()) && |
| 1335 | "writing module as a relocatable PCH?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1336 | { |
| 1337 | RecordData::value_type Record[] = {METADATA, VERSION_MAJOR, VERSION_MINOR, |
| 1338 | CLANG_VERSION_MAJOR, CLANG_VERSION_MINOR, |
| 1339 | !isysroot.empty(), IncludeTimestamps, |
| 1340 | ASTHasCompilerErrors}; |
| 1341 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1342 | getClangFullRepositoryVersion()); |
| 1343 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1344 | if (WritingModule) { |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1345 | // For implicit modules we output a signature that we can use to ensure |
| 1346 | // duplicate module builds don't collide in the cache as their output order |
| 1347 | // is non-deterministic. |
| 1348 | // FIXME: Remove this when output is deterministic. |
| 1349 | if (Context.getLangOpts().ImplicitModules) { |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1350 | Signature = getSignature(); |
| 1351 | RecordData::value_type Record[] = {Signature}; |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1352 | Stream.EmitRecord(SIGNATURE, Record); |
| 1353 | } |
| 1354 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1355 | // Module name |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1356 | auto *Abbrev = new BitCodeAbbrev(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1357 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1358 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1359 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1360 | RecordData::value_type Record[] = {MODULE_NAME}; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1361 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1362 | } |
| 1363 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1364 | if (WritingModule && WritingModule->Directory) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1365 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1366 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1367 | |
| 1368 | // If the home of the module is the current working directory, then we |
| 1369 | // want to pick up the cwd of the build process loading the module, not |
| 1370 | // our cwd, when we load this module. |
| 1371 | if (!PP.getHeaderSearchInfo() |
| 1372 | .getHeaderSearchOpts() |
| 1373 | .ModuleMapFileHomeIsCwd || |
| 1374 | WritingModule->Directory->getName() != StringRef(".")) { |
| 1375 | // Module directory. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1376 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1377 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1378 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
| 1379 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1380 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1381 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1382 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1383 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1384 | |
| 1385 | // Write out all other paths relative to the base directory if possible. |
| 1386 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1387 | } else if (!isysroot.empty()) { |
| 1388 | // Write out paths relative to the sysroot if possible. |
| 1389 | BaseDirectory = isysroot; |
| 1390 | } |
| 1391 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1392 | // Module map file |
| 1393 | if (WritingModule) { |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1394 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1395 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1396 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 1397 | |
| 1398 | // Primary module map file. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1399 | AddPath(Map.getModuleMapFileForUniquing(WritingModule)->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1400 | |
| 1401 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1402 | if (auto *AdditionalModMaps = |
| 1403 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1404 | Record.push_back(AdditionalModMaps->size()); |
| 1405 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1406 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1407 | } else { |
| 1408 | Record.push_back(0); |
| 1409 | } |
| 1410 | |
| 1411 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1414 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1415 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1416 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1417 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1418 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1419 | for (auto *M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1420 | // Skip modules that weren't directly imported. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1421 | if (!M->isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1422 | continue; |
| 1423 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1424 | Record.push_back((unsigned)M->Kind); // FIXME: Stable encoding |
| 1425 | AddSourceLocation(M->ImportLoc, Record); |
| 1426 | Record.push_back(M->File->getSize()); |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1427 | Record.push_back(getTimestampForOutput(M->File)); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1428 | Record.push_back(M->Signature); |
| 1429 | AddPath(M->FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1430 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1431 | Stream.EmitRecord(IMPORTS, Record); |
| 1432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1434 | // Write the options block. |
| 1435 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); |
| 1436 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1437 | // Language options. |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1438 | Record.clear(); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1439 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1440 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1441 | Record.push_back(LangOpts.Name); |
| 1442 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1443 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1444 | #include "clang/Basic/LangOptions.def" |
| 1445 | #define SANITIZER(NAME, ID) \ |
| 1446 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1447 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1448 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1449 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1450 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1451 | AddString(Feature, Record); |
| 1452 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1453 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1454 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1455 | |
| 1456 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1457 | |
| 1458 | // Comment options. |
| 1459 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1460 | for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) { |
| 1461 | AddString(I, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1462 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1463 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1464 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1465 | // OpenMP offloading options. |
| 1466 | Record.push_back(LangOpts.OMPTargetTriples.size()); |
| 1467 | for (auto &T : LangOpts.OMPTargetTriples) |
| 1468 | AddString(T.getTriple(), Record); |
| 1469 | |
| 1470 | AddString(LangOpts.OMPHostIRFile, Record); |
| 1471 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1472 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1473 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1474 | // Target options. |
| 1475 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1476 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1477 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1478 | AddString(TargetOpts.Triple, Record); |
| 1479 | AddString(TargetOpts.CPU, Record); |
| 1480 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1481 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1482 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1483 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1484 | } |
| 1485 | Record.push_back(TargetOpts.Features.size()); |
| 1486 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1487 | AddString(TargetOpts.Features[I], Record); |
| 1488 | } |
| 1489 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1490 | |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1491 | // Diagnostic options. |
| 1492 | Record.clear(); |
| 1493 | const DiagnosticOptions &DiagOpts |
| 1494 | = Context.getDiagnostics().getDiagnosticOptions(); |
| 1495 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1496 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1497 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1498 | #include "clang/Basic/DiagnosticOptions.def" |
| 1499 | Record.push_back(DiagOpts.Warnings.size()); |
| 1500 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1501 | AddString(DiagOpts.Warnings[I], Record); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 1502 | Record.push_back(DiagOpts.Remarks.size()); |
| 1503 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1504 | AddString(DiagOpts.Remarks[I], Record); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1505 | // Note: we don't serialize the log or serialization file names, because they |
| 1506 | // are generally transient files and will almost always be overridden. |
| 1507 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1508 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1509 | // File system options. |
| 1510 | Record.clear(); |
Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1511 | const FileSystemOptions &FSOpts = |
| 1512 | Context.getSourceManager().getFileManager().getFileSystemOpts(); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1513 | AddString(FSOpts.WorkingDir, Record); |
| 1514 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1515 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1516 | // Header search options. |
| 1517 | Record.clear(); |
| 1518 | const HeaderSearchOptions &HSOpts |
| 1519 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1520 | AddString(HSOpts.Sysroot, Record); |
| 1521 | |
| 1522 | // Include entries. |
| 1523 | Record.push_back(HSOpts.UserEntries.size()); |
| 1524 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1525 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1526 | AddString(Entry.Path, Record); |
| 1527 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1528 | Record.push_back(Entry.IsFramework); |
| 1529 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | // System header prefixes. |
| 1533 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1534 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1535 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1536 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1537 | } |
| 1538 | |
| 1539 | AddString(HSOpts.ResourceDir, Record); |
| 1540 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1541 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1542 | Record.push_back(HSOpts.DisableModuleHash); |
| 1543 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1544 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1545 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1546 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1547 | // Write out the specific module cache path that contains the module files. |
| 1548 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1549 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1550 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1551 | // Preprocessor options. |
| 1552 | Record.clear(); |
| 1553 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1554 | |
| 1555 | // Macro definitions. |
| 1556 | Record.push_back(PPOpts.Macros.size()); |
| 1557 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1558 | AddString(PPOpts.Macros[I].first, Record); |
| 1559 | Record.push_back(PPOpts.Macros[I].second); |
| 1560 | } |
| 1561 | |
| 1562 | // Includes |
| 1563 | Record.push_back(PPOpts.Includes.size()); |
| 1564 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1565 | AddString(PPOpts.Includes[I], Record); |
| 1566 | |
| 1567 | // Macro includes |
| 1568 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1569 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1570 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1571 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1572 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1573 | // Detailed record is important since it is used for the module cache hash. |
| 1574 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1575 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1576 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1577 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1578 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1579 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1580 | // Leave the options block. |
| 1581 | Stream.ExitBlock(); |
| 1582 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1583 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1584 | SourceManager &SM = Context.getSourceManager(); |
| 1585 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1586 | auto *FileAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1587 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1588 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1589 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1590 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1591 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1592 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1593 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1594 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1595 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1596 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1597 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1598 | Record.clear(); |
| 1599 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1600 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1601 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1602 | // Original PCH directory |
| 1603 | if (!OutputFile.empty() && OutputFile != "-") { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1604 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1605 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1606 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1607 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1608 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1609 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1610 | |
Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1611 | SM.getFileManager().makeAbsolutePath(OutputPath); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1612 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1613 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1614 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1615 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1616 | } |
| 1617 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1618 | WriteInputFiles(Context.SourceMgr, |
| 1619 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1620 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1621 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1622 | return Signature; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1625 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1626 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1627 | /// \brief An input file. |
| 1628 | struct InputFileEntry { |
| 1629 | const FileEntry *File; |
| 1630 | bool IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1631 | bool IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1632 | bool BufferOverridden; |
| 1633 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1634 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1635 | } // end anonymous namespace |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1636 | |
| 1637 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1638 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1639 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1640 | using namespace llvm; |
| 1641 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1642 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1643 | // Create input-file abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1644 | auto *IFAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1645 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1646 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1647 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1648 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1649 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1650 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1651 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1652 | unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); |
| 1653 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1654 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1655 | // 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] | 1656 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1657 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1658 | // Get this source location entry. |
| 1659 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1660 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1661 | |
| 1662 | // We only care about file entries that were not overridden. |
| 1663 | if (!SLoc->isFile()) |
| 1664 | continue; |
| 1665 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1666 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1667 | continue; |
| 1668 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1669 | InputFileEntry Entry; |
| 1670 | Entry.File = Cache->OrigEntry; |
| 1671 | Entry.IsSystemFile = Cache->IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1672 | Entry.IsTransient = Cache->IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1673 | Entry.BufferOverridden = Cache->BufferOverridden; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1674 | if (Cache->IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1675 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1676 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1677 | SortedFiles.push_front(Entry); |
| 1678 | } |
| 1679 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1680 | unsigned UserFilesNum = 0; |
| 1681 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1682 | std::vector<uint64_t> InputFileOffsets; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1683 | for (const auto &Entry : SortedFiles) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1684 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1685 | if (InputFileID != 0) |
| 1686 | continue; // already recorded this file. |
| 1687 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1688 | // Record this entry's offset. |
| 1689 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1690 | |
| 1691 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1692 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1693 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1694 | ++UserFilesNum; |
| 1695 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1696 | // Emit size/modification time for this file. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1697 | // And whether this file was overridden. |
| 1698 | RecordData::value_type Record[] = { |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1699 | INPUT_FILE, |
| 1700 | InputFileOffsets.size(), |
| 1701 | (uint64_t)Entry.File->getSize(), |
| 1702 | (uint64_t)getTimestampForOutput(Entry.File), |
| 1703 | Entry.BufferOverridden, |
| 1704 | Entry.IsTransient}; |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1705 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1706 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1707 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1708 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1709 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1710 | |
| 1711 | // Create input file offsets abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1712 | auto *OffsetsAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1713 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1714 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1715 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1716 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1717 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
| 1718 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(OffsetsAbbrev); |
| 1719 | |
| 1720 | // Write input file offsets. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1721 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, |
| 1722 | InputFileOffsets.size(), UserFilesNum}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1723 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1726 | //===----------------------------------------------------------------------===// |
| 1727 | // Source Manager Serialization |
| 1728 | //===----------------------------------------------------------------------===// |
| 1729 | |
| 1730 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1731 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1732 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1733 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1734 | |
| 1735 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1736 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1737 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1738 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1739 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1740 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1741 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1742 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1743 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1744 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1745 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1746 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1750 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1751 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1752 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1753 | |
| 1754 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1755 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1756 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1757 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1758 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1759 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1760 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1761 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1765 | /// buffer's blob. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1766 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, |
| 1767 | bool Compressed) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1768 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1769 | |
| 1770 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1771 | Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED |
| 1772 | : SM_SLOC_BUFFER_BLOB)); |
| 1773 | if (Compressed) |
| 1774 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1775 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1776 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1779 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1780 | /// expansion. |
| 1781 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1782 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1783 | |
| 1784 | auto *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1785 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1786 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1787 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1788 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1789 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1790 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1791 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1794 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1795 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1796 | // Trait used for the on-disk hash table of header search information. |
| 1797 | class HeaderFileInfoTrait { |
| 1798 | ASTWriter &Writer; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1799 | const HeaderSearch &HS; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1800 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1801 | // Keep track of the framework names we've used during serialization. |
| 1802 | SmallVector<char, 128> FrameworkStringData; |
| 1803 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1804 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1805 | public: |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1806 | HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) |
| 1807 | : Writer(Writer), HS(HS) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1808 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1809 | struct key_type { |
| 1810 | const FileEntry *FE; |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1811 | StringRef Filename; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1812 | }; |
| 1813 | typedef const key_type &key_type_ref; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1814 | |
| 1815 | typedef HeaderFileInfo data_type; |
| 1816 | typedef const data_type &data_type_ref; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 1817 | typedef unsigned hash_value_type; |
| 1818 | typedef unsigned offset_type; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1819 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1820 | hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1821 | // The hash is based only on size/time of the file, so that the reader can |
| 1822 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1823 | // change the form of the name. However, complete path is still the key. |
| 1824 | return llvm::hash_combine(key.FE->getSize(), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1825 | Writer.getTimestampForOutput(key.FE)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | std::pair<unsigned,unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1829 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1830 | using namespace llvm::support; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1831 | endian::Writer<little> LE(Out); |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1832 | unsigned KeyLen = key.Filename.size() + 1 + 8 + 8; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1833 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1834 | unsigned DataLen = 1 + 2 + 4 + 4; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1835 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) |
| 1836 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) |
| 1837 | DataLen += 4; |
| 1838 | LE.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1839 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1842 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1843 | using namespace llvm::support; |
| 1844 | endian::Writer<little> LE(Out); |
| 1845 | LE.write<uint64_t>(key.FE->getSize()); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1846 | KeyLen -= 8; |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1847 | LE.write<uint64_t>(Writer.getTimestampForOutput(key.FE)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1848 | KeyLen -= 8; |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1849 | Out.write(key.Filename.data(), KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1852 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1853 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1854 | using namespace llvm::support; |
| 1855 | endian::Writer<little> LE(Out); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1856 | uint64_t Start = Out.tell(); (void)Start; |
| 1857 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1858 | unsigned char Flags = (Data.isImport << 4) |
| 1859 | | (Data.isPragmaOnce << 3) |
| 1860 | | (Data.DirInfo << 1) |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1861 | | Data.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1862 | LE.write<uint8_t>(Flags); |
| 1863 | LE.write<uint16_t>(Data.NumIncludes); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1864 | |
| 1865 | if (!Data.ControllingMacro) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1866 | LE.write<uint32_t>(Data.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1867 | else |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1868 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1869 | |
| 1870 | unsigned Offset = 0; |
| 1871 | if (!Data.Framework.empty()) { |
| 1872 | // If this header refers into a framework, save the framework name. |
| 1873 | llvm::StringMap<unsigned>::iterator Pos |
| 1874 | = FrameworkNameOffset.find(Data.Framework); |
| 1875 | if (Pos == FrameworkNameOffset.end()) { |
| 1876 | Offset = FrameworkStringData.size() + 1; |
| 1877 | FrameworkStringData.append(Data.Framework.begin(), |
| 1878 | Data.Framework.end()); |
| 1879 | FrameworkStringData.push_back(0); |
| 1880 | |
| 1881 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1882 | } else |
| 1883 | Offset = Pos->second; |
| 1884 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1885 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1886 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1887 | // FIXME: If the header is excluded, we should write out some |
| 1888 | // record of that fact. |
| 1889 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) { |
| 1890 | if (uint32_t ModID = |
| 1891 | Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) { |
| 1892 | uint32_t Value = (ModID << 2) | (unsigned)ModInfo.getRole(); |
| 1893 | assert((Value >> 2) == ModID && "overflow in header module info"); |
| 1894 | LE.write<uint32_t>(Value); |
| 1895 | } |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1898 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1899 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1900 | |
| 1901 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1902 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1903 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1904 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1905 | } // end anonymous namespace |
| 1906 | |
| 1907 | /// \brief Write the header search block for the list of files that |
| 1908 | /// |
| 1909 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1910 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1911 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1912 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1913 | |
| 1914 | if (FilesByUID.size() > HS.header_file_size()) |
| 1915 | FilesByUID.resize(HS.header_file_size()); |
| 1916 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1917 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 1918 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1919 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1920 | unsigned NumHeaderSearchEntries = 0; |
| 1921 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1922 | const FileEntry *File = FilesByUID[UID]; |
| 1923 | if (!File) |
| 1924 | continue; |
| 1925 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1926 | // Get the file info. This will load info from the external source if |
| 1927 | // necessary. Skip emitting this file if we have no information on it |
| 1928 | // as a header file (in which case HFI will be null) or if it hasn't |
| 1929 | // changed since it was loaded. Also skip it if it's for a modular header |
| 1930 | // from a different module; in that case, we rely on the module(s) |
| 1931 | // containing the header to provide this information. |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1932 | const HeaderFileInfo *HFI = |
| 1933 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); |
| 1934 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 1935 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1936 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1937 | // Massage the file path into an appropriate form. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1938 | StringRef Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1939 | SmallString<128> FilenameTmp(Filename); |
| 1940 | if (PreparePathForOutput(FilenameTmp)) { |
| 1941 | // If we performed any translation on the file name at all, we need to |
| 1942 | // save this string, since the generator will refer to it later. |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1943 | Filename = StringRef(strdup(FilenameTmp.c_str())); |
| 1944 | SavedStrings.push_back(Filename.data()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1945 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1946 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1947 | HeaderFileInfoTrait::key_type key = { File, Filename }; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1948 | Generator.insert(key, *HFI, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1949 | ++NumHeaderSearchEntries; |
| 1950 | } |
| 1951 | |
| 1952 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1953 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1954 | uint32_t BucketOffset; |
| 1955 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1956 | using namespace llvm::support; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1957 | llvm::raw_svector_ostream Out(TableData); |
| 1958 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1959 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1960 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1961 | } |
| 1962 | |
| 1963 | // Create a blob abbreviation |
| 1964 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1965 | |
| 1966 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1967 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1968 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1969 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1970 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1971 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1972 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1973 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1974 | // Write the header search table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1975 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, |
| 1976 | NumHeaderSearchEntries, TableData.size()}; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1977 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 1978 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1979 | |
| 1980 | // Free all of the strings we had to duplicate. |
| 1981 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1982 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1985 | /// \brief Writes the block containing the serialized form of the |
| 1986 | /// source manager. |
| 1987 | /// |
| 1988 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1989 | /// blob), indexed based on the file name, so that we only create |
| 1990 | /// entries for files that we actually need. In the common case (no |
| 1991 | /// errors), we probably won't have to create file entries for any of |
| 1992 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1993 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1994 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1995 | RecordData Record; |
| 1996 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1997 | // Enter the source manager block. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1998 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1999 | |
| 2000 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 2001 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 2002 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2003 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false); |
| 2004 | unsigned SLocBufferBlobCompressedAbbrv = |
| 2005 | CreateSLocBufferBlobAbbrev(Stream, true); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2006 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2007 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2008 | // Write out the source location entry table. We skip the first |
| 2009 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 2010 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2011 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2012 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 2013 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2014 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2015 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2016 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2017 | FileID FID = FileID::get(I); |
| 2018 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2019 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2020 | // Record the offset of this source-location entry. |
| 2021 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2022 | |
| 2023 | // Figure out which record code to use. |
| 2024 | unsigned Code; |
| 2025 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2026 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 2027 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2028 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2029 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2030 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2031 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2032 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2033 | Record.clear(); |
| 2034 | Record.push_back(Code); |
| 2035 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2036 | // Starting offset of this entry within this module, so skip the dummy. |
| 2037 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2038 | if (SLoc->isFile()) { |
| 2039 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2040 | AddSourceLocation(File.getIncludeLoc(), Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2041 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 2042 | Record.push_back(File.hasLineDirectives()); |
| 2043 | |
| 2044 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2045 | bool EmitBlob = false; |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2046 | if (Content->OrigEntry) { |
| 2047 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2048 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 2049 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 2050 | // The source location entry is a file. Emit input file ID. |
| 2051 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 2052 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2053 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 2054 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2055 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 2056 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2057 | if (FDI != FileDeclIDs.end()) { |
| 2058 | Record.push_back(FDI->second->FirstDeclIndex); |
| 2059 | Record.push_back(FDI->second->DeclIDs.size()); |
| 2060 | } else { |
| 2061 | Record.push_back(0); |
| 2062 | Record.push_back(0); |
| 2063 | } |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2064 | |
| 2065 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
| 2066 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2067 | if (Content->BufferOverridden || Content->IsTransient) |
| 2068 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2069 | } else { |
| 2070 | // The source location entry is a buffer. The blob associated |
| 2071 | // with this entry contains the contents of the buffer. |
| 2072 | |
| 2073 | // We add one to the size so that we capture the trailing NULL |
| 2074 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 2075 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 2076 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 2077 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2078 | StringRef Name = Buffer->getBufferIdentifier(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2079 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2080 | StringRef(Name.data(), Name.size() + 1)); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2081 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2082 | |
Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 2083 | if (Name == "<built-in>") |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2084 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2085 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2086 | |
| 2087 | if (EmitBlob) { |
| 2088 | // Include the implicit terminating null character in the on-disk buffer |
| 2089 | // if we're writing it uncompressed. |
| 2090 | const llvm::MemoryBuffer *Buffer = |
| 2091 | Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 2092 | StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1); |
| 2093 | |
| 2094 | // Compress the buffer if possible. We expect that almost all PCM |
| 2095 | // consumers will not want its contents. |
| 2096 | SmallString<0> CompressedBuffer; |
| 2097 | if (llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer) == |
| 2098 | llvm::zlib::StatusOK) { |
| 2099 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, |
| 2100 | Blob.size() - 1}; |
| 2101 | Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, |
| 2102 | CompressedBuffer); |
| 2103 | } else { |
| 2104 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB}; |
| 2105 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob); |
| 2106 | } |
| 2107 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2108 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2109 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 2110 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2111 | AddSourceLocation(Expansion.getSpellingLoc(), Record); |
| 2112 | AddSourceLocation(Expansion.getExpansionLocStart(), Record); |
| 2113 | AddSourceLocation(Expansion.isMacroArgExpansion() |
| 2114 | ? SourceLocation() |
| 2115 | : Expansion.getExpansionLocEnd(), |
| 2116 | Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2117 | |
| 2118 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2119 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2120 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2121 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2122 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2123 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2124 | } |
| 2125 | } |
| 2126 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2127 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2128 | |
| 2129 | if (SLocEntryOffsets.empty()) |
| 2130 | return; |
| 2131 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2132 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2133 | // table is used for lazily loading source-location information. |
| 2134 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2135 | |
| 2136 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2137 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2138 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2139 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2140 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 2141 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2142 | { |
| 2143 | RecordData::value_type Record[] = { |
| 2144 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), |
| 2145 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */}; |
| 2146 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
| 2147 | bytes(SLocEntryOffsets)); |
| 2148 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2149 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2150 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2151 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2152 | |
| 2153 | // Write the line table. It depends on remapping working, so it must come |
| 2154 | // after the source location offsets. |
| 2155 | if (SourceMgr.hasLineTable()) { |
| 2156 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 2157 | |
| 2158 | Record.clear(); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2159 | |
| 2160 | // Emit the needed file names. |
| 2161 | llvm::DenseMap<int, int> FilenameMap; |
| 2162 | for (const auto &L : LineTable) { |
| 2163 | if (L.first.ID < 0) |
| 2164 | continue; |
| 2165 | for (auto &LE : L.second) { |
| 2166 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, |
| 2167 | FilenameMap.size())).second) |
| 2168 | AddPath(LineTable.getFilename(LE.FilenameID), Record); |
| 2169 | } |
| 2170 | } |
| 2171 | Record.push_back(0); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2172 | |
| 2173 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2174 | for (const auto &L : LineTable) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2175 | // Only emit entries for local files. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2176 | if (L.first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2177 | continue; |
| 2178 | |
| 2179 | // Emit the file ID |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2180 | Record.push_back(L.first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2181 | |
| 2182 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2183 | Record.push_back(L.second.size()); |
| 2184 | for (const auto &LE : L.second) { |
| 2185 | Record.push_back(LE.FileOffset); |
| 2186 | Record.push_back(LE.LineNo); |
| 2187 | Record.push_back(FilenameMap[LE.FilenameID]); |
| 2188 | Record.push_back((unsigned)LE.FileKind); |
| 2189 | Record.push_back(LE.IncludeOffset); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2190 | } |
| 2191 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2192 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2193 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 2194 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2195 | } |
| 2196 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2197 | //===----------------------------------------------------------------------===// |
| 2198 | // Preprocessor Serialization |
| 2199 | //===----------------------------------------------------------------------===// |
| 2200 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2201 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 2202 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2203 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 2204 | if (MI->isBuiltinMacro()) |
| 2205 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2206 | |
| 2207 | if (IsModule) { |
| 2208 | SourceLocation Loc = MD->getLocation(); |
| 2209 | if (Loc.isInvalid()) |
| 2210 | return true; |
| 2211 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 2212 | return true; |
| 2213 | } |
| 2214 | |
| 2215 | return false; |
| 2216 | } |
| 2217 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2218 | /// \brief Writes the block containing the serialized form of the |
| 2219 | /// preprocessor. |
| 2220 | /// |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2221 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2222 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2223 | if (PPRec) |
| 2224 | WritePreprocessorDetail(*PPRec); |
| 2225 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2226 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2227 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2228 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2229 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2230 | if (PP.getCounterValue() != 0) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2231 | RecordData::value_type Record[] = {PP.getCounterValue()}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2232 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2236 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2237 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2238 | // 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] | 2239 | // 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] | 2240 | if (PP.SawDateOrTime()) |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2241 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2242 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2243 | // 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] | 2244 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2245 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2246 | // Construct the list of identifiers with macro directives that need to be |
| 2247 | // serialized. |
| 2248 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2249 | for (auto &Id : PP.getIdentifierTable()) |
| 2250 | if (Id.second->hadMacroDefinition() && |
| 2251 | (!Id.second->isFromAST() || |
| 2252 | Id.second->hasChangedSinceDeserialization())) |
| 2253 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2254 | // Sort the set of macro definitions that need to be serialized by the |
| 2255 | // name of the macro, to provide a stable ordering. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2256 | std::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(), |
| 2257 | llvm::less_ptr<IdentifierInfo>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2258 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2259 | // Emit the macro directives as a list and associate the offset with the |
| 2260 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2261 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2262 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2263 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2264 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2265 | // Emit the macro directives in reverse source order. |
| 2266 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2267 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2268 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2269 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2270 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2271 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2272 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2273 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2274 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2275 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2276 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2277 | Record.push_back(VisMD->isPublic()); |
| 2278 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2279 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2280 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2281 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2282 | bool EmittedModuleMacros = false; |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2283 | // We write out exported module macros for PCH as well. |
| 2284 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2285 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2286 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2287 | while (!Worklist.empty()) { |
| 2288 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2289 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2290 | // Emit a record indicating this submodule exports this macro. |
| 2291 | ModuleMacroRecord.push_back( |
| 2292 | getSubmoduleID(Macro->getOwningModule())); |
| 2293 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
| 2294 | for (auto *M : Macro->overrides()) |
| 2295 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2296 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2297 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2298 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2299 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2300 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2301 | for (auto *M : Macro->overrides()) |
| 2302 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2303 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2304 | |
Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2305 | EmittedModuleMacros = true; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2306 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2307 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2308 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2309 | continue; |
| 2310 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2311 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2312 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2313 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2314 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2315 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2316 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 2317 | /// the local macro ID |
| 2318 | /// |
| 2319 | /// For each identifier that is associated with a macro, this map |
| 2320 | /// provides the offset into the bitstream where that macro is |
| 2321 | /// defined. |
| 2322 | std::vector<uint32_t> MacroOffsets; |
| 2323 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2324 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2325 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2326 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2327 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2328 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2329 | if (ID < FirstMacroID) { |
| 2330 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2331 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2332 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2333 | |
| 2334 | // Record the local offset of this macro. |
| 2335 | unsigned Index = ID - FirstMacroID; |
| 2336 | if (Index == MacroOffsets.size()) |
| 2337 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2338 | else { |
| 2339 | if (Index > MacroOffsets.size()) |
| 2340 | MacroOffsets.resize(Index + 1); |
| 2341 | |
| 2342 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2343 | } |
| 2344 | |
| 2345 | AddIdentifierRef(Name, Record); |
| 2346 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
| 2347 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2348 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2349 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2350 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2351 | unsigned Code; |
| 2352 | if (MI->isObjectLike()) { |
| 2353 | Code = PP_MACRO_OBJECT_LIKE; |
| 2354 | } else { |
| 2355 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2356 | |
| 2357 | Record.push_back(MI->isC99Varargs()); |
| 2358 | Record.push_back(MI->isGNUVarargs()); |
| 2359 | Record.push_back(MI->hasCommaPasting()); |
| 2360 | Record.push_back(MI->getNumArgs()); |
Daniel Marjamaki | e4770da | 2015-05-29 09:15:24 +0000 | [diff] [blame] | 2361 | for (const IdentifierInfo *Arg : MI->args()) |
| 2362 | AddIdentifierRef(Arg, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | // If we have a detailed preprocessing record, record the macro definition |
| 2366 | // ID that corresponds to this macro. |
| 2367 | if (PPRec) |
| 2368 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2369 | |
| 2370 | Stream.EmitRecord(Code, Record); |
| 2371 | Record.clear(); |
| 2372 | |
| 2373 | // Emit the tokens array. |
| 2374 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2375 | // Note that we know that the preprocessor does not have any annotation |
| 2376 | // tokens in it because they are created by the parser, and thus can't |
| 2377 | // be in a macro definition. |
| 2378 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2379 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2380 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2381 | Record.clear(); |
| 2382 | } |
| 2383 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2384 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2385 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2386 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2387 | |
| 2388 | // Write the offsets table for macro IDs. |
| 2389 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2390 | |
Richard Smith | 13090a2 | 2015-04-10 02:02:24 +0000 | [diff] [blame] | 2391 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2392 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2393 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2394 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2395 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2396 | |
| 2397 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2398 | { |
| 2399 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), |
| 2400 | FirstMacroID - NUM_PREDEF_MACRO_IDS}; |
| 2401 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); |
| 2402 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2406 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2407 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2408 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2409 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2410 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2411 | // Enter the preprocessor block. |
| 2412 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2413 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2414 | // If the preprocessor has a preprocessing record, emit it. |
| 2415 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2416 | using namespace llvm; |
| 2417 | |
| 2418 | // Set up the abbreviation for |
| 2419 | unsigned InclusionAbbrev = 0; |
| 2420 | { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2421 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2422 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2423 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2424 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2425 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2426 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2427 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2428 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2429 | } |
| 2430 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2431 | unsigned FirstPreprocessorEntityID |
| 2432 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 2433 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2434 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2435 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2436 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2437 | EEnd = PPRec.local_end(); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2438 | E != EEnd; |
| 2439 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2440 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2441 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2442 | PreprocessedEntityOffsets.push_back( |
| 2443 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2444 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2445 | if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2446 | // Record this macro definition's ID. |
| 2447 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2448 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2449 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2450 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2451 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2452 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2453 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2454 | if (auto *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2455 | Record.push_back(ME->isBuiltinMacro()); |
| 2456 | if (ME->isBuiltinMacro()) |
| 2457 | AddIdentifierRef(ME->getName(), Record); |
| 2458 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2459 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2460 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2461 | continue; |
| 2462 | } |
| 2463 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2464 | if (auto *ID = dyn_cast<InclusionDirective>(*E)) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2465 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2466 | Record.push_back(ID->getFileName().size()); |
| 2467 | Record.push_back(ID->wasInQuotes()); |
| 2468 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2469 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2470 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2471 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2472 | // Check that the FileEntry is not null because it was not resolved and |
| 2473 | // we create a PCH even with compiler errors. |
| 2474 | if (ID->getFile()) |
| 2475 | Buffer += ID->getFile()->getName(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2476 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2477 | continue; |
| 2478 | } |
| 2479 | |
| 2480 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2481 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2482 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2483 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2484 | // Write the offsets table for the preprocessing record. |
| 2485 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2486 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2487 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2488 | // Write the offsets table for identifier IDs. |
| 2489 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2490 | |
| 2491 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2492 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2493 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2494 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2495 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2496 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2497 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, |
| 2498 | FirstPreprocessorEntityID - |
| 2499 | NUM_PREDEF_PP_ENTITY_IDS}; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2500 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2501 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2502 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2505 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2506 | if (!Mod) |
| 2507 | return 0; |
| 2508 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2509 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2510 | if (Known != SubmoduleIDs.end()) |
| 2511 | return Known->second; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2512 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2513 | auto *Top = Mod->getTopLevelModule(); |
| 2514 | if (Top != WritingModule && |
| 2515 | !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule))) |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2516 | return 0; |
| 2517 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2518 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2519 | } |
| 2520 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2521 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2522 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2523 | // did not result in us loading a module file for that submodule. For |
| 2524 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2525 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); |
| 2526 | assert((ID || !Mod) && |
| 2527 | "asked for module ID for non-local, non-imported module"); |
| 2528 | return ID; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2529 | } |
| 2530 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2531 | /// \brief Compute the number of modules within the given tree (including the |
| 2532 | /// given module). |
| 2533 | static unsigned getNumberOfModules(Module *Mod) { |
| 2534 | unsigned ChildModules = 0; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2535 | for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2536 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2537 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2538 | |
| 2539 | return ChildModules + 1; |
| 2540 | } |
| 2541 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2542 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2543 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2544 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2545 | |
| 2546 | // Write the abbreviations needed for the submodules block. |
| 2547 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2548 | |
| 2549 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2550 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2551 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2552 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2553 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2554 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2555 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2556 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2557 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2558 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2559 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2560 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2561 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2562 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2563 | |
| 2564 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2565 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2566 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2567 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2568 | |
| 2569 | Abbrev = new BitCodeAbbrev(); |
| 2570 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2571 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2572 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2573 | |
| 2574 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2575 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2576 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2577 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2578 | |
| 2579 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2580 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2581 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2582 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2583 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2584 | Abbrev = new BitCodeAbbrev(); |
| 2585 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2586 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2587 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2588 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2589 | |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2590 | Abbrev = new BitCodeAbbrev(); |
| 2591 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2592 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2593 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2594 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2595 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2596 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2597 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2598 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2599 | |
| 2600 | Abbrev = new BitCodeAbbrev(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2601 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2602 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2603 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2604 | |
| 2605 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2606 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2607 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2608 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2609 | |
| 2610 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2611 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2612 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2613 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2614 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2615 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2616 | Abbrev = new BitCodeAbbrev(); |
| 2617 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2618 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
| 2619 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2620 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2621 | Abbrev = new BitCodeAbbrev(); |
| 2622 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2623 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2624 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
| 2625 | unsigned ConflictAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2626 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2627 | // Write the submodule metadata block. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2628 | RecordData::value_type Record[] = {getNumberOfModules(WritingModule), |
| 2629 | FirstSubmoduleID - |
| 2630 | NUM_PREDEF_SUBMODULE_IDS}; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2631 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2632 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2633 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2634 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2635 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2636 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2637 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2638 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2639 | unsigned ID = getSubmoduleID(Mod); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2640 | |
| 2641 | uint64_t ParentID = 0; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2642 | if (Mod->Parent) { |
| 2643 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2644 | ParentID = SubmoduleIDs[Mod->Parent]; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2645 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2646 | |
| 2647 | // Emit the definition of the block. |
| 2648 | { |
| 2649 | RecordData::value_type Record[] = { |
| 2650 | SUBMODULE_DEFINITION, ID, ParentID, Mod->IsFramework, Mod->IsExplicit, |
| 2651 | Mod->IsSystem, Mod->IsExternC, Mod->InferSubmodules, |
| 2652 | Mod->InferExplicitSubmodules, Mod->InferExportWildcard, |
| 2653 | Mod->ConfigMacrosExhaustive}; |
| 2654 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2655 | } |
| 2656 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2657 | // Emit the requirements. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2658 | for (const auto &R : Mod->Requirements) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2659 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2660 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2661 | } |
| 2662 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2663 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2664 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2665 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2666 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2667 | UmbrellaHeader.NameAsWritten); |
| 2668 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2669 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; |
| 2670 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2671 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2672 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2673 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2674 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2675 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2676 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2677 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2678 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2679 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2680 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 2681 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 2682 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2683 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2684 | Module::HK_PrivateTextual}, |
| 2685 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2686 | }; |
| 2687 | for (auto &HL : HeaderLists) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2688 | RecordData::value_type Record[] = {HL.RecordKind}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2689 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 2690 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 2691 | } |
| 2692 | |
| 2693 | // Emit the top headers. |
| 2694 | { |
| 2695 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2696 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2697 | for (auto *H : TopHeaders) |
| 2698 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2699 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2700 | |
| 2701 | // Emit the imports. |
| 2702 | if (!Mod->Imports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2703 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2704 | for (auto *I : Mod->Imports) |
| 2705 | Record.push_back(getSubmoduleID(I)); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2706 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2707 | } |
| 2708 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2709 | // Emit the exports. |
| 2710 | if (!Mod->Exports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2711 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2712 | for (const auto &E : Mod->Exports) { |
| 2713 | // FIXME: This may fail; we don't require that all exported modules |
| 2714 | // are local or imported. |
| 2715 | Record.push_back(getSubmoduleID(E.getPointer())); |
| 2716 | Record.push_back(E.getInt()); |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2717 | } |
| 2718 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2719 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2720 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2721 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 2722 | // Might be unnecessary as use declarations are only used to build the |
| 2723 | // module itself. |
| 2724 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2725 | // Emit the link libraries. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2726 | for (const auto &LL : Mod->LinkLibraries) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2727 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, |
| 2728 | LL.IsFramework}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2729 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2732 | // Emit the conflicts. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2733 | for (const auto &C : Mod->Conflicts) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2734 | // FIXME: This may fail; we don't require that all conflicting modules |
| 2735 | // are local or imported. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2736 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, |
| 2737 | getSubmoduleID(C.Other)}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2738 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2741 | // Emit the configuration macros. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2742 | for (const auto &CM : Mod->ConfigMacros) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2743 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2744 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2745 | } |
| 2746 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2747 | // Emit the initializers, if any. |
| 2748 | RecordData Inits; |
| 2749 | for (Decl *D : Context->getModuleInitializers(Mod)) |
| 2750 | Inits.push_back(GetDeclRef(D)); |
| 2751 | if (!Inits.empty()) |
| 2752 | Stream.EmitRecord(SUBMODULE_INITIALIZERS, Inits); |
| 2753 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2754 | // Queue up the submodules of this module. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2755 | for (auto *M : Mod->submodules()) |
| 2756 | Q.push(M); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2760 | |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2761 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 2762 | getNumberOfModules(WritingModule)) && |
| 2763 | "Wrong # of submodules; found a reference to a non-local, " |
| 2764 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2765 | } |
| 2766 | |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2767 | serialization::SubmoduleID |
| 2768 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2769 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2770 | return 0; // No submodule |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2771 | |
| 2772 | // Find the module that owns this location. |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2773 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2774 | Module *OwningMod |
| 2775 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2776 | if (!OwningMod) |
| 2777 | return 0; |
| 2778 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2779 | // Check whether this submodule is part of our own module. |
| 2780 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2781 | return 0; |
| 2782 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2783 | return getSubmoduleID(OwningMod); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 2786 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 2787 | bool isModule) { |
| 2788 | // Make sure set diagnostic pragmas don't affect the translation unit that |
| 2789 | // imports the module. |
| 2790 | // FIXME: Make diagnostic pragma sections work properly with modules. |
| 2791 | if (isModule) |
| 2792 | return; |
| 2793 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2794 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2795 | DiagStateIDMap; |
| 2796 | unsigned CurrID = 0; |
| 2797 | DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2798 | RecordData Record; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2799 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2800 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2801 | I != E; ++I) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2802 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2803 | if (point.Loc.isInvalid()) |
| 2804 | continue; |
| 2805 | |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2806 | AddSourceLocation(point.Loc, Record); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2807 | unsigned &DiagStateID = DiagStateIDMap[point.State]; |
| 2808 | Record.push_back(DiagStateID); |
| 2809 | |
| 2810 | if (DiagStateID == 0) { |
| 2811 | DiagStateID = ++CurrID; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2812 | for (const auto &I : *(point.State)) { |
| 2813 | if (I.second.isPragma()) { |
| 2814 | Record.push_back(I.first); |
| 2815 | Record.push_back((unsigned)I.second.getSeverity()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2816 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2817 | } |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2818 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2819 | // location. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2820 | } |
| 2821 | } |
| 2822 | |
Argyrios Kyrtzidis | b0ca9eb | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2823 | if (!Record.empty()) |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2824 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2827 | //===----------------------------------------------------------------------===// |
| 2828 | // Type Serialization |
| 2829 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2830 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2831 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2832 | void ASTWriter::WriteType(QualType T) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2833 | TypeIdx &IdxRef = TypeIdxs[T]; |
| 2834 | if (IdxRef.getIndex() == 0) // we haven't seen this type before. |
| 2835 | IdxRef = TypeIdx(NextTypeID++); |
| 2836 | TypeIdx Idx = IdxRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2837 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2838 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2839 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2840 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2841 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2842 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2843 | ASTTypeWriter W(*this, Record); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2844 | W.Visit(T); |
| 2845 | uint64_t Offset = W.Emit(); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2846 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2847 | // Record the offset for this type. |
| 2848 | unsigned Index = Idx.getIndex() - FirstTypeID; |
| 2849 | if (TypeOffsets.size() == Index) |
| 2850 | TypeOffsets.push_back(Offset); |
| 2851 | else if (TypeOffsets.size() < Index) { |
| 2852 | TypeOffsets.resize(Index + 1); |
| 2853 | TypeOffsets[Index] = Offset; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2854 | } else { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2855 | llvm_unreachable("Types emitted in wrong order"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2856 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2857 | } |
| 2858 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2859 | //===----------------------------------------------------------------------===// |
| 2860 | // Declaration Serialization |
| 2861 | //===----------------------------------------------------------------------===// |
| 2862 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2863 | /// \brief Write the block containing all of the declaration IDs |
| 2864 | /// lexically declared within the given DeclContext. |
| 2865 | /// |
| 2866 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2867 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2868 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2869 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2870 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2871 | return 0; |
| 2872 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2873 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2874 | SmallVector<uint32_t, 128> KindDeclPairs; |
| 2875 | for (const auto *D : DC->decls()) { |
| 2876 | KindDeclPairs.push_back(D->getKind()); |
| 2877 | KindDeclPairs.push_back(GetDeclRef(D)); |
| 2878 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2879 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2880 | ++NumLexicalDeclContexts; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2881 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2882 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, |
| 2883 | bytes(KindDeclPairs)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2884 | return Offset; |
| 2885 | } |
| 2886 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2887 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2888 | using namespace llvm; |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2889 | |
| 2890 | // Write the type offsets array |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2891 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2892 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2893 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2894 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2895 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2896 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2897 | { |
| 2898 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), |
| 2899 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; |
| 2900 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
| 2901 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2902 | |
| 2903 | // Write the declaration offsets array |
| 2904 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2905 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2906 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2907 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2908 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2909 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2910 | { |
| 2911 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), |
| 2912 | FirstDeclID - NUM_PREDEF_DECL_IDS}; |
| 2913 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
| 2914 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2917 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2918 | using namespace llvm; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2919 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2920 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 2921 | FileDeclIDs.begin(), FileDeclIDs.end()); |
| 2922 | std::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), |
| 2923 | llvm::less_first()); |
| 2924 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2925 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2926 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 2927 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 2928 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 2929 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 2930 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 2931 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2934 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2935 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2936 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2937 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2938 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2939 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, |
| 2940 | FileGroupedDeclIDs.size()}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2941 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2942 | } |
| 2943 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2944 | void ASTWriter::WriteComments() { |
| 2945 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2946 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2947 | RecordData Record; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2948 | for (const auto *I : RawComments) { |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2949 | Record.clear(); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2950 | AddSourceRange(I->getSourceRange(), Record); |
| 2951 | Record.push_back(I->getKind()); |
| 2952 | Record.push_back(I->isTrailingComment()); |
| 2953 | Record.push_back(I->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2954 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2955 | } |
| 2956 | Stream.ExitBlock(); |
| 2957 | } |
| 2958 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2959 | //===----------------------------------------------------------------------===// |
| 2960 | // Global Method Pool and Selector Serialization |
| 2961 | //===----------------------------------------------------------------------===// |
| 2962 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2963 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2964 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2965 | // 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] | 2966 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2967 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2968 | |
| 2969 | public: |
| 2970 | typedef Selector key_type; |
| 2971 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2972 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2973 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2974 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2975 | ObjCMethodList Instance, Factory; |
| 2976 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2977 | typedef const data_type& data_type_ref; |
| 2978 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2979 | typedef unsigned hash_value_type; |
| 2980 | typedef unsigned offset_type; |
| 2981 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2982 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2983 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2984 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2985 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2986 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2987 | |
| 2988 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2989 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2990 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2991 | using namespace llvm::support; |
| 2992 | endian::Writer<little> LE(Out); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2993 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2994 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2995 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2996 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2997 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2998 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2999 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3000 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3001 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3002 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3003 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3004 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3005 | return std::make_pair(KeyLen, DataLen); |
| 3006 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3007 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3008 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3009 | using namespace llvm::support; |
| 3010 | endian::Writer<little> LE(Out); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3012 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 3013 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3014 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3015 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3016 | if (N == 0) |
| 3017 | N = 1; |
| 3018 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3019 | LE.write<uint32_t>( |
| 3020 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3021 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3022 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3023 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3024 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3025 | using namespace llvm::support; |
| 3026 | endian::Writer<little> LE(Out); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3027 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3028 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3029 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3030 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3031 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3032 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3033 | ++NumInstanceMethods; |
| 3034 | |
| 3035 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3036 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3037 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3038 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3039 | ++NumFactoryMethods; |
| 3040 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3041 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 3042 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3043 | unsigned InstanceHasMoreThanOneDeclBit = |
| 3044 | Methods.Instance.hasMoreThanOneDecl(); |
| 3045 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 3046 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 3047 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3048 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 3049 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3050 | unsigned FactoryHasMoreThanOneDeclBit = |
| 3051 | Methods.Factory.hasMoreThanOneDecl(); |
| 3052 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 3053 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 3054 | FactoryBits; |
| 3055 | LE.write<uint16_t>(FullInstanceBits); |
| 3056 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3057 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3058 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3059 | if (Method->getMethod()) |
| 3060 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3061 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3062 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3063 | if (Method->getMethod()) |
| 3064 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3065 | |
| 3066 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3067 | } |
| 3068 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3069 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3070 | } // end anonymous namespace |
| 3071 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3072 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3073 | /// |
| 3074 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3075 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 3076 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3077 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3078 | using namespace llvm; |
| 3079 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3080 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3081 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3082 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3083 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3084 | // 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] | 3085 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3086 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3087 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3088 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3089 | // Create the on-disk hash table representation. We walk through every |
| 3090 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3091 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3092 | for (auto &SelectorAndID : SelectorIDs) { |
| 3093 | Selector S = SelectorAndID.first; |
| 3094 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3095 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3096 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3097 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3098 | ObjCMethodList(), |
| 3099 | ObjCMethodList() |
| 3100 | }; |
| 3101 | if (F != SemaRef.MethodPool.end()) { |
| 3102 | Data.Instance = F->second.first; |
| 3103 | Data.Factory = F->second.second; |
| 3104 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3105 | // 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] | 3106 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3107 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3108 | // Selector already exists. Did it change? |
| 3109 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3110 | for (ObjCMethodList *M = &Data.Instance; |
| 3111 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 3112 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3113 | changed = true; |
| 3114 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3115 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3116 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3117 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3118 | changed = true; |
| 3119 | } |
| 3120 | if (!changed) |
| 3121 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3122 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3123 | // A new method pool entry. |
| 3124 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3125 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3126 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3127 | } |
| 3128 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3129 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3130 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3131 | uint32_t BucketOffset; |
| 3132 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3133 | using namespace llvm::support; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3134 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3135 | llvm::raw_svector_ostream Out(MethodPool); |
| 3136 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3137 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3138 | BucketOffset = Generator.Emit(Out, Trait); |
| 3139 | } |
| 3140 | |
| 3141 | // Create a blob abbreviation |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3142 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3143 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3144 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3145 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3146 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3147 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3148 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3149 | // Write the method pool |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3150 | { |
| 3151 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, |
| 3152 | NumTableEntries}; |
| 3153 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
| 3154 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3155 | |
| 3156 | // Create a blob abbreviation for the selector table offsets. |
| 3157 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3158 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3159 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3160 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3161 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3162 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3163 | |
| 3164 | // Write the selector offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3165 | { |
| 3166 | RecordData::value_type Record[] = { |
| 3167 | SELECTOR_OFFSETS, SelectorOffsets.size(), |
| 3168 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; |
| 3169 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 3170 | bytes(SelectorOffsets)); |
| 3171 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3172 | } |
| 3173 | } |
| 3174 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3175 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3176 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3177 | using namespace llvm; |
| 3178 | if (SemaRef.ReferencedSelectors.empty()) |
| 3179 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3180 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3181 | RecordData Record; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3182 | ASTRecordWriter Writer(*this, Record); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3183 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3184 | // 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] | 3185 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3186 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3187 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3188 | Selector Sel = SelectorAndLocation.first; |
| 3189 | SourceLocation Loc = SelectorAndLocation.second; |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3190 | Writer.AddSelectorRef(Sel); |
| 3191 | Writer.AddSourceLocation(Loc); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3192 | } |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3193 | Writer.Emit(REFERENCED_SELECTOR_POOL); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3194 | } |
| 3195 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3196 | //===----------------------------------------------------------------------===// |
| 3197 | // Identifier Table Serialization |
| 3198 | //===----------------------------------------------------------------------===// |
| 3199 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3200 | /// Determine the declaration that should be put into the name lookup table to |
| 3201 | /// represent the given declaration in this module. This is usually D itself, |
| 3202 | /// but if D was imported and merged into a local declaration, we want the most |
| 3203 | /// recent local declaration instead. The chosen declaration will be the most |
| 3204 | /// recent declaration in any module that imports this one. |
| 3205 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3206 | NamedDecl *D) { |
| 3207 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3208 | return D; |
| 3209 | |
| 3210 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3211 | // For Redeclarable decls, a prior declaration might be local. |
| 3212 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3213 | // If we find a local decl, we're done. |
| 3214 | if (!Redecl->isFromASTFile()) { |
| 3215 | // Exception: in very rare cases (for injected-class-names), not all |
| 3216 | // redeclarations are in the same semantic context. Skip ones in a |
| 3217 | // different context. They don't go in this lookup table at all. |
| 3218 | if (!Redecl->getDeclContext()->getRedeclContext()->Equals( |
| 3219 | D->getDeclContext()->getRedeclContext())) |
| 3220 | continue; |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3221 | return cast<NamedDecl>(Redecl); |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3224 | // 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] | 3225 | // local one. |
Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3226 | if (Redecl->getOwningModuleID() == 0) |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3227 | break; |
| 3228 | } |
| 3229 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3230 | // For Mergeable decls, the first decl might be local. |
| 3231 | if (!First->isFromASTFile()) |
| 3232 | return cast<NamedDecl>(First); |
| 3233 | } |
| 3234 | |
| 3235 | // All declarations are imported. Our most recent declaration will also be |
| 3236 | // the most recent one in anyone who imports us. |
| 3237 | return D; |
| 3238 | } |
| 3239 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3240 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3241 | |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3242 | class ASTIdentifierTableTrait { |
| 3243 | ASTWriter &Writer; |
| 3244 | Preprocessor &PP; |
| 3245 | IdentifierResolver &IdResolver; |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3246 | bool IsModule; |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3247 | bool NeedDecls; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3248 | ASTWriter::RecordData *InterestingIdentifierOffsets; |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3249 | |
| 3250 | /// \brief Determines whether this is an "interesting" identifier that needs a |
| 3251 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3252 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3253 | /// to check that. |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3254 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3255 | if (MacroOffset || |
| 3256 | II->isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3257 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3258 | II->hasRevertedTokenIDToIdentifier() || |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3259 | (NeedDecls && II->getFETokenInfo<void>())) |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3260 | return true; |
| 3261 | |
| 3262 | return false; |
| 3263 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3264 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3265 | public: |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3266 | typedef IdentifierInfo* key_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3267 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3268 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3269 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3270 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3271 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3272 | typedef unsigned hash_value_type; |
| 3273 | typedef unsigned offset_type; |
| 3274 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3275 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3276 | IdentifierResolver &IdResolver, bool IsModule, |
| 3277 | ASTWriter::RecordData *InterestingIdentifierOffsets) |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3278 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3279 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), |
| 3280 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3281 | |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3282 | bool needDecls() const { return NeedDecls; } |
| 3283 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3284 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 3285 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3286 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3287 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3288 | bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 3289 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3290 | return isInterestingIdentifier(II, MacroOffset); |
| 3291 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3292 | |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3293 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { |
| 3294 | return isInterestingIdentifier(II, 0); |
| 3295 | } |
| 3296 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3297 | std::pair<unsigned,unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3298 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3299 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3300 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3301 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3302 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3303 | DataLen += 2; // 2 bytes for builtin ID |
| 3304 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3305 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3306 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3307 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3308 | if (NeedDecls) { |
| 3309 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3310 | DEnd = IdResolver.end(); |
| 3311 | D != DEnd; ++D) |
| 3312 | DataLen += 4; |
| 3313 | } |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3314 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3315 | using namespace llvm::support; |
| 3316 | endian::Writer<little> LE(Out); |
| 3317 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3318 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3319 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3320 | // We emit the key length after the data length so that every |
| 3321 | // string is preceded by a 16-bit length. This matches the PTH |
| 3322 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3323 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3324 | return std::make_pair(KeyLen, DataLen); |
| 3325 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3326 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3327 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3328 | unsigned KeyLen) { |
| 3329 | // Record the location of the key data. This is used when generating |
| 3330 | // the mapping from persistent IDs to strings. |
| 3331 | Writer.SetIdentifierOffset(II, Out.tell()); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3332 | |
| 3333 | // Emit the offset of the key/data length information to the interesting |
| 3334 | // identifiers table if necessary. |
| 3335 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) |
| 3336 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); |
| 3337 | |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3338 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3339 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3340 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3341 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3342 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3343 | using namespace llvm::support; |
| 3344 | endian::Writer<little> LE(Out); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3345 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3346 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3347 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3348 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3349 | return; |
| 3350 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3351 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3352 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3353 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3354 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3355 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3356 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3357 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3358 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3359 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3360 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3361 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3362 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3363 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3364 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3365 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3366 | if (HadMacroDefinition) |
| 3367 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3368 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3369 | if (NeedDecls) { |
| 3370 | // Emit the declaration IDs in reverse order, because the |
| 3371 | // IdentifierResolver provides the declarations as they would be |
| 3372 | // visible (e.g., the function "stat" would come before the struct |
| 3373 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3374 | // (so we need to see the struct "stat" before the function "stat"). |
| 3375 | // Only emit declarations that aren't from a chained PCH, though. |
| 3376 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), |
| 3377 | IdResolver.end()); |
| 3378 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3379 | DEnd = Decls.rend(); |
| 3380 | D != DEnd; ++D) |
| 3381 | LE.write<uint32_t>( |
| 3382 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
| 3383 | } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3384 | } |
| 3385 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3386 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3387 | } // end anonymous namespace |
| 3388 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3389 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3390 | /// |
| 3391 | /// The identifier table consists of a blob containing string data |
| 3392 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3393 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3394 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 3395 | IdentifierResolver &IdResolver, |
| 3396 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3397 | using namespace llvm; |
| 3398 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3399 | RecordData InterestingIdents; |
| 3400 | |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3401 | // Create and write out the blob that contains the identifier |
| 3402 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3403 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3404 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3405 | ASTIdentifierTableTrait Trait( |
| 3406 | *this, PP, IdResolver, IsModule, |
| 3407 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3408 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3409 | // Look for any identifiers that were named while processing the |
| 3410 | // headers, but are otherwise not needed. We add these to the hash |
| 3411 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3412 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3413 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3414 | SmallVector<const IdentifierInfo *, 128> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3415 | for (const auto &ID : PP.getIdentifierTable()) |
| 3416 | IIs.push_back(ID.second); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3417 | // Sort the identifiers lexicographically before getting them references so |
| 3418 | // that their order is stable. |
| 3419 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 3420 | for (const IdentifierInfo *II : IIs) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3421 | if (Trait.isInterestingNonMacroIdentifier(II)) |
| 3422 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3423 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3424 | // Create the on-disk hash table representation. We only store offsets |
| 3425 | // for identifiers that appear here for the first time. |
| 3426 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3427 | for (auto IdentIDPair : IdentifierIDs) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3428 | auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3429 | IdentID ID = IdentIDPair.second; |
| 3430 | assert(II && "NULL identifier in identifier table"); |
Vassil Vassilev | 262f41e | 2016-03-30 20:16:03 +0000 | [diff] [blame] | 3431 | // Write out identifiers if either the ID is local or the identifier has |
| 3432 | // changed since it was loaded. |
| 3433 | if (ID >= FirstIdentID || !Chain || !II->isFromAST() |
| 3434 | || II->hasChangedSinceDeserialization() || |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3435 | (Trait.needDecls() && |
| 3436 | II->hasFETokenInfoChangedSinceDeserialization())) |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3437 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3438 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3439 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3440 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3441 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3442 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3443 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3444 | using namespace llvm::support; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3445 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3446 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3447 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3448 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
| 3451 | // Create a blob abbreviation |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3452 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3453 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3454 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3455 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3456 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3457 | |
| 3458 | // Write the identifier table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3459 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3460 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | // Write the offsets table for identifier IDs. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3464 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3465 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3466 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3467 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3468 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3469 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3470 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3471 | #ifndef NDEBUG |
| 3472 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3473 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3474 | #endif |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3475 | |
| 3476 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, |
| 3477 | IdentifierOffsets.size(), |
| 3478 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3479 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3480 | bytes(IdentifierOffsets)); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3481 | |
| 3482 | // In C++, write the list of interesting identifiers (those that are |
| 3483 | // defined as macros, poisoned, or similar unusual things). |
| 3484 | if (!InterestingIdents.empty()) |
| 3485 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3486 | } |
| 3487 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3488 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3489 | // DeclContext's Name Lookup Table Serialization |
| 3490 | //===----------------------------------------------------------------------===// |
| 3491 | |
| 3492 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3493 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3494 | // Trait used for the on-disk hash table used in the method pool. |
| 3495 | class ASTDeclContextNameLookupTrait { |
| 3496 | ASTWriter &Writer; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3497 | llvm::SmallVector<DeclID, 64> DeclIDs; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3498 | |
| 3499 | public: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3500 | typedef DeclarationNameKey key_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3501 | typedef key_type key_type_ref; |
| 3502 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3503 | /// A start and end index into DeclIDs, representing a sequence of decls. |
| 3504 | typedef std::pair<unsigned, unsigned> data_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3505 | typedef const data_type& data_type_ref; |
| 3506 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3507 | typedef unsigned hash_value_type; |
| 3508 | typedef unsigned offset_type; |
| 3509 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3510 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 3511 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3512 | template<typename Coll> |
| 3513 | data_type getData(const Coll &Decls) { |
| 3514 | unsigned Start = DeclIDs.size(); |
| 3515 | for (NamedDecl *D : Decls) { |
| 3516 | DeclIDs.push_back( |
| 3517 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); |
| 3518 | } |
| 3519 | return std::make_pair(Start, DeclIDs.size()); |
| 3520 | } |
| 3521 | |
| 3522 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { |
| 3523 | unsigned Start = DeclIDs.size(); |
| 3524 | for (auto ID : FromReader) |
| 3525 | DeclIDs.push_back(ID); |
| 3526 | return std::make_pair(Start, DeclIDs.size()); |
| 3527 | } |
| 3528 | |
| 3529 | static bool EqualKey(key_type_ref a, key_type_ref b) { |
| 3530 | return a == b; |
| 3531 | } |
| 3532 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3533 | hash_value_type ComputeHash(DeclarationNameKey Name) { |
| 3534 | return Name.getHash(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3535 | } |
| 3536 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3537 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { |
| 3538 | assert(Writer.hasChain() && |
| 3539 | "have reference to loaded module file but no chain?"); |
| 3540 | |
| 3541 | using namespace llvm::support; |
| 3542 | endian::Writer<little>(Out) |
| 3543 | .write<uint32_t>(Writer.getChain()->getModuleFileID(F)); |
| 3544 | } |
| 3545 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3546 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, |
| 3547 | DeclarationNameKey Name, |
| 3548 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3549 | using namespace llvm::support; |
| 3550 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3551 | unsigned KeyLen = 1; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3552 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3553 | case DeclarationName::Identifier: |
| 3554 | case DeclarationName::ObjCZeroArgSelector: |
| 3555 | case DeclarationName::ObjCOneArgSelector: |
| 3556 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3557 | case DeclarationName::CXXLiteralOperatorName: |
| 3558 | KeyLen += 4; |
| 3559 | break; |
| 3560 | case DeclarationName::CXXOperatorName: |
| 3561 | KeyLen += 1; |
| 3562 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3563 | case DeclarationName::CXXConstructorName: |
| 3564 | case DeclarationName::CXXDestructorName: |
| 3565 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3566 | case DeclarationName::CXXUsingDirective: |
| 3567 | break; |
| 3568 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3569 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3570 | |
Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3571 | // 4 bytes for each DeclID. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3572 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); |
| 3573 | assert(uint16_t(DataLen) == DataLen && |
| 3574 | "too many decls for serialized lookup result"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3575 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3576 | |
| 3577 | return std::make_pair(KeyLen, DataLen); |
| 3578 | } |
| 3579 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3580 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3581 | using namespace llvm::support; |
| 3582 | endian::Writer<little> LE(Out); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3583 | LE.write<uint8_t>(Name.getKind()); |
| 3584 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3585 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3586 | case DeclarationName::CXXLiteralOperatorName: |
| 3587 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3588 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3589 | case DeclarationName::ObjCZeroArgSelector: |
| 3590 | case DeclarationName::ObjCOneArgSelector: |
| 3591 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3592 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3593 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3594 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3595 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3596 | "Invalid operator?"); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3597 | LE.write<uint8_t>(Name.getOperatorKind()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3598 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3599 | case DeclarationName::CXXConstructorName: |
| 3600 | case DeclarationName::CXXDestructorName: |
| 3601 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3602 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3603 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3604 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3605 | |
| 3606 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3607 | } |
| 3608 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3609 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, |
| 3610 | unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3611 | using namespace llvm::support; |
| 3612 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3613 | uint64_t Start = Out.tell(); (void)Start; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3614 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) |
| 3615 | LE.write<uint32_t>(DeclIDs[I]); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3616 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3617 | } |
| 3618 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3619 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3620 | } // end anonymous namespace |
| 3621 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3622 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 3623 | DeclContext *DC) { |
| 3624 | return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage; |
| 3625 | } |
| 3626 | |
| 3627 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 3628 | DeclContext *DC) { |
| 3629 | for (auto *D : Result.getLookupResult()) |
| 3630 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 3631 | return false; |
| 3632 | |
| 3633 | return true; |
| 3634 | } |
| 3635 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3636 | void |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3637 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3638 | llvm::SmallVectorImpl<char> &LookupTable) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3639 | assert(!ConstDC->HasLazyLocalLexicalLookups && |
| 3640 | !ConstDC->HasLazyExternalLexicalLookups && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3641 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3642 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3643 | // FIXME: We need to build the lookups table, which is logically const. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3644 | auto *DC = const_cast<DeclContext*>(ConstDC); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3645 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 3646 | |
| 3647 | // Create the on-disk hash table representation. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3648 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, |
| 3649 | ASTDeclContextNameLookupTrait> Generator; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3650 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3651 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3652 | // The first step is to collect the declaration names which we need to |
| 3653 | // serialize into the name lookup table, and to collect them in a stable |
| 3654 | // order. |
| 3655 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3656 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3657 | // We also build up small sets of the constructor and conversion function |
| 3658 | // names which are visible. |
| 3659 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3660 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3661 | for (auto &Lookup : *DC->buildLookup()) { |
| 3662 | auto &Name = Lookup.first; |
| 3663 | auto &Result = Lookup.second; |
| 3664 | |
Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 3665 | // If there are no local declarations in our lookup result, we |
| 3666 | // don't need to write an entry for the name at all. If we can't |
| 3667 | // write out a lookup set without performing more deserialization, |
| 3668 | // just skip this entry. |
| 3669 | if (isLookupResultExternal(Result, DC) && |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3670 | isLookupResultEntirelyExternal(Result, DC)) |
| 3671 | continue; |
| 3672 | |
| 3673 | // We also skip empty results. If any of the results could be external and |
| 3674 | // the currently available results are empty, then all of the results are |
| 3675 | // external and we skip it above. So the only way we get here with an empty |
| 3676 | // results is when no results could have been external *and* we have |
| 3677 | // external results. |
| 3678 | // |
| 3679 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 3680 | // lookups into a decl context as an optimization, today we *have* to skip |
| 3681 | // them because there are names with empty lookup results in decl contexts |
| 3682 | // which we can't emit in any stable ordering: we lookup constructors and |
| 3683 | // conversion functions in the enclosing namespace scope creating empty |
| 3684 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 3685 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 3686 | // here by omitting lookups with empty results. |
| 3687 | if (Lookup.second.getLookupResult().empty()) |
| 3688 | continue; |
| 3689 | |
| 3690 | switch (Lookup.first.getNameKind()) { |
| 3691 | default: |
| 3692 | Names.push_back(Lookup.first); |
| 3693 | break; |
| 3694 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3695 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3696 | assert(isa<CXXRecordDecl>(DC) && |
| 3697 | "Cannot have a constructor name outside of a class!"); |
| 3698 | ConstructorNameSet.insert(Name); |
| 3699 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3700 | |
| 3701 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3702 | assert(isa<CXXRecordDecl>(DC) && |
| 3703 | "Cannot have a conversion function name outside of a class!"); |
| 3704 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 3705 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3706 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3707 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3708 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3709 | // Sort the names into a stable order. |
| 3710 | std::sort(Names.begin(), Names.end()); |
| 3711 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3712 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3713 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3714 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3715 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3716 | // First we try the easy case by forming the current context's constructor |
| 3717 | // name and adding that name first. This is a very useful optimization to |
| 3718 | // avoid walking the lexical declarations in many cases, and it also |
| 3719 | // handles the only case where a constructor name can come from some other |
| 3720 | // lexical context -- when that name is an implicit constructor merged from |
| 3721 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 3722 | // conversion function which doesn't occur in all the lexical contexts |
| 3723 | // would be an ODR violation. |
| 3724 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 3725 | Context->getCanonicalType(Context->getRecordType(D))); |
| 3726 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 3727 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3728 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3729 | // If we still have constructors or conversion functions, we walk all the |
| 3730 | // names in the decl and add the constructors and conversion functions |
| 3731 | // which are visible in the order they lexically occur within the context. |
| 3732 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 3733 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 3734 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 3735 | auto Name = ChildND->getDeclName(); |
| 3736 | switch (Name.getNameKind()) { |
| 3737 | default: |
| 3738 | continue; |
| 3739 | |
| 3740 | case DeclarationName::CXXConstructorName: |
| 3741 | if (ConstructorNameSet.erase(Name)) |
| 3742 | Names.push_back(Name); |
| 3743 | break; |
| 3744 | |
| 3745 | case DeclarationName::CXXConversionFunctionName: |
| 3746 | if (ConversionNameSet.erase(Name)) |
| 3747 | Names.push_back(Name); |
| 3748 | break; |
| 3749 | } |
| 3750 | |
| 3751 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 3752 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3755 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 3756 | "constructors by walking all the " |
| 3757 | "lexical members of the context."); |
| 3758 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 3759 | "conversion functions by walking all " |
| 3760 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3761 | } |
| 3762 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3763 | // Next we need to do a lookup with each name into this decl context to fully |
| 3764 | // populate any results from external sources. We don't actually use the |
| 3765 | // results of these lookups because we only want to use the results after all |
| 3766 | // results have been loaded and the pointers into them will be stable. |
| 3767 | for (auto &Name : Names) |
| 3768 | DC->lookup(Name); |
| 3769 | |
| 3770 | // Now we need to insert the results for each name into the hash table. For |
| 3771 | // constructor names and conversion function names, we actually need to merge |
| 3772 | // all of the results for them into one list of results each and insert |
| 3773 | // those. |
| 3774 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 3775 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 3776 | |
| 3777 | // Now loop over the names, either inserting them or appending for the two |
| 3778 | // special cases. |
| 3779 | for (auto &Name : Names) { |
| 3780 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 3781 | |
| 3782 | switch (Name.getNameKind()) { |
| 3783 | default: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3784 | Generator.insert(Name, Trait.getData(Result), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3785 | break; |
| 3786 | |
| 3787 | case DeclarationName::CXXConstructorName: |
| 3788 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 3789 | break; |
| 3790 | |
| 3791 | case DeclarationName::CXXConversionFunctionName: |
| 3792 | ConversionDecls.append(Result.begin(), Result.end()); |
| 3793 | break; |
| 3794 | } |
| 3795 | } |
| 3796 | |
| 3797 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 3798 | // the first declaration's name here because the name itself isn't part of |
| 3799 | // the key, only the kind of name is used. |
| 3800 | if (!ConstructorDecls.empty()) |
| 3801 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3802 | Trait.getData(ConstructorDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3803 | if (!ConversionDecls.empty()) |
| 3804 | Generator.insert(ConversionDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3805 | Trait.getData(ConversionDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3806 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3807 | // Create the on-disk hash table. Also emit the existing imported and |
| 3808 | // merged table if there is one. |
| 3809 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; |
| 3810 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3811 | } |
| 3812 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3813 | /// \brief Write the block containing all of the declaration IDs |
| 3814 | /// visible from the given DeclContext. |
| 3815 | /// |
| 3816 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3817 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3818 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 3819 | DeclContext *DC) { |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3820 | // If we imported a key declaration of this namespace, write the visible |
| 3821 | // lookup results as an update record for it rather than including them |
| 3822 | // on this declaration. We will only look at key declarations on reload. |
| 3823 | if (isa<NamespaceDecl>(DC) && Chain && |
| 3824 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { |
| 3825 | // Only do this once, for the first local declaration of the namespace. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3826 | for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3827 | Prev = Prev->getPreviousDecl()) |
| 3828 | if (!Prev->isFromASTFile()) |
| 3829 | return 0; |
| 3830 | |
| 3831 | // Note that we need to emit an update record for the primary context. |
| 3832 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); |
| 3833 | |
| 3834 | // Make sure all visible decls are written. They will be recorded later. We |
| 3835 | // do this using a side data structure so we can sort the names into |
| 3836 | // a deterministic order. |
| 3837 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); |
| 3838 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> |
| 3839 | LookupResults; |
| 3840 | if (Map) { |
| 3841 | LookupResults.reserve(Map->size()); |
| 3842 | for (auto &Entry : *Map) |
| 3843 | LookupResults.push_back( |
| 3844 | std::make_pair(Entry.first, Entry.second.getLookupResult())); |
| 3845 | } |
| 3846 | |
| 3847 | std::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); |
| 3848 | for (auto &NameAndResult : LookupResults) { |
| 3849 | DeclarationName Name = NameAndResult.first; |
| 3850 | DeclContext::lookup_result Result = NameAndResult.second; |
| 3851 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || |
| 3852 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 3853 | // We have to work around a name lookup bug here where negative lookup |
| 3854 | // results for these names get cached in namespace lookup tables (these |
| 3855 | // names should never be looked up in a namespace). |
| 3856 | assert(Result.empty() && "Cannot have a constructor or conversion " |
| 3857 | "function name in a namespace!"); |
| 3858 | continue; |
| 3859 | } |
| 3860 | |
| 3861 | for (NamedDecl *ND : Result) |
| 3862 | if (!ND->isFromASTFile()) |
| 3863 | GetDeclRef(ND); |
| 3864 | } |
| 3865 | |
| 3866 | return 0; |
| 3867 | } |
| 3868 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3869 | if (DC->getPrimaryContext() != DC) |
| 3870 | return 0; |
| 3871 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3872 | // Skip contexts which don't support name lookup. |
| 3873 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3874 | return 0; |
| 3875 | |
| 3876 | // If not in C++, we perform name lookup for the translation unit via the |
| 3877 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3878 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3879 | return 0; |
| 3880 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3881 | // Serialize the contents of the mapping used for lookup. Note that, |
| 3882 | // although we have two very different code paths, the serialized |
| 3883 | // representation is the same for both cases: a declaration name, |
| 3884 | // followed by a size, followed by references to the visible |
| 3885 | // declarations that have that name. |
| 3886 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3887 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3888 | if (!Map || Map->empty()) |
| 3889 | return 0; |
| 3890 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3891 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3892 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3893 | GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3894 | |
| 3895 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3896 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3897 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3898 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3899 | ++NumVisibleDeclContexts; |
| 3900 | return Offset; |
| 3901 | } |
| 3902 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3903 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3904 | /// |
| 3905 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3906 | /// 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] | 3907 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3908 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3909 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3910 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3911 | if (!Map || Map->empty()) |
| 3912 | return; |
| 3913 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3914 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3915 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3916 | GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3917 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3918 | // If we're updating a namespace, select a key declaration as the key for the |
| 3919 | // update record; those are the only ones that will be checked on reload. |
| 3920 | if (isa<NamespaceDecl>(DC)) |
| 3921 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); |
| 3922 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3923 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3924 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3925 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3928 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3929 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3930 | RecordData::value_type Record[] = {Opts.fp_contract}; |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3931 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3932 | } |
| 3933 | |
| 3934 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3935 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3936 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3937 | return; |
| 3938 | |
| 3939 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3940 | RecordData Record; |
| 3941 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3942 | #include "clang/Basic/OpenCLExtensions.def" |
| 3943 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3944 | } |
| 3945 | |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 3946 | void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) { |
| 3947 | if (SemaRef.ForceCUDAHostDeviceDepth > 0) { |
| 3948 | RecordData::value_type Record[] = {SemaRef.ForceCUDAHostDeviceDepth}; |
| 3949 | Stream.EmitRecord(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH, Record); |
| 3950 | } |
| 3951 | } |
| 3952 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3953 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3954 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3955 | RecordData Categories; |
| 3956 | |
| 3957 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3958 | unsigned Size = 0; |
| 3959 | unsigned StartIndex = Categories.size(); |
| 3960 | |
| 3961 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3962 | |
| 3963 | // Allocate space for the size. |
| 3964 | Categories.push_back(0); |
| 3965 | |
| 3966 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3967 | for (ObjCInterfaceDecl::known_categories_iterator |
| 3968 | Cat = Class->known_categories_begin(), |
| 3969 | CatEnd = Class->known_categories_end(); |
| 3970 | Cat != CatEnd; ++Cat, ++Size) { |
| 3971 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 3972 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | // Update the size. |
| 3976 | Categories[StartIndex] = Size; |
| 3977 | |
| 3978 | // Record this interface -> category map. |
| 3979 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3980 | CategoriesMap.push_back(CatInfo); |
| 3981 | } |
| 3982 | |
| 3983 | // Sort the categories map by the definition ID, since the reader will be |
| 3984 | // performing binary searches on this information. |
| 3985 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3986 | |
| 3987 | // Emit the categories map. |
| 3988 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3989 | |
| 3990 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3991 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3992 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3993 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3994 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3995 | |
| 3996 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; |
| 3997 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3998 | reinterpret_cast<char *>(CategoriesMap.data()), |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3999 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4001 | // Emit the category lists. |
| 4002 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 4003 | } |
| 4004 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4005 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 4006 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 4007 | |
| 4008 | if (LPTMap.empty()) |
| 4009 | return; |
| 4010 | |
| 4011 | RecordData Record; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4012 | for (auto &LPTMapEntry : LPTMap) { |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4013 | const FunctionDecl *FD = LPTMapEntry.first; |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4014 | LateParsedTemplate &LPT = *LPTMapEntry.second; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4015 | AddDeclRef(FD, Record); |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4016 | AddDeclRef(LPT.D, Record); |
| 4017 | Record.push_back(LPT.Toks.size()); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4018 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4019 | for (const auto &Tok : LPT.Toks) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4020 | AddToken(Tok, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4021 | } |
| 4022 | } |
| 4023 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 4024 | } |
| 4025 | |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4026 | /// \brief Write the state of 'pragma clang optimize' at the end of the module. |
| 4027 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 4028 | RecordData Record; |
| 4029 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 4030 | AddSourceLocation(PragmaLoc, Record); |
| 4031 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 4032 | } |
| 4033 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4034 | /// \brief Write the state of 'pragma ms_struct' at the end of the module. |
| 4035 | void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) { |
| 4036 | RecordData Record; |
| 4037 | Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF); |
| 4038 | Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record); |
| 4039 | } |
| 4040 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4041 | /// \brief Write the state of 'pragma pointers_to_members' at the end of the |
| 4042 | //module. |
| 4043 | void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) { |
| 4044 | RecordData Record; |
| 4045 | Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod); |
| 4046 | AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record); |
| 4047 | Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record); |
| 4048 | } |
| 4049 | |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4050 | void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, |
| 4051 | ModuleFileExtensionWriter &Writer) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4052 | // Enter the extension block. |
| 4053 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); |
| 4054 | |
| 4055 | // Emit the metadata record abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4056 | auto *Abv = new llvm::BitCodeAbbrev(); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4057 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); |
| 4058 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4059 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4060 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4061 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 4062 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4063 | unsigned Abbrev = Stream.EmitAbbrev(Abv); |
| 4064 | |
| 4065 | // Emit the metadata record. |
| 4066 | RecordData Record; |
| 4067 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); |
| 4068 | Record.push_back(EXTENSION_METADATA); |
| 4069 | Record.push_back(Metadata.MajorVersion); |
| 4070 | Record.push_back(Metadata.MinorVersion); |
| 4071 | Record.push_back(Metadata.BlockName.size()); |
| 4072 | Record.push_back(Metadata.UserInfo.size()); |
| 4073 | SmallString<64> Buffer; |
| 4074 | Buffer += Metadata.BlockName; |
| 4075 | Buffer += Metadata.UserInfo; |
| 4076 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); |
| 4077 | |
| 4078 | // Emit the contents of the extension block. |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4079 | Writer.writeExtensionContents(SemaRef, Stream); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4080 | |
| 4081 | // Exit the extension block. |
| 4082 | Stream.ExitBlock(); |
| 4083 | } |
| 4084 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4085 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4086 | // General Serialization Routines |
| 4087 | //===----------------------------------------------------------------------===// |
| 4088 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4089 | /// \brief Emit the list of attributes to the specified record. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4090 | void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) { |
| 4091 | auto &Record = *this; |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 4092 | Record.push_back(Attrs.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4093 | for (const auto *A : Attrs) { |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 4094 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4095 | Record.AddSourceRange(A->getRange()); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4096 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 4097 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 4098 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4099 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 4102 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 4103 | AddSourceLocation(Tok.getLocation(), Record); |
| 4104 | Record.push_back(Tok.getLength()); |
| 4105 | |
| 4106 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 4107 | // if it is needed. |
| 4108 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 4109 | // FIXME: Should translate token kind to a stable encoding. |
| 4110 | Record.push_back(Tok.getKind()); |
| 4111 | // FIXME: Should translate token flags to a stable encoding. |
| 4112 | Record.push_back(Tok.getFlags()); |
| 4113 | } |
| 4114 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4115 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4116 | Record.push_back(Str.size()); |
| 4117 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 4118 | } |
| 4119 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4120 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4121 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4122 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4123 | bool Changed = |
| 4124 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4125 | |
| 4126 | // Remove a prefix to make the path relative, if relevant. |
| 4127 | const char *PathBegin = Path.data(); |
| 4128 | const char *PathPtr = |
| 4129 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 4130 | if (PathPtr != PathBegin) { |
| 4131 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 4132 | Changed = true; |
| 4133 | } |
| 4134 | |
| 4135 | return Changed; |
| 4136 | } |
| 4137 | |
| 4138 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 4139 | SmallString<128> FilePath(Path); |
| 4140 | PreparePathForOutput(FilePath); |
| 4141 | AddString(FilePath, Record); |
| 4142 | } |
| 4143 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4144 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4145 | StringRef Path) { |
| 4146 | SmallString<128> FilePath(Path); |
| 4147 | PreparePathForOutput(FilePath); |
| 4148 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 4149 | } |
| 4150 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4151 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 4152 | RecordDataImpl &Record) { |
| 4153 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4154 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4155 | Record.push_back(*Minor + 1); |
| 4156 | else |
| 4157 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4158 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4159 | Record.push_back(*Subminor + 1); |
| 4160 | else |
| 4161 | Record.push_back(0); |
| 4162 | } |
| 4163 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4164 | /// \brief Note that the identifier II occurs at the given offset |
| 4165 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4166 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4167 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4168 | // 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] | 4169 | // up earlier in the chain and thus don't need an offset. |
| 4170 | if (ID >= FirstIdentID) |
| 4171 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4172 | } |
| 4173 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4174 | /// \brief Note that the selector Sel occurs at the given offset |
| 4175 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4176 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4177 | unsigned ID = SelectorIDs[Sel]; |
| 4178 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4179 | // Don't record offsets for selectors that are also available in a different |
| 4180 | // file. |
| 4181 | if (ID < FirstSelectorID) |
| 4182 | return; |
| 4183 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4184 | } |
| 4185 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4186 | ASTWriter::ASTWriter( |
| 4187 | llvm::BitstreamWriter &Stream, |
| 4188 | ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions, |
| 4189 | bool IncludeTimestamps) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4190 | : Stream(Stream), Context(nullptr), PP(nullptr), Chain(nullptr), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4191 | WritingModule(nullptr), IncludeTimestamps(IncludeTimestamps), |
| 4192 | WritingAST(false), DoneWritingDeclsAndTypes(false), |
| 4193 | ASTHasCompilerErrors(false), FirstDeclID(NUM_PREDEF_DECL_IDS), |
| 4194 | NextDeclID(FirstDeclID), FirstTypeID(NUM_PREDEF_TYPE_IDS), |
| 4195 | NextTypeID(FirstTypeID), FirstIdentID(NUM_PREDEF_IDENT_IDS), |
| 4196 | NextIdentID(FirstIdentID), FirstMacroID(NUM_PREDEF_MACRO_IDS), |
| 4197 | NextMacroID(FirstMacroID), FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4198 | NextSubmoduleID(FirstSubmoduleID), |
| 4199 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4200 | NumStatements(0), NumMacros(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4201 | NumLexicalDeclContexts(0), NumVisibleDeclContexts(0), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4202 | TypeExtQualAbbrev(0), TypeFunctionProtoAbbrev(0), DeclParmVarAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4203 | DeclContextLexicalAbbrev(0), DeclContextVisibleLookupAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4204 | UpdateVisibleAbbrev(0), DeclRecordAbbrev(0), DeclTypedefAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4205 | DeclVarAbbrev(0), DeclFieldAbbrev(0), DeclEnumAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4206 | DeclObjCIvarAbbrev(0), DeclCXXMethodAbbrev(0), DeclRefExprAbbrev(0), |
| 4207 | CharacterLiteralAbbrev(0), IntegerLiteralAbbrev(0), |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4208 | ExprImplicitCastAbbrev(0) { |
| 4209 | for (const auto &Ext : Extensions) { |
| 4210 | if (auto Writer = Ext->createExtensionWriter(*this)) |
| 4211 | ModuleFileExtensionWriters.push_back(std::move(Writer)); |
| 4212 | } |
| 4213 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4214 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4215 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 4216 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4217 | } |
| 4218 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4219 | const LangOptions &ASTWriter::getLangOpts() const { |
| 4220 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 4221 | return Context->getLangOpts(); |
| 4222 | } |
| 4223 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4224 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { |
| 4225 | return IncludeTimestamps ? E->getModificationTime() : 0; |
| 4226 | } |
| 4227 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4228 | uint64_t ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile, |
| 4229 | Module *WritingModule, StringRef isysroot, |
| 4230 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4231 | WritingAST = true; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4232 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4233 | ASTHasCompilerErrors = hasErrors; |
| 4234 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4235 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4236 | Stream.Emit((unsigned)'C', 8); |
| 4237 | Stream.Emit((unsigned)'P', 8); |
| 4238 | Stream.Emit((unsigned)'C', 8); |
| 4239 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4240 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4241 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4242 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4243 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4244 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4245 | this->WritingModule = WritingModule; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4246 | ASTFileSignature Signature = |
| 4247 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4248 | Context = nullptr; |
| 4249 | PP = nullptr; |
| 4250 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4251 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4252 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4253 | WritingAST = false; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4254 | return Signature; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4257 | template<typename Vector> |
| 4258 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4259 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4260 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4261 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4262 | Writer.AddDeclRef(*I, Record); |
| 4263 | } |
| 4264 | } |
| 4265 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4266 | uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, |
| 4267 | const std::string &OutputFile, |
| 4268 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4269 | using namespace llvm; |
| 4270 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4271 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4272 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4273 | // Make sure that the AST reader knows to finalize itself. |
| 4274 | if (Chain) |
| 4275 | Chain->finalizeForWriting(); |
| 4276 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4277 | ASTContext &Context = SemaRef.Context; |
| 4278 | Preprocessor &PP = SemaRef.PP; |
| 4279 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4280 | // Set up predefined declaration IDs. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4281 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { |
| 4282 | if (D) { |
| 4283 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); |
| 4284 | DeclIDs[D] = ID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4285 | } |
| 4286 | }; |
| 4287 | RegisterPredefDecl(Context.getTranslationUnitDecl(), |
| 4288 | PREDEF_DECL_TRANSLATION_UNIT_ID); |
| 4289 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); |
| 4290 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); |
| 4291 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); |
| 4292 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, |
| 4293 | PREDEF_DECL_OBJC_PROTOCOL_ID); |
| 4294 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); |
| 4295 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); |
| 4296 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, |
| 4297 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); |
| 4298 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4299 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4300 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, |
| 4301 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4302 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4303 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, |
| 4304 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 4305 | RegisterPredefDecl(Context.CFConstantStringTypeDecl, |
| 4306 | PREDEF_DECL_CF_CONSTANT_STRING_ID); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 4307 | RegisterPredefDecl(Context.CFConstantStringTagDecl, |
| 4308 | PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 4309 | RegisterPredefDecl(Context.TypePackElementDecl, |
| 4310 | PREDEF_DECL_TYPE_PACK_ELEMENT_ID); |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4311 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4312 | // 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] | 4313 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4314 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4315 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4316 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4317 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4318 | // Build a record containing all of the file scoped decls in this file. |
| 4319 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4320 | if (!isModule) |
| 4321 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4322 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4323 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4324 | // Build a record containing all of the delegating constructors we still need |
| 4325 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4326 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4327 | if (!isModule) |
| 4328 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4329 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4330 | // Write the set of weak, undeclared identifiers. We always write the |
| 4331 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4332 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4333 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4334 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4335 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4336 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4337 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4338 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4339 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4340 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4341 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4342 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4343 | // Build a record containing all of the ext_vector declarations. |
| 4344 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4345 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4346 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4347 | // Build a record containing all of the VTable uses information. |
| 4348 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4349 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4350 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4351 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4352 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4353 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4354 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4357 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4358 | RecordData UnusedLocalTypedefNameCandidates; |
| 4359 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4360 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4361 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4362 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4363 | RecordData PendingInstantiations; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4364 | for (const auto &I : SemaRef.PendingInstantiations) { |
| 4365 | AddDeclRef(I.first, PendingInstantiations); |
| 4366 | AddSourceLocation(I.second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4367 | } |
| 4368 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4369 | "There are local ones at end of translation unit!"); |
| 4370 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4371 | // Build a record containing some declaration references. |
| 4372 | RecordData SemaDeclRefs; |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4373 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) { |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4374 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4375 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4376 | AddDeclRef(SemaRef.getStdAlignValT(), SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4379 | RecordData CUDASpecialDeclRefs; |
| 4380 | if (Context.getcudaConfigureCallDecl()) { |
| 4381 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4382 | } |
| 4383 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4384 | // Build a record containing all of the known namespaces. |
| 4385 | RecordData KnownNamespaces; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4386 | for (const auto &I : SemaRef.KnownNamespaces) { |
| 4387 | if (!I.second) |
| 4388 | AddDeclRef(I.first, KnownNamespaces); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4389 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4390 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4391 | // Build a record of all used, undefined objects that require definitions. |
| 4392 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4393 | |
| 4394 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4395 | SemaRef.getUndefinedButUsed(Undefined); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4396 | for (const auto &I : Undefined) { |
| 4397 | AddDeclRef(I.first, UndefinedButUsed); |
| 4398 | AddSourceLocation(I.second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4399 | } |
| 4400 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4401 | // Build a record containing all delete-expressions that we would like to |
| 4402 | // analyze later in AST. |
| 4403 | RecordData DeleteExprsToAnalyze; |
| 4404 | |
| 4405 | for (const auto &DeleteExprsInfo : |
| 4406 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4407 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4408 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4409 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4410 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4411 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4412 | } |
| 4413 | } |
| 4414 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4415 | // Write the control block |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4416 | uint64_t Signature = WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4417 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4418 | // Write the remaining AST contents. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4419 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4420 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4421 | // This is so that older clang versions, before the introduction |
| 4422 | // of the control block, can read and reject the newer PCH format. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4423 | { |
| 4424 | RecordData Record = {VERSION_MAJOR}; |
| 4425 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4426 | } |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4427 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4428 | // Create a lexical update block containing all of the declarations in the |
| 4429 | // translation unit that do not come from other AST files. |
| 4430 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4431 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; |
| 4432 | for (const auto *D : TU->noload_decls()) { |
| 4433 | if (!D->isFromASTFile()) { |
| 4434 | NewGlobalKindDeclPairs.push_back(D->getKind()); |
| 4435 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); |
| 4436 | } |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4437 | } |
| 4438 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4439 | auto *Abv = new llvm::BitCodeAbbrev(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4440 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4441 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4442 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4443 | { |
| 4444 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; |
| 4445 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 4446 | bytes(NewGlobalKindDeclPairs)); |
| 4447 | } |
| 4448 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4449 | // And a visible updates block for the translation unit. |
| 4450 | Abv = new llvm::BitCodeAbbrev(); |
| 4451 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4452 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4453 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4454 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 4455 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4456 | |
| 4457 | // If we have any extern "C" names, write out a visible update for them. |
| 4458 | if (Context.ExternCContext) |
| 4459 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4460 | |
| 4461 | // If the translation unit has an anonymous namespace, and we don't already |
| 4462 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4463 | // 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] | 4464 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4465 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4466 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4467 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4468 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4469 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4470 | // Add update records for all mangling numbers and static local numbers. |
| 4471 | // These aren't really update records, but this is a convenient way of |
| 4472 | // tagging this rare extra data onto the declarations. |
| 4473 | for (const auto &Number : Context.MangleNumbers) |
| 4474 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4475 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4476 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4477 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4478 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4479 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4480 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4481 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4482 | // Make sure visible decls, added to DeclContexts previously loaded from |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 4483 | // an AST file, are registered for serialization. Likewise for template |
| 4484 | // specializations added to imported templates. |
| 4485 | for (const auto *I : DeclsToEmitEvenIfUnreferenced) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4486 | GetDeclRef(I); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4487 | } |
| 4488 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4489 | // Make sure all decls associated with an identifier are registered for |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4490 | // serialization, if we're storing decls with identifiers. |
| 4491 | if (!WritingModule || !getLangOpts().CPlusPlus) { |
| 4492 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4493 | for (const auto &ID : PP.getIdentifierTable()) { |
| 4494 | const IdentifierInfo *II = ID.second; |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4495 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 4496 | IIs.push_back(II); |
| 4497 | } |
| 4498 | // Sort the identifiers to visit based on their name. |
| 4499 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 4500 | for (const IdentifierInfo *II : IIs) { |
| 4501 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4502 | DEnd = SemaRef.IdResolver.end(); |
| 4503 | D != DEnd; ++D) { |
| 4504 | GetDeclRef(*D); |
| 4505 | } |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4506 | } |
| 4507 | } |
| 4508 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 4509 | // For method pool in the module, if it contains an entry for a selector, |
| 4510 | // the entry should be complete, containing everything introduced by that |
| 4511 | // module and all modules it imports. It's possible that the entry is out of |
| 4512 | // date, so we need to pull in the new content here. |
| 4513 | |
| 4514 | // It's possible that updateOutOfDateSelector can update SelectorIDs. To be |
| 4515 | // safe, we copy all selectors out. |
| 4516 | llvm::SmallVector<Selector, 256> AllSelectors; |
| 4517 | for (auto &SelectorAndID : SelectorIDs) |
| 4518 | AllSelectors.push_back(SelectorAndID.first); |
| 4519 | for (auto &Selector : AllSelectors) |
| 4520 | SemaRef.updateOutOfDateSelector(Selector); |
| 4521 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4522 | // Form the record of special types. |
| 4523 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4524 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4525 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 4526 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 4527 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 4528 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 4529 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4530 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4531 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4532 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4533 | if (Chain) { |
| 4534 | // Write the mapping information describing our module dependencies and how |
| 4535 | // each of those modules were mapped into our own offset/ID space, so that |
| 4536 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4537 | // The map consists solely of a blob with the following format: |
| 4538 | // *(module-name-len:i16 module-name:len*i8 |
| 4539 | // source-location-offset:i32 |
| 4540 | // identifier-id:i32 |
| 4541 | // preprocessed-entity-id:i32 |
| 4542 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4543 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4544 | // selector-id:i32 |
| 4545 | // declaration-id:i32 |
| 4546 | // c++-base-specifiers-id:i32 |
| 4547 | // type-id:i32) |
| 4548 | // |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4549 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4550 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4551 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 4552 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4553 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4554 | { |
| 4555 | llvm::raw_svector_ostream Out(Buffer); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4556 | for (ModuleFile *M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4557 | using namespace llvm::support; |
| 4558 | endian::Writer<little> LE(Out); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4559 | StringRef FileName = M->FileName; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4560 | LE.write<uint16_t>(FileName.size()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4561 | Out.write(FileName.data(), FileName.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4562 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4563 | // Note: if a base ID was uint max, it would not be possible to load |
| 4564 | // another module after it or have more than one entity inside it. |
| 4565 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 4566 | |
| 4567 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 4568 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 4569 | if (ShouldWrite) |
| 4570 | LE.write<uint32_t>(BaseID); |
| 4571 | else |
| 4572 | LE.write<uint32_t>(None); |
| 4573 | }; |
| 4574 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4575 | // These values should be unique within a chain, since they will be read |
| 4576 | // as keys into ContinuousRangeMaps. |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4577 | writeBaseIDOrNone(M->SLocEntryBaseOffset, M->LocalNumSLocEntries); |
| 4578 | writeBaseIDOrNone(M->BaseIdentifierID, M->LocalNumIdentifiers); |
| 4579 | writeBaseIDOrNone(M->BaseMacroID, M->LocalNumMacros); |
| 4580 | writeBaseIDOrNone(M->BasePreprocessedEntityID, |
| 4581 | M->NumPreprocessedEntities); |
| 4582 | writeBaseIDOrNone(M->BaseSubmoduleID, M->LocalNumSubmodules); |
| 4583 | writeBaseIDOrNone(M->BaseSelectorID, M->LocalNumSelectors); |
| 4584 | writeBaseIDOrNone(M->BaseDeclID, M->LocalNumDecls); |
| 4585 | writeBaseIDOrNone(M->BaseTypeIndex, M->LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4586 | } |
| 4587 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4588 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4589 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4590 | Buffer.data(), Buffer.size()); |
| 4591 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4592 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4593 | RecordData DeclUpdatesOffsetsRecord; |
| 4594 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4595 | // Keep writing types, declarations, and declaration update records |
| 4596 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4597 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 4598 | WriteTypeAbbrevs(); |
| 4599 | WriteDeclAbbrevs(); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4600 | do { |
| 4601 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 4602 | while (!DeclTypesToEmit.empty()) { |
| 4603 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 4604 | DeclTypesToEmit.pop(); |
| 4605 | if (DOT.isType()) |
| 4606 | WriteType(DOT.getType()); |
| 4607 | else |
| 4608 | WriteDecl(Context, DOT.getDecl()); |
| 4609 | } |
| 4610 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4611 | Stream.ExitBlock(); |
| 4612 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4613 | DoneWritingDeclsAndTypes = true; |
| 4614 | |
| 4615 | // These things can only be done once we've written out decls and types. |
| 4616 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4617 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 4618 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4619 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4620 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4621 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4622 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4623 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4624 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4625 | WriteReferencedSelectorsPool(SemaRef); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 4626 | WriteLateParsedTemplates(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4627 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4628 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 4629 | WriteOpenCLExtensions(SemaRef); |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 4630 | WriteCUDAPragmas(SemaRef); |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 4631 | WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4632 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4633 | // If we're emitting a module, write out the submodule information. |
| 4634 | if (WritingModule) |
| 4635 | WriteSubmodules(WritingModule); |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 4636 | else if (!getLangOpts().CurrentModule.empty()) { |
| 4637 | // If we're building a PCH in the implementation of a module, we may need |
| 4638 | // the description of the current module. |
| 4639 | // |
| 4640 | // FIXME: We may need other modules that we did not load from an AST file, |
| 4641 | // such as if a module declares a 'conflicts' on a different module. |
| 4642 | Module *M = PP.getHeaderSearchInfo().getModuleMap().findModule( |
| 4643 | getLangOpts().CurrentModule); |
| 4644 | if (M && !M->IsFromModuleFile) |
| 4645 | WriteSubmodules(M); |
| 4646 | } |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4647 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4648 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 4649 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4650 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 4651 | if (!EagerlyDeserializedDecls.empty()) |
| 4652 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4653 | |
| 4654 | // Write the record containing tentative definitions. |
| 4655 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4656 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4657 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4658 | // Write the record containing unused file scoped decls. |
| 4659 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4660 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4661 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4662 | // Write the record containing weak undeclared identifiers. |
| 4663 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4664 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4665 | WeakUndeclaredIdentifiers); |
| 4666 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4667 | // Write the record containing ext_vector type names. |
| 4668 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4669 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4671 | // Write the record containing VTable uses information. |
| 4672 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4673 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4674 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4675 | // Write the record containing potentially unused local typedefs. |
| 4676 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 4677 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 4678 | UnusedLocalTypedefNameCandidates); |
| 4679 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4680 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4681 | if (!PendingInstantiations.empty()) |
| 4682 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4683 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4684 | // Write the record containing declaration references of Sema. |
| 4685 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4686 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4687 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4688 | // Write the record containing CUDA-specific declaration references. |
| 4689 | if (!CUDASpecialDeclRefs.empty()) |
| 4690 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4691 | |
| 4692 | // Write the delegating constructors. |
| 4693 | if (!DelegatingCtorDecls.empty()) |
| 4694 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4695 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4696 | // Write the known namespaces. |
| 4697 | if (!KnownNamespaces.empty()) |
| 4698 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4699 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4700 | // Write the undefined internal functions and variables, and inline functions. |
| 4701 | if (!UndefinedButUsed.empty()) |
| 4702 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4703 | |
| 4704 | if (!DeleteExprsToAnalyze.empty()) |
| 4705 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 4706 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4707 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4708 | for (auto *DC : UpdatedDeclContexts) |
| 4709 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4710 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4711 | if (!WritingModule) { |
| 4712 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4713 | struct ModuleInfo { |
| 4714 | uint64_t ID; |
| 4715 | Module *M; |
| 4716 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 4717 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4718 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 4719 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4720 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4721 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 4722 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4723 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4724 | |
| 4725 | if (!Imports.empty()) { |
| 4726 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4727 | return A.ID < B.ID; |
| 4728 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4729 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4730 | return A.ID == B.ID; |
| 4731 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4732 | |
| 4733 | // Sort and deduplicate module IDs. |
| 4734 | std::sort(Imports.begin(), Imports.end(), Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4735 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4736 | Imports.end()); |
| 4737 | |
| 4738 | RecordData ImportedModules; |
| 4739 | for (const auto &Import : Imports) { |
| 4740 | ImportedModules.push_back(Import.ID); |
| 4741 | // FIXME: If the module has macros imported then later has declarations |
| 4742 | // imported, this location won't be the right one as a location for the |
| 4743 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 4744 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4745 | } |
| 4746 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4747 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 4748 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4749 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4750 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4751 | WriteObjCCategories(); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4752 | if(!WritingModule) { |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4753 | WriteOptimizePragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4754 | WriteMSStructPragmaOptions(SemaRef); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4755 | WriteMSPointersToMembersPragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4756 | } |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4757 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4758 | // Some simple statistics |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4759 | RecordData::value_type Record[] = { |
| 4760 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4761 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4762 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4763 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4764 | // Write the module file extension blocks. |
| 4765 | for (const auto &ExtWriter : ModuleFileExtensionWriters) |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4766 | WriteModuleFileExtension(SemaRef, *ExtWriter); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4767 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4768 | return Signature; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4769 | } |
| 4770 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4771 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4772 | if (DeclUpdates.empty()) |
| 4773 | return; |
| 4774 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4775 | DeclUpdateMap LocalUpdates; |
| 4776 | LocalUpdates.swap(DeclUpdates); |
| 4777 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4778 | for (auto &DeclUpdate : LocalUpdates) { |
| 4779 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 4780 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4781 | bool HasUpdatedBody = false; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4782 | RecordData RecordData; |
| 4783 | ASTRecordWriter Record(*this, RecordData); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4784 | for (auto &Update : DeclUpdate.second) { |
| 4785 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 4786 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4787 | // An updated body is emitted last, so that the reader doesn't need |
| 4788 | // to skip over the lazy body to reach statements for other records. |
| 4789 | if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION) |
| 4790 | HasUpdatedBody = true; |
| 4791 | else |
| 4792 | Record.push_back(Kind); |
| 4793 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4794 | switch (Kind) { |
| 4795 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 4796 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 4797 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4798 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4799 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 4800 | break; |
| 4801 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4802 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4803 | break; |
| 4804 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4805 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4806 | Record.AddSourceLocation(Update.getLoc()); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4807 | break; |
| 4808 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4809 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4810 | Record.AddStmt(const_cast<Expr *>( |
| 4811 | cast<ParmVarDecl>(Update.getDecl())->getDefaultArg())); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4812 | break; |
| 4813 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4814 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: |
| 4815 | Record.AddStmt( |
| 4816 | cast<FieldDecl>(Update.getDecl())->getInClassInitializer()); |
| 4817 | break; |
| 4818 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4819 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4820 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 4821 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4822 | Record.AddCXXDefinitionData(RD); |
Richard Smith | 72e50fe | 2016-04-14 00:50:18 +0000 | [diff] [blame] | 4823 | Record.AddOffset(WriteDeclContextLexicalBlock( |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4824 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 4825 | |
| 4826 | // This state is sometimes updated by template instantiation, when we |
| 4827 | // switch from the specialization referring to the template declaration |
| 4828 | // to it referring to the template definition. |
| 4829 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 4830 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4831 | Record.AddSourceLocation(MSInfo->getPointOfInstantiation()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4832 | } else { |
| 4833 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 4834 | Record.push_back(Spec->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4835 | Record.AddSourceLocation(Spec->getPointOfInstantiation()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4836 | |
| 4837 | // The instantiation might have been resolved to a partial |
| 4838 | // specialization. If so, record which one. |
| 4839 | auto From = Spec->getInstantiatedFrom(); |
| 4840 | if (auto PartialSpec = |
| 4841 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 4842 | Record.push_back(true); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4843 | Record.AddDeclRef(PartialSpec); |
| 4844 | Record.AddTemplateArgumentList( |
| 4845 | &Spec->getTemplateInstantiationArgs()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4846 | } else { |
| 4847 | Record.push_back(false); |
| 4848 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4849 | } |
| 4850 | Record.push_back(RD->getTagKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4851 | Record.AddSourceLocation(RD->getLocation()); |
| 4852 | Record.AddSourceLocation(RD->getLocStart()); |
Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 4853 | Record.AddSourceRange(RD->getBraceRange()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4854 | |
| 4855 | // Instantiation may change attributes; write them all out afresh. |
| 4856 | Record.push_back(D->hasAttrs()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4857 | if (D->hasAttrs()) |
| 4858 | Record.AddAttributes(D->getAttrs()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4859 | |
| 4860 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 4861 | break; |
| 4862 | } |
| 4863 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4864 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4865 | Record.AddDeclRef(Update.getDecl()); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4866 | break; |
| 4867 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4868 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 4869 | addExceptionSpec( |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4870 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 4871 | Record); |
| 4872 | break; |
| 4873 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4874 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 4875 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 4876 | break; |
| 4877 | |
| 4878 | case UPD_DECL_MARKED_USED: |
| 4879 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4880 | |
| 4881 | case UPD_MANGLING_NUMBER: |
| 4882 | case UPD_STATIC_LOCAL_NUMBER: |
| 4883 | Record.push_back(Update.getNumber()); |
| 4884 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4885 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4886 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4887 | Record.AddSourceRange( |
| 4888 | D->getAttr<OMPThreadPrivateDeclAttr>()->getRange()); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4889 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4890 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 4891 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: |
| 4892 | Record.AddSourceRange( |
| 4893 | D->getAttr<OMPDeclareTargetDeclAttr>()->getRange()); |
| 4894 | break; |
| 4895 | |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4896 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 4897 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4898 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4899 | |
| 4900 | case UPD_ADDED_ATTR_TO_RECORD: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4901 | Record.AddAttributes(llvm::makeArrayRef(Update.getAttr())); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4902 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4903 | } |
| 4904 | } |
| 4905 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4906 | if (HasUpdatedBody) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4907 | const auto *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4908 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4909 | Record.push_back(Def->isInlined()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4910 | Record.AddSourceLocation(Def->getInnerLocStart()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4911 | Record.AddFunctionDefinition(Def); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4912 | } |
| 4913 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4914 | OffsetsRecord.push_back(GetDeclRef(D)); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4915 | OffsetsRecord.push_back(Record.Emit(DECL_UPDATES)); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4916 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4917 | } |
| 4918 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4919 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 4920 | uint32_t Raw = Loc.getRawEncoding(); |
| 4921 | Record.push_back((Raw << 1) | (Raw >> 31)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4922 | } |
| 4923 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4924 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4925 | AddSourceLocation(Range.getBegin(), Record); |
| 4926 | AddSourceLocation(Range.getEnd(), Record); |
| 4927 | } |
| 4928 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4929 | void ASTRecordWriter::AddAPInt(const llvm::APInt &Value) { |
| 4930 | Record->push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4931 | const uint64_t *Words = Value.getRawData(); |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4932 | Record->append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4933 | } |
| 4934 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4935 | void ASTRecordWriter::AddAPSInt(const llvm::APSInt &Value) { |
| 4936 | Record->push_back(Value.isUnsigned()); |
| 4937 | AddAPInt(Value); |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4938 | } |
| 4939 | |
Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 4940 | void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) { |
| 4941 | AddAPInt(Value.bitcastToAPInt()); |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4944 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4945 | Record.push_back(getIdentifierRef(II)); |
| 4946 | } |
| 4947 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4948 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4949 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4950 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4951 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4952 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4953 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4954 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4955 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4956 | } |
| 4957 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4958 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4959 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 4960 | // have been redefined by the header (in which case they are not |
| 4961 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4962 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4963 | return 0; |
| 4964 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4965 | MacroID &ID = MacroIDs[MI]; |
| 4966 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4967 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4968 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 4969 | MacroInfosToEmit.push_back(Info); |
| 4970 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4971 | return ID; |
| 4972 | } |
| 4973 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4974 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4975 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4976 | return 0; |
| 4977 | |
| 4978 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 4979 | return MacroIDs[MI]; |
| 4980 | } |
| 4981 | |
| 4982 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 4983 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4984 | } |
| 4985 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 4986 | void ASTRecordWriter::AddSelectorRef(const Selector SelRef) { |
| 4987 | Record->push_back(Writer->getSelectorRef(SelRef)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4990 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4991 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4992 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4993 | } |
| 4994 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4995 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4996 | if (SID == 0 && Chain) { |
| 4997 | // This might trigger a ReadSelector callback, which will set the ID for |
| 4998 | // this selector. |
| 4999 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5000 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5001 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5002 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5003 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5004 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5005 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5006 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5009 | void ASTRecordWriter::AddCXXTemporary(const CXXTemporary *Temp) { |
| 5010 | AddDeclRef(Temp->getDestructor()); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5011 | } |
| 5012 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5013 | void ASTRecordWriter::AddTemplateArgumentLocInfo( |
| 5014 | TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5015 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5016 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5017 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5018 | break; |
| 5019 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5020 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5021 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5022 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5023 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5024 | AddSourceLocation(Arg.getTemplateNameLoc()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5025 | break; |
| 5026 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5027 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 5028 | AddSourceLocation(Arg.getTemplateNameLoc()); |
| 5029 | AddSourceLocation(Arg.getTemplateEllipsisLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5030 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5031 | case TemplateArgument::Null: |
| 5032 | case TemplateArgument::Integral: |
| 5033 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5034 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5035 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5036 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5037 | break; |
| 5038 | } |
| 5039 | } |
| 5040 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5041 | void ASTRecordWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg) { |
| 5042 | AddTemplateArgument(Arg.getArgument()); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5043 | |
| 5044 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 5045 | bool InfoHasSameExpr |
| 5046 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5047 | Record->push_back(InfoHasSameExpr); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5048 | if (InfoHasSameExpr) |
| 5049 | return; // Avoid storing the same expr twice. |
| 5050 | } |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5051 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo()); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5052 | } |
| 5053 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5054 | void ASTRecordWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5055 | if (!TInfo) { |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5056 | AddTypeRef(QualType()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5057 | return; |
| 5058 | } |
| 5059 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5060 | AddTypeLoc(TInfo->getTypeLoc()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5061 | } |
| 5062 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5063 | void ASTRecordWriter::AddTypeLoc(TypeLoc TL) { |
| 5064 | AddTypeRef(TL.getType()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5065 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5066 | TypeLocWriter TLW(*this); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5067 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 5068 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5069 | } |
| 5070 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5071 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 5072 | Record.push_back(GetOrCreateTypeID(T)); |
| 5073 | } |
| 5074 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5075 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5076 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5077 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5078 | if (T.isNull()) |
| 5079 | return TypeIdx(); |
| 5080 | assert(!T.getLocalFastQualifiers()); |
| 5081 | |
| 5082 | TypeIdx &Idx = TypeIdxs[T]; |
| 5083 | if (Idx.getIndex() == 0) { |
| 5084 | if (DoneWritingDeclsAndTypes) { |
| 5085 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 5086 | return TypeIdx(); |
| 5087 | } |
| 5088 | |
| 5089 | // We haven't seen this type before. Assign it a new ID and put it |
| 5090 | // into the queue of types to emit. |
| 5091 | Idx = TypeIdx(NextTypeID++); |
| 5092 | DeclTypesToEmit.push(T); |
| 5093 | } |
| 5094 | return Idx; |
| 5095 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 5096 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5097 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 5098 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5099 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5100 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5101 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5102 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5103 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5104 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5105 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 5106 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 5107 | return I->second; |
| 5108 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5109 | } |
| 5110 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5111 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5112 | Record.push_back(GetDeclRef(D)); |
| 5113 | } |
| 5114 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5115 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5116 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5117 | |
| 5118 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5119 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5120 | } |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5121 | |
| 5122 | // If D comes from an AST file, its declaration ID is already known and |
| 5123 | // fixed. |
| 5124 | if (D->isFromASTFile()) |
| 5125 | return D->getGlobalID(); |
| 5126 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5127 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5128 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5129 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5130 | if (DoneWritingDeclsAndTypes) { |
| 5131 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 5132 | return 0; |
| 5133 | } |
| 5134 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5135 | // We haven't seen this declaration before. Give it a new ID and |
| 5136 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5137 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5138 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5139 | } |
| 5140 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5141 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5142 | } |
| 5143 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5144 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5145 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5146 | return 0; |
| 5147 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5148 | // If D comes from an AST file, its declaration ID is already known and |
| 5149 | // fixed. |
| 5150 | if (D->isFromASTFile()) |
| 5151 | return D->getGlobalID(); |
| 5152 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5153 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 5154 | return DeclIDs[D]; |
| 5155 | } |
| 5156 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5157 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5158 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5159 | assert(D); |
| 5160 | |
| 5161 | SourceLocation Loc = D->getLocation(); |
| 5162 | if (Loc.isInvalid()) |
| 5163 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5164 | |
| 5165 | // We only keep track of the file-level declarations of each file. |
| 5166 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 5167 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5168 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 5169 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5170 | if (isa<ParmVarDecl>(D)) |
| 5171 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5172 | |
| 5173 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5174 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5175 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5176 | FileID FID; |
| 5177 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5178 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5179 | if (FID.isInvalid()) |
| 5180 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5181 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5182 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5183 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5184 | if (!Info) |
| 5185 | Info = new DeclIDInFileInfo(); |
| 5186 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5187 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5188 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 5189 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5190 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5191 | Decls.push_back(LocDecl); |
| 5192 | return; |
| 5193 | } |
| 5194 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5195 | LocDeclIDsTy::iterator I = |
| 5196 | std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5197 | |
| 5198 | Decls.insert(I, LocDecl); |
| 5199 | } |
| 5200 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5201 | void ASTRecordWriter::AddDeclarationName(DeclarationName Name) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 5202 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5203 | Record->push_back(Name.getNameKind()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5204 | switch (Name.getNameKind()) { |
| 5205 | case DeclarationName::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5206 | AddIdentifierRef(Name.getAsIdentifierInfo()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5207 | break; |
| 5208 | |
| 5209 | case DeclarationName::ObjCZeroArgSelector: |
| 5210 | case DeclarationName::ObjCOneArgSelector: |
| 5211 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5212 | AddSelectorRef(Name.getObjCSelector()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5213 | break; |
| 5214 | |
| 5215 | case DeclarationName::CXXConstructorName: |
| 5216 | case DeclarationName::CXXDestructorName: |
| 5217 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5218 | AddTypeRef(Name.getCXXNameType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5219 | break; |
| 5220 | |
| 5221 | case DeclarationName::CXXOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5222 | Record->push_back(Name.getCXXOverloadedOperator()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5223 | break; |
| 5224 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5225 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5226 | AddIdentifierRef(Name.getCXXLiteralIdentifier()); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5227 | break; |
| 5228 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5229 | case DeclarationName::CXXUsingDirective: |
| 5230 | // No extra data to emit |
| 5231 | break; |
| 5232 | } |
| 5233 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5234 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5235 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5236 | assert(needsAnonymousDeclarationNumber(D) && |
| 5237 | "expected an anonymous declaration"); |
| 5238 | |
| 5239 | // Number the anonymous declarations within this context, if we've not |
| 5240 | // already done so. |
| 5241 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5242 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5243 | auto *DC = D->getLexicalDeclContext(); |
| 5244 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5245 | AnonymousDeclarationNumbers[ND] = Number; |
| 5246 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5247 | |
| 5248 | It = AnonymousDeclarationNumbers.find(D); |
| 5249 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5250 | "declaration not found within its lexical context"); |
| 5251 | } |
| 5252 | |
| 5253 | return It->second; |
| 5254 | } |
| 5255 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5256 | void ASTRecordWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
| 5257 | DeclarationName Name) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5258 | switch (Name.getNameKind()) { |
| 5259 | case DeclarationName::CXXConstructorName: |
| 5260 | case DeclarationName::CXXDestructorName: |
| 5261 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5262 | AddTypeSourceInfo(DNLoc.NamedType.TInfo); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5263 | break; |
| 5264 | |
| 5265 | case DeclarationName::CXXOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5266 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5267 | DNLoc.CXXOperatorName.BeginOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5268 | AddSourceLocation( |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5269 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5270 | break; |
| 5271 | |
| 5272 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5273 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5274 | DNLoc.CXXLiteralOperatorName.OpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5275 | break; |
| 5276 | |
| 5277 | case DeclarationName::Identifier: |
| 5278 | case DeclarationName::ObjCZeroArgSelector: |
| 5279 | case DeclarationName::ObjCOneArgSelector: |
| 5280 | case DeclarationName::ObjCMultiArgSelector: |
| 5281 | case DeclarationName::CXXUsingDirective: |
| 5282 | break; |
| 5283 | } |
| 5284 | } |
| 5285 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5286 | void ASTRecordWriter::AddDeclarationNameInfo( |
| 5287 | const DeclarationNameInfo &NameInfo) { |
| 5288 | AddDeclarationName(NameInfo.getName()); |
| 5289 | AddSourceLocation(NameInfo.getLoc()); |
| 5290 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName()); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5291 | } |
| 5292 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5293 | void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { |
| 5294 | AddNestedNameSpecifierLoc(Info.QualifierLoc); |
| 5295 | Record->push_back(Info.NumTemplParamLists); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5296 | for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5297 | AddTemplateParameterList(Info.TemplParamLists[i]); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5298 | } |
| 5299 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5300 | void ASTRecordWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5301 | // 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] | 5302 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5303 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5304 | |
| 5305 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5306 | while (NNS) { |
| 5307 | NestedNames.push_back(NNS); |
| 5308 | NNS = NNS->getPrefix(); |
| 5309 | } |
| 5310 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5311 | Record->push_back(NestedNames.size()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5312 | while(!NestedNames.empty()) { |
| 5313 | NNS = NestedNames.pop_back_val(); |
| 5314 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5315 | Record->push_back(Kind); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5316 | switch (Kind) { |
| 5317 | case NestedNameSpecifier::Identifier: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5318 | AddIdentifierRef(NNS->getAsIdentifier()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5319 | break; |
| 5320 | |
| 5321 | case NestedNameSpecifier::Namespace: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5322 | AddDeclRef(NNS->getAsNamespace()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5323 | break; |
| 5324 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5325 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5326 | AddDeclRef(NNS->getAsNamespaceAlias()); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5327 | break; |
| 5328 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5329 | case NestedNameSpecifier::TypeSpec: |
| 5330 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5331 | AddTypeRef(QualType(NNS->getAsType(), 0)); |
| 5332 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5333 | break; |
| 5334 | |
| 5335 | case NestedNameSpecifier::Global: |
| 5336 | // Don't need to write an associated value. |
| 5337 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5338 | |
| 5339 | case NestedNameSpecifier::Super: |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5340 | AddDeclRef(NNS->getAsRecordDecl()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5341 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5342 | } |
| 5343 | } |
| 5344 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5345 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5346 | void ASTRecordWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5347 | // 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] | 5348 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5349 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5350 | |
| 5351 | // Push each of the nested-name-specifiers's onto a stack for |
| 5352 | // serialization in reverse order. |
| 5353 | while (NNS) { |
| 5354 | NestedNames.push_back(NNS); |
| 5355 | NNS = NNS.getPrefix(); |
| 5356 | } |
| 5357 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5358 | Record->push_back(NestedNames.size()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5359 | while(!NestedNames.empty()) { |
| 5360 | NNS = NestedNames.pop_back_val(); |
| 5361 | NestedNameSpecifier::SpecifierKind Kind |
| 5362 | = NNS.getNestedNameSpecifier()->getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5363 | Record->push_back(Kind); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5364 | switch (Kind) { |
| 5365 | case NestedNameSpecifier::Identifier: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5366 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier()); |
| 5367 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5368 | break; |
| 5369 | |
| 5370 | case NestedNameSpecifier::Namespace: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5371 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace()); |
| 5372 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5373 | break; |
| 5374 | |
| 5375 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5376 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias()); |
| 5377 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5378 | break; |
| 5379 | |
| 5380 | case NestedNameSpecifier::TypeSpec: |
| 5381 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5382 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5383 | AddTypeLoc(NNS.getTypeLoc()); |
| 5384 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5385 | break; |
| 5386 | |
| 5387 | case NestedNameSpecifier::Global: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5388 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5389 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5390 | |
| 5391 | case NestedNameSpecifier::Super: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5392 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl()); |
| 5393 | AddSourceRange(NNS.getLocalSourceRange()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5394 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5395 | } |
| 5396 | } |
| 5397 | } |
| 5398 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5399 | void ASTRecordWriter::AddTemplateName(TemplateName Name) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5400 | TemplateName::NameKind Kind = Name.getKind(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5401 | Record->push_back(Kind); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5402 | switch (Kind) { |
| 5403 | case TemplateName::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5404 | AddDeclRef(Name.getAsTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5405 | break; |
| 5406 | |
| 5407 | case TemplateName::OverloadedTemplate: { |
| 5408 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5409 | Record->push_back(OvT->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5410 | for (const auto &I : *OvT) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5411 | AddDeclRef(I); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5412 | break; |
| 5413 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5414 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5415 | case TemplateName::QualifiedTemplate: { |
| 5416 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5417 | AddNestedNameSpecifier(QualT->getQualifier()); |
| 5418 | Record->push_back(QualT->hasTemplateKeyword()); |
| 5419 | AddDeclRef(QualT->getTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5420 | break; |
| 5421 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5422 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5423 | case TemplateName::DependentTemplate: { |
| 5424 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5425 | AddNestedNameSpecifier(DepT->getQualifier()); |
| 5426 | Record->push_back(DepT->isIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5427 | if (DepT->isIdentifier()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5428 | AddIdentifierRef(DepT->getIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5429 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5430 | Record->push_back(DepT->getOperator()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5431 | break; |
| 5432 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5433 | |
| 5434 | case TemplateName::SubstTemplateTemplateParm: { |
| 5435 | SubstTemplateTemplateParmStorage *subst |
| 5436 | = Name.getAsSubstTemplateTemplateParm(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5437 | AddDeclRef(subst->getParameter()); |
| 5438 | AddTemplateName(subst->getReplacement()); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5439 | break; |
| 5440 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5441 | |
| 5442 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5443 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5444 | = Name.getAsSubstTemplateTemplateParmPack(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5445 | AddDeclRef(SubstPack->getParameterPack()); |
| 5446 | AddTemplateArgument(SubstPack->getArgumentPack()); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5447 | break; |
| 5448 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5449 | } |
| 5450 | } |
| 5451 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5452 | void ASTRecordWriter::AddTemplateArgument(const TemplateArgument &Arg) { |
| 5453 | Record->push_back(Arg.getKind()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5454 | switch (Arg.getKind()) { |
| 5455 | case TemplateArgument::Null: |
| 5456 | break; |
| 5457 | case TemplateArgument::Type: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5458 | AddTypeRef(Arg.getAsType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5459 | break; |
| 5460 | case TemplateArgument::Declaration: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5461 | AddDeclRef(Arg.getAsDecl()); |
| 5462 | AddTypeRef(Arg.getParamTypeForDecl()); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5463 | break; |
| 5464 | case TemplateArgument::NullPtr: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5465 | AddTypeRef(Arg.getNullPtrType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5466 | break; |
| 5467 | case TemplateArgument::Integral: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5468 | AddAPSInt(Arg.getAsIntegral()); |
| 5469 | AddTypeRef(Arg.getIntegralType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5470 | break; |
| 5471 | case TemplateArgument::Template: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5472 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5473 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5474 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5475 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5476 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5477 | Record->push_back(*NumExpansions + 1); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5478 | else |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5479 | Record->push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5480 | break; |
| 5481 | case TemplateArgument::Expression: |
| 5482 | AddStmt(Arg.getAsExpr()); |
| 5483 | break; |
| 5484 | case TemplateArgument::Pack: |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5485 | Record->push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 5486 | for (const auto &P : Arg.pack_elements()) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5487 | AddTemplateArgument(P); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5488 | break; |
| 5489 | } |
| 5490 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5491 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5492 | void ASTRecordWriter::AddTemplateParameterList( |
| 5493 | const TemplateParameterList *TemplateParams) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5494 | assert(TemplateParams && "No TemplateParams!"); |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5495 | AddSourceLocation(TemplateParams->getTemplateLoc()); |
| 5496 | AddSourceLocation(TemplateParams->getLAngleLoc()); |
| 5497 | AddSourceLocation(TemplateParams->getRAngleLoc()); |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 5498 | // TODO: Concepts |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5499 | Record->push_back(TemplateParams->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5500 | for (const auto &P : *TemplateParams) |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5501 | AddDeclRef(P); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | /// \brief Emit a template argument list. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5505 | void ASTRecordWriter::AddTemplateArgumentList( |
| 5506 | const TemplateArgumentList *TemplateArgs) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5507 | assert(TemplateArgs && "No TemplateArgs!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5508 | Record->push_back(TemplateArgs->size()); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5509 | for (int i = 0, e = TemplateArgs->size(); i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5510 | AddTemplateArgument(TemplateArgs->get(i)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5511 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5512 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5513 | void ASTRecordWriter::AddASTTemplateArgumentListInfo( |
| 5514 | const ASTTemplateArgumentListInfo *ASTTemplArgList) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5515 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5516 | AddSourceLocation(ASTTemplArgList->LAngleLoc); |
| 5517 | AddSourceLocation(ASTTemplArgList->RAngleLoc); |
| 5518 | Record->push_back(ASTTemplArgList->NumTemplateArgs); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5519 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5520 | for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5521 | AddTemplateArgumentLoc(TemplArgs[i]); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5522 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5523 | |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5524 | void ASTRecordWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set) { |
| 5525 | Record->push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5526 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5527 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5528 | AddDeclRef(I.getDecl()); |
| 5529 | Record->push_back(I.getAccess()); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5530 | } |
| 5531 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5532 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5533 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5534 | void ASTRecordWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base) { |
| 5535 | Record->push_back(Base.isVirtual()); |
| 5536 | Record->push_back(Base.isBaseOfClass()); |
| 5537 | Record->push_back(Base.getAccessSpecifierAsWritten()); |
| 5538 | Record->push_back(Base.getInheritConstructors()); |
| 5539 | AddTypeSourceInfo(Base.getTypeSourceInfo()); |
| 5540 | AddSourceRange(Base.getSourceRange()); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5541 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5542 | : SourceLocation()); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5543 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5544 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5545 | static uint64_t EmitCXXBaseSpecifiers(ASTWriter &W, |
| 5546 | ArrayRef<CXXBaseSpecifier> Bases) { |
| 5547 | ASTWriter::RecordData Record; |
| 5548 | ASTRecordWriter Writer(W, Record); |
| 5549 | Writer.push_back(Bases.size()); |
Dmitry Polukhin | 790b540 | 2016-04-06 10:01:46 +0000 | [diff] [blame] | 5550 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5551 | for (auto &Base : Bases) |
| 5552 | Writer.AddCXXBaseSpecifier(Base); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5553 | |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5554 | return Writer.Emit(serialization::DECL_CXX_BASE_SPECIFIERS); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5555 | } |
| 5556 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5557 | // FIXME: Move this out of the main ASTRecordWriter interface. |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5558 | void ASTRecordWriter::AddCXXBaseSpecifiers(ArrayRef<CXXBaseSpecifier> Bases) { |
| 5559 | AddOffset(EmitCXXBaseSpecifiers(*Writer, Bases)); |
| 5560 | } |
| 5561 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5562 | static uint64_t |
| 5563 | EmitCXXCtorInitializers(ASTWriter &W, |
| 5564 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 5565 | ASTWriter::RecordData Record; |
| 5566 | ASTRecordWriter Writer(W, Record); |
| 5567 | Writer.push_back(CtorInits.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5568 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5569 | for (auto *Init : CtorInits) { |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5570 | if (Init->isBaseInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5571 | Writer.push_back(CTOR_INITIALIZER_BASE); |
| 5572 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
| 5573 | Writer.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5574 | } else if (Init->isDelegatingInitializer()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5575 | Writer.push_back(CTOR_INITIALIZER_DELEGATING); |
| 5576 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5577 | } else if (Init->isMemberInitializer()){ |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5578 | Writer.push_back(CTOR_INITIALIZER_MEMBER); |
| 5579 | Writer.AddDeclRef(Init->getMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5580 | } else { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5581 | Writer.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 5582 | Writer.AddDeclRef(Init->getIndirectMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5583 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5584 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5585 | Writer.AddSourceLocation(Init->getMemberLocation()); |
| 5586 | Writer.AddStmt(Init->getInit()); |
| 5587 | Writer.AddSourceLocation(Init->getLParenLoc()); |
| 5588 | Writer.AddSourceLocation(Init->getRParenLoc()); |
| 5589 | Writer.push_back(Init->isWritten()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5590 | if (Init->isWritten()) { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5591 | Writer.push_back(Init->getSourceOrder()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5592 | } else { |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5593 | Writer.push_back(Init->getNumArrayIndices()); |
| 5594 | for (auto *VD : Init->getArrayIndices()) |
| 5595 | Writer.AddDeclRef(VD); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5596 | } |
| 5597 | } |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5598 | |
| 5599 | return Writer.Emit(serialization::DECL_CXX_CTOR_INITIALIZERS); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5600 | } |
| 5601 | |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5602 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5603 | void ASTRecordWriter::AddCXXCtorInitializers( |
| 5604 | ArrayRef<CXXCtorInitializer *> CtorInits) { |
| 5605 | AddOffset(EmitCXXCtorInitializers(*Writer, CtorInits)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5608 | void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5609 | auto &Data = D->data(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5610 | Record->push_back(Data.IsLambda); |
| 5611 | Record->push_back(Data.UserDeclaredConstructor); |
| 5612 | Record->push_back(Data.UserDeclaredSpecialMembers); |
| 5613 | Record->push_back(Data.Aggregate); |
| 5614 | Record->push_back(Data.PlainOldData); |
| 5615 | Record->push_back(Data.Empty); |
| 5616 | Record->push_back(Data.Polymorphic); |
| 5617 | Record->push_back(Data.Abstract); |
| 5618 | Record->push_back(Data.IsStandardLayout); |
| 5619 | Record->push_back(Data.HasNoNonEmptyBases); |
| 5620 | Record->push_back(Data.HasPrivateFields); |
| 5621 | Record->push_back(Data.HasProtectedFields); |
| 5622 | Record->push_back(Data.HasPublicFields); |
| 5623 | Record->push_back(Data.HasMutableFields); |
| 5624 | Record->push_back(Data.HasVariantMembers); |
| 5625 | Record->push_back(Data.HasOnlyCMembers); |
| 5626 | Record->push_back(Data.HasInClassInitializer); |
| 5627 | Record->push_back(Data.HasUninitializedReferenceMember); |
| 5628 | Record->push_back(Data.HasUninitializedFields); |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 5629 | Record->push_back(Data.HasInheritedConstructor); |
| 5630 | Record->push_back(Data.HasInheritedAssignment); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5631 | Record->push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 5632 | Record->push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 5633 | Record->push_back(Data.NeedOverloadResolutionForDestructor); |
| 5634 | Record->push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 5635 | Record->push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 5636 | Record->push_back(Data.DefaultedDestructorIsDeleted); |
| 5637 | Record->push_back(Data.HasTrivialSpecialMembers); |
| 5638 | Record->push_back(Data.DeclaredNonTrivialSpecialMembers); |
| 5639 | Record->push_back(Data.HasIrrelevantDestructor); |
| 5640 | Record->push_back(Data.HasConstexprNonCopyMoveConstructor); |
| 5641 | Record->push_back(Data.HasDefaultedDefaultConstructor); |
| 5642 | Record->push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
| 5643 | Record->push_back(Data.HasConstexprDefaultConstructor); |
| 5644 | Record->push_back(Data.HasNonLiteralTypeFieldsOrBases); |
| 5645 | Record->push_back(Data.ComputedVisibleConversions); |
| 5646 | Record->push_back(Data.UserProvidedDefaultConstructor); |
| 5647 | Record->push_back(Data.DeclaredSpecialMembers); |
| 5648 | Record->push_back(Data.ImplicitCopyConstructorHasConstParam); |
| 5649 | Record->push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 5650 | Record->push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 5651 | Record->push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5652 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5653 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5654 | Record->push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5655 | if (Data.NumBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5656 | AddCXXBaseSpecifiers(Data.bases()); |
| 5657 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5658 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5659 | Record->push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5660 | if (Data.NumVBases > 0) |
Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5661 | AddCXXBaseSpecifiers(Data.vbases()); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5662 | |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5663 | AddUnresolvedSet(Data.Conversions.get(*Writer->Context)); |
| 5664 | AddUnresolvedSet(Data.VisibleConversions.get(*Writer->Context)); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5665 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5666 | AddDeclRef(D->getFirstFriend()); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5667 | |
| 5668 | // Add lambda-specific data. |
| 5669 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5670 | auto &Lambda = D->getLambdaData(); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5671 | Record->push_back(Lambda.Dependent); |
| 5672 | Record->push_back(Lambda.IsGenericLambda); |
| 5673 | Record->push_back(Lambda.CaptureDefault); |
| 5674 | Record->push_back(Lambda.NumCaptures); |
| 5675 | Record->push_back(Lambda.NumExplicitCaptures); |
| 5676 | Record->push_back(Lambda.ManglingNumber); |
Richard Smith | 0bae624 | 2016-08-25 00:34:00 +0000 | [diff] [blame] | 5677 | AddDeclRef(D->getLambdaContextDecl()); |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5678 | AddTypeSourceInfo(Lambda.MethodTyInfo); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5679 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 5680 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5681 | AddSourceLocation(Capture.getLocation()); |
| 5682 | Record->push_back(Capture.isImplicit()); |
| 5683 | Record->push_back(Capture.getCaptureKind()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5684 | switch (Capture.getCaptureKind()) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 5685 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5686 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 5687 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5688 | break; |
| 5689 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 5690 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5691 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5692 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5693 | AddDeclRef(Var); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5694 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5695 | : SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5696 | break; |
| 5697 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5698 | } |
| 5699 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5700 | } |
| 5701 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5702 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5703 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5704 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5705 | assert(FirstDeclID == NextDeclID && |
| 5706 | FirstTypeID == NextTypeID && |
| 5707 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5708 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5709 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5710 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5711 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5712 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5713 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5714 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 5715 | // Note, this will get called multiple times, once one the reader starts up |
| 5716 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5717 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 5718 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 5719 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5720 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5721 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5722 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5723 | NextDeclID = FirstDeclID; |
| 5724 | NextTypeID = FirstTypeID; |
| 5725 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5726 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5727 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5728 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5729 | } |
| 5730 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5731 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5732 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5733 | IdentID &StoredID = IdentifierIDs[II]; |
| 5734 | if (ID > StoredID) |
| 5735 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5736 | } |
| 5737 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5738 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5739 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5740 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5741 | if (ID > StoredID) |
| 5742 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5743 | } |
| 5744 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5745 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5746 | // Always take the highest-numbered type index. This copes with an interesting |
| 5747 | // 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] | 5748 | // 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] | 5749 | // keep the higher-numbered entry so that we can properly write it out to |
| 5750 | // the AST file. |
| 5751 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 5752 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 5753 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5754 | } |
| 5755 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5756 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5757 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5758 | SelectorID &StoredID = SelectorIDs[S]; |
| 5759 | if (ID > StoredID) |
| 5760 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5761 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5762 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5763 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5764 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5765 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5766 | MacroDefinitions[MD] = ID; |
| 5767 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5768 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 5769 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 5770 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 5771 | SubmoduleIDs[Mod] = ID; |
| 5772 | } |
| 5773 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5774 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5775 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5776 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5777 | assert(!WritingAST && "Already writing the AST!"); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5778 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5779 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5780 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5781 | // A forward reference was mutated into a definition. Rewrite it. |
| 5782 | // FIXME: This happens during template instantiation, should we |
| 5783 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5784 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 5785 | "completed a tag from another module but not by instantiation?"); |
| 5786 | DeclUpdates[RD].push_back( |
| 5787 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5788 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5789 | } |
| 5790 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5791 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5792 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { |
| 5793 | if (D->isFromASTFile()) |
| 5794 | return true; |
| 5795 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5796 | // The predefined __va_list_tag struct is imported if we imported any decls. |
| 5797 | // FIXME: This is a gross hack. |
| 5798 | return D == D->getASTContext().getVaListTagDecl(); |
| 5799 | } |
| 5800 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5801 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5802 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
| 5803 | assert(DC->isLookupContext() && |
Vassil Vassilev | 71eafde | 2016-04-06 20:56:03 +0000 | [diff] [blame] | 5804 | "Should not add lookup results to non-lookup contexts!"); |
| 5805 | |
Vassil Vassilev | 632eac3 | 2016-03-16 11:17:04 +0000 | [diff] [blame] | 5806 | // TU is handled elsewhere. |
| 5807 | if (isa<TranslationUnitDecl>(DC)) |
| 5808 | return; |
| 5809 | |
| 5810 | // Namespaces are handled elsewhere, except for template instantiations of |
| 5811 | // FunctionTemplateDecls in namespaces. We are interested in cases where the |
| 5812 | // local instantiations are added to an imported context. Only happens when |
| 5813 | // adding ADL lookup candidates, for example templated friends. |
| 5814 | if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && |
| 5815 | !isa<FunctionTemplateDecl>(D)) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5816 | return; |
| 5817 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5818 | // We're only interested in cases where a local declaration is added to an |
| 5819 | // imported context. |
| 5820 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) |
| 5821 | return; |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5822 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 5823 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5824 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5825 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5826 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { |
| 5827 | // We're adding a visible declaration to a predefined decl context. Ensure |
| 5828 | // that we write out all of its lookup results so we don't get a nasty |
| 5829 | // surprise when we try to emit its lookup table. |
| 5830 | for (auto *Child : DC->decls()) |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 5831 | DeclsToEmitEvenIfUnreferenced.push_back(Child); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5832 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 5833 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5834 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5835 | |
| 5836 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5837 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5838 | assert(D->isImplicit()); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5839 | |
| 5840 | // We're only interested in cases where a local declaration is added to an |
| 5841 | // imported context. |
| 5842 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) |
| 5843 | return; |
| 5844 | |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5845 | if (!isa<CXXMethodDecl>(D)) |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5846 | return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5847 | |
| 5848 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5849 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5850 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5851 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5852 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5853 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5854 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5855 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5856 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 5857 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5858 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5859 | // If we don't already know the exception specification for this redecl |
| 5860 | // chain, add an update record for it. |
| 5861 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 5862 | ->getType() |
| 5863 | ->castAs<FunctionProtoType>() |
| 5864 | ->getExceptionSpecType())) |
| 5865 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 5866 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5867 | } |
| 5868 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5869 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5870 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5871 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5872 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5873 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5874 | DeclUpdates[D].push_back( |
| 5875 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 5876 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5877 | } |
| 5878 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5879 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
| 5880 | const FunctionDecl *Delete) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5881 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5882 | assert(!WritingAST && "Already writing the AST!"); |
| 5883 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5884 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5885 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5886 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 5887 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5888 | } |
| 5889 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5890 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5891 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5892 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5893 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5894 | return; // Declaration not imported from PCH. |
| 5895 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5896 | // Implicit function decl from a PCH was defined. |
| 5897 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5898 | } |
| 5899 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5900 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5901 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5902 | assert(!WritingAST && "Already writing the AST!"); |
| 5903 | if (!D->isFromASTFile()) |
| 5904 | return; |
| 5905 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5906 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5907 | } |
| 5908 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5909 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *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 | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5913 | return; |
| 5914 | |
| 5915 | // Since the actual instantiation is delayed, this really means that we need |
| 5916 | // to update the instantiation location. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5917 | DeclUpdates[D].push_back( |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5918 | DeclUpdate(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER, |
| 5919 | D->getMemberSpecializationInfo()->getPointOfInstantiation())); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5920 | } |
| 5921 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5922 | void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5923 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5924 | assert(!WritingAST && "Already writing the AST!"); |
| 5925 | if (!D->isFromASTFile()) |
| 5926 | return; |
| 5927 | |
| 5928 | DeclUpdates[D].push_back( |
| 5929 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D)); |
| 5930 | } |
| 5931 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 5932 | void ASTWriter::DefaultMemberInitializerInstantiated(const FieldDecl *D) { |
| 5933 | assert(!WritingAST && "Already writing the AST!"); |
| 5934 | if (!D->isFromASTFile()) |
| 5935 | return; |
| 5936 | |
| 5937 | DeclUpdates[D].push_back( |
| 5938 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER, D)); |
| 5939 | } |
| 5940 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5941 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 5942 | const ObjCInterfaceDecl *IFD) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5943 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5944 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5945 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5946 | return; // Declaration not imported from PCH. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5947 | |
| 5948 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 5949 | ObjCClassesWithCategories.insert( |
| 5950 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5951 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 5952 | |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5953 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5954 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5955 | assert(!WritingAST && "Already writing the AST!"); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 5956 | |
| 5957 | // If there is *any* declaration of the entity that's not from an AST file, |
| 5958 | // we can skip writing the update record. We make sure that isUsed() triggers |
| 5959 | // completion of the redeclaration chain of the entity. |
| 5960 | for (auto Prev = D->getMostRecentDecl(); Prev; Prev = Prev->getPreviousDecl()) |
| 5961 | if (IsLocalDecl(Prev)) |
| 5962 | return; |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5963 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5964 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5965 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5966 | |
| 5967 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5968 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5969 | assert(!WritingAST && "Already writing the AST!"); |
| 5970 | if (!D->isFromASTFile()) |
| 5971 | return; |
| 5972 | |
| 5973 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 5974 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5975 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 5976 | void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, |
| 5977 | const Attr *Attr) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5978 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5979 | assert(!WritingAST && "Already writing the AST!"); |
| 5980 | if (!D->isFromASTFile()) |
| 5981 | return; |
| 5982 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 5983 | DeclUpdates[D].push_back( |
| 5984 | DeclUpdate(UPD_DECL_MARKED_OPENMP_DECLARETARGET, Attr)); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5985 | } |
| 5986 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5987 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5988 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5989 | assert(!WritingAST && "Already writing the AST!"); |
| 5990 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5991 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5992 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5993 | |
| 5994 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 5995 | const RecordDecl *Record) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5996 | if (Chain && Chain->isProcessingUpdateRecords()) return; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5997 | assert(!WritingAST && "Already writing the AST!"); |
| 5998 | if (!Record->isFromASTFile()) |
| 5999 | return; |
| 6000 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 6001 | } |
Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6002 | |
| 6003 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6004 | const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) { |
| 6005 | assert(!WritingAST && "Already writing the AST!"); |
| 6006 | |
| 6007 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6008 | return; |
| 6009 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6010 | return; |
| 6011 | |
| 6012 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6013 | } |
| 6014 | |
| 6015 | void ASTWriter::AddedCXXTemplateSpecialization( |
| 6016 | const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) { |
| 6017 | assert(!WritingAST && "Already writing the AST!"); |
| 6018 | |
| 6019 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6020 | return; |
| 6021 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6022 | return; |
| 6023 | |
| 6024 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6025 | } |
| 6026 | |
| 6027 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 6028 | const FunctionDecl *D) { |
| 6029 | assert(!WritingAST && "Already writing the AST!"); |
| 6030 | |
| 6031 | if (!TD->getFirstDecl()->isFromASTFile()) |
| 6032 | return; |
| 6033 | if (Chain && Chain->isProcessingUpdateRecords()) |
| 6034 | return; |
| 6035 | |
| 6036 | DeclsToEmitEvenIfUnreferenced.push_back(D); |
| 6037 | } |