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" |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 15 | #include "clang/Serialization/ModuleFileExtension.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 17 | #include "ASTReaderInternals.h" |
| 18 | #include "MultiOnDiskHashTable.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTContext.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclContextInternals.h" |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclFriend.h" |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclLookups.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" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 27 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 28 | #include "clang/AST/TypeLocVisitor.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 29 | #include "clang/Basic/DiagnosticOptions.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 30 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 31 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 33 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 34 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | cb177f1 | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 35 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 36 | #include "clang/Basic/Version.h" |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 37 | #include "clang/Basic/VersionTuple.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 38 | #include "clang/Lex/HeaderSearch.h" |
| 39 | #include "clang/Lex/HeaderSearchOptions.h" |
| 40 | #include "clang/Lex/MacroInfo.h" |
| 41 | #include "clang/Lex/PreprocessingRecord.h" |
| 42 | #include "clang/Lex/Preprocessor.h" |
| 43 | #include "clang/Lex/PreprocessorOptions.h" |
| 44 | #include "clang/Sema/IdentifierResolver.h" |
| 45 | #include "clang/Sema/Sema.h" |
| 46 | #include "clang/Serialization/ASTReader.h" |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 47 | #include "clang/Serialization/SerializationDiagnostic.h" |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 48 | #include "llvm/ADT/APFloat.h" |
| 49 | #include "llvm/ADT/APInt.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 50 | #include "llvm/ADT/Hashing.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 51 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 52 | #include "llvm/Bitcode/BitstreamWriter.h" |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 53 | #include "llvm/Support/Compression.h" |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 54 | #include "llvm/Support/EndianStream.h" |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 55 | #include "llvm/Support/FileSystem.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 56 | #include "llvm/Support/MemoryBuffer.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 57 | #include "llvm/Support/OnDiskHashTable.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 58 | #include "llvm/Support/Path.h" |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 59 | #include "llvm/Support/Process.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 60 | #include <algorithm> |
Chris Lattner | 225dd6c | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 61 | #include <cstdio> |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 62 | #include <string.h> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 63 | #include <utility> |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 64 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 65 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 66 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 67 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 68 | template <typename T, typename Allocator> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 69 | static StringRef bytes(const std::vector<T, Allocator> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 70 | if (v.empty()) return StringRef(); |
| 71 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 72 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 73 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 74 | |
| 75 | template <typename T> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 76 | static StringRef bytes(const SmallVectorImpl<T> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 77 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 78 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 81 | //===----------------------------------------------------------------------===// |
| 82 | // Type serialization |
| 83 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 84 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 85 | namespace clang { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 86 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 87 | ASTWriter &Writer; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 88 | ASTRecordWriter Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 89 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 90 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 91 | TypeCode Code; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 92 | /// \brief Abbreviation to use for the record, if any. |
| 93 | unsigned AbbrevToUse; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 94 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 95 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 96 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 97 | : Writer(Writer), Record(Writer, Record), Code((TypeCode)0), AbbrevToUse(0) { } |
| 98 | |
| 99 | uint64_t Emit() { |
| 100 | return Record.Emit(Code, AbbrevToUse); |
| 101 | } |
| 102 | |
| 103 | void Visit(QualType T) { |
| 104 | if (T.hasLocalNonFastQualifiers()) { |
| 105 | Qualifiers Qs = T.getLocalQualifiers(); |
| 106 | Record.AddTypeRef(T.getLocalUnqualifiedType()); |
| 107 | Record.push_back(Qs.getAsOpaqueValue()); |
| 108 | Code = TYPE_EXT_QUAL; |
| 109 | AbbrevToUse = Writer.TypeExtQualAbbrev; |
| 110 | } else { |
| 111 | switch (T->getTypeClass()) { |
| 112 | // For all of the concrete, non-dependent types, call the |
| 113 | // appropriate visitor function. |
| 114 | #define TYPE(Class, Base) \ |
| 115 | case Type::Class: Visit##Class##Type(cast<Class##Type>(T)); break; |
| 116 | #define ABSTRACT_TYPE(Class, Base) |
| 117 | #include "clang/AST/TypeNodes.def" |
| 118 | } |
| 119 | } |
| 120 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 121 | |
| 122 | void VisitArrayType(const ArrayType *T); |
| 123 | void VisitFunctionType(const FunctionType *T); |
| 124 | void VisitTagType(const TagType *T); |
| 125 | |
| 126 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 127 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 128 | #include "clang/AST/TypeNodes.def" |
| 129 | }; |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 130 | } // end namespace clang |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 131 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 132 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 133 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 136 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 137 | Record.AddTypeRef(T->getElementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 138 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 141 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 142 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 143 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 146 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 147 | Record.AddTypeRef(T->getOriginalType()); |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 148 | Code = TYPE_DECAYED; |
| 149 | } |
| 150 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 151 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 152 | Record.AddTypeRef(T->getOriginalType()); |
| 153 | Record.AddTypeRef(T->getAdjustedType()); |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 154 | Code = TYPE_ADJUSTED; |
| 155 | } |
| 156 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 157 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 158 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 159 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 162 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 163 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 164 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 165 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 168 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 169 | Record.AddTypeRef(T->getPointeeTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 170 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 173 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 174 | Record.AddTypeRef(T->getPointeeType()); |
| 175 | Record.AddTypeRef(QualType(T->getClass(), 0)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 176 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 179 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 180 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 181 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 182 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 185 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 186 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 187 | Record.AddAPInt(T->getSize()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 188 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 191 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 192 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 193 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 196 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 197 | VisitArrayType(T); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 198 | Record.AddSourceLocation(T->getLBracketLoc()); |
| 199 | Record.AddSourceLocation(T->getRBracketLoc()); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 200 | Record.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 201 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 204 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 205 | Record.AddTypeRef(T->getElementType()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 206 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 207 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 208 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 211 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 212 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 213 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 216 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 217 | Record.AddTypeRef(T->getReturnType()); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 218 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 219 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 220 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 221 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 222 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 223 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 224 | Record.push_back(C.getProducesResult()); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 225 | |
| 226 | if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult()) |
| 227 | AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 230 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 231 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 232 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 235 | static void addExceptionSpec(const FunctionProtoType *T, |
| 236 | ASTRecordWriter &Record) { |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 237 | Record.push_back(T->getExceptionSpecType()); |
| 238 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 239 | Record.push_back(T->getNumExceptions()); |
| 240 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 241 | Record.AddTypeRef(T->getExceptionType(I)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 242 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 243 | Record.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 244 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 245 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
| 246 | Record.AddDeclRef(T->getExceptionSpecTemplate()); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 247 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 248 | Record.AddDeclRef(T->getExceptionSpecDecl()); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 249 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 253 | VisitFunctionType(T); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 254 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 255 | Record.push_back(T->isVariadic()); |
| 256 | Record.push_back(T->hasTrailingReturn()); |
| 257 | Record.push_back(T->getTypeQuals()); |
| 258 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 259 | addExceptionSpec(T, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 260 | |
| 261 | Record.push_back(T->getNumParams()); |
| 262 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 263 | Record.AddTypeRef(T->getParamType(I)); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 264 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 265 | if (T->hasExtParameterInfos()) { |
| 266 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 267 | Record.push_back(T->getExtParameterInfo(I).getOpaqueValue()); |
| 268 | } |
| 269 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 270 | if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 271 | T->getRefQualifier() || T->getExceptionSpecType() != EST_None || |
| 272 | T->hasExtParameterInfos()) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 273 | AbbrevToUse = 0; |
| 274 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 275 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 278 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 279 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 280 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 281 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 282 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 283 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 284 | Record.AddDeclRef(T->getDecl()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 285 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 286 | Record.AddTypeRef(T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 287 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 290 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 291 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 292 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 295 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 296 | Record.AddTypeRef(T->getUnderlyingType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 297 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 300 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 301 | Record.AddTypeRef(T->getUnderlyingType()); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 302 | Record.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 303 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 306 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 307 | Record.AddTypeRef(T->getBaseType()); |
| 308 | Record.AddTypeRef(T->getUnderlyingType()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 309 | Record.push_back(T->getUTTKind()); |
| 310 | Code = TYPE_UNARY_TRANSFORM; |
| 311 | } |
| 312 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 313 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 314 | Record.AddTypeRef(T->getDeducedType()); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 315 | Record.push_back((unsigned)T->getKeyword()); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 316 | if (T->getDeducedType().isNull()) |
| 317 | Record.push_back(T->isDependentType()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 318 | Code = TYPE_AUTO; |
| 319 | } |
| 320 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 321 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 322 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 323 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 324 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 325 | "Cannot serialize in the middle of a type definition"); |
| 326 | } |
| 327 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 328 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 329 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 330 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 333 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 334 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 335 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 336 | } |
| 337 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 338 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 339 | Record.AddTypeRef(T->getModifiedType()); |
| 340 | Record.AddTypeRef(T->getEquivalentType()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 341 | Record.push_back(T->getAttrKind()); |
| 342 | Code = TYPE_ATTRIBUTED; |
| 343 | } |
| 344 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 345 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 346 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 347 | const SubstTemplateTypeParmType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 348 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 349 | Record.AddTypeRef(T->getReplacementType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 350 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 354 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 355 | const SubstTemplateTypeParmPackType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 356 | Record.AddTypeRef(QualType(T->getReplacedParameter(), 0)); |
| 357 | Record.AddTemplateArgument(T->getArgumentPack()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 358 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 359 | } |
| 360 | |
| 361 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 362 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 363 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 364 | Record.push_back(T->isDependentType()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 365 | Record.AddTemplateName(T->getTemplateName()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 366 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 367 | for (const auto &ArgI : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 368 | Record.AddTemplateArgument(ArgI); |
| 369 | Record.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() |
| 370 | : T->isCanonicalUnqualified() |
| 371 | ? QualType() |
| 372 | : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 373 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 377 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 378 | VisitArrayType(T); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 379 | Record.AddStmt(T->getSizeExpr()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 380 | Record.AddSourceRange(T->getBracketsRange()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 381 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 385 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 386 | const DependentSizedExtVectorType *T) { |
| 387 | // FIXME: Serialize this type (C++ only) |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 388 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 392 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 393 | Record.push_back(T->getDepth()); |
| 394 | Record.push_back(T->getIndex()); |
| 395 | Record.push_back(T->isParameterPack()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 396 | Record.AddDeclRef(T->getDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 397 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 401 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 402 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 403 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 404 | Record.AddIdentifierRef(T->getIdentifier()); |
| 405 | Record.AddTypeRef( |
| 406 | T->isCanonicalUnqualified() ? QualType() : T->getCanonicalTypeInternal()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 407 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 411 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 412 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 413 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 414 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 415 | Record.AddIdentifierRef(T->getIdentifier()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 416 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 417 | for (const auto &I : *T) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 418 | Record.AddTemplateArgument(I); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 419 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 422 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 423 | Record.AddTypeRef(T->getPattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 424 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 425 | Record.push_back(*NumExpansions + 1); |
| 426 | else |
| 427 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 428 | Code = TYPE_PACK_EXPANSION; |
| 429 | } |
| 430 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 431 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 432 | Record.AddTypeRef(T->getInnerType()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 433 | Code = TYPE_PAREN; |
| 434 | } |
| 435 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 436 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 437 | Record.push_back(T->getKeyword()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 438 | Record.AddNestedNameSpecifier(T->getQualifier()); |
| 439 | Record.AddTypeRef(T->getNamedType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 440 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 443 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 444 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
| 445 | Record.AddTypeRef(T->getInjectedSpecializationType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 446 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 449 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 450 | Record.AddDeclRef(T->getDecl()->getCanonicalDecl()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 451 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 454 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 455 | Record.AddTypeRef(T->getBaseType()); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 456 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 457 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 458 | Record.AddTypeRef(TypeArg); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 459 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 460 | for (const auto *I : T->quals()) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 461 | Record.AddDeclRef(I); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 462 | Record.push_back(T->isKindOfTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 463 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 466 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 467 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 468 | Record.AddTypeRef(T->getPointeeType()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 469 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 472 | void |
| 473 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 474 | Record.AddTypeRef(T->getValueType()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 475 | Code = TYPE_ATOMIC; |
| 476 | } |
| 477 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 478 | void |
| 479 | ASTTypeWriter::VisitPipeType(const PipeType *T) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 480 | Record.AddTypeRef(T->getElementType()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 481 | Code = TYPE_PIPE; |
| 482 | } |
| 483 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 484 | namespace { |
| 485 | |
| 486 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 487 | ASTRecordWriter &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 488 | |
| 489 | public: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 490 | TypeLocWriter(ASTRecordWriter &Record) |
| 491 | : Record(Record) { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 492 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 493 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 494 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 495 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 496 | #include "clang/AST/TypeLocNodes.def" |
| 497 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 498 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 499 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 500 | }; |
| 501 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 502 | } // end anonymous namespace |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 503 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 504 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 505 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 506 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 507 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 508 | Record.AddSourceLocation(TL.getBuiltinLoc()); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 509 | if (TL.needsExtraLocalData()) { |
| 510 | Record.push_back(TL.getWrittenTypeSpec()); |
| 511 | Record.push_back(TL.getWrittenSignSpec()); |
| 512 | Record.push_back(TL.getWrittenWidthSpec()); |
| 513 | Record.push_back(TL.hasModeAttr()); |
| 514 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 515 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 516 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 517 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 518 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 519 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 520 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 521 | } |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 522 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 523 | // nothing to do |
| 524 | } |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 525 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 526 | // nothing to do |
| 527 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 528 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 529 | Record.AddSourceLocation(TL.getCaretLoc()); |
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 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 532 | Record.AddSourceLocation(TL.getAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 533 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 534 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 535 | Record.AddSourceLocation(TL.getAmpAmpLoc()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 536 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 537 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 538 | Record.AddSourceLocation(TL.getStarLoc()); |
| 539 | Record.AddTypeSourceInfo(TL.getClassTInfo()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 540 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 541 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 542 | Record.AddSourceLocation(TL.getLBracketLoc()); |
| 543 | Record.AddSourceLocation(TL.getRBracketLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 544 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 545 | if (TL.getSizeExpr()) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 546 | Record.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 547 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 548 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 549 | VisitArrayTypeLoc(TL); |
| 550 | } |
| 551 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 552 | VisitArrayTypeLoc(TL); |
| 553 | } |
| 554 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 555 | VisitArrayTypeLoc(TL); |
| 556 | } |
| 557 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 558 | DependentSizedArrayTypeLoc TL) { |
| 559 | VisitArrayTypeLoc(TL); |
| 560 | } |
| 561 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 562 | DependentSizedExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 563 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 564 | } |
| 565 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 566 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 567 | } |
| 568 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 569 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 570 | } |
| 571 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 572 | Record.AddSourceLocation(TL.getLocalRangeBegin()); |
| 573 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 574 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 575 | Record.AddSourceLocation(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 576 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 577 | Record.AddDeclRef(TL.getParam(i)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 578 | } |
| 579 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 580 | VisitFunctionTypeLoc(TL); |
| 581 | } |
| 582 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 583 | VisitFunctionTypeLoc(TL); |
| 584 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 585 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 586 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 587 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 588 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 589 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 590 | } |
| 591 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 592 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 593 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 594 | Record.AddSourceLocation(TL.getRParenLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 595 | } |
| 596 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 597 | Record.AddSourceLocation(TL.getTypeofLoc()); |
| 598 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 599 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 600 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 601 | } |
| 602 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 603 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 604 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 605 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 606 | Record.AddSourceLocation(TL.getKWLoc()); |
| 607 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 608 | Record.AddSourceLocation(TL.getRParenLoc()); |
| 609 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 610 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 611 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 612 | Record.AddSourceLocation(TL.getNameLoc()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 613 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 614 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 615 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 616 | } |
| 617 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 618 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 619 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 620 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 621 | Record.AddSourceLocation(TL.getAttrNameLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 622 | if (TL.hasAttrOperand()) { |
| 623 | SourceRange range = TL.getAttrOperandParensRange(); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 624 | Record.AddSourceLocation(range.getBegin()); |
| 625 | Record.AddSourceLocation(range.getEnd()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 626 | } |
| 627 | if (TL.hasAttrExprOperand()) { |
| 628 | Expr *operand = TL.getAttrExprOperand(); |
| 629 | Record.push_back(operand ? 1 : 0); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 630 | if (operand) Record.AddStmt(operand); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 631 | } else if (TL.hasAttrEnumOperand()) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 632 | Record.AddSourceLocation(TL.getAttrEnumOperandLoc()); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 633 | } |
| 634 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 635 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 636 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 637 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 638 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 639 | SubstTemplateTypeParmTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 640 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 641 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 642 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 643 | SubstTemplateTypeParmPackTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 644 | Record.AddSourceLocation(TL.getNameLoc()); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 645 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 646 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 647 | TemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 648 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 649 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 650 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 651 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 652 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 653 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 654 | TL.getArgLoc(i).getLocInfo()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 655 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 656 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 657 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 658 | Record.AddSourceLocation(TL.getRParenLoc()); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 659 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 660 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 661 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 662 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 663 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 664 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 665 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 666 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 667 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 668 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 669 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 670 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 671 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 672 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 673 | DependentTemplateSpecializationTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 674 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); |
| 675 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 676 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); |
| 677 | Record.AddSourceLocation(TL.getTemplateNameLoc()); |
| 678 | Record.AddSourceLocation(TL.getLAngleLoc()); |
| 679 | Record.AddSourceLocation(TL.getRAngleLoc()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 680 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 681 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 682 | TL.getArgLoc(I).getLocInfo()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 683 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 684 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 685 | Record.AddSourceLocation(TL.getEllipsisLoc()); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 686 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 687 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 688 | Record.AddSourceLocation(TL.getNameLoc()); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 689 | } |
| 690 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 691 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 692 | Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); |
| 693 | Record.AddSourceLocation(TL.getTypeArgsRAngleLoc()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 694 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 695 | Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i)); |
| 696 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); |
| 697 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 698 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 699 | Record.AddSourceLocation(TL.getProtocolLoc(i)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 700 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 701 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 702 | Record.AddSourceLocation(TL.getStarLoc()); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 703 | } |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 704 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 705 | Record.AddSourceLocation(TL.getKWLoc()); |
| 706 | Record.AddSourceLocation(TL.getLParenLoc()); |
| 707 | Record.AddSourceLocation(TL.getRParenLoc()); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 708 | } |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 709 | void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 710 | Record.AddSourceLocation(TL.getKWLoc()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 711 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 712 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 713 | void ASTWriter::WriteTypeAbbrevs() { |
| 714 | using namespace llvm; |
| 715 | |
| 716 | BitCodeAbbrev *Abv; |
| 717 | |
| 718 | // Abbreviation for TYPE_EXT_QUAL |
| 719 | Abv = new BitCodeAbbrev(); |
| 720 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 721 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 722 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
| 723 | TypeExtQualAbbrev = Stream.EmitAbbrev(Abv); |
| 724 | |
| 725 | // Abbreviation for TYPE_FUNCTION_PROTO |
| 726 | Abv = new BitCodeAbbrev(); |
| 727 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 728 | // FunctionType |
| 729 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 730 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 731 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 732 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 733 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 734 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
| 735 | // FunctionProtoType |
| 736 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 737 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 738 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 739 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 740 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 741 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 742 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 743 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
| 744 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(Abv); |
| 745 | } |
| 746 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 747 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 748 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 749 | //===----------------------------------------------------------------------===// |
| 750 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 751 | static void EmitBlockID(unsigned ID, const char *Name, |
| 752 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 753 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 754 | Record.clear(); |
| 755 | Record.push_back(ID); |
| 756 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 757 | |
| 758 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 759 | if (!Name || Name[0] == 0) |
| 760 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 761 | Record.clear(); |
| 762 | while (*Name) |
| 763 | Record.push_back(*Name++); |
| 764 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 765 | } |
| 766 | |
| 767 | static void EmitRecordID(unsigned ID, const char *Name, |
| 768 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 769 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 770 | Record.clear(); |
| 771 | Record.push_back(ID); |
| 772 | while (*Name) |
| 773 | Record.push_back(*Name++); |
| 774 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 778 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 779 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 780 | RECORD(STMT_STOP); |
| 781 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 782 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 783 | RECORD(STMT_NULL); |
| 784 | RECORD(STMT_COMPOUND); |
| 785 | RECORD(STMT_CASE); |
| 786 | RECORD(STMT_DEFAULT); |
| 787 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 788 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 789 | RECORD(STMT_IF); |
| 790 | RECORD(STMT_SWITCH); |
| 791 | RECORD(STMT_WHILE); |
| 792 | RECORD(STMT_DO); |
| 793 | RECORD(STMT_FOR); |
| 794 | RECORD(STMT_GOTO); |
| 795 | RECORD(STMT_INDIRECT_GOTO); |
| 796 | RECORD(STMT_CONTINUE); |
| 797 | RECORD(STMT_BREAK); |
| 798 | RECORD(STMT_RETURN); |
| 799 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 800 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 801 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 802 | RECORD(EXPR_PREDEFINED); |
| 803 | RECORD(EXPR_DECL_REF); |
| 804 | RECORD(EXPR_INTEGER_LITERAL); |
| 805 | RECORD(EXPR_FLOATING_LITERAL); |
| 806 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 807 | RECORD(EXPR_STRING_LITERAL); |
| 808 | RECORD(EXPR_CHARACTER_LITERAL); |
| 809 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 810 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 811 | RECORD(EXPR_UNARY_OPERATOR); |
| 812 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 813 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 814 | RECORD(EXPR_CALL); |
| 815 | RECORD(EXPR_MEMBER); |
| 816 | RECORD(EXPR_BINARY_OPERATOR); |
| 817 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 818 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 819 | RECORD(EXPR_IMPLICIT_CAST); |
| 820 | RECORD(EXPR_CSTYLE_CAST); |
| 821 | RECORD(EXPR_COMPOUND_LITERAL); |
| 822 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 823 | RECORD(EXPR_INIT_LIST); |
| 824 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 825 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 826 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 827 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 828 | RECORD(EXPR_VA_ARG); |
| 829 | RECORD(EXPR_ADDR_LABEL); |
| 830 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 831 | RECORD(EXPR_CHOOSE); |
| 832 | RECORD(EXPR_GNU_NULL); |
| 833 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 834 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 835 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 836 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 837 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 838 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 839 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 840 | RECORD(EXPR_OBJC_ENCODE); |
| 841 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 842 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 843 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 844 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 845 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 846 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 847 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 848 | RECORD(STMT_OBJC_CATCH); |
| 849 | RECORD(STMT_OBJC_FINALLY); |
| 850 | RECORD(STMT_OBJC_AT_TRY); |
| 851 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 852 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 853 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 854 | RECORD(STMT_CXX_CATCH); |
| 855 | RECORD(STMT_CXX_TRY); |
| 856 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 857 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 858 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 859 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 860 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 861 | RECORD(EXPR_CXX_STATIC_CAST); |
| 862 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 863 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 864 | RECORD(EXPR_CXX_CONST_CAST); |
| 865 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 866 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 867 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 868 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 869 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 870 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 871 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 872 | RECORD(EXPR_CXX_THIS); |
| 873 | RECORD(EXPR_CXX_THROW); |
| 874 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 875 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 876 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 877 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 878 | RECORD(EXPR_CXX_NEW); |
| 879 | RECORD(EXPR_CXX_DELETE); |
| 880 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 881 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 882 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 883 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 884 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 885 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 886 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 887 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 888 | RECORD(EXPR_CXX_NOEXCEPT); |
| 889 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 890 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 891 | RECORD(EXPR_TYPE_TRAIT); |
| 892 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 893 | RECORD(EXPR_PACK_EXPANSION); |
| 894 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 895 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 896 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 897 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 898 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 899 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 900 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 901 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 902 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 903 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 904 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 906 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 907 | RecordData Record; |
| 908 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 910 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 911 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 912 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 913 | // Control Block. |
| 914 | BLOCK(CONTROL_BLOCK); |
| 915 | RECORD(METADATA); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 916 | RECORD(SIGNATURE); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 917 | RECORD(MODULE_NAME); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 918 | RECORD(MODULE_DIRECTORY); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 919 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 920 | RECORD(IMPORTS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 921 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 922 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 923 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 924 | RECORD(INPUT_FILE_OFFSETS); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 925 | |
| 926 | BLOCK(OPTIONS_BLOCK); |
| 927 | RECORD(LANGUAGE_OPTIONS); |
| 928 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 929 | RECORD(DIAGNOSTIC_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 930 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 931 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 932 | RECORD(PREPROCESSOR_OPTIONS); |
| 933 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 934 | BLOCK(INPUT_FILES_BLOCK); |
| 935 | RECORD(INPUT_FILE); |
| 936 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 937 | // AST Top-Level Block. |
| 938 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 939 | RECORD(TYPE_OFFSET); |
| 940 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 941 | RECORD(IDENTIFIER_OFFSET); |
| 942 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 943 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 944 | RECORD(SPECIAL_TYPES); |
| 945 | RECORD(STATISTICS); |
| 946 | RECORD(TENTATIVE_DEFINITIONS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 947 | RECORD(SELECTOR_OFFSETS); |
| 948 | RECORD(METHOD_POOL); |
| 949 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 950 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 951 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 952 | RECORD(EXT_VECTOR_DECLS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 953 | RECORD(UNUSED_FILESCOPED_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 954 | RECORD(PPD_ENTITIES_OFFSETS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 955 | RECORD(VTABLE_USES); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 956 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 957 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 958 | RECORD(SEMA_DECL_REFS); |
| 959 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 960 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 961 | RECORD(UPDATE_VISIBLE); |
| 962 | RECORD(DECL_UPDATE_OFFSETS); |
| 963 | RECORD(DECL_UPDATES); |
| 964 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 965 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 966 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 967 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 968 | RECORD(FP_PRAGMA_OPTIONS); |
| 969 | RECORD(OPENCL_EXTENSIONS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 970 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 971 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 972 | RECORD(MODULE_OFFSET_MAP); |
| 973 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 974 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 975 | RECORD(FILE_SORTED_DECLS); |
| 976 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 977 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 978 | RECORD(MACRO_OFFSET); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 979 | RECORD(INTERESTING_IDENTIFIERS); |
| 980 | RECORD(UNDEFINED_BUT_USED); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 981 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 982 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 983 | RECORD(MSSTRUCT_PRAGMA_OPTIONS); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 984 | RECORD(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 985 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); |
| 986 | RECORD(CXX_CTOR_INITIALIZERS_OFFSETS); |
| 987 | RECORD(DELETE_EXPRS_TO_ANALYZE); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 988 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 989 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 990 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 991 | RECORD(SM_SLOC_FILE_ENTRY); |
| 992 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 993 | RECORD(SM_SLOC_BUFFER_BLOB); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 994 | RECORD(SM_SLOC_BUFFER_BLOB_COMPRESSED); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 995 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 997 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 998 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 999 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1000 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1001 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 1002 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1003 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1004 | |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 1005 | // Submodule Block. |
| 1006 | BLOCK(SUBMODULE_BLOCK); |
| 1007 | RECORD(SUBMODULE_METADATA); |
| 1008 | RECORD(SUBMODULE_DEFINITION); |
| 1009 | RECORD(SUBMODULE_UMBRELLA_HEADER); |
| 1010 | RECORD(SUBMODULE_HEADER); |
| 1011 | RECORD(SUBMODULE_TOPHEADER); |
| 1012 | RECORD(SUBMODULE_UMBRELLA_DIR); |
| 1013 | RECORD(SUBMODULE_IMPORTS); |
| 1014 | RECORD(SUBMODULE_EXPORTS); |
| 1015 | RECORD(SUBMODULE_REQUIRES); |
| 1016 | RECORD(SUBMODULE_EXCLUDED_HEADER); |
| 1017 | RECORD(SUBMODULE_LINK_LIBRARY); |
| 1018 | RECORD(SUBMODULE_CONFIG_MACRO); |
| 1019 | RECORD(SUBMODULE_CONFLICT); |
| 1020 | RECORD(SUBMODULE_PRIVATE_HEADER); |
| 1021 | RECORD(SUBMODULE_TEXTUAL_HEADER); |
| 1022 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); |
| 1023 | |
| 1024 | // Comments Block. |
| 1025 | BLOCK(COMMENTS_BLOCK); |
| 1026 | RECORD(COMMENTS_RAW_COMMENT); |
| 1027 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1028 | // Decls and Types block. |
| 1029 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1030 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1031 | RECORD(TYPE_COMPLEX); |
| 1032 | RECORD(TYPE_POINTER); |
| 1033 | RECORD(TYPE_BLOCK_POINTER); |
| 1034 | RECORD(TYPE_LVALUE_REFERENCE); |
| 1035 | RECORD(TYPE_RVALUE_REFERENCE); |
| 1036 | RECORD(TYPE_MEMBER_POINTER); |
| 1037 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1038 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1039 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1040 | RECORD(TYPE_VECTOR); |
| 1041 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1042 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1043 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1044 | RECORD(TYPE_TYPEDEF); |
| 1045 | RECORD(TYPE_TYPEOF_EXPR); |
| 1046 | RECORD(TYPE_TYPEOF); |
| 1047 | RECORD(TYPE_RECORD); |
| 1048 | RECORD(TYPE_ENUM); |
| 1049 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1050 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1051 | RECORD(TYPE_DECLTYPE); |
| 1052 | RECORD(TYPE_ELABORATED); |
| 1053 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 1054 | RECORD(TYPE_UNRESOLVED_USING); |
| 1055 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 1056 | RECORD(TYPE_OBJC_OBJECT); |
| 1057 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 1058 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 1059 | RECORD(TYPE_DEPENDENT_NAME); |
| 1060 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 1061 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 1062 | RECORD(TYPE_PAREN); |
| 1063 | RECORD(TYPE_PACK_EXPANSION); |
| 1064 | RECORD(TYPE_ATTRIBUTED); |
| 1065 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1066 | RECORD(TYPE_AUTO); |
| 1067 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1068 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1069 | RECORD(TYPE_DECAYED); |
| 1070 | RECORD(TYPE_ADJUSTED); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 1071 | RECORD(LOCAL_REDECLARATIONS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1072 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1073 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1074 | RECORD(DECL_ENUM); |
| 1075 | RECORD(DECL_RECORD); |
| 1076 | RECORD(DECL_ENUM_CONSTANT); |
| 1077 | RECORD(DECL_FUNCTION); |
| 1078 | RECORD(DECL_OBJC_METHOD); |
| 1079 | RECORD(DECL_OBJC_INTERFACE); |
| 1080 | RECORD(DECL_OBJC_PROTOCOL); |
| 1081 | RECORD(DECL_OBJC_IVAR); |
| 1082 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1083 | RECORD(DECL_OBJC_CATEGORY); |
| 1084 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1085 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1086 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1087 | RECORD(DECL_OBJC_PROPERTY); |
| 1088 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1089 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1090 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1091 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1092 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1093 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1094 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1095 | RECORD(DECL_BLOCK); |
| 1096 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1097 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1098 | RECORD(DECL_NAMESPACE); |
| 1099 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1100 | RECORD(DECL_USING); |
| 1101 | RECORD(DECL_USING_SHADOW); |
| 1102 | RECORD(DECL_USING_DIRECTIVE); |
| 1103 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1104 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1105 | RECORD(DECL_LINKAGE_SPEC); |
| 1106 | RECORD(DECL_CXX_RECORD); |
| 1107 | RECORD(DECL_CXX_METHOD); |
| 1108 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 1109 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1110 | RECORD(DECL_CXX_CONVERSION); |
| 1111 | RECORD(DECL_ACCESS_SPEC); |
| 1112 | RECORD(DECL_FRIEND); |
| 1113 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1114 | RECORD(DECL_CLASS_TEMPLATE); |
| 1115 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1116 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1117 | RECORD(DECL_VAR_TEMPLATE); |
| 1118 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1119 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1120 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1121 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1122 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1123 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 1124 | RECORD(DECL_STATIC_ASSERT); |
| 1125 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 1126 | RECORD(DECL_INDIRECTFIELD); |
| 1127 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 1128 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1129 | // Statements and Exprs can occur in the Decls and Types block. |
| 1130 | AddStmtsExprs(Stream, Record); |
| 1131 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1132 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1133 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1134 | RECORD(PPD_MACRO_DEFINITION); |
| 1135 | RECORD(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 1136 | |
| 1137 | // Decls and Types block. |
| 1138 | BLOCK(EXTENSION_BLOCK); |
| 1139 | RECORD(EXTENSION_METADATA); |
| 1140 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1141 | #undef RECORD |
| 1142 | #undef BLOCK |
| 1143 | Stream.ExitBlock(); |
| 1144 | } |
| 1145 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1146 | /// \brief Prepares a path for being written to an AST file by converting it |
| 1147 | /// to an absolute path and removing nested './'s. |
| 1148 | /// |
| 1149 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1150 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1151 | SmallVectorImpl<char> &Path) { |
Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 1152 | bool Changed = FileMgr.makeAbsolutePath(Path); |
Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame] | 1153 | return Changed | llvm::sys::path::remove_dots(Path); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1156 | /// \brief Adjusts the given filename to only write out the portion of the |
| 1157 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1159 | /// \param Filename the file name to adjust. |
| 1160 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1161 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1162 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1163 | /// |
| 1164 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1165 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1166 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1167 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1168 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1170 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1171 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1173 | // Verify that the filename and the system root have the same prefix. |
| 1174 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1175 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1176 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1177 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1178 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1179 | // We hit the end of the filename before we hit the end of the system root. |
| 1180 | if (!Filename[Pos]) |
| 1181 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1182 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1183 | // If there's not a path separator at the end of the base directory nor |
| 1184 | // immediately after it, then this isn't within the base directory. |
| 1185 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1186 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1187 | return Filename; |
| 1188 | } else { |
| 1189 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1190 | // We distinguish relative paths from absolute paths by the |
| 1191 | // absence of '/' at the beginning of relative paths. |
| 1192 | // |
| 1193 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1194 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1195 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1196 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1197 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1199 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1200 | return Filename + Pos; |
| 1201 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1202 | |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1203 | static ASTFileSignature getSignature() { |
| 1204 | while (1) { |
| 1205 | if (ASTFileSignature S = llvm::sys::Process::GetRandomNumber()) |
| 1206 | return S; |
| 1207 | // Rely on GetRandomNumber to eventually return non-zero... |
| 1208 | } |
| 1209 | } |
| 1210 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1211 | /// \brief Write the control block. |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1212 | uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP, |
| 1213 | ASTContext &Context, |
| 1214 | StringRef isysroot, |
| 1215 | const std::string &OutputFile) { |
| 1216 | ASTFileSignature Signature = 0; |
| 1217 | |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1218 | using namespace llvm; |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1219 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1220 | RecordData Record; |
| 1221 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1222 | // Metadata |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1223 | auto *MetadataAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1224 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1225 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1226 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1227 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1228 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1229 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1230 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1231 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1232 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1233 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1234 | assert((!WritingModule || isysroot.empty()) && |
| 1235 | "writing module as a relocatable PCH?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1236 | { |
| 1237 | RecordData::value_type Record[] = {METADATA, VERSION_MAJOR, VERSION_MINOR, |
| 1238 | CLANG_VERSION_MAJOR, CLANG_VERSION_MINOR, |
| 1239 | !isysroot.empty(), IncludeTimestamps, |
| 1240 | ASTHasCompilerErrors}; |
| 1241 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1242 | getClangFullRepositoryVersion()); |
| 1243 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1244 | if (WritingModule) { |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1245 | // For implicit modules we output a signature that we can use to ensure |
| 1246 | // duplicate module builds don't collide in the cache as their output order |
| 1247 | // is non-deterministic. |
| 1248 | // FIXME: Remove this when output is deterministic. |
| 1249 | if (Context.getLangOpts().ImplicitModules) { |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1250 | Signature = getSignature(); |
| 1251 | RecordData::value_type Record[] = {Signature}; |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1252 | Stream.EmitRecord(SIGNATURE, Record); |
| 1253 | } |
| 1254 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1255 | // Module name |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1256 | auto *Abbrev = new BitCodeAbbrev(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1257 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1258 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1259 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1260 | RecordData::value_type Record[] = {MODULE_NAME}; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1261 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1262 | } |
| 1263 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1264 | if (WritingModule && WritingModule->Directory) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1265 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1266 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1267 | |
| 1268 | // If the home of the module is the current working directory, then we |
| 1269 | // want to pick up the cwd of the build process loading the module, not |
| 1270 | // our cwd, when we load this module. |
| 1271 | if (!PP.getHeaderSearchInfo() |
| 1272 | .getHeaderSearchOpts() |
| 1273 | .ModuleMapFileHomeIsCwd || |
| 1274 | WritingModule->Directory->getName() != StringRef(".")) { |
| 1275 | // Module directory. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1276 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1277 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1278 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
| 1279 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1280 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1281 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1282 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1283 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1284 | |
| 1285 | // Write out all other paths relative to the base directory if possible. |
| 1286 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1287 | } else if (!isysroot.empty()) { |
| 1288 | // Write out paths relative to the sysroot if possible. |
| 1289 | BaseDirectory = isysroot; |
| 1290 | } |
| 1291 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1292 | // Module map file |
| 1293 | if (WritingModule) { |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1294 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1295 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1296 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 1297 | |
| 1298 | // Primary module map file. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1299 | AddPath(Map.getModuleMapFileForUniquing(WritingModule)->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1300 | |
| 1301 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1302 | if (auto *AdditionalModMaps = |
| 1303 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1304 | Record.push_back(AdditionalModMaps->size()); |
| 1305 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1306 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1307 | } else { |
| 1308 | Record.push_back(0); |
| 1309 | } |
| 1310 | |
| 1311 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1314 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1315 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1316 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1317 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1318 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1319 | for (auto *M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1320 | // Skip modules that weren't directly imported. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1321 | if (!M->isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1322 | continue; |
| 1323 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1324 | Record.push_back((unsigned)M->Kind); // FIXME: Stable encoding |
| 1325 | AddSourceLocation(M->ImportLoc, Record); |
| 1326 | Record.push_back(M->File->getSize()); |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1327 | Record.push_back(getTimestampForOutput(M->File)); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1328 | Record.push_back(M->Signature); |
| 1329 | AddPath(M->FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1330 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1331 | Stream.EmitRecord(IMPORTS, Record); |
| 1332 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1334 | // Write the options block. |
| 1335 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); |
| 1336 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1337 | // Language options. |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1338 | Record.clear(); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1339 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1340 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1341 | Record.push_back(LangOpts.Name); |
| 1342 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1343 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1344 | #include "clang/Basic/LangOptions.def" |
| 1345 | #define SANITIZER(NAME, ID) \ |
| 1346 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1347 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1348 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1349 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1350 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1351 | AddString(Feature, Record); |
| 1352 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1353 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1354 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1355 | |
| 1356 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1357 | |
| 1358 | // Comment options. |
| 1359 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1360 | for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) { |
| 1361 | AddString(I, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1362 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1363 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1364 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1365 | // OpenMP offloading options. |
| 1366 | Record.push_back(LangOpts.OMPTargetTriples.size()); |
| 1367 | for (auto &T : LangOpts.OMPTargetTriples) |
| 1368 | AddString(T.getTriple(), Record); |
| 1369 | |
| 1370 | AddString(LangOpts.OMPHostIRFile, Record); |
| 1371 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1372 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1373 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1374 | // Target options. |
| 1375 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1376 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1377 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1378 | AddString(TargetOpts.Triple, Record); |
| 1379 | AddString(TargetOpts.CPU, Record); |
| 1380 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1381 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1382 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1383 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1384 | } |
| 1385 | Record.push_back(TargetOpts.Features.size()); |
| 1386 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1387 | AddString(TargetOpts.Features[I], Record); |
| 1388 | } |
| 1389 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1390 | |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1391 | // Diagnostic options. |
| 1392 | Record.clear(); |
| 1393 | const DiagnosticOptions &DiagOpts |
| 1394 | = Context.getDiagnostics().getDiagnosticOptions(); |
| 1395 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1396 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1397 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1398 | #include "clang/Basic/DiagnosticOptions.def" |
| 1399 | Record.push_back(DiagOpts.Warnings.size()); |
| 1400 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1401 | AddString(DiagOpts.Warnings[I], Record); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 1402 | Record.push_back(DiagOpts.Remarks.size()); |
| 1403 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1404 | AddString(DiagOpts.Remarks[I], Record); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1405 | // Note: we don't serialize the log or serialization file names, because they |
| 1406 | // are generally transient files and will almost always be overridden. |
| 1407 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1408 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1409 | // File system options. |
| 1410 | Record.clear(); |
Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1411 | const FileSystemOptions &FSOpts = |
| 1412 | Context.getSourceManager().getFileManager().getFileSystemOpts(); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1413 | AddString(FSOpts.WorkingDir, Record); |
| 1414 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1415 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1416 | // Header search options. |
| 1417 | Record.clear(); |
| 1418 | const HeaderSearchOptions &HSOpts |
| 1419 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1420 | AddString(HSOpts.Sysroot, Record); |
| 1421 | |
| 1422 | // Include entries. |
| 1423 | Record.push_back(HSOpts.UserEntries.size()); |
| 1424 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1425 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1426 | AddString(Entry.Path, Record); |
| 1427 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1428 | Record.push_back(Entry.IsFramework); |
| 1429 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | // System header prefixes. |
| 1433 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1434 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1435 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1436 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1437 | } |
| 1438 | |
| 1439 | AddString(HSOpts.ResourceDir, Record); |
| 1440 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1441 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1442 | Record.push_back(HSOpts.DisableModuleHash); |
| 1443 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1444 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1445 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1446 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1447 | // Write out the specific module cache path that contains the module files. |
| 1448 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1449 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1450 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1451 | // Preprocessor options. |
| 1452 | Record.clear(); |
| 1453 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1454 | |
| 1455 | // Macro definitions. |
| 1456 | Record.push_back(PPOpts.Macros.size()); |
| 1457 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1458 | AddString(PPOpts.Macros[I].first, Record); |
| 1459 | Record.push_back(PPOpts.Macros[I].second); |
| 1460 | } |
| 1461 | |
| 1462 | // Includes |
| 1463 | Record.push_back(PPOpts.Includes.size()); |
| 1464 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1465 | AddString(PPOpts.Includes[I], Record); |
| 1466 | |
| 1467 | // Macro includes |
| 1468 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1469 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1470 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1471 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1472 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1473 | // Detailed record is important since it is used for the module cache hash. |
| 1474 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1475 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1476 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1477 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1478 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1479 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1480 | // Leave the options block. |
| 1481 | Stream.ExitBlock(); |
| 1482 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1483 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1484 | SourceManager &SM = Context.getSourceManager(); |
| 1485 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1486 | auto *FileAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1487 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1488 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1489 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1490 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1491 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1492 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1493 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1494 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1495 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1496 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1497 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1498 | Record.clear(); |
| 1499 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1500 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1501 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1502 | // Original PCH directory |
| 1503 | if (!OutputFile.empty() && OutputFile != "-") { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1504 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1505 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1506 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1507 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1508 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1509 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1510 | |
Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1511 | SM.getFileManager().makeAbsolutePath(OutputPath); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1512 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1513 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1514 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1515 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1516 | } |
| 1517 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1518 | WriteInputFiles(Context.SourceMgr, |
| 1519 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1520 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1521 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1522 | return Signature; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1525 | namespace { |
| 1526 | /// \brief An input file. |
| 1527 | struct InputFileEntry { |
| 1528 | const FileEntry *File; |
| 1529 | bool IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1530 | bool IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1531 | bool BufferOverridden; |
| 1532 | }; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1533 | } // end anonymous namespace |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1534 | |
| 1535 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1536 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1537 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1538 | using namespace llvm; |
| 1539 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1540 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1541 | // Create input-file abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1542 | auto *IFAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1543 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1544 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1545 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1546 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1547 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1548 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1549 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1550 | unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); |
| 1551 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1552 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1553 | // 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] | 1554 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1555 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1556 | // Get this source location entry. |
| 1557 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1558 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1559 | |
| 1560 | // We only care about file entries that were not overridden. |
| 1561 | if (!SLoc->isFile()) |
| 1562 | continue; |
| 1563 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1564 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1565 | continue; |
| 1566 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1567 | InputFileEntry Entry; |
| 1568 | Entry.File = Cache->OrigEntry; |
| 1569 | Entry.IsSystemFile = Cache->IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1570 | Entry.IsTransient = Cache->IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1571 | Entry.BufferOverridden = Cache->BufferOverridden; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1572 | if (Cache->IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1573 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1574 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1575 | SortedFiles.push_front(Entry); |
| 1576 | } |
| 1577 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1578 | unsigned UserFilesNum = 0; |
| 1579 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1580 | std::vector<uint64_t> InputFileOffsets; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1581 | for (const auto &Entry : SortedFiles) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1582 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1583 | if (InputFileID != 0) |
| 1584 | continue; // already recorded this file. |
| 1585 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1586 | // Record this entry's offset. |
| 1587 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1588 | |
| 1589 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1590 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1591 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1592 | ++UserFilesNum; |
| 1593 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1594 | // Emit size/modification time for this file. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1595 | // And whether this file was overridden. |
| 1596 | RecordData::value_type Record[] = { |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1597 | INPUT_FILE, |
| 1598 | InputFileOffsets.size(), |
| 1599 | (uint64_t)Entry.File->getSize(), |
| 1600 | (uint64_t)getTimestampForOutput(Entry.File), |
| 1601 | Entry.BufferOverridden, |
| 1602 | Entry.IsTransient}; |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1603 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1604 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1605 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1606 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1607 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1608 | |
| 1609 | // Create input file offsets abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1610 | auto *OffsetsAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1611 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1612 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1613 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1614 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1615 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
| 1616 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(OffsetsAbbrev); |
| 1617 | |
| 1618 | // Write input file offsets. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1619 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, |
| 1620 | InputFileOffsets.size(), UserFilesNum}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1621 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1624 | //===----------------------------------------------------------------------===// |
| 1625 | // Source Manager Serialization |
| 1626 | //===----------------------------------------------------------------------===// |
| 1627 | |
| 1628 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1629 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1630 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1631 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1632 | |
| 1633 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1634 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1635 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1636 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1637 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1638 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1639 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1640 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1641 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1642 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1643 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1644 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1648 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1649 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1650 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1651 | |
| 1652 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1653 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1654 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1655 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1656 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1657 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1658 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1659 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1663 | /// buffer's blob. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1664 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, |
| 1665 | bool Compressed) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1666 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1667 | |
| 1668 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1669 | Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED |
| 1670 | : SM_SLOC_BUFFER_BLOB)); |
| 1671 | if (Compressed) |
| 1672 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1673 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1674 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1675 | } |
| 1676 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1677 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1678 | /// expansion. |
| 1679 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1680 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1681 | |
| 1682 | auto *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1683 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1684 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1685 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1686 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1687 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1688 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1689 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1692 | namespace { |
| 1693 | // Trait used for the on-disk hash table of header search information. |
| 1694 | class HeaderFileInfoTrait { |
| 1695 | ASTWriter &Writer; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1696 | const HeaderSearch &HS; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1697 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1698 | // Keep track of the framework names we've used during serialization. |
| 1699 | SmallVector<char, 128> FrameworkStringData; |
| 1700 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1701 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1702 | public: |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1703 | HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) |
| 1704 | : Writer(Writer), HS(HS) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1705 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1706 | struct key_type { |
| 1707 | const FileEntry *FE; |
| 1708 | const char *Filename; |
| 1709 | }; |
| 1710 | typedef const key_type &key_type_ref; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1711 | |
| 1712 | typedef HeaderFileInfo data_type; |
| 1713 | typedef const data_type &data_type_ref; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 1714 | typedef unsigned hash_value_type; |
| 1715 | typedef unsigned offset_type; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1716 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1717 | hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1718 | // The hash is based only on size/time of the file, so that the reader can |
| 1719 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1720 | // change the form of the name. However, complete path is still the key. |
| 1721 | return llvm::hash_combine(key.FE->getSize(), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1722 | Writer.getTimestampForOutput(key.FE)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | std::pair<unsigned,unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1726 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1727 | using namespace llvm::support; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1728 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1729 | unsigned KeyLen = strlen(key.Filename) + 1 + 8 + 8; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1730 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1731 | unsigned DataLen = 1 + 2 + 4 + 4; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1732 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) |
| 1733 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) |
| 1734 | DataLen += 4; |
| 1735 | LE.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1736 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1739 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1740 | using namespace llvm::support; |
| 1741 | endian::Writer<little> LE(Out); |
| 1742 | LE.write<uint64_t>(key.FE->getSize()); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1743 | KeyLen -= 8; |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1744 | LE.write<uint64_t>(Writer.getTimestampForOutput(key.FE)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1745 | KeyLen -= 8; |
| 1746 | Out.write(key.Filename, KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1749 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1750 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1751 | using namespace llvm::support; |
| 1752 | endian::Writer<little> LE(Out); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1753 | uint64_t Start = Out.tell(); (void)Start; |
| 1754 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1755 | unsigned char Flags = (Data.isImport << 4) |
| 1756 | | (Data.isPragmaOnce << 3) |
| 1757 | | (Data.DirInfo << 1) |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1758 | | Data.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1759 | LE.write<uint8_t>(Flags); |
| 1760 | LE.write<uint16_t>(Data.NumIncludes); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1761 | |
| 1762 | if (!Data.ControllingMacro) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1763 | LE.write<uint32_t>(Data.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1764 | else |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1765 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1766 | |
| 1767 | unsigned Offset = 0; |
| 1768 | if (!Data.Framework.empty()) { |
| 1769 | // If this header refers into a framework, save the framework name. |
| 1770 | llvm::StringMap<unsigned>::iterator Pos |
| 1771 | = FrameworkNameOffset.find(Data.Framework); |
| 1772 | if (Pos == FrameworkNameOffset.end()) { |
| 1773 | Offset = FrameworkStringData.size() + 1; |
| 1774 | FrameworkStringData.append(Data.Framework.begin(), |
| 1775 | Data.Framework.end()); |
| 1776 | FrameworkStringData.push_back(0); |
| 1777 | |
| 1778 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1779 | } else |
| 1780 | Offset = Pos->second; |
| 1781 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1782 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1783 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1784 | // FIXME: If the header is excluded, we should write out some |
| 1785 | // record of that fact. |
| 1786 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) { |
| 1787 | if (uint32_t ModID = |
| 1788 | Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) { |
| 1789 | uint32_t Value = (ModID << 2) | (unsigned)ModInfo.getRole(); |
| 1790 | assert((Value >> 2) == ModID && "overflow in header module info"); |
| 1791 | LE.write<uint32_t>(Value); |
| 1792 | } |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1795 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1796 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1797 | |
| 1798 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1799 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1800 | }; |
| 1801 | } // end anonymous namespace |
| 1802 | |
| 1803 | /// \brief Write the header search block for the list of files that |
| 1804 | /// |
| 1805 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1806 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1807 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1808 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1809 | |
| 1810 | if (FilesByUID.size() > HS.header_file_size()) |
| 1811 | FilesByUID.resize(HS.header_file_size()); |
| 1812 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1813 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 1814 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1815 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1816 | unsigned NumHeaderSearchEntries = 0; |
| 1817 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1818 | const FileEntry *File = FilesByUID[UID]; |
| 1819 | if (!File) |
| 1820 | continue; |
| 1821 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1822 | // Get the file info. This will load info from the external source if |
| 1823 | // necessary. Skip emitting this file if we have no information on it |
| 1824 | // as a header file (in which case HFI will be null) or if it hasn't |
| 1825 | // changed since it was loaded. Also skip it if it's for a modular header |
| 1826 | // from a different module; in that case, we rely on the module(s) |
| 1827 | // containing the header to provide this information. |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1828 | const HeaderFileInfo *HFI = |
| 1829 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); |
| 1830 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 1831 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1832 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1833 | // Massage the file path into an appropriate form. |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1834 | const char *Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1835 | SmallString<128> FilenameTmp(Filename); |
| 1836 | if (PreparePathForOutput(FilenameTmp)) { |
| 1837 | // If we performed any translation on the file name at all, we need to |
| 1838 | // save this string, since the generator will refer to it later. |
| 1839 | Filename = strdup(FilenameTmp.c_str()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1840 | SavedStrings.push_back(Filename); |
| 1841 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1842 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1843 | HeaderFileInfoTrait::key_type key = { File, Filename }; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1844 | Generator.insert(key, *HFI, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1845 | ++NumHeaderSearchEntries; |
| 1846 | } |
| 1847 | |
| 1848 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1849 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1850 | uint32_t BucketOffset; |
| 1851 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1852 | using namespace llvm::support; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1853 | llvm::raw_svector_ostream Out(TableData); |
| 1854 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1855 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1856 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1857 | } |
| 1858 | |
| 1859 | // Create a blob abbreviation |
| 1860 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1861 | |
| 1862 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1863 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1864 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1865 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1866 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1867 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1868 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1869 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1870 | // Write the header search table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1871 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, |
| 1872 | NumHeaderSearchEntries, TableData.size()}; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1873 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 1874 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1875 | |
| 1876 | // Free all of the strings we had to duplicate. |
| 1877 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1878 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1881 | /// \brief Writes the block containing the serialized form of the |
| 1882 | /// source manager. |
| 1883 | /// |
| 1884 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1885 | /// blob), indexed based on the file name, so that we only create |
| 1886 | /// entries for files that we actually need. In the common case (no |
| 1887 | /// errors), we probably won't have to create file entries for any of |
| 1888 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1889 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1890 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1891 | RecordData Record; |
| 1892 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1893 | // Enter the source manager block. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1894 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1895 | |
| 1896 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1897 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1898 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1899 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false); |
| 1900 | unsigned SLocBufferBlobCompressedAbbrv = |
| 1901 | CreateSLocBufferBlobAbbrev(Stream, true); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1902 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1903 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1904 | // Write out the source location entry table. We skip the first |
| 1905 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1906 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1907 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1908 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1909 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1910 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1911 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1912 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1913 | FileID FID = FileID::get(I); |
| 1914 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1915 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1916 | // Record the offset of this source-location entry. |
| 1917 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1918 | |
| 1919 | // Figure out which record code to use. |
| 1920 | unsigned Code; |
| 1921 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1922 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1923 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1924 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1925 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1926 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1927 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1928 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1929 | Record.clear(); |
| 1930 | Record.push_back(Code); |
| 1931 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1932 | // Starting offset of this entry within this module, so skip the dummy. |
| 1933 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1934 | if (SLoc->isFile()) { |
| 1935 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 1936 | AddSourceLocation(File.getIncludeLoc(), Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1937 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1938 | Record.push_back(File.hasLineDirectives()); |
| 1939 | |
| 1940 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1941 | bool EmitBlob = false; |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1942 | if (Content->OrigEntry) { |
| 1943 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1944 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1945 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1946 | // The source location entry is a file. Emit input file ID. |
| 1947 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 1948 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1950 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1951 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1952 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1953 | if (FDI != FileDeclIDs.end()) { |
| 1954 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1955 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1956 | } else { |
| 1957 | Record.push_back(0); |
| 1958 | Record.push_back(0); |
| 1959 | } |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1960 | |
| 1961 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
| 1962 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1963 | if (Content->BufferOverridden || Content->IsTransient) |
| 1964 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1965 | } else { |
| 1966 | // The source location entry is a buffer. The blob associated |
| 1967 | // with this entry contains the contents of the buffer. |
| 1968 | |
| 1969 | // We add one to the size so that we capture the trailing NULL |
| 1970 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1971 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1972 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1973 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1974 | const char *Name = Buffer->getBufferIdentifier(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1975 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1976 | StringRef(Name, strlen(Name) + 1)); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1977 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1978 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1979 | if (strcmp(Name, "<built-in>") == 0) { |
| 1980 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1981 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1982 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1983 | |
| 1984 | if (EmitBlob) { |
| 1985 | // Include the implicit terminating null character in the on-disk buffer |
| 1986 | // if we're writing it uncompressed. |
| 1987 | const llvm::MemoryBuffer *Buffer = |
| 1988 | Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 1989 | StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1); |
| 1990 | |
| 1991 | // Compress the buffer if possible. We expect that almost all PCM |
| 1992 | // consumers will not want its contents. |
| 1993 | SmallString<0> CompressedBuffer; |
| 1994 | if (llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer) == |
| 1995 | llvm::zlib::StatusOK) { |
| 1996 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, |
| 1997 | Blob.size() - 1}; |
| 1998 | Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, |
| 1999 | CompressedBuffer); |
| 2000 | } else { |
| 2001 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB}; |
| 2002 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob); |
| 2003 | } |
| 2004 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2005 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2006 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 2007 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2008 | AddSourceLocation(Expansion.getSpellingLoc(), Record); |
| 2009 | AddSourceLocation(Expansion.getExpansionLocStart(), Record); |
| 2010 | AddSourceLocation(Expansion.isMacroArgExpansion() |
| 2011 | ? SourceLocation() |
| 2012 | : Expansion.getExpansionLocEnd(), |
| 2013 | Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2014 | |
| 2015 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2016 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2017 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2018 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2019 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2020 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2024 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2025 | |
| 2026 | if (SLocEntryOffsets.empty()) |
| 2027 | return; |
| 2028 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2029 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2030 | // table is used for lazily loading source-location information. |
| 2031 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2032 | |
| 2033 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2034 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2035 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2036 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2037 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 2038 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2039 | { |
| 2040 | RecordData::value_type Record[] = { |
| 2041 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), |
| 2042 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */}; |
| 2043 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
| 2044 | bytes(SLocEntryOffsets)); |
| 2045 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2046 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2047 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2048 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2049 | |
| 2050 | // Write the line table. It depends on remapping working, so it must come |
| 2051 | // after the source location offsets. |
| 2052 | if (SourceMgr.hasLineTable()) { |
| 2053 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 2054 | |
| 2055 | Record.clear(); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2056 | |
| 2057 | // Emit the needed file names. |
| 2058 | llvm::DenseMap<int, int> FilenameMap; |
| 2059 | for (const auto &L : LineTable) { |
| 2060 | if (L.first.ID < 0) |
| 2061 | continue; |
| 2062 | for (auto &LE : L.second) { |
| 2063 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, |
| 2064 | FilenameMap.size())).second) |
| 2065 | AddPath(LineTable.getFilename(LE.FilenameID), Record); |
| 2066 | } |
| 2067 | } |
| 2068 | Record.push_back(0); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2069 | |
| 2070 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2071 | for (const auto &L : LineTable) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2072 | // Only emit entries for local files. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2073 | if (L.first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2074 | continue; |
| 2075 | |
| 2076 | // Emit the file ID |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2077 | Record.push_back(L.first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2078 | |
| 2079 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2080 | Record.push_back(L.second.size()); |
| 2081 | for (const auto &LE : L.second) { |
| 2082 | Record.push_back(LE.FileOffset); |
| 2083 | Record.push_back(LE.LineNo); |
| 2084 | Record.push_back(FilenameMap[LE.FilenameID]); |
| 2085 | Record.push_back((unsigned)LE.FileKind); |
| 2086 | Record.push_back(LE.IncludeOffset); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2087 | } |
| 2088 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2089 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2090 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 2091 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2092 | } |
| 2093 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2094 | //===----------------------------------------------------------------------===// |
| 2095 | // Preprocessor Serialization |
| 2096 | //===----------------------------------------------------------------------===// |
| 2097 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2098 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 2099 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2100 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 2101 | if (MI->isBuiltinMacro()) |
| 2102 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2103 | |
| 2104 | if (IsModule) { |
| 2105 | SourceLocation Loc = MD->getLocation(); |
| 2106 | if (Loc.isInvalid()) |
| 2107 | return true; |
| 2108 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 2109 | return true; |
| 2110 | } |
| 2111 | |
| 2112 | return false; |
| 2113 | } |
| 2114 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2115 | /// \brief Writes the block containing the serialized form of the |
| 2116 | /// preprocessor. |
| 2117 | /// |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2118 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2119 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2120 | if (PPRec) |
| 2121 | WritePreprocessorDetail(*PPRec); |
| 2122 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2123 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2124 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2125 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2126 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2127 | if (PP.getCounterValue() != 0) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2128 | RecordData::value_type Record[] = {PP.getCounterValue()}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2129 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2133 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2134 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2135 | // 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] | 2136 | // 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] | 2137 | if (PP.SawDateOrTime()) |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2138 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2139 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2140 | // 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] | 2141 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2142 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2143 | // Construct the list of identifiers with macro directives that need to be |
| 2144 | // serialized. |
| 2145 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2146 | for (auto &Id : PP.getIdentifierTable()) |
| 2147 | if (Id.second->hadMacroDefinition() && |
| 2148 | (!Id.second->isFromAST() || |
| 2149 | Id.second->hasChangedSinceDeserialization())) |
| 2150 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2151 | // Sort the set of macro definitions that need to be serialized by the |
| 2152 | // name of the macro, to provide a stable ordering. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2153 | std::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(), |
| 2154 | llvm::less_ptr<IdentifierInfo>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2155 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2156 | // Emit the macro directives as a list and associate the offset with the |
| 2157 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2158 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2159 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2160 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2161 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2162 | // Emit the macro directives in reverse source order. |
| 2163 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2164 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2165 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2166 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2167 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2168 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2169 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2170 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2171 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2172 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2173 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2174 | Record.push_back(VisMD->isPublic()); |
| 2175 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2176 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2177 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2178 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2179 | bool EmittedModuleMacros = false; |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2180 | if (IsModule) { |
| 2181 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2182 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2183 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2184 | while (!Worklist.empty()) { |
| 2185 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2186 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2187 | // Emit a record indicating this submodule exports this macro. |
| 2188 | ModuleMacroRecord.push_back( |
| 2189 | getSubmoduleID(Macro->getOwningModule())); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2190 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2191 | for (auto *M : Macro->overrides()) |
| 2192 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2193 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2194 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2195 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2196 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2197 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2198 | for (auto *M : Macro->overrides()) |
| 2199 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2200 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2201 | |
| 2202 | EmittedModuleMacros = true; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2203 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2204 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2205 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2206 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2207 | continue; |
| 2208 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2209 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2210 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2211 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2212 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2213 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2214 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 2215 | /// the local macro ID |
| 2216 | /// |
| 2217 | /// For each identifier that is associated with a macro, this map |
| 2218 | /// provides the offset into the bitstream where that macro is |
| 2219 | /// defined. |
| 2220 | std::vector<uint32_t> MacroOffsets; |
| 2221 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2222 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2223 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2224 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2225 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2226 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2227 | if (ID < FirstMacroID) { |
| 2228 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2229 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2230 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2231 | |
| 2232 | // Record the local offset of this macro. |
| 2233 | unsigned Index = ID - FirstMacroID; |
| 2234 | if (Index == MacroOffsets.size()) |
| 2235 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2236 | else { |
| 2237 | if (Index > MacroOffsets.size()) |
| 2238 | MacroOffsets.resize(Index + 1); |
| 2239 | |
| 2240 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2241 | } |
| 2242 | |
| 2243 | AddIdentifierRef(Name, Record); |
| 2244 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
| 2245 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2246 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2247 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2248 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2249 | unsigned Code; |
| 2250 | if (MI->isObjectLike()) { |
| 2251 | Code = PP_MACRO_OBJECT_LIKE; |
| 2252 | } else { |
| 2253 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2254 | |
| 2255 | Record.push_back(MI->isC99Varargs()); |
| 2256 | Record.push_back(MI->isGNUVarargs()); |
| 2257 | Record.push_back(MI->hasCommaPasting()); |
| 2258 | Record.push_back(MI->getNumArgs()); |
Daniel Marjamaki | e4770da | 2015-05-29 09:15:24 +0000 | [diff] [blame] | 2259 | for (const IdentifierInfo *Arg : MI->args()) |
| 2260 | AddIdentifierRef(Arg, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | // If we have a detailed preprocessing record, record the macro definition |
| 2264 | // ID that corresponds to this macro. |
| 2265 | if (PPRec) |
| 2266 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2267 | |
| 2268 | Stream.EmitRecord(Code, Record); |
| 2269 | Record.clear(); |
| 2270 | |
| 2271 | // Emit the tokens array. |
| 2272 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2273 | // Note that we know that the preprocessor does not have any annotation |
| 2274 | // tokens in it because they are created by the parser, and thus can't |
| 2275 | // be in a macro definition. |
| 2276 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2277 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2278 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2279 | Record.clear(); |
| 2280 | } |
| 2281 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2282 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2283 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2284 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2285 | |
| 2286 | // Write the offsets table for macro IDs. |
| 2287 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2288 | |
Richard Smith | 13090a2 | 2015-04-10 02:02:24 +0000 | [diff] [blame] | 2289 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2290 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2291 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2292 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2293 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2294 | |
| 2295 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2296 | { |
| 2297 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), |
| 2298 | FirstMacroID - NUM_PREDEF_MACRO_IDS}; |
| 2299 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); |
| 2300 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2304 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2305 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2306 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2307 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2308 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2309 | // Enter the preprocessor block. |
| 2310 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2311 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2312 | // If the preprocessor has a preprocessing record, emit it. |
| 2313 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2314 | using namespace llvm; |
| 2315 | |
| 2316 | // Set up the abbreviation for |
| 2317 | unsigned InclusionAbbrev = 0; |
| 2318 | { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2319 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2320 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2321 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2322 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2323 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2324 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2325 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2326 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2327 | } |
| 2328 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2329 | unsigned FirstPreprocessorEntityID |
| 2330 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 2331 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2332 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2333 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2334 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2335 | EEnd = PPRec.local_end(); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2336 | E != EEnd; |
| 2337 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2338 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2339 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2340 | PreprocessedEntityOffsets.push_back( |
| 2341 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2342 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2343 | if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2344 | // Record this macro definition's ID. |
| 2345 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2346 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2347 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2348 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2349 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2350 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2351 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2352 | if (auto *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2353 | Record.push_back(ME->isBuiltinMacro()); |
| 2354 | if (ME->isBuiltinMacro()) |
| 2355 | AddIdentifierRef(ME->getName(), Record); |
| 2356 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2357 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2358 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2359 | continue; |
| 2360 | } |
| 2361 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2362 | if (auto *ID = dyn_cast<InclusionDirective>(*E)) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2363 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2364 | Record.push_back(ID->getFileName().size()); |
| 2365 | Record.push_back(ID->wasInQuotes()); |
| 2366 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2367 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2368 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2369 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2370 | // Check that the FileEntry is not null because it was not resolved and |
| 2371 | // we create a PCH even with compiler errors. |
| 2372 | if (ID->getFile()) |
| 2373 | Buffer += ID->getFile()->getName(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2374 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2375 | continue; |
| 2376 | } |
| 2377 | |
| 2378 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2379 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2380 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2381 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2382 | // Write the offsets table for the preprocessing record. |
| 2383 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2384 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2385 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2386 | // Write the offsets table for identifier IDs. |
| 2387 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2388 | |
| 2389 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2390 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2391 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2392 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2393 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2394 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2395 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, |
| 2396 | FirstPreprocessorEntityID - |
| 2397 | NUM_PREDEF_PP_ENTITY_IDS}; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2398 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2399 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2400 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2403 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2404 | if (!Mod) |
| 2405 | return 0; |
| 2406 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2407 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2408 | if (Known != SubmoduleIDs.end()) |
| 2409 | return Known->second; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2410 | |
| 2411 | if (Mod->getTopLevelModule() != WritingModule) |
| 2412 | return 0; |
| 2413 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2414 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2415 | } |
| 2416 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2417 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2418 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2419 | // did not result in us loading a module file for that submodule. For |
| 2420 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2421 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); |
| 2422 | assert((ID || !Mod) && |
| 2423 | "asked for module ID for non-local, non-imported module"); |
| 2424 | return ID; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2427 | /// \brief Compute the number of modules within the given tree (including the |
| 2428 | /// given module). |
| 2429 | static unsigned getNumberOfModules(Module *Mod) { |
| 2430 | unsigned ChildModules = 0; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2431 | for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2432 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2433 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2434 | |
| 2435 | return ChildModules + 1; |
| 2436 | } |
| 2437 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2438 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2439 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2440 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2441 | |
| 2442 | // Write the abbreviations needed for the submodules block. |
| 2443 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2444 | |
| 2445 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2446 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2447 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2448 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2449 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2450 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2451 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2452 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2453 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2454 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2455 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2456 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2457 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2458 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2459 | |
| 2460 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2461 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2462 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2463 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2464 | |
| 2465 | Abbrev = new BitCodeAbbrev(); |
| 2466 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2467 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2468 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2469 | |
| 2470 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2471 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2472 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2473 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2474 | |
| 2475 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2476 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2477 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2478 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2479 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2480 | Abbrev = new BitCodeAbbrev(); |
| 2481 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2482 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2483 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2484 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2485 | |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2486 | Abbrev = new BitCodeAbbrev(); |
| 2487 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2488 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2489 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2490 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2491 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2492 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2493 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2494 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2495 | |
| 2496 | Abbrev = new BitCodeAbbrev(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2497 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2498 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2499 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2500 | |
| 2501 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2502 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2503 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2504 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2505 | |
| 2506 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2507 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2508 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2509 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2510 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2511 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2512 | Abbrev = new BitCodeAbbrev(); |
| 2513 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2514 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
| 2515 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2516 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2517 | Abbrev = new BitCodeAbbrev(); |
| 2518 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2519 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2520 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
| 2521 | unsigned ConflictAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2522 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2523 | // Write the submodule metadata block. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2524 | RecordData::value_type Record[] = {getNumberOfModules(WritingModule), |
| 2525 | FirstSubmoduleID - |
| 2526 | NUM_PREDEF_SUBMODULE_IDS}; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2527 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2528 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2529 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2530 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2531 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2532 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2533 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2534 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2535 | unsigned ID = getSubmoduleID(Mod); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2536 | |
| 2537 | uint64_t ParentID = 0; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2538 | if (Mod->Parent) { |
| 2539 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2540 | ParentID = SubmoduleIDs[Mod->Parent]; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2541 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2542 | |
| 2543 | // Emit the definition of the block. |
| 2544 | { |
| 2545 | RecordData::value_type Record[] = { |
| 2546 | SUBMODULE_DEFINITION, ID, ParentID, Mod->IsFramework, Mod->IsExplicit, |
| 2547 | Mod->IsSystem, Mod->IsExternC, Mod->InferSubmodules, |
| 2548 | Mod->InferExplicitSubmodules, Mod->InferExportWildcard, |
| 2549 | Mod->ConfigMacrosExhaustive}; |
| 2550 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2551 | } |
| 2552 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2553 | // Emit the requirements. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2554 | for (const auto &R : Mod->Requirements) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2555 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2556 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2559 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2560 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2561 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2562 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2563 | UmbrellaHeader.NameAsWritten); |
| 2564 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2565 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; |
| 2566 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2567 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2568 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2569 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2570 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2571 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2572 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2573 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2574 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2575 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2576 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 2577 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 2578 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2579 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2580 | Module::HK_PrivateTextual}, |
| 2581 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2582 | }; |
| 2583 | for (auto &HL : HeaderLists) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2584 | RecordData::value_type Record[] = {HL.RecordKind}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2585 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 2586 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 2587 | } |
| 2588 | |
| 2589 | // Emit the top headers. |
| 2590 | { |
| 2591 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2592 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2593 | for (auto *H : TopHeaders) |
| 2594 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2595 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2596 | |
| 2597 | // Emit the imports. |
| 2598 | if (!Mod->Imports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2599 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2600 | for (auto *I : Mod->Imports) |
| 2601 | Record.push_back(getSubmoduleID(I)); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2602 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2603 | } |
| 2604 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2605 | // Emit the exports. |
| 2606 | if (!Mod->Exports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2607 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2608 | for (const auto &E : Mod->Exports) { |
| 2609 | // FIXME: This may fail; we don't require that all exported modules |
| 2610 | // are local or imported. |
| 2611 | Record.push_back(getSubmoduleID(E.getPointer())); |
| 2612 | Record.push_back(E.getInt()); |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2613 | } |
| 2614 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2615 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2616 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2617 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 2618 | // Might be unnecessary as use declarations are only used to build the |
| 2619 | // module itself. |
| 2620 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2621 | // Emit the link libraries. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2622 | for (const auto &LL : Mod->LinkLibraries) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2623 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, |
| 2624 | LL.IsFramework}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2625 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2628 | // Emit the conflicts. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2629 | for (const auto &C : Mod->Conflicts) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2630 | // FIXME: This may fail; we don't require that all conflicting modules |
| 2631 | // are local or imported. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2632 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, |
| 2633 | getSubmoduleID(C.Other)}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2634 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2637 | // Emit the configuration macros. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2638 | for (const auto &CM : Mod->ConfigMacros) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2639 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2640 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2643 | // Queue up the submodules of this module. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2644 | for (auto *M : Mod->submodules()) |
| 2645 | Q.push(M); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2649 | |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2650 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 2651 | getNumberOfModules(WritingModule)) && |
| 2652 | "Wrong # of submodules; found a reference to a non-local, " |
| 2653 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2654 | } |
| 2655 | |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2656 | serialization::SubmoduleID |
| 2657 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2658 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2659 | return 0; // No submodule |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2660 | |
| 2661 | // Find the module that owns this location. |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2662 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2663 | Module *OwningMod |
| 2664 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2665 | if (!OwningMod) |
| 2666 | return 0; |
| 2667 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2668 | // Check whether this submodule is part of our own module. |
| 2669 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2670 | return 0; |
| 2671 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2672 | return getSubmoduleID(OwningMod); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2673 | } |
| 2674 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 2675 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 2676 | bool isModule) { |
| 2677 | // Make sure set diagnostic pragmas don't affect the translation unit that |
| 2678 | // imports the module. |
| 2679 | // FIXME: Make diagnostic pragma sections work properly with modules. |
| 2680 | if (isModule) |
| 2681 | return; |
| 2682 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2683 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2684 | DiagStateIDMap; |
| 2685 | unsigned CurrID = 0; |
| 2686 | DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2687 | RecordData Record; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2688 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2689 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2690 | I != E; ++I) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2691 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2692 | if (point.Loc.isInvalid()) |
| 2693 | continue; |
| 2694 | |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2695 | AddSourceLocation(point.Loc, Record); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2696 | unsigned &DiagStateID = DiagStateIDMap[point.State]; |
| 2697 | Record.push_back(DiagStateID); |
| 2698 | |
| 2699 | if (DiagStateID == 0) { |
| 2700 | DiagStateID = ++CurrID; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2701 | for (const auto &I : *(point.State)) { |
| 2702 | if (I.second.isPragma()) { |
| 2703 | Record.push_back(I.first); |
| 2704 | Record.push_back((unsigned)I.second.getSeverity()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2705 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2706 | } |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2707 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2708 | // location. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2709 | } |
| 2710 | } |
| 2711 | |
Argyrios Kyrtzidis | b0ca9eb | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2712 | if (!Record.empty()) |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2713 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2714 | } |
| 2715 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2716 | void ASTWriter::WriteCXXCtorInitializersOffsets() { |
| 2717 | if (CXXCtorInitializersOffsets.empty()) |
| 2718 | return; |
| 2719 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2720 | // Create a blob abbreviation for the C++ ctor initializer offsets. |
| 2721 | using namespace llvm; |
| 2722 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2723 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2724 | Abbrev->Add(BitCodeAbbrevOp(CXX_CTOR_INITIALIZERS_OFFSETS)); |
| 2725 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2726 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2727 | unsigned CtorInitializersOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2728 | |
| 2729 | // Write the base specifier offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2730 | RecordData::value_type Record[] = {CXX_CTOR_INITIALIZERS_OFFSETS, |
| 2731 | CXXCtorInitializersOffsets.size()}; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2732 | Stream.EmitRecordWithBlob(CtorInitializersOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2733 | bytes(CXXCtorInitializersOffsets)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2736 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 2737 | if (CXXBaseSpecifiersOffsets.empty()) |
| 2738 | return; |
| 2739 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2740 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 2741 | using namespace llvm; |
| 2742 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2743 | auto *Abbrev = new BitCodeAbbrev(); |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2744 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 2745 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2746 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2747 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2748 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2749 | // Write the base specifier offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2750 | RecordData::value_type Record[] = {CXX_BASE_SPECIFIER_OFFSETS, |
| 2751 | CXXBaseSpecifiersOffsets.size()}; |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2752 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2753 | bytes(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2756 | //===----------------------------------------------------------------------===// |
| 2757 | // Type Serialization |
| 2758 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2759 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2760 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2761 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | a7fbbb0 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 2762 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2763 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 2764 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2765 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2766 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2767 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2768 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2769 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2770 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2771 | ASTTypeWriter W(*this, Record); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 2772 | W.Visit(T); |
| 2773 | uint64_t Offset = W.Emit(); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2774 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 2775 | // Record the offset for this type. |
| 2776 | unsigned Index = Idx.getIndex() - FirstTypeID; |
| 2777 | if (TypeOffsets.size() == Index) |
| 2778 | TypeOffsets.push_back(Offset); |
| 2779 | else if (TypeOffsets.size() < Index) { |
| 2780 | TypeOffsets.resize(Index + 1); |
| 2781 | TypeOffsets[Index] = Offset; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2782 | } else { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 2783 | llvm_unreachable("Types emitted in wrong order"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2784 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2787 | //===----------------------------------------------------------------------===// |
| 2788 | // Declaration Serialization |
| 2789 | //===----------------------------------------------------------------------===// |
| 2790 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2791 | /// \brief Write the block containing all of the declaration IDs |
| 2792 | /// lexically declared within the given DeclContext. |
| 2793 | /// |
| 2794 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2795 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2796 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2797 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2798 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2799 | return 0; |
| 2800 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2801 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2802 | SmallVector<uint32_t, 128> KindDeclPairs; |
| 2803 | for (const auto *D : DC->decls()) { |
| 2804 | KindDeclPairs.push_back(D->getKind()); |
| 2805 | KindDeclPairs.push_back(GetDeclRef(D)); |
| 2806 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2807 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2808 | ++NumLexicalDeclContexts; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2809 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2810 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, |
| 2811 | bytes(KindDeclPairs)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2812 | return Offset; |
| 2813 | } |
| 2814 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2815 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2816 | using namespace llvm; |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2817 | |
| 2818 | // Write the type offsets array |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2819 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2820 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2821 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2822 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2823 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2824 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2825 | { |
| 2826 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), |
| 2827 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; |
| 2828 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
| 2829 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2830 | |
| 2831 | // Write the declaration offsets array |
| 2832 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2833 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2834 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2835 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2836 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2837 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2838 | { |
| 2839 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), |
| 2840 | FirstDeclID - NUM_PREDEF_DECL_IDS}; |
| 2841 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
| 2842 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2843 | } |
| 2844 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2845 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2846 | using namespace llvm; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2847 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2848 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 2849 | FileDeclIDs.begin(), FileDeclIDs.end()); |
| 2850 | std::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), |
| 2851 | llvm::less_first()); |
| 2852 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2853 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2854 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 2855 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 2856 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 2857 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 2858 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 2859 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2860 | } |
| 2861 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2862 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2863 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2864 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2865 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2866 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2867 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, |
| 2868 | FileGroupedDeclIDs.size()}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2869 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2872 | void ASTWriter::WriteComments() { |
| 2873 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2874 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2875 | RecordData Record; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2876 | for (const auto *I : RawComments) { |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2877 | Record.clear(); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2878 | AddSourceRange(I->getSourceRange(), Record); |
| 2879 | Record.push_back(I->getKind()); |
| 2880 | Record.push_back(I->isTrailingComment()); |
| 2881 | Record.push_back(I->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2882 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2883 | } |
| 2884 | Stream.ExitBlock(); |
| 2885 | } |
| 2886 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2887 | //===----------------------------------------------------------------------===// |
| 2888 | // Global Method Pool and Selector Serialization |
| 2889 | //===----------------------------------------------------------------------===// |
| 2890 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2891 | namespace { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2892 | // 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] | 2893 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2894 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2895 | |
| 2896 | public: |
| 2897 | typedef Selector key_type; |
| 2898 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2899 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2900 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2901 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2902 | ObjCMethodList Instance, Factory; |
| 2903 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2904 | typedef const data_type& data_type_ref; |
| 2905 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2906 | typedef unsigned hash_value_type; |
| 2907 | typedef unsigned offset_type; |
| 2908 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2909 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2910 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2911 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2912 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2913 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2914 | |
| 2915 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2916 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2917 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2918 | using namespace llvm::support; |
| 2919 | endian::Writer<little> LE(Out); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2920 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2921 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2922 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2923 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2924 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2925 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2926 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2927 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2928 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2929 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2930 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2931 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2932 | return std::make_pair(KeyLen, DataLen); |
| 2933 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2934 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2935 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2936 | using namespace llvm::support; |
| 2937 | endian::Writer<little> LE(Out); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2938 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2939 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2940 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2941 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2942 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2943 | if (N == 0) |
| 2944 | N = 1; |
| 2945 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2946 | LE.write<uint32_t>( |
| 2947 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2948 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2949 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2950 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2951 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2952 | using namespace llvm::support; |
| 2953 | endian::Writer<little> LE(Out); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2954 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2955 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2956 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2957 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2958 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2959 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2960 | ++NumInstanceMethods; |
| 2961 | |
| 2962 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2963 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2964 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2965 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2966 | ++NumFactoryMethods; |
| 2967 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2968 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 2969 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2970 | unsigned InstanceHasMoreThanOneDeclBit = |
| 2971 | Methods.Instance.hasMoreThanOneDecl(); |
| 2972 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 2973 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 2974 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2975 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 2976 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2977 | unsigned FactoryHasMoreThanOneDeclBit = |
| 2978 | Methods.Factory.hasMoreThanOneDecl(); |
| 2979 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 2980 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 2981 | FactoryBits; |
| 2982 | LE.write<uint16_t>(FullInstanceBits); |
| 2983 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2984 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2985 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2986 | if (Method->getMethod()) |
| 2987 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2988 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2989 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2990 | if (Method->getMethod()) |
| 2991 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2992 | |
| 2993 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2994 | } |
| 2995 | }; |
| 2996 | } // end anonymous namespace |
| 2997 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2998 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2999 | /// |
| 3000 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3001 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 3002 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3003 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3004 | using namespace llvm; |
| 3005 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3006 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3007 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3008 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3009 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3010 | // 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] | 3011 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3012 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3013 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3014 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3015 | // Create the on-disk hash table representation. We walk through every |
| 3016 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3017 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3018 | for (auto &SelectorAndID : SelectorIDs) { |
| 3019 | Selector S = SelectorAndID.first; |
| 3020 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3021 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3022 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3023 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3024 | ObjCMethodList(), |
| 3025 | ObjCMethodList() |
| 3026 | }; |
| 3027 | if (F != SemaRef.MethodPool.end()) { |
| 3028 | Data.Instance = F->second.first; |
| 3029 | Data.Factory = F->second.second; |
| 3030 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3031 | // 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] | 3032 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3033 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3034 | // Selector already exists. Did it change? |
| 3035 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3036 | for (ObjCMethodList *M = &Data.Instance; |
| 3037 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 3038 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3039 | changed = true; |
| 3040 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3041 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3042 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3043 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3044 | changed = true; |
| 3045 | } |
| 3046 | if (!changed) |
| 3047 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3048 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3049 | // A new method pool entry. |
| 3050 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3051 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3052 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3053 | } |
| 3054 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3055 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3056 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3057 | uint32_t BucketOffset; |
| 3058 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3059 | using namespace llvm::support; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3060 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3061 | llvm::raw_svector_ostream Out(MethodPool); |
| 3062 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3063 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3064 | BucketOffset = Generator.Emit(Out, Trait); |
| 3065 | } |
| 3066 | |
| 3067 | // Create a blob abbreviation |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3068 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3069 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3070 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3071 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3072 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3073 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3074 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3075 | // Write the method pool |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3076 | { |
| 3077 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, |
| 3078 | NumTableEntries}; |
| 3079 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
| 3080 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3081 | |
| 3082 | // Create a blob abbreviation for the selector table offsets. |
| 3083 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3084 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3085 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3086 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3087 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3088 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3089 | |
| 3090 | // Write the selector offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3091 | { |
| 3092 | RecordData::value_type Record[] = { |
| 3093 | SELECTOR_OFFSETS, SelectorOffsets.size(), |
| 3094 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; |
| 3095 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 3096 | bytes(SelectorOffsets)); |
| 3097 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3098 | } |
| 3099 | } |
| 3100 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3101 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3102 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3103 | using namespace llvm; |
| 3104 | if (SemaRef.ReferencedSelectors.empty()) |
| 3105 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3106 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3107 | RecordData Record; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3108 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3109 | // 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] | 3110 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3111 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3112 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3113 | Selector Sel = SelectorAndLocation.first; |
| 3114 | SourceLocation Loc = SelectorAndLocation.second; |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3115 | AddSelectorRef(Sel, Record); |
| 3116 | AddSourceLocation(Loc, Record); |
| 3117 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3118 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3121 | //===----------------------------------------------------------------------===// |
| 3122 | // Identifier Table Serialization |
| 3123 | //===----------------------------------------------------------------------===// |
| 3124 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3125 | /// Determine the declaration that should be put into the name lookup table to |
| 3126 | /// represent the given declaration in this module. This is usually D itself, |
| 3127 | /// but if D was imported and merged into a local declaration, we want the most |
| 3128 | /// recent local declaration instead. The chosen declaration will be the most |
| 3129 | /// recent declaration in any module that imports this one. |
| 3130 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3131 | NamedDecl *D) { |
| 3132 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3133 | return D; |
| 3134 | |
| 3135 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3136 | // For Redeclarable decls, a prior declaration might be local. |
| 3137 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
| 3138 | if (!Redecl->isFromASTFile()) |
| 3139 | return cast<NamedDecl>(Redecl); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3140 | // 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] | 3141 | // local one. |
| 3142 | if (D->getOwningModuleID() == 0) |
| 3143 | break; |
| 3144 | } |
| 3145 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3146 | // For Mergeable decls, the first decl might be local. |
| 3147 | if (!First->isFromASTFile()) |
| 3148 | return cast<NamedDecl>(First); |
| 3149 | } |
| 3150 | |
| 3151 | // All declarations are imported. Our most recent declaration will also be |
| 3152 | // the most recent one in anyone who imports us. |
| 3153 | return D; |
| 3154 | } |
| 3155 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3156 | namespace { |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3157 | class ASTIdentifierTableTrait { |
| 3158 | ASTWriter &Writer; |
| 3159 | Preprocessor &PP; |
| 3160 | IdentifierResolver &IdResolver; |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3161 | bool IsModule; |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3162 | bool NeedDecls; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3163 | ASTWriter::RecordData *InterestingIdentifierOffsets; |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3164 | |
| 3165 | /// \brief Determines whether this is an "interesting" identifier that needs a |
| 3166 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3167 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3168 | /// to check that. |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3169 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3170 | if (MacroOffset || |
| 3171 | II->isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3172 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3173 | II->hasRevertedTokenIDToIdentifier() || |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3174 | (NeedDecls && II->getFETokenInfo<void>())) |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3175 | return true; |
| 3176 | |
| 3177 | return false; |
| 3178 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3179 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3180 | public: |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3181 | typedef IdentifierInfo* key_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3182 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3183 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3184 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3185 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3187 | typedef unsigned hash_value_type; |
| 3188 | typedef unsigned offset_type; |
| 3189 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3190 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3191 | IdentifierResolver &IdResolver, bool IsModule, |
| 3192 | ASTWriter::RecordData *InterestingIdentifierOffsets) |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3193 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3194 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), |
| 3195 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3196 | |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3197 | bool needDecls() const { return NeedDecls; } |
| 3198 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3199 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 3200 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3201 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3202 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3203 | bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 3204 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3205 | return isInterestingIdentifier(II, MacroOffset); |
| 3206 | } |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3207 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { |
| 3208 | return isInterestingIdentifier(II, 0); |
| 3209 | } |
| 3210 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3211 | std::pair<unsigned,unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3212 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3213 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3214 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3215 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3216 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3217 | DataLen += 2; // 2 bytes for builtin ID |
| 3218 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3219 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3220 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3221 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3222 | if (NeedDecls) { |
| 3223 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3224 | DEnd = IdResolver.end(); |
| 3225 | D != DEnd; ++D) |
| 3226 | DataLen += 4; |
| 3227 | } |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3228 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3229 | using namespace llvm::support; |
| 3230 | endian::Writer<little> LE(Out); |
| 3231 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3232 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3233 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3234 | // We emit the key length after the data length so that every |
| 3235 | // string is preceded by a 16-bit length. This matches the PTH |
| 3236 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3237 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3238 | return std::make_pair(KeyLen, DataLen); |
| 3239 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3240 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3241 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3242 | unsigned KeyLen) { |
| 3243 | // Record the location of the key data. This is used when generating |
| 3244 | // the mapping from persistent IDs to strings. |
| 3245 | Writer.SetIdentifierOffset(II, Out.tell()); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3246 | |
| 3247 | // Emit the offset of the key/data length information to the interesting |
| 3248 | // identifiers table if necessary. |
| 3249 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) |
| 3250 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); |
| 3251 | |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3252 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3253 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3254 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3255 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3256 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3257 | using namespace llvm::support; |
| 3258 | endian::Writer<little> LE(Out); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3259 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3260 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3261 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3262 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3263 | return; |
| 3264 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3265 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3266 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3267 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3268 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3269 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3270 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3271 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3272 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3273 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3274 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3275 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3276 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3277 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3278 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3279 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3280 | if (HadMacroDefinition) |
| 3281 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3282 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3283 | if (NeedDecls) { |
| 3284 | // Emit the declaration IDs in reverse order, because the |
| 3285 | // IdentifierResolver provides the declarations as they would be |
| 3286 | // visible (e.g., the function "stat" would come before the struct |
| 3287 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3288 | // (so we need to see the struct "stat" before the function "stat"). |
| 3289 | // Only emit declarations that aren't from a chained PCH, though. |
| 3290 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), |
| 3291 | IdResolver.end()); |
| 3292 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3293 | DEnd = Decls.rend(); |
| 3294 | D != DEnd; ++D) |
| 3295 | LE.write<uint32_t>( |
| 3296 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
| 3297 | } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3298 | } |
| 3299 | }; |
| 3300 | } // end anonymous namespace |
| 3301 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3302 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3303 | /// |
| 3304 | /// The identifier table consists of a blob containing string data |
| 3305 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3306 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3307 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 3308 | IdentifierResolver &IdResolver, |
| 3309 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3310 | using namespace llvm; |
| 3311 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3312 | RecordData InterestingIdents; |
| 3313 | |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3314 | // Create and write out the blob that contains the identifier |
| 3315 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3316 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3317 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3318 | ASTIdentifierTableTrait Trait( |
| 3319 | *this, PP, IdResolver, IsModule, |
| 3320 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3321 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3322 | // Look for any identifiers that were named while processing the |
| 3323 | // headers, but are otherwise not needed. We add these to the hash |
| 3324 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3325 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3326 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3327 | SmallVector<const IdentifierInfo *, 128> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3328 | for (const auto &ID : PP.getIdentifierTable()) |
| 3329 | IIs.push_back(ID.second); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3330 | // Sort the identifiers lexicographically before getting them references so |
| 3331 | // that their order is stable. |
| 3332 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 3333 | for (const IdentifierInfo *II : IIs) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3334 | if (Trait.isInterestingNonMacroIdentifier(II)) |
| 3335 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3336 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3337 | // Create the on-disk hash table representation. We only store offsets |
| 3338 | // for identifiers that appear here for the first time. |
| 3339 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3340 | for (auto IdentIDPair : IdentifierIDs) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3341 | auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3342 | IdentID ID = IdentIDPair.second; |
| 3343 | assert(II && "NULL identifier in identifier table"); |
Vassil Vassilev | 262f41e | 2016-03-30 20:16:03 +0000 | [diff] [blame] | 3344 | // Write out identifiers if either the ID is local or the identifier has |
| 3345 | // changed since it was loaded. |
| 3346 | if (ID >= FirstIdentID || !Chain || !II->isFromAST() |
| 3347 | || II->hasChangedSinceDeserialization() || |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3348 | (Trait.needDecls() && |
| 3349 | II->hasFETokenInfoChangedSinceDeserialization())) |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3350 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3351 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3352 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3353 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3354 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3355 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3356 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3357 | using namespace llvm::support; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3358 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3359 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3360 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3361 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | // Create a blob abbreviation |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3365 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3366 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3367 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3368 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3369 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3370 | |
| 3371 | // Write the identifier table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3372 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3373 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | // Write the offsets table for identifier IDs. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3377 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3378 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3379 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3380 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3381 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3382 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3383 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3384 | #ifndef NDEBUG |
| 3385 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3386 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3387 | #endif |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3388 | |
| 3389 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, |
| 3390 | IdentifierOffsets.size(), |
| 3391 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3392 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3393 | bytes(IdentifierOffsets)); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3394 | |
| 3395 | // In C++, write the list of interesting identifiers (those that are |
| 3396 | // defined as macros, poisoned, or similar unusual things). |
| 3397 | if (!InterestingIdents.empty()) |
| 3398 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3399 | } |
| 3400 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3401 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3402 | // DeclContext's Name Lookup Table Serialization |
| 3403 | //===----------------------------------------------------------------------===// |
| 3404 | |
| 3405 | namespace { |
| 3406 | // Trait used for the on-disk hash table used in the method pool. |
| 3407 | class ASTDeclContextNameLookupTrait { |
| 3408 | ASTWriter &Writer; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3409 | llvm::SmallVector<DeclID, 64> DeclIDs; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3410 | |
| 3411 | public: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3412 | typedef DeclarationNameKey key_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3413 | typedef key_type key_type_ref; |
| 3414 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3415 | /// A start and end index into DeclIDs, representing a sequence of decls. |
| 3416 | typedef std::pair<unsigned, unsigned> data_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3417 | typedef const data_type& data_type_ref; |
| 3418 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3419 | typedef unsigned hash_value_type; |
| 3420 | typedef unsigned offset_type; |
| 3421 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3422 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 3423 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3424 | template<typename Coll> |
| 3425 | data_type getData(const Coll &Decls) { |
| 3426 | unsigned Start = DeclIDs.size(); |
| 3427 | for (NamedDecl *D : Decls) { |
| 3428 | DeclIDs.push_back( |
| 3429 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); |
| 3430 | } |
| 3431 | return std::make_pair(Start, DeclIDs.size()); |
| 3432 | } |
| 3433 | |
| 3434 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { |
| 3435 | unsigned Start = DeclIDs.size(); |
| 3436 | for (auto ID : FromReader) |
| 3437 | DeclIDs.push_back(ID); |
| 3438 | return std::make_pair(Start, DeclIDs.size()); |
| 3439 | } |
| 3440 | |
| 3441 | static bool EqualKey(key_type_ref a, key_type_ref b) { |
| 3442 | return a == b; |
| 3443 | } |
| 3444 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3445 | hash_value_type ComputeHash(DeclarationNameKey Name) { |
| 3446 | return Name.getHash(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3449 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { |
| 3450 | assert(Writer.hasChain() && |
| 3451 | "have reference to loaded module file but no chain?"); |
| 3452 | |
| 3453 | using namespace llvm::support; |
| 3454 | endian::Writer<little>(Out) |
| 3455 | .write<uint32_t>(Writer.getChain()->getModuleFileID(F)); |
| 3456 | } |
| 3457 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3458 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, |
| 3459 | DeclarationNameKey Name, |
| 3460 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3461 | using namespace llvm::support; |
| 3462 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3463 | unsigned KeyLen = 1; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3464 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3465 | case DeclarationName::Identifier: |
| 3466 | case DeclarationName::ObjCZeroArgSelector: |
| 3467 | case DeclarationName::ObjCOneArgSelector: |
| 3468 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3469 | case DeclarationName::CXXLiteralOperatorName: |
| 3470 | KeyLen += 4; |
| 3471 | break; |
| 3472 | case DeclarationName::CXXOperatorName: |
| 3473 | KeyLen += 1; |
| 3474 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3475 | case DeclarationName::CXXConstructorName: |
| 3476 | case DeclarationName::CXXDestructorName: |
| 3477 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3478 | case DeclarationName::CXXUsingDirective: |
| 3479 | break; |
| 3480 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3481 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3482 | |
Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3483 | // 4 bytes for each DeclID. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3484 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); |
| 3485 | assert(uint16_t(DataLen) == DataLen && |
| 3486 | "too many decls for serialized lookup result"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3487 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3488 | |
| 3489 | return std::make_pair(KeyLen, DataLen); |
| 3490 | } |
| 3491 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3492 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3493 | using namespace llvm::support; |
| 3494 | endian::Writer<little> LE(Out); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3495 | LE.write<uint8_t>(Name.getKind()); |
| 3496 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3497 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3498 | case DeclarationName::CXXLiteralOperatorName: |
| 3499 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3500 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3501 | case DeclarationName::ObjCZeroArgSelector: |
| 3502 | case DeclarationName::ObjCOneArgSelector: |
| 3503 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3504 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3505 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3506 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3507 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3508 | "Invalid operator?"); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3509 | LE.write<uint8_t>(Name.getOperatorKind()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3510 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3511 | case DeclarationName::CXXConstructorName: |
| 3512 | case DeclarationName::CXXDestructorName: |
| 3513 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3514 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3515 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3516 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3517 | |
| 3518 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3519 | } |
| 3520 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3521 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, |
| 3522 | unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3523 | using namespace llvm::support; |
| 3524 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3525 | uint64_t Start = Out.tell(); (void)Start; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3526 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) |
| 3527 | LE.write<uint32_t>(DeclIDs[I]); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3528 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3529 | } |
| 3530 | }; |
| 3531 | } // end anonymous namespace |
| 3532 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3533 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 3534 | DeclContext *DC) { |
| 3535 | return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage; |
| 3536 | } |
| 3537 | |
| 3538 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 3539 | DeclContext *DC) { |
| 3540 | for (auto *D : Result.getLookupResult()) |
| 3541 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 3542 | return false; |
| 3543 | |
| 3544 | return true; |
| 3545 | } |
| 3546 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3547 | void |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3548 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3549 | llvm::SmallVectorImpl<char> &LookupTable) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3550 | assert(!ConstDC->HasLazyLocalLexicalLookups && |
| 3551 | !ConstDC->HasLazyExternalLexicalLookups && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3552 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3553 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3554 | // FIXME: We need to build the lookups table, which is logically const. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3555 | auto *DC = const_cast<DeclContext*>(ConstDC); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3556 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 3557 | |
| 3558 | // Create the on-disk hash table representation. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3559 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, |
| 3560 | ASTDeclContextNameLookupTrait> Generator; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3561 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3562 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3563 | // The first step is to collect the declaration names which we need to |
| 3564 | // serialize into the name lookup table, and to collect them in a stable |
| 3565 | // order. |
| 3566 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3567 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3568 | // We also build up small sets of the constructor and conversion function |
| 3569 | // names which are visible. |
| 3570 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3571 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3572 | for (auto &Lookup : *DC->buildLookup()) { |
| 3573 | auto &Name = Lookup.first; |
| 3574 | auto &Result = Lookup.second; |
| 3575 | |
Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 3576 | // If there are no local declarations in our lookup result, we |
| 3577 | // don't need to write an entry for the name at all. If we can't |
| 3578 | // write out a lookup set without performing more deserialization, |
| 3579 | // just skip this entry. |
| 3580 | if (isLookupResultExternal(Result, DC) && |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3581 | isLookupResultEntirelyExternal(Result, DC)) |
| 3582 | continue; |
| 3583 | |
| 3584 | // We also skip empty results. If any of the results could be external and |
| 3585 | // the currently available results are empty, then all of the results are |
| 3586 | // external and we skip it above. So the only way we get here with an empty |
| 3587 | // results is when no results could have been external *and* we have |
| 3588 | // external results. |
| 3589 | // |
| 3590 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 3591 | // lookups into a decl context as an optimization, today we *have* to skip |
| 3592 | // them because there are names with empty lookup results in decl contexts |
| 3593 | // which we can't emit in any stable ordering: we lookup constructors and |
| 3594 | // conversion functions in the enclosing namespace scope creating empty |
| 3595 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 3596 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 3597 | // here by omitting lookups with empty results. |
| 3598 | if (Lookup.second.getLookupResult().empty()) |
| 3599 | continue; |
| 3600 | |
| 3601 | switch (Lookup.first.getNameKind()) { |
| 3602 | default: |
| 3603 | Names.push_back(Lookup.first); |
| 3604 | break; |
| 3605 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3606 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3607 | assert(isa<CXXRecordDecl>(DC) && |
| 3608 | "Cannot have a constructor name outside of a class!"); |
| 3609 | ConstructorNameSet.insert(Name); |
| 3610 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3611 | |
| 3612 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3613 | assert(isa<CXXRecordDecl>(DC) && |
| 3614 | "Cannot have a conversion function name outside of a class!"); |
| 3615 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 3616 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3617 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3618 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3619 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3620 | // Sort the names into a stable order. |
| 3621 | std::sort(Names.begin(), Names.end()); |
| 3622 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3623 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3624 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3625 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3626 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3627 | // First we try the easy case by forming the current context's constructor |
| 3628 | // name and adding that name first. This is a very useful optimization to |
| 3629 | // avoid walking the lexical declarations in many cases, and it also |
| 3630 | // handles the only case where a constructor name can come from some other |
| 3631 | // lexical context -- when that name is an implicit constructor merged from |
| 3632 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 3633 | // conversion function which doesn't occur in all the lexical contexts |
| 3634 | // would be an ODR violation. |
| 3635 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 3636 | Context->getCanonicalType(Context->getRecordType(D))); |
| 3637 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 3638 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3639 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3640 | // If we still have constructors or conversion functions, we walk all the |
| 3641 | // names in the decl and add the constructors and conversion functions |
| 3642 | // which are visible in the order they lexically occur within the context. |
| 3643 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 3644 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 3645 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 3646 | auto Name = ChildND->getDeclName(); |
| 3647 | switch (Name.getNameKind()) { |
| 3648 | default: |
| 3649 | continue; |
| 3650 | |
| 3651 | case DeclarationName::CXXConstructorName: |
| 3652 | if (ConstructorNameSet.erase(Name)) |
| 3653 | Names.push_back(Name); |
| 3654 | break; |
| 3655 | |
| 3656 | case DeclarationName::CXXConversionFunctionName: |
| 3657 | if (ConversionNameSet.erase(Name)) |
| 3658 | Names.push_back(Name); |
| 3659 | break; |
| 3660 | } |
| 3661 | |
| 3662 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 3663 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3664 | } |
| 3665 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3666 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 3667 | "constructors by walking all the " |
| 3668 | "lexical members of the context."); |
| 3669 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 3670 | "conversion functions by walking all " |
| 3671 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3672 | } |
| 3673 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3674 | // Next we need to do a lookup with each name into this decl context to fully |
| 3675 | // populate any results from external sources. We don't actually use the |
| 3676 | // results of these lookups because we only want to use the results after all |
| 3677 | // results have been loaded and the pointers into them will be stable. |
| 3678 | for (auto &Name : Names) |
| 3679 | DC->lookup(Name); |
| 3680 | |
| 3681 | // Now we need to insert the results for each name into the hash table. For |
| 3682 | // constructor names and conversion function names, we actually need to merge |
| 3683 | // all of the results for them into one list of results each and insert |
| 3684 | // those. |
| 3685 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 3686 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 3687 | |
| 3688 | // Now loop over the names, either inserting them or appending for the two |
| 3689 | // special cases. |
| 3690 | for (auto &Name : Names) { |
| 3691 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 3692 | |
| 3693 | switch (Name.getNameKind()) { |
| 3694 | default: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3695 | Generator.insert(Name, Trait.getData(Result), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3696 | break; |
| 3697 | |
| 3698 | case DeclarationName::CXXConstructorName: |
| 3699 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 3700 | break; |
| 3701 | |
| 3702 | case DeclarationName::CXXConversionFunctionName: |
| 3703 | ConversionDecls.append(Result.begin(), Result.end()); |
| 3704 | break; |
| 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 3709 | // the first declaration's name here because the name itself isn't part of |
| 3710 | // the key, only the kind of name is used. |
| 3711 | if (!ConstructorDecls.empty()) |
| 3712 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3713 | Trait.getData(ConstructorDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3714 | if (!ConversionDecls.empty()) |
| 3715 | Generator.insert(ConversionDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3716 | Trait.getData(ConversionDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3717 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3718 | // Create the on-disk hash table. Also emit the existing imported and |
| 3719 | // merged table if there is one. |
| 3720 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; |
| 3721 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3724 | /// \brief Write the block containing all of the declaration IDs |
| 3725 | /// visible from the given DeclContext. |
| 3726 | /// |
| 3727 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3728 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3729 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 3730 | DeclContext *DC) { |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3731 | // If we imported a key declaration of this namespace, write the visible |
| 3732 | // lookup results as an update record for it rather than including them |
| 3733 | // on this declaration. We will only look at key declarations on reload. |
| 3734 | if (isa<NamespaceDecl>(DC) && Chain && |
| 3735 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { |
| 3736 | // Only do this once, for the first local declaration of the namespace. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3737 | for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3738 | Prev = Prev->getPreviousDecl()) |
| 3739 | if (!Prev->isFromASTFile()) |
| 3740 | return 0; |
| 3741 | |
| 3742 | // Note that we need to emit an update record for the primary context. |
| 3743 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); |
| 3744 | |
| 3745 | // Make sure all visible decls are written. They will be recorded later. We |
| 3746 | // do this using a side data structure so we can sort the names into |
| 3747 | // a deterministic order. |
| 3748 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); |
| 3749 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> |
| 3750 | LookupResults; |
| 3751 | if (Map) { |
| 3752 | LookupResults.reserve(Map->size()); |
| 3753 | for (auto &Entry : *Map) |
| 3754 | LookupResults.push_back( |
| 3755 | std::make_pair(Entry.first, Entry.second.getLookupResult())); |
| 3756 | } |
| 3757 | |
| 3758 | std::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); |
| 3759 | for (auto &NameAndResult : LookupResults) { |
| 3760 | DeclarationName Name = NameAndResult.first; |
| 3761 | DeclContext::lookup_result Result = NameAndResult.second; |
| 3762 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || |
| 3763 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 3764 | // We have to work around a name lookup bug here where negative lookup |
| 3765 | // results for these names get cached in namespace lookup tables (these |
| 3766 | // names should never be looked up in a namespace). |
| 3767 | assert(Result.empty() && "Cannot have a constructor or conversion " |
| 3768 | "function name in a namespace!"); |
| 3769 | continue; |
| 3770 | } |
| 3771 | |
| 3772 | for (NamedDecl *ND : Result) |
| 3773 | if (!ND->isFromASTFile()) |
| 3774 | GetDeclRef(ND); |
| 3775 | } |
| 3776 | |
| 3777 | return 0; |
| 3778 | } |
| 3779 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3780 | if (DC->getPrimaryContext() != DC) |
| 3781 | return 0; |
| 3782 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3783 | // Skip contexts which don't support name lookup. |
| 3784 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3785 | return 0; |
| 3786 | |
| 3787 | // If not in C++, we perform name lookup for the translation unit via the |
| 3788 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3789 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3790 | return 0; |
| 3791 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3792 | // Serialize the contents of the mapping used for lookup. Note that, |
| 3793 | // although we have two very different code paths, the serialized |
| 3794 | // representation is the same for both cases: a declaration name, |
| 3795 | // followed by a size, followed by references to the visible |
| 3796 | // declarations that have that name. |
| 3797 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3798 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3799 | if (!Map || Map->empty()) |
| 3800 | return 0; |
| 3801 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3802 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3803 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3804 | GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3805 | |
| 3806 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3807 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3808 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3809 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3810 | ++NumVisibleDeclContexts; |
| 3811 | return Offset; |
| 3812 | } |
| 3813 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3814 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3815 | /// |
| 3816 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3817 | /// 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] | 3818 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3819 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3820 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3821 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3822 | if (!Map || Map->empty()) |
| 3823 | return; |
| 3824 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3825 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3826 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3827 | GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3828 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3829 | // If we're updating a namespace, select a key declaration as the key for the |
| 3830 | // update record; those are the only ones that will be checked on reload. |
| 3831 | if (isa<NamespaceDecl>(DC)) |
| 3832 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); |
| 3833 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3834 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3835 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3836 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3837 | } |
| 3838 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3839 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3840 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3841 | RecordData::value_type Record[] = {Opts.fp_contract}; |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3842 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3843 | } |
| 3844 | |
| 3845 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3846 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3847 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3848 | return; |
| 3849 | |
| 3850 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3851 | RecordData Record; |
| 3852 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3853 | #include "clang/Basic/OpenCLExtensions.def" |
| 3854 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3855 | } |
| 3856 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3857 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3858 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3859 | RecordData Categories; |
| 3860 | |
| 3861 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3862 | unsigned Size = 0; |
| 3863 | unsigned StartIndex = Categories.size(); |
| 3864 | |
| 3865 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3866 | |
| 3867 | // Allocate space for the size. |
| 3868 | Categories.push_back(0); |
| 3869 | |
| 3870 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3871 | for (ObjCInterfaceDecl::known_categories_iterator |
| 3872 | Cat = Class->known_categories_begin(), |
| 3873 | CatEnd = Class->known_categories_end(); |
| 3874 | Cat != CatEnd; ++Cat, ++Size) { |
| 3875 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 3876 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | // Update the size. |
| 3880 | Categories[StartIndex] = Size; |
| 3881 | |
| 3882 | // Record this interface -> category map. |
| 3883 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3884 | CategoriesMap.push_back(CatInfo); |
| 3885 | } |
| 3886 | |
| 3887 | // Sort the categories map by the definition ID, since the reader will be |
| 3888 | // performing binary searches on this information. |
| 3889 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3890 | |
| 3891 | // Emit the categories map. |
| 3892 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3893 | |
| 3894 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3895 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3896 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3897 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3898 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3899 | |
| 3900 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; |
| 3901 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3902 | reinterpret_cast<char *>(CategoriesMap.data()), |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3903 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3904 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3905 | // Emit the category lists. |
| 3906 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3907 | } |
| 3908 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3909 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 3910 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 3911 | |
| 3912 | if (LPTMap.empty()) |
| 3913 | return; |
| 3914 | |
| 3915 | RecordData Record; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 3916 | for (auto LPTMapEntry : LPTMap) { |
| 3917 | const FunctionDecl *FD = LPTMapEntry.first; |
| 3918 | LateParsedTemplate *LPT = LPTMapEntry.second; |
| 3919 | AddDeclRef(FD, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3920 | AddDeclRef(LPT->D, Record); |
| 3921 | Record.push_back(LPT->Toks.size()); |
| 3922 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3923 | for (const auto &Tok : LPT->Toks) { |
| 3924 | AddToken(Tok, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3925 | } |
| 3926 | } |
| 3927 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 3928 | } |
| 3929 | |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3930 | /// \brief Write the state of 'pragma clang optimize' at the end of the module. |
| 3931 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 3932 | RecordData Record; |
| 3933 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 3934 | AddSourceLocation(PragmaLoc, Record); |
| 3935 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 3936 | } |
| 3937 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 3938 | /// \brief Write the state of 'pragma ms_struct' at the end of the module. |
| 3939 | void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) { |
| 3940 | RecordData Record; |
| 3941 | Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF); |
| 3942 | Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record); |
| 3943 | } |
| 3944 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 3945 | /// \brief Write the state of 'pragma pointers_to_members' at the end of the |
| 3946 | //module. |
| 3947 | void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) { |
| 3948 | RecordData Record; |
| 3949 | Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod); |
| 3950 | AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record); |
| 3951 | Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record); |
| 3952 | } |
| 3953 | |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 3954 | void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, |
| 3955 | ModuleFileExtensionWriter &Writer) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3956 | // Enter the extension block. |
| 3957 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); |
| 3958 | |
| 3959 | // Emit the metadata record abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3960 | auto *Abv = new llvm::BitCodeAbbrev(); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3961 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); |
| 3962 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3963 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3964 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3965 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3966 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3967 | unsigned Abbrev = Stream.EmitAbbrev(Abv); |
| 3968 | |
| 3969 | // Emit the metadata record. |
| 3970 | RecordData Record; |
| 3971 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); |
| 3972 | Record.push_back(EXTENSION_METADATA); |
| 3973 | Record.push_back(Metadata.MajorVersion); |
| 3974 | Record.push_back(Metadata.MinorVersion); |
| 3975 | Record.push_back(Metadata.BlockName.size()); |
| 3976 | Record.push_back(Metadata.UserInfo.size()); |
| 3977 | SmallString<64> Buffer; |
| 3978 | Buffer += Metadata.BlockName; |
| 3979 | Buffer += Metadata.UserInfo; |
| 3980 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); |
| 3981 | |
| 3982 | // Emit the contents of the extension block. |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 3983 | Writer.writeExtensionContents(SemaRef, Stream); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3984 | |
| 3985 | // Exit the extension block. |
| 3986 | Stream.ExitBlock(); |
| 3987 | } |
| 3988 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3989 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3990 | // General Serialization Routines |
| 3991 | //===----------------------------------------------------------------------===// |
| 3992 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 3993 | /// \brief Emit the list of attributes to the specified record. |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 3994 | void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) { |
| 3995 | auto &Record = *this; |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3996 | Record.push_back(Attrs.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3997 | for (const auto *A : Attrs) { |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3998 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 3999 | Record.AddSourceRange(A->getRange()); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4000 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 4001 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 4002 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4003 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4004 | } |
| 4005 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 4006 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 4007 | AddSourceLocation(Tok.getLocation(), Record); |
| 4008 | Record.push_back(Tok.getLength()); |
| 4009 | |
| 4010 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 4011 | // if it is needed. |
| 4012 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 4013 | // FIXME: Should translate token kind to a stable encoding. |
| 4014 | Record.push_back(Tok.getKind()); |
| 4015 | // FIXME: Should translate token flags to a stable encoding. |
| 4016 | Record.push_back(Tok.getFlags()); |
| 4017 | } |
| 4018 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4019 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4020 | Record.push_back(Str.size()); |
| 4021 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 4022 | } |
| 4023 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4024 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4025 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4026 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4027 | bool Changed = |
| 4028 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4029 | |
| 4030 | // Remove a prefix to make the path relative, if relevant. |
| 4031 | const char *PathBegin = Path.data(); |
| 4032 | const char *PathPtr = |
| 4033 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 4034 | if (PathPtr != PathBegin) { |
| 4035 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 4036 | Changed = true; |
| 4037 | } |
| 4038 | |
| 4039 | return Changed; |
| 4040 | } |
| 4041 | |
| 4042 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 4043 | SmallString<128> FilePath(Path); |
| 4044 | PreparePathForOutput(FilePath); |
| 4045 | AddString(FilePath, Record); |
| 4046 | } |
| 4047 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4048 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4049 | StringRef Path) { |
| 4050 | SmallString<128> FilePath(Path); |
| 4051 | PreparePathForOutput(FilePath); |
| 4052 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 4053 | } |
| 4054 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4055 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 4056 | RecordDataImpl &Record) { |
| 4057 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4058 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4059 | Record.push_back(*Minor + 1); |
| 4060 | else |
| 4061 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4062 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4063 | Record.push_back(*Subminor + 1); |
| 4064 | else |
| 4065 | Record.push_back(0); |
| 4066 | } |
| 4067 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4068 | /// \brief Note that the identifier II occurs at the given offset |
| 4069 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4070 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4071 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4072 | // 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] | 4073 | // up earlier in the chain and thus don't need an offset. |
| 4074 | if (ID >= FirstIdentID) |
| 4075 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4076 | } |
| 4077 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4078 | /// \brief Note that the selector Sel occurs at the given offset |
| 4079 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4080 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4081 | unsigned ID = SelectorIDs[Sel]; |
| 4082 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4083 | // Don't record offsets for selectors that are also available in a different |
| 4084 | // file. |
| 4085 | if (ID < FirstSelectorID) |
| 4086 | return; |
| 4087 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4088 | } |
| 4089 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4090 | ASTWriter::ASTWriter( |
| 4091 | llvm::BitstreamWriter &Stream, |
| 4092 | ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions, |
| 4093 | bool IncludeTimestamps) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4094 | : Stream(Stream), Context(nullptr), PP(nullptr), Chain(nullptr), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4095 | WritingModule(nullptr), IncludeTimestamps(IncludeTimestamps), |
| 4096 | WritingAST(false), DoneWritingDeclsAndTypes(false), |
| 4097 | ASTHasCompilerErrors(false), FirstDeclID(NUM_PREDEF_DECL_IDS), |
| 4098 | NextDeclID(FirstDeclID), FirstTypeID(NUM_PREDEF_TYPE_IDS), |
| 4099 | NextTypeID(FirstTypeID), FirstIdentID(NUM_PREDEF_IDENT_IDS), |
| 4100 | NextIdentID(FirstIdentID), FirstMacroID(NUM_PREDEF_MACRO_IDS), |
| 4101 | NextMacroID(FirstMacroID), FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4102 | NextSubmoduleID(FirstSubmoduleID), |
| 4103 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4104 | NumStatements(0), NumMacros(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4105 | NumLexicalDeclContexts(0), NumVisibleDeclContexts(0), |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4106 | NextCXXBaseSpecifiersID(1), NextCXXCtorInitializersID(1), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4107 | TypeExtQualAbbrev(0), TypeFunctionProtoAbbrev(0), DeclParmVarAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4108 | DeclContextLexicalAbbrev(0), DeclContextVisibleLookupAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4109 | UpdateVisibleAbbrev(0), DeclRecordAbbrev(0), DeclTypedefAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4110 | DeclVarAbbrev(0), DeclFieldAbbrev(0), DeclEnumAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4111 | DeclObjCIvarAbbrev(0), DeclCXXMethodAbbrev(0), DeclRefExprAbbrev(0), |
| 4112 | CharacterLiteralAbbrev(0), IntegerLiteralAbbrev(0), |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4113 | ExprImplicitCastAbbrev(0) { |
| 4114 | for (const auto &Ext : Extensions) { |
| 4115 | if (auto Writer = Ext->createExtensionWriter(*this)) |
| 4116 | ModuleFileExtensionWriters.push_back(std::move(Writer)); |
| 4117 | } |
| 4118 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4119 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4120 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 4121 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4122 | } |
| 4123 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4124 | const LangOptions &ASTWriter::getLangOpts() const { |
| 4125 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 4126 | return Context->getLangOpts(); |
| 4127 | } |
| 4128 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4129 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { |
| 4130 | return IncludeTimestamps ? E->getModificationTime() : 0; |
| 4131 | } |
| 4132 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4133 | uint64_t ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile, |
| 4134 | Module *WritingModule, StringRef isysroot, |
| 4135 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4136 | WritingAST = true; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4137 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4138 | ASTHasCompilerErrors = hasErrors; |
| 4139 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4140 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4141 | Stream.Emit((unsigned)'C', 8); |
| 4142 | Stream.Emit((unsigned)'P', 8); |
| 4143 | Stream.Emit((unsigned)'C', 8); |
| 4144 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4145 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4146 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4147 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4148 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4149 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4150 | this->WritingModule = WritingModule; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4151 | ASTFileSignature Signature = |
| 4152 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4153 | Context = nullptr; |
| 4154 | PP = nullptr; |
| 4155 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4156 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4157 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4158 | WritingAST = false; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4159 | return Signature; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4162 | template<typename Vector> |
| 4163 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4164 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4165 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4166 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4167 | Writer.AddDeclRef(*I, Record); |
| 4168 | } |
| 4169 | } |
| 4170 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4171 | uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, |
| 4172 | const std::string &OutputFile, |
| 4173 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4174 | using namespace llvm; |
| 4175 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4176 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4177 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4178 | // Make sure that the AST reader knows to finalize itself. |
| 4179 | if (Chain) |
| 4180 | Chain->finalizeForWriting(); |
| 4181 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4182 | ASTContext &Context = SemaRef.Context; |
| 4183 | Preprocessor &PP = SemaRef.PP; |
| 4184 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4185 | // Set up predefined declaration IDs. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4186 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { |
| 4187 | if (D) { |
| 4188 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); |
| 4189 | DeclIDs[D] = ID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4190 | } |
| 4191 | }; |
| 4192 | RegisterPredefDecl(Context.getTranslationUnitDecl(), |
| 4193 | PREDEF_DECL_TRANSLATION_UNIT_ID); |
| 4194 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); |
| 4195 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); |
| 4196 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); |
| 4197 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, |
| 4198 | PREDEF_DECL_OBJC_PROTOCOL_ID); |
| 4199 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); |
| 4200 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); |
| 4201 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, |
| 4202 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); |
| 4203 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4204 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4205 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, |
| 4206 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4207 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4208 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, |
| 4209 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 4210 | RegisterPredefDecl(Context.CFConstantStringTypeDecl, |
| 4211 | PREDEF_DECL_CF_CONSTANT_STRING_ID); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 4212 | RegisterPredefDecl(Context.CFConstantStringTagDecl, |
| 4213 | PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4214 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4215 | // 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] | 4216 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4217 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4218 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4219 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4220 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4221 | // Build a record containing all of the file scoped decls in this file. |
| 4222 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4223 | if (!isModule) |
| 4224 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4225 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4226 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4227 | // Build a record containing all of the delegating constructors we still need |
| 4228 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4229 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4230 | if (!isModule) |
| 4231 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4232 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4233 | // Write the set of weak, undeclared identifiers. We always write the |
| 4234 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4235 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4236 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4237 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4238 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4239 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4240 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4241 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4242 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4243 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4244 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4245 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4246 | // Build a record containing all of the ext_vector declarations. |
| 4247 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4248 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4249 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4250 | // Build a record containing all of the VTable uses information. |
| 4251 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4252 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4253 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4254 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4255 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4256 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4257 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4258 | } |
| 4259 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4260 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4261 | RecordData UnusedLocalTypedefNameCandidates; |
| 4262 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4263 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4264 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4265 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4266 | RecordData PendingInstantiations; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4267 | for (const auto &I : SemaRef.PendingInstantiations) { |
| 4268 | AddDeclRef(I.first, PendingInstantiations); |
| 4269 | AddSourceLocation(I.second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4270 | } |
| 4271 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4272 | "There are local ones at end of translation unit!"); |
| 4273 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4274 | // Build a record containing some declaration references. |
| 4275 | RecordData SemaDeclRefs; |
| 4276 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 4277 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4278 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 4279 | } |
| 4280 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4281 | RecordData CUDASpecialDeclRefs; |
| 4282 | if (Context.getcudaConfigureCallDecl()) { |
| 4283 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4284 | } |
| 4285 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4286 | // Build a record containing all of the known namespaces. |
| 4287 | RecordData KnownNamespaces; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4288 | for (const auto &I : SemaRef.KnownNamespaces) { |
| 4289 | if (!I.second) |
| 4290 | AddDeclRef(I.first, KnownNamespaces); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4291 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4292 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4293 | // Build a record of all used, undefined objects that require definitions. |
| 4294 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4295 | |
| 4296 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4297 | SemaRef.getUndefinedButUsed(Undefined); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4298 | for (const auto &I : Undefined) { |
| 4299 | AddDeclRef(I.first, UndefinedButUsed); |
| 4300 | AddSourceLocation(I.second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4301 | } |
| 4302 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4303 | // Build a record containing all delete-expressions that we would like to |
| 4304 | // analyze later in AST. |
| 4305 | RecordData DeleteExprsToAnalyze; |
| 4306 | |
| 4307 | for (const auto &DeleteExprsInfo : |
| 4308 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4309 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4310 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4311 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4312 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4313 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4314 | } |
| 4315 | } |
| 4316 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4317 | // Write the control block |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4318 | uint64_t Signature = WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4319 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4320 | // Write the remaining AST contents. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4321 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4322 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4323 | // This is so that older clang versions, before the introduction |
| 4324 | // of the control block, can read and reject the newer PCH format. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4325 | { |
| 4326 | RecordData Record = {VERSION_MAJOR}; |
| 4327 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4328 | } |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4329 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4330 | // Create a lexical update block containing all of the declarations in the |
| 4331 | // translation unit that do not come from other AST files. |
| 4332 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4333 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; |
| 4334 | for (const auto *D : TU->noload_decls()) { |
| 4335 | if (!D->isFromASTFile()) { |
| 4336 | NewGlobalKindDeclPairs.push_back(D->getKind()); |
| 4337 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); |
| 4338 | } |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4339 | } |
| 4340 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4341 | auto *Abv = new llvm::BitCodeAbbrev(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4342 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4343 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4344 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4345 | { |
| 4346 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; |
| 4347 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 4348 | bytes(NewGlobalKindDeclPairs)); |
| 4349 | } |
| 4350 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4351 | // And a visible updates block for the translation unit. |
| 4352 | Abv = new llvm::BitCodeAbbrev(); |
| 4353 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4354 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4355 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4356 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 4357 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4358 | |
| 4359 | // If we have any extern "C" names, write out a visible update for them. |
| 4360 | if (Context.ExternCContext) |
| 4361 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4362 | |
| 4363 | // If the translation unit has an anonymous namespace, and we don't already |
| 4364 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4365 | // 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] | 4366 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4367 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4368 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4369 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4370 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4371 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4372 | // Add update records for all mangling numbers and static local numbers. |
| 4373 | // These aren't really update records, but this is a convenient way of |
| 4374 | // tagging this rare extra data onto the declarations. |
| 4375 | for (const auto &Number : Context.MangleNumbers) |
| 4376 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4377 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4378 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4379 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4380 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4381 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4382 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4383 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4384 | // Make sure visible decls, added to DeclContexts previously loaded from |
| 4385 | // an AST file, are registered for serialization. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4386 | for (const auto *I : UpdatingVisibleDecls) { |
| 4387 | GetDeclRef(I); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4390 | // Make sure all decls associated with an identifier are registered for |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4391 | // serialization, if we're storing decls with identifiers. |
| 4392 | if (!WritingModule || !getLangOpts().CPlusPlus) { |
| 4393 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4394 | for (const auto &ID : PP.getIdentifierTable()) { |
| 4395 | const IdentifierInfo *II = ID.second; |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4396 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 4397 | IIs.push_back(II); |
| 4398 | } |
| 4399 | // Sort the identifiers to visit based on their name. |
| 4400 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 4401 | for (const IdentifierInfo *II : IIs) { |
| 4402 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4403 | DEnd = SemaRef.IdResolver.end(); |
| 4404 | D != DEnd; ++D) { |
| 4405 | GetDeclRef(*D); |
| 4406 | } |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4407 | } |
| 4408 | } |
| 4409 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4410 | // Form the record of special types. |
| 4411 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4412 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4413 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 4414 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 4415 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 4416 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 4417 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4418 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4419 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4420 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4421 | if (Chain) { |
| 4422 | // Write the mapping information describing our module dependencies and how |
| 4423 | // each of those modules were mapped into our own offset/ID space, so that |
| 4424 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4425 | // The map consists solely of a blob with the following format: |
| 4426 | // *(module-name-len:i16 module-name:len*i8 |
| 4427 | // source-location-offset:i32 |
| 4428 | // identifier-id:i32 |
| 4429 | // preprocessed-entity-id:i32 |
| 4430 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4431 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4432 | // selector-id:i32 |
| 4433 | // declaration-id:i32 |
| 4434 | // c++-base-specifiers-id:i32 |
| 4435 | // type-id:i32) |
| 4436 | // |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4437 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4438 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4439 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 4440 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4441 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4442 | { |
| 4443 | llvm::raw_svector_ostream Out(Buffer); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4444 | for (ModuleFile *M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4445 | using namespace llvm::support; |
| 4446 | endian::Writer<little> LE(Out); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4447 | StringRef FileName = M->FileName; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4448 | LE.write<uint16_t>(FileName.size()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4449 | Out.write(FileName.data(), FileName.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4450 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4451 | // Note: if a base ID was uint max, it would not be possible to load |
| 4452 | // another module after it or have more than one entity inside it. |
| 4453 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 4454 | |
| 4455 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 4456 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 4457 | if (ShouldWrite) |
| 4458 | LE.write<uint32_t>(BaseID); |
| 4459 | else |
| 4460 | LE.write<uint32_t>(None); |
| 4461 | }; |
| 4462 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4463 | // These values should be unique within a chain, since they will be read |
| 4464 | // as keys into ContinuousRangeMaps. |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4465 | writeBaseIDOrNone(M->SLocEntryBaseOffset, M->LocalNumSLocEntries); |
| 4466 | writeBaseIDOrNone(M->BaseIdentifierID, M->LocalNumIdentifiers); |
| 4467 | writeBaseIDOrNone(M->BaseMacroID, M->LocalNumMacros); |
| 4468 | writeBaseIDOrNone(M->BasePreprocessedEntityID, |
| 4469 | M->NumPreprocessedEntities); |
| 4470 | writeBaseIDOrNone(M->BaseSubmoduleID, M->LocalNumSubmodules); |
| 4471 | writeBaseIDOrNone(M->BaseSelectorID, M->LocalNumSelectors); |
| 4472 | writeBaseIDOrNone(M->BaseDeclID, M->LocalNumDecls); |
| 4473 | writeBaseIDOrNone(M->BaseTypeIndex, M->LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4474 | } |
| 4475 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4476 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4477 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4478 | Buffer.data(), Buffer.size()); |
| 4479 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4480 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4481 | RecordData DeclUpdatesOffsetsRecord; |
| 4482 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4483 | // Keep writing types, declarations, and declaration update records |
| 4484 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4485 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 4486 | WriteTypeAbbrevs(); |
| 4487 | WriteDeclAbbrevs(); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4488 | do { |
| 4489 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 4490 | while (!DeclTypesToEmit.empty()) { |
| 4491 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 4492 | DeclTypesToEmit.pop(); |
| 4493 | if (DOT.isType()) |
| 4494 | WriteType(DOT.getType()); |
| 4495 | else |
| 4496 | WriteDecl(Context, DOT.getDecl()); |
| 4497 | } |
| 4498 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4499 | Stream.ExitBlock(); |
| 4500 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4501 | DoneWritingDeclsAndTypes = true; |
| 4502 | |
| 4503 | // These things can only be done once we've written out decls and types. |
| 4504 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4505 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 4506 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4507 | WriteCXXBaseSpecifiersOffsets(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4508 | WriteCXXCtorInitializersOffsets(); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4509 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4510 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4511 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4512 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4513 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4514 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4515 | WriteReferencedSelectorsPool(SemaRef); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 4516 | WriteLateParsedTemplates(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4517 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4518 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 4519 | WriteOpenCLExtensions(SemaRef); |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 4520 | WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4521 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4522 | // If we're emitting a module, write out the submodule information. |
| 4523 | if (WritingModule) |
| 4524 | WriteSubmodules(WritingModule); |
| 4525 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4526 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 4527 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4528 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 4529 | if (!EagerlyDeserializedDecls.empty()) |
| 4530 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4531 | |
| 4532 | // Write the record containing tentative definitions. |
| 4533 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4534 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4535 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4536 | // Write the record containing unused file scoped decls. |
| 4537 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4538 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4539 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4540 | // Write the record containing weak undeclared identifiers. |
| 4541 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4542 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4543 | WeakUndeclaredIdentifiers); |
| 4544 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4545 | // Write the record containing ext_vector type names. |
| 4546 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4547 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4548 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4549 | // Write the record containing VTable uses information. |
| 4550 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4551 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4552 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4553 | // Write the record containing potentially unused local typedefs. |
| 4554 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 4555 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 4556 | UnusedLocalTypedefNameCandidates); |
| 4557 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4558 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4559 | if (!PendingInstantiations.empty()) |
| 4560 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4561 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4562 | // Write the record containing declaration references of Sema. |
| 4563 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4564 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4565 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4566 | // Write the record containing CUDA-specific declaration references. |
| 4567 | if (!CUDASpecialDeclRefs.empty()) |
| 4568 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4569 | |
| 4570 | // Write the delegating constructors. |
| 4571 | if (!DelegatingCtorDecls.empty()) |
| 4572 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4573 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4574 | // Write the known namespaces. |
| 4575 | if (!KnownNamespaces.empty()) |
| 4576 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4577 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4578 | // Write the undefined internal functions and variables, and inline functions. |
| 4579 | if (!UndefinedButUsed.empty()) |
| 4580 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4581 | |
| 4582 | if (!DeleteExprsToAnalyze.empty()) |
| 4583 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 4584 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4585 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4586 | for (auto *DC : UpdatedDeclContexts) |
| 4587 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4588 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4589 | if (!WritingModule) { |
| 4590 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4591 | struct ModuleInfo { |
| 4592 | uint64_t ID; |
| 4593 | Module *M; |
| 4594 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 4595 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4596 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 4597 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4598 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4599 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 4600 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4601 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4602 | |
| 4603 | if (!Imports.empty()) { |
| 4604 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4605 | return A.ID < B.ID; |
| 4606 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4607 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4608 | return A.ID == B.ID; |
| 4609 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4610 | |
| 4611 | // Sort and deduplicate module IDs. |
| 4612 | std::sort(Imports.begin(), Imports.end(), Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4613 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4614 | Imports.end()); |
| 4615 | |
| 4616 | RecordData ImportedModules; |
| 4617 | for (const auto &Import : Imports) { |
| 4618 | ImportedModules.push_back(Import.ID); |
| 4619 | // FIXME: If the module has macros imported then later has declarations |
| 4620 | // imported, this location won't be the right one as a location for the |
| 4621 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 4622 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4623 | } |
| 4624 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4625 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 4626 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4627 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4628 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4629 | WriteObjCCategories(); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4630 | if(!WritingModule) { |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4631 | WriteOptimizePragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4632 | WriteMSStructPragmaOptions(SemaRef); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4633 | WriteMSPointersToMembersPragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4634 | } |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4635 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4636 | // Some simple statistics |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4637 | RecordData::value_type Record[] = { |
| 4638 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4639 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4640 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4641 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4642 | // Write the module file extension blocks. |
| 4643 | for (const auto &ExtWriter : ModuleFileExtensionWriters) |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4644 | WriteModuleFileExtension(SemaRef, *ExtWriter); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4645 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4646 | return Signature; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4649 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4650 | if (DeclUpdates.empty()) |
| 4651 | return; |
| 4652 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4653 | DeclUpdateMap LocalUpdates; |
| 4654 | LocalUpdates.swap(DeclUpdates); |
| 4655 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4656 | for (auto &DeclUpdate : LocalUpdates) { |
| 4657 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 4658 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4659 | bool HasUpdatedBody = false; |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4660 | RecordData RecordData; |
| 4661 | ASTRecordWriter Record(*this, RecordData); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4662 | for (auto &Update : DeclUpdate.second) { |
| 4663 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 4664 | |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4665 | // An updated body is emitted last, so that the reader doesn't need |
| 4666 | // to skip over the lazy body to reach statements for other records. |
| 4667 | if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION) |
| 4668 | HasUpdatedBody = true; |
| 4669 | else |
| 4670 | Record.push_back(Kind); |
| 4671 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4672 | switch (Kind) { |
| 4673 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 4674 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 4675 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4676 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4677 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 4678 | break; |
| 4679 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4680 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4681 | break; |
| 4682 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4683 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4684 | Record.AddSourceLocation(Update.getLoc()); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4685 | break; |
| 4686 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4687 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4688 | Record.AddStmt(const_cast<Expr *>( |
| 4689 | cast<ParmVarDecl>(Update.getDecl())->getDefaultArg())); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4690 | break; |
| 4691 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4692 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4693 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 4694 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4695 | Record.AddCXXDefinitionData(RD); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4696 | Record.push_back(WriteDeclContextLexicalBlock( |
| 4697 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 4698 | |
| 4699 | // This state is sometimes updated by template instantiation, when we |
| 4700 | // switch from the specialization referring to the template declaration |
| 4701 | // to it referring to the template definition. |
| 4702 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 4703 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4704 | Record.AddSourceLocation(MSInfo->getPointOfInstantiation()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4705 | } else { |
| 4706 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 4707 | Record.push_back(Spec->getTemplateSpecializationKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4708 | Record.AddSourceLocation(Spec->getPointOfInstantiation()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4709 | |
| 4710 | // The instantiation might have been resolved to a partial |
| 4711 | // specialization. If so, record which one. |
| 4712 | auto From = Spec->getInstantiatedFrom(); |
| 4713 | if (auto PartialSpec = |
| 4714 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 4715 | Record.push_back(true); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4716 | Record.AddDeclRef(PartialSpec); |
| 4717 | Record.AddTemplateArgumentList( |
| 4718 | &Spec->getTemplateInstantiationArgs()); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4719 | } else { |
| 4720 | Record.push_back(false); |
| 4721 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4722 | } |
| 4723 | Record.push_back(RD->getTagKind()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4724 | Record.AddSourceLocation(RD->getLocation()); |
| 4725 | Record.AddSourceLocation(RD->getLocStart()); |
| 4726 | Record.AddSourceLocation(RD->getRBraceLoc()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4727 | |
| 4728 | // Instantiation may change attributes; write them all out afresh. |
| 4729 | Record.push_back(D->hasAttrs()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4730 | if (D->hasAttrs()) |
| 4731 | Record.AddAttributes(D->getAttrs()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4732 | |
| 4733 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 4734 | break; |
| 4735 | } |
| 4736 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4737 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4738 | Record.AddDeclRef(Update.getDecl()); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4739 | break; |
| 4740 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4741 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 4742 | addExceptionSpec( |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4743 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 4744 | Record); |
| 4745 | break; |
| 4746 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4747 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 4748 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 4749 | break; |
| 4750 | |
| 4751 | case UPD_DECL_MARKED_USED: |
| 4752 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4753 | |
| 4754 | case UPD_MANGLING_NUMBER: |
| 4755 | case UPD_STATIC_LOCAL_NUMBER: |
| 4756 | Record.push_back(Update.getNumber()); |
| 4757 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4758 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4759 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4760 | Record.AddSourceRange( |
| 4761 | D->getAttr<OMPThreadPrivateDeclAttr>()->getRange()); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4762 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4763 | |
| 4764 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 4765 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4766 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4767 | |
| 4768 | case UPD_ADDED_ATTR_TO_RECORD: |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4769 | Record.AddAttributes(llvm::makeArrayRef(Update.getAttr())); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4770 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4771 | } |
| 4772 | } |
| 4773 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4774 | if (HasUpdatedBody) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4775 | const auto *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4776 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4777 | Record.push_back(Def->isInlined()); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4778 | Record.AddSourceLocation(Def->getInnerLocStart()); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4779 | Record.AddFunctionDefinition(Def); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4780 | } |
| 4781 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4782 | OffsetsRecord.push_back(GetDeclRef(D)); |
Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4783 | OffsetsRecord.push_back(Record.Emit(DECL_UPDATES)); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4784 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4785 | FlushPendingAfterDecl(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4786 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4787 | } |
| 4788 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4789 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 4790 | uint32_t Raw = Loc.getRawEncoding(); |
| 4791 | Record.push_back((Raw << 1) | (Raw >> 31)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4792 | } |
| 4793 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4794 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4795 | AddSourceLocation(Range.getBegin(), Record); |
| 4796 | AddSourceLocation(Range.getEnd(), Record); |
| 4797 | } |
| 4798 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4799 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4800 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4801 | const uint64_t *Words = Value.getRawData(); |
| 4802 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4803 | } |
| 4804 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4805 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4806 | Record.push_back(Value.isUnsigned()); |
| 4807 | AddAPInt(Value, Record); |
| 4808 | } |
| 4809 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4810 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4811 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 4812 | } |
| 4813 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4814 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4815 | Record.push_back(getIdentifierRef(II)); |
| 4816 | } |
| 4817 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4818 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4819 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4820 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4821 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4822 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4823 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4824 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4825 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4826 | } |
| 4827 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4828 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4829 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 4830 | // have been redefined by the header (in which case they are not |
| 4831 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4832 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4833 | return 0; |
| 4834 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4835 | MacroID &ID = MacroIDs[MI]; |
| 4836 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4837 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4838 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 4839 | MacroInfosToEmit.push_back(Info); |
| 4840 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4841 | return ID; |
| 4842 | } |
| 4843 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4844 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4845 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4846 | return 0; |
| 4847 | |
| 4848 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 4849 | return MacroIDs[MI]; |
| 4850 | } |
| 4851 | |
| 4852 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 4853 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4854 | } |
| 4855 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4856 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4857 | Record.push_back(getSelectorRef(SelRef)); |
| 4858 | } |
| 4859 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4860 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4861 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4862 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4865 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4866 | if (SID == 0 && Chain) { |
| 4867 | // This might trigger a ReadSelector callback, which will set the ID for |
| 4868 | // this selector. |
| 4869 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4870 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4871 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4872 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4873 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4874 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4875 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4876 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4877 | } |
| 4878 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4879 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4880 | AddDeclRef(Temp->getDestructor(), Record); |
| 4881 | } |
| 4882 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4883 | void ASTWriter::AddCXXCtorInitializersRef(ArrayRef<CXXCtorInitializer *> Inits, |
| 4884 | RecordDataImpl &Record) { |
| 4885 | assert(!Inits.empty() && "Empty ctor initializer sets are not recorded"); |
| 4886 | CXXCtorInitializersToWrite.push_back( |
| 4887 | QueuedCXXCtorInitializers(NextCXXCtorInitializersID, Inits)); |
| 4888 | Record.push_back(NextCXXCtorInitializersID++); |
| 4889 | } |
| 4890 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4891 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4892 | CXXBaseSpecifier const *BasesEnd, |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4893 | RecordDataImpl &Record) { |
| 4894 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 4895 | CXXBaseSpecifiersToWrite.push_back( |
| 4896 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 4897 | Bases, BasesEnd)); |
| 4898 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 4899 | } |
| 4900 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4901 | void ASTRecordWriter::AddTemplateArgumentLocInfo( |
| 4902 | TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4903 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4904 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4905 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4906 | break; |
| 4907 | case TemplateArgument::Type: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4908 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4909 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4910 | case TemplateArgument::Template: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4911 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 4912 | AddSourceLocation(Arg.getTemplateNameLoc()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4913 | break; |
| 4914 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4915 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); |
| 4916 | AddSourceLocation(Arg.getTemplateNameLoc()); |
| 4917 | AddSourceLocation(Arg.getTemplateEllipsisLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4918 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4919 | case TemplateArgument::Null: |
| 4920 | case TemplateArgument::Integral: |
| 4921 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4922 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4923 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4924 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4925 | break; |
| 4926 | } |
| 4927 | } |
| 4928 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4929 | void ASTRecordWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg) { |
| 4930 | AddTemplateArgument(Arg.getArgument()); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4931 | |
| 4932 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 4933 | bool InfoHasSameExpr |
| 4934 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4935 | Record->push_back(InfoHasSameExpr); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4936 | if (InfoHasSameExpr) |
| 4937 | return; // Avoid storing the same expr twice. |
| 4938 | } |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4939 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo()); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4940 | } |
| 4941 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4942 | void ASTRecordWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4943 | if (!TInfo) { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4944 | AddTypeRef(QualType()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4945 | return; |
| 4946 | } |
| 4947 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4948 | AddTypeLoc(TInfo->getTypeLoc()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4949 | } |
| 4950 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4951 | void ASTRecordWriter::AddTypeLoc(TypeLoc TL) { |
| 4952 | AddTypeRef(TL.getType()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4953 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 4954 | TypeLocWriter TLW(*this); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4955 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4956 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4957 | } |
| 4958 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4959 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 4960 | Record.push_back(GetOrCreateTypeID(T)); |
| 4961 | } |
| 4962 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4963 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4964 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4965 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 4966 | if (T.isNull()) |
| 4967 | return TypeIdx(); |
| 4968 | assert(!T.getLocalFastQualifiers()); |
| 4969 | |
| 4970 | TypeIdx &Idx = TypeIdxs[T]; |
| 4971 | if (Idx.getIndex() == 0) { |
| 4972 | if (DoneWritingDeclsAndTypes) { |
| 4973 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 4974 | return TypeIdx(); |
| 4975 | } |
| 4976 | |
| 4977 | // We haven't seen this type before. Assign it a new ID and put it |
| 4978 | // into the queue of types to emit. |
| 4979 | Idx = TypeIdx(NextTypeID++); |
| 4980 | DeclTypesToEmit.push(T); |
| 4981 | } |
| 4982 | return Idx; |
| 4983 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 4984 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4985 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4986 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4987 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4988 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 4989 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4990 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4991 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4992 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4993 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 4994 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 4995 | return I->second; |
| 4996 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4997 | } |
| 4998 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4999 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5000 | Record.push_back(GetDeclRef(D)); |
| 5001 | } |
| 5002 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5003 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5004 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5005 | |
| 5006 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5007 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5008 | } |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5009 | |
| 5010 | // If D comes from an AST file, its declaration ID is already known and |
| 5011 | // fixed. |
| 5012 | if (D->isFromASTFile()) |
| 5013 | return D->getGlobalID(); |
| 5014 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5015 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5016 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5017 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5018 | if (DoneWritingDeclsAndTypes) { |
| 5019 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 5020 | return 0; |
| 5021 | } |
| 5022 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5023 | // We haven't seen this declaration before. Give it a new ID and |
| 5024 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5025 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5026 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5027 | } |
| 5028 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5029 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5030 | } |
| 5031 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5032 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5033 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5034 | return 0; |
| 5035 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5036 | // If D comes from an AST file, its declaration ID is already known and |
| 5037 | // fixed. |
| 5038 | if (D->isFromASTFile()) |
| 5039 | return D->getGlobalID(); |
| 5040 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5041 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 5042 | return DeclIDs[D]; |
| 5043 | } |
| 5044 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5045 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5046 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5047 | assert(D); |
| 5048 | |
| 5049 | SourceLocation Loc = D->getLocation(); |
| 5050 | if (Loc.isInvalid()) |
| 5051 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5052 | |
| 5053 | // We only keep track of the file-level declarations of each file. |
| 5054 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 5055 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5056 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 5057 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5058 | if (isa<ParmVarDecl>(D)) |
| 5059 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5060 | |
| 5061 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5062 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5063 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5064 | FileID FID; |
| 5065 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5066 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5067 | if (FID.isInvalid()) |
| 5068 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5069 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5070 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5071 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5072 | if (!Info) |
| 5073 | Info = new DeclIDInFileInfo(); |
| 5074 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5075 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5076 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 5077 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5078 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5079 | Decls.push_back(LocDecl); |
| 5080 | return; |
| 5081 | } |
| 5082 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5083 | LocDeclIDsTy::iterator I = |
| 5084 | std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5085 | |
| 5086 | Decls.insert(I, LocDecl); |
| 5087 | } |
| 5088 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5089 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 5090 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5091 | Record.push_back(Name.getNameKind()); |
| 5092 | switch (Name.getNameKind()) { |
| 5093 | case DeclarationName::Identifier: |
| 5094 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 5095 | break; |
| 5096 | |
| 5097 | case DeclarationName::ObjCZeroArgSelector: |
| 5098 | case DeclarationName::ObjCOneArgSelector: |
| 5099 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5100 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5101 | break; |
| 5102 | |
| 5103 | case DeclarationName::CXXConstructorName: |
| 5104 | case DeclarationName::CXXDestructorName: |
| 5105 | case DeclarationName::CXXConversionFunctionName: |
| 5106 | AddTypeRef(Name.getCXXNameType(), Record); |
| 5107 | break; |
| 5108 | |
| 5109 | case DeclarationName::CXXOperatorName: |
| 5110 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 5111 | break; |
| 5112 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5113 | case DeclarationName::CXXLiteralOperatorName: |
| 5114 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 5115 | break; |
| 5116 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5117 | case DeclarationName::CXXUsingDirective: |
| 5118 | // No extra data to emit |
| 5119 | break; |
| 5120 | } |
| 5121 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5122 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5123 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5124 | assert(needsAnonymousDeclarationNumber(D) && |
| 5125 | "expected an anonymous declaration"); |
| 5126 | |
| 5127 | // Number the anonymous declarations within this context, if we've not |
| 5128 | // already done so. |
| 5129 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5130 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5131 | auto *DC = D->getLexicalDeclContext(); |
| 5132 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5133 | AnonymousDeclarationNumbers[ND] = Number; |
| 5134 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5135 | |
| 5136 | It = AnonymousDeclarationNumbers.find(D); |
| 5137 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5138 | "declaration not found within its lexical context"); |
| 5139 | } |
| 5140 | |
| 5141 | return It->second; |
| 5142 | } |
| 5143 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5144 | void ASTRecordWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
| 5145 | DeclarationName Name) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5146 | switch (Name.getNameKind()) { |
| 5147 | case DeclarationName::CXXConstructorName: |
| 5148 | case DeclarationName::CXXDestructorName: |
| 5149 | case DeclarationName::CXXConversionFunctionName: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5150 | AddTypeSourceInfo(DNLoc.NamedType.TInfo); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5151 | break; |
| 5152 | |
| 5153 | case DeclarationName::CXXOperatorName: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5154 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5155 | DNLoc.CXXOperatorName.BeginOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5156 | AddSourceLocation( |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5157 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5158 | break; |
| 5159 | |
| 5160 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5161 | AddSourceLocation(SourceLocation::getFromRawEncoding( |
| 5162 | DNLoc.CXXLiteralOperatorName.OpNameLoc)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5163 | break; |
| 5164 | |
| 5165 | case DeclarationName::Identifier: |
| 5166 | case DeclarationName::ObjCZeroArgSelector: |
| 5167 | case DeclarationName::ObjCOneArgSelector: |
| 5168 | case DeclarationName::ObjCMultiArgSelector: |
| 5169 | case DeclarationName::CXXUsingDirective: |
| 5170 | break; |
| 5171 | } |
| 5172 | } |
| 5173 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5174 | void ASTRecordWriter::AddDeclarationNameInfo( |
| 5175 | const DeclarationNameInfo &NameInfo) { |
| 5176 | AddDeclarationName(NameInfo.getName()); |
| 5177 | AddSourceLocation(NameInfo.getLoc()); |
| 5178 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName()); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5179 | } |
| 5180 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5181 | void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { |
| 5182 | AddNestedNameSpecifierLoc(Info.QualifierLoc); |
| 5183 | Record->push_back(Info.NumTemplParamLists); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5184 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5185 | AddTemplateParameterList(Info.TemplParamLists[i]); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5186 | } |
| 5187 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5188 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5189 | RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5190 | // 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] | 5191 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5192 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5193 | |
| 5194 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5195 | while (NNS) { |
| 5196 | NestedNames.push_back(NNS); |
| 5197 | NNS = NNS->getPrefix(); |
| 5198 | } |
| 5199 | |
| 5200 | Record.push_back(NestedNames.size()); |
| 5201 | while(!NestedNames.empty()) { |
| 5202 | NNS = NestedNames.pop_back_val(); |
| 5203 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 5204 | Record.push_back(Kind); |
| 5205 | switch (Kind) { |
| 5206 | case NestedNameSpecifier::Identifier: |
| 5207 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 5208 | break; |
| 5209 | |
| 5210 | case NestedNameSpecifier::Namespace: |
| 5211 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 5212 | break; |
| 5213 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5214 | case NestedNameSpecifier::NamespaceAlias: |
| 5215 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 5216 | break; |
| 5217 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5218 | case NestedNameSpecifier::TypeSpec: |
| 5219 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 5220 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 5221 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5222 | break; |
| 5223 | |
| 5224 | case NestedNameSpecifier::Global: |
| 5225 | // Don't need to write an associated value. |
| 5226 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5227 | |
| 5228 | case NestedNameSpecifier::Super: |
| 5229 | AddDeclRef(NNS->getAsRecordDecl(), Record); |
| 5230 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5231 | } |
| 5232 | } |
| 5233 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5234 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5235 | void ASTRecordWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5236 | // 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] | 5237 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5238 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5239 | |
| 5240 | // Push each of the nested-name-specifiers's onto a stack for |
| 5241 | // serialization in reverse order. |
| 5242 | while (NNS) { |
| 5243 | NestedNames.push_back(NNS); |
| 5244 | NNS = NNS.getPrefix(); |
| 5245 | } |
| 5246 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5247 | Record->push_back(NestedNames.size()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5248 | while(!NestedNames.empty()) { |
| 5249 | NNS = NestedNames.pop_back_val(); |
| 5250 | NestedNameSpecifier::SpecifierKind Kind |
| 5251 | = NNS.getNestedNameSpecifier()->getKind(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5252 | Record->push_back(Kind); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5253 | switch (Kind) { |
| 5254 | case NestedNameSpecifier::Identifier: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5255 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier()); |
| 5256 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5257 | break; |
| 5258 | |
| 5259 | case NestedNameSpecifier::Namespace: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5260 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace()); |
| 5261 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5262 | break; |
| 5263 | |
| 5264 | case NestedNameSpecifier::NamespaceAlias: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5265 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias()); |
| 5266 | AddSourceRange(NNS.getLocalSourceRange()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5267 | break; |
| 5268 | |
| 5269 | case NestedNameSpecifier::TypeSpec: |
| 5270 | case NestedNameSpecifier::TypeSpecWithTemplate: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5271 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5272 | AddTypeLoc(NNS.getTypeLoc()); |
| 5273 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5274 | break; |
| 5275 | |
| 5276 | case NestedNameSpecifier::Global: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5277 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5278 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5279 | |
| 5280 | case NestedNameSpecifier::Super: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5281 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl()); |
| 5282 | AddSourceRange(NNS.getLocalSourceRange()); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5283 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5284 | } |
| 5285 | } |
| 5286 | } |
| 5287 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5288 | void ASTRecordWriter::AddTemplateName(TemplateName Name) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5289 | TemplateName::NameKind Kind = Name.getKind(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5290 | Record->push_back(Kind); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5291 | switch (Kind) { |
| 5292 | case TemplateName::Template: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5293 | AddDeclRef(Name.getAsTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5294 | break; |
| 5295 | |
| 5296 | case TemplateName::OverloadedTemplate: { |
| 5297 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5298 | Record->push_back(OvT->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5299 | for (const auto &I : *OvT) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5300 | AddDeclRef(I); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5301 | break; |
| 5302 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5303 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5304 | case TemplateName::QualifiedTemplate: { |
| 5305 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5306 | AddNestedNameSpecifier(QualT->getQualifier()); |
| 5307 | Record->push_back(QualT->hasTemplateKeyword()); |
| 5308 | AddDeclRef(QualT->getTemplateDecl()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5309 | break; |
| 5310 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5311 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5312 | case TemplateName::DependentTemplate: { |
| 5313 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5314 | AddNestedNameSpecifier(DepT->getQualifier()); |
| 5315 | Record->push_back(DepT->isIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5316 | if (DepT->isIdentifier()) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5317 | AddIdentifierRef(DepT->getIdentifier()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5318 | else |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5319 | Record->push_back(DepT->getOperator()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5320 | break; |
| 5321 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5322 | |
| 5323 | case TemplateName::SubstTemplateTemplateParm: { |
| 5324 | SubstTemplateTemplateParmStorage *subst |
| 5325 | = Name.getAsSubstTemplateTemplateParm(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5326 | AddDeclRef(subst->getParameter()); |
| 5327 | AddTemplateName(subst->getReplacement()); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5328 | break; |
| 5329 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5330 | |
| 5331 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5332 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5333 | = Name.getAsSubstTemplateTemplateParmPack(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5334 | AddDeclRef(SubstPack->getParameterPack()); |
| 5335 | AddTemplateArgument(SubstPack->getArgumentPack()); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5336 | break; |
| 5337 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5338 | } |
| 5339 | } |
| 5340 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5341 | void ASTRecordWriter::AddTemplateArgument(const TemplateArgument &Arg) { |
| 5342 | Record->push_back(Arg.getKind()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5343 | switch (Arg.getKind()) { |
| 5344 | case TemplateArgument::Null: |
| 5345 | break; |
| 5346 | case TemplateArgument::Type: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5347 | AddTypeRef(Arg.getAsType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5348 | break; |
| 5349 | case TemplateArgument::Declaration: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5350 | AddDeclRef(Arg.getAsDecl()); |
| 5351 | AddTypeRef(Arg.getParamTypeForDecl()); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5352 | break; |
| 5353 | case TemplateArgument::NullPtr: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5354 | AddTypeRef(Arg.getNullPtrType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5355 | break; |
| 5356 | case TemplateArgument::Integral: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5357 | AddAPSInt(Arg.getAsIntegral()); |
| 5358 | AddTypeRef(Arg.getIntegralType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5359 | break; |
| 5360 | case TemplateArgument::Template: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5361 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5362 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5363 | case TemplateArgument::TemplateExpansion: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5364 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5365 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5366 | Record->push_back(*NumExpansions + 1); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5367 | else |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5368 | Record->push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5369 | break; |
| 5370 | case TemplateArgument::Expression: |
| 5371 | AddStmt(Arg.getAsExpr()); |
| 5372 | break; |
| 5373 | case TemplateArgument::Pack: |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5374 | Record->push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 5375 | for (const auto &P : Arg.pack_elements()) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5376 | AddTemplateArgument(P); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5377 | break; |
| 5378 | } |
| 5379 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5380 | |
| 5381 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5382 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5383 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5384 | assert(TemplateParams && "No TemplateParams!"); |
| 5385 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 5386 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 5387 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 5388 | Record.push_back(TemplateParams->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5389 | for (const auto &P : *TemplateParams) |
| 5390 | AddDeclRef(P, Record); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | /// \brief Emit a template argument list. |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5394 | void ASTRecordWriter::AddTemplateArgumentList( |
| 5395 | const TemplateArgumentList *TemplateArgs) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5396 | assert(TemplateArgs && "No TemplateArgs!"); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5397 | Record->push_back(TemplateArgs->size()); |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5398 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5399 | AddTemplateArgument(TemplateArgs->get(i)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5400 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5401 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5402 | void ASTRecordWriter::AddASTTemplateArgumentListInfo( |
| 5403 | const ASTTemplateArgumentListInfo *ASTTemplArgList) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5404 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5405 | AddSourceLocation(ASTTemplArgList->LAngleLoc); |
| 5406 | AddSourceLocation(ASTTemplArgList->RAngleLoc); |
| 5407 | Record->push_back(ASTTemplArgList->NumTemplateArgs); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5408 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
| 5409 | for (int i=0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5410 | AddTemplateArgumentLoc(TemplArgs[i]); |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5411 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5412 | |
| 5413 | void |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5414 | ASTWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5415 | Record.push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5416 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5417 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 5418 | AddDeclRef(I.getDecl(), Record); |
| 5419 | Record.push_back(I.getAccess()); |
| 5420 | } |
| 5421 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5422 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5423 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5424 | void ASTRecordWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base) { |
| 5425 | Record->push_back(Base.isVirtual()); |
| 5426 | Record->push_back(Base.isBaseOfClass()); |
| 5427 | Record->push_back(Base.getAccessSpecifierAsWritten()); |
| 5428 | Record->push_back(Base.getInheritConstructors()); |
| 5429 | AddTypeSourceInfo(Base.getTypeSourceInfo()); |
| 5430 | AddSourceRange(Base.getSourceRange()); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5431 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5432 | : SourceLocation()); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5433 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5434 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5435 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 5436 | RecordData Record; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5437 | unsigned N = CXXBaseSpecifiersToWrite.size(); |
| 5438 | for (unsigned I = 0; I != N; ++I) { |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5439 | Record.clear(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5440 | |
| 5441 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 5442 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5443 | |
| 5444 | // Write the base specifier set. |
| 5445 | ASTRecordWriter Writer(*this, Record); |
| 5446 | Writer.push_back(BEnd - B); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5447 | for (; B != BEnd; ++B) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5448 | Writer.AddCXXBaseSpecifier(*B); |
| 5449 | uint64_t Offset = Writer.Emit(serialization::DECL_CXX_BASE_SPECIFIERS); |
Douglas Gregor | d585304 | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 5450 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5451 | // Record the offset of this base-specifier set. |
| 5452 | // |
| 5453 | // FIXME: We don't need an indirect lookup table for these; instead, write |
| 5454 | // the base specifier record prior to the decl record and store its offset |
| 5455 | // from the decl record rather than its ID. |
| 5456 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
| 5457 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 5458 | CXXBaseSpecifiersOffsets.push_back(Offset); |
| 5459 | else { |
| 5460 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 5461 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 5462 | CXXBaseSpecifiersOffsets[Index] = Offset; |
| 5463 | } |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5464 | } |
| 5465 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5466 | assert(N == CXXBaseSpecifiersToWrite.size() && |
| 5467 | "added more base specifiers while writing base specifiers"); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5468 | CXXBaseSpecifiersToWrite.clear(); |
| 5469 | } |
| 5470 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5471 | // FIXME: Move this out of the main ASTRecordWriter interface. |
| 5472 | void ASTRecordWriter::AddCXXCtorInitializers( |
| 5473 | const CXXCtorInitializer *const *CtorInitializers, |
| 5474 | unsigned NumCtorInitializers) { |
| 5475 | Record->push_back(NumCtorInitializers); |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5476 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 5477 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5478 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5479 | if (Init->isBaseInitializer()) { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5480 | Record->push_back(CTOR_INITIALIZER_BASE); |
| 5481 | AddTypeSourceInfo(Init->getTypeSourceInfo()); |
| 5482 | Record->push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5483 | } else if (Init->isDelegatingInitializer()) { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5484 | Record->push_back(CTOR_INITIALIZER_DELEGATING); |
| 5485 | AddTypeSourceInfo(Init->getTypeSourceInfo()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5486 | } else if (Init->isMemberInitializer()){ |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5487 | Record->push_back(CTOR_INITIALIZER_MEMBER); |
| 5488 | AddDeclRef(Init->getMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5489 | } else { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5490 | Record->push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 5491 | AddDeclRef(Init->getIndirectMember()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5492 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5493 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5494 | AddSourceLocation(Init->getMemberLocation()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5495 | AddStmt(Init->getInit()); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5496 | AddSourceLocation(Init->getLParenLoc()); |
| 5497 | AddSourceLocation(Init->getRParenLoc()); |
| 5498 | Record->push_back(Init->isWritten()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5499 | if (Init->isWritten()) { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5500 | Record->push_back(Init->getSourceOrder()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5501 | } else { |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5502 | Record->push_back(Init->getNumArrayIndices()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5503 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5504 | AddDeclRef(Init->getArrayIndex(i)); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5505 | } |
| 5506 | } |
| 5507 | } |
| 5508 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5509 | void ASTWriter::FlushCXXCtorInitializers() { |
| 5510 | RecordData Record; |
| 5511 | |
| 5512 | unsigned N = CXXCtorInitializersToWrite.size(); |
Daniel Jasper | c77b0a1 | 2015-03-24 08:06:38 +0000 | [diff] [blame] | 5513 | (void)N; // Silence unused warning in non-assert builds. |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5514 | for (auto &Init : CXXCtorInitializersToWrite) { |
| 5515 | Record.clear(); |
| 5516 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5517 | ASTRecordWriter Writer(*this, Record); |
| 5518 | Writer.AddCXXCtorInitializers(Init.Inits.data(), Init.Inits.size()); |
| 5519 | uint64_t Offset = Writer.Emit(serialization::DECL_CXX_CTOR_INITIALIZERS); |
| 5520 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5521 | // Record the offset of this mem-initializer list. |
| 5522 | unsigned Index = Init.ID - 1; |
| 5523 | if (Index == CXXCtorInitializersOffsets.size()) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5524 | CXXCtorInitializersOffsets.push_back(Offset); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5525 | else { |
| 5526 | if (Index > CXXCtorInitializersOffsets.size()) |
| 5527 | CXXCtorInitializersOffsets.resize(Index + 1); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5528 | CXXCtorInitializersOffsets[Index] = Offset; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5529 | } |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | assert(N == CXXCtorInitializersToWrite.size() && |
| 5533 | "added more ctor initializers while writing ctor initializers"); |
| 5534 | CXXCtorInitializersToWrite.clear(); |
| 5535 | } |
| 5536 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5537 | void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5538 | auto &Data = D->data(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5539 | Record->push_back(Data.IsLambda); |
| 5540 | Record->push_back(Data.UserDeclaredConstructor); |
| 5541 | Record->push_back(Data.UserDeclaredSpecialMembers); |
| 5542 | Record->push_back(Data.Aggregate); |
| 5543 | Record->push_back(Data.PlainOldData); |
| 5544 | Record->push_back(Data.Empty); |
| 5545 | Record->push_back(Data.Polymorphic); |
| 5546 | Record->push_back(Data.Abstract); |
| 5547 | Record->push_back(Data.IsStandardLayout); |
| 5548 | Record->push_back(Data.HasNoNonEmptyBases); |
| 5549 | Record->push_back(Data.HasPrivateFields); |
| 5550 | Record->push_back(Data.HasProtectedFields); |
| 5551 | Record->push_back(Data.HasPublicFields); |
| 5552 | Record->push_back(Data.HasMutableFields); |
| 5553 | Record->push_back(Data.HasVariantMembers); |
| 5554 | Record->push_back(Data.HasOnlyCMembers); |
| 5555 | Record->push_back(Data.HasInClassInitializer); |
| 5556 | Record->push_back(Data.HasUninitializedReferenceMember); |
| 5557 | Record->push_back(Data.HasUninitializedFields); |
| 5558 | Record->push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 5559 | Record->push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 5560 | Record->push_back(Data.NeedOverloadResolutionForDestructor); |
| 5561 | Record->push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 5562 | Record->push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 5563 | Record->push_back(Data.DefaultedDestructorIsDeleted); |
| 5564 | Record->push_back(Data.HasTrivialSpecialMembers); |
| 5565 | Record->push_back(Data.DeclaredNonTrivialSpecialMembers); |
| 5566 | Record->push_back(Data.HasIrrelevantDestructor); |
| 5567 | Record->push_back(Data.HasConstexprNonCopyMoveConstructor); |
| 5568 | Record->push_back(Data.HasDefaultedDefaultConstructor); |
| 5569 | Record->push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
| 5570 | Record->push_back(Data.HasConstexprDefaultConstructor); |
| 5571 | Record->push_back(Data.HasNonLiteralTypeFieldsOrBases); |
| 5572 | Record->push_back(Data.ComputedVisibleConversions); |
| 5573 | Record->push_back(Data.UserProvidedDefaultConstructor); |
| 5574 | Record->push_back(Data.DeclaredSpecialMembers); |
| 5575 | Record->push_back(Data.ImplicitCopyConstructorHasConstParam); |
| 5576 | Record->push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 5577 | Record->push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 5578 | Record->push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5579 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5580 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5581 | Record->push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5582 | if (Data.NumBases > 0) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5583 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5584 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5585 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5586 | Record->push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5587 | if (Data.NumVBases > 0) |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5588 | AddCXXBaseSpecifiersRef(Data.getVBases(), |
| 5589 | Data.getVBases() + Data.NumVBases); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5590 | |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5591 | AddUnresolvedSet(Data.Conversions.get(*Writer->Context)); |
| 5592 | AddUnresolvedSet(Data.VisibleConversions.get(*Writer->Context)); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5593 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5594 | AddDeclRef(D->getFirstFriend()); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5595 | |
| 5596 | // Add lambda-specific data. |
| 5597 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5598 | auto &Lambda = D->getLambdaData(); |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5599 | Record->push_back(Lambda.Dependent); |
| 5600 | Record->push_back(Lambda.IsGenericLambda); |
| 5601 | Record->push_back(Lambda.CaptureDefault); |
| 5602 | Record->push_back(Lambda.NumCaptures); |
| 5603 | Record->push_back(Lambda.NumExplicitCaptures); |
| 5604 | Record->push_back(Lambda.ManglingNumber); |
| 5605 | AddDeclRef(Lambda.ContextDecl); |
| 5606 | AddTypeSourceInfo(Lambda.MethodTyInfo); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5607 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 5608 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5609 | AddSourceLocation(Capture.getLocation()); |
| 5610 | Record->push_back(Capture.isImplicit()); |
| 5611 | Record->push_back(Capture.getCaptureKind()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5612 | switch (Capture.getCaptureKind()) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 5613 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5614 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 5615 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5616 | break; |
| 5617 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 5618 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5619 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5620 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5621 | AddDeclRef(Var); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5622 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
Richard Smith | 5811c40 | 2016-04-06 06:26:08 +0000 | [diff] [blame^] | 5623 | : SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5624 | break; |
| 5625 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5626 | } |
| 5627 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5628 | } |
| 5629 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5630 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5631 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5632 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5633 | assert(FirstDeclID == NextDeclID && |
| 5634 | FirstTypeID == NextTypeID && |
| 5635 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5636 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5637 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5638 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5639 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5640 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5641 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5642 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 5643 | // Note, this will get called multiple times, once one the reader starts up |
| 5644 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5645 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 5646 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 5647 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5648 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5649 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5650 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5651 | NextDeclID = FirstDeclID; |
| 5652 | NextTypeID = FirstTypeID; |
| 5653 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5654 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5655 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5656 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5657 | } |
| 5658 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5659 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5660 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5661 | IdentID &StoredID = IdentifierIDs[II]; |
| 5662 | if (ID > StoredID) |
| 5663 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5664 | } |
| 5665 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5666 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5667 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5668 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5669 | if (ID > StoredID) |
| 5670 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5671 | } |
| 5672 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5673 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5674 | // Always take the highest-numbered type index. This copes with an interesting |
| 5675 | // 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] | 5676 | // 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] | 5677 | // keep the higher-numbered entry so that we can properly write it out to |
| 5678 | // the AST file. |
| 5679 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 5680 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 5681 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5682 | } |
| 5683 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5684 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5685 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5686 | SelectorID &StoredID = SelectorIDs[S]; |
| 5687 | if (ID > StoredID) |
| 5688 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5689 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5690 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5691 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5692 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5693 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5694 | MacroDefinitions[MD] = ID; |
| 5695 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5696 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 5697 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 5698 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 5699 | SubmoduleIDs[Mod] = ID; |
| 5700 | } |
| 5701 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5702 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5703 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5704 | assert(!WritingAST && "Already writing the AST!"); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5705 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5706 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5707 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5708 | // A forward reference was mutated into a definition. Rewrite it. |
| 5709 | // FIXME: This happens during template instantiation, should we |
| 5710 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5711 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 5712 | "completed a tag from another module but not by instantiation?"); |
| 5713 | DeclUpdates[RD].push_back( |
| 5714 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5715 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5716 | } |
| 5717 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5718 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5719 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { |
| 5720 | if (D->isFromASTFile()) |
| 5721 | return true; |
| 5722 | |
| 5723 | // If we've not loaded any modules, this can't be imported. |
| 5724 | if (!Chain || !Chain->getModuleManager().size()) |
| 5725 | return false; |
| 5726 | |
| 5727 | // The predefined __va_list_tag struct is imported if we imported any decls. |
| 5728 | // FIXME: This is a gross hack. |
| 5729 | return D == D->getASTContext().getVaListTagDecl(); |
| 5730 | } |
| 5731 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5732 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Vassil Vassilev | 632eac3 | 2016-03-16 11:17:04 +0000 | [diff] [blame] | 5733 | // TU is handled elsewhere. |
| 5734 | if (isa<TranslationUnitDecl>(DC)) |
| 5735 | return; |
| 5736 | |
| 5737 | // Namespaces are handled elsewhere, except for template instantiations of |
| 5738 | // FunctionTemplateDecls in namespaces. We are interested in cases where the |
| 5739 | // local instantiations are added to an imported context. Only happens when |
| 5740 | // adding ADL lookup candidates, for example templated friends. |
| 5741 | if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && |
| 5742 | !isa<FunctionTemplateDecl>(D)) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5743 | return; |
| 5744 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5745 | // We're only interested in cases where a local declaration is added to an |
| 5746 | // imported context. |
| 5747 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) |
| 5748 | return; |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5749 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 5750 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5751 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5752 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5753 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { |
| 5754 | // We're adding a visible declaration to a predefined decl context. Ensure |
| 5755 | // that we write out all of its lookup results so we don't get a nasty |
| 5756 | // surprise when we try to emit its lookup table. |
| 5757 | for (auto *Child : DC->decls()) |
| 5758 | UpdatingVisibleDecls.push_back(Child); |
| 5759 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5760 | UpdatingVisibleDecls.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5761 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5762 | |
| 5763 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
| 5764 | assert(D->isImplicit()); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5765 | |
| 5766 | // We're only interested in cases where a local declaration is added to an |
| 5767 | // imported context. |
| 5768 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) |
| 5769 | return; |
| 5770 | |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5771 | if (!isa<CXXMethodDecl>(D)) |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5772 | return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5773 | |
| 5774 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5775 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5776 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5777 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5778 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5779 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5780 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5781 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 5782 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5783 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5784 | // If we don't already know the exception specification for this redecl |
| 5785 | // chain, add an update record for it. |
| 5786 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 5787 | ->getType() |
| 5788 | ->castAs<FunctionProtoType>() |
| 5789 | ->getExceptionSpecType())) |
| 5790 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 5791 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5792 | } |
| 5793 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5794 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
| 5795 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5796 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5797 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5798 | DeclUpdates[D].push_back( |
| 5799 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 5800 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5801 | } |
| 5802 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5803 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
| 5804 | const FunctionDecl *Delete) { |
| 5805 | assert(!WritingAST && "Already writing the AST!"); |
| 5806 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5807 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5808 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5809 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 5810 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5811 | } |
| 5812 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5813 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5814 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5815 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5816 | return; // Declaration not imported from PCH. |
| 5817 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5818 | // Implicit function decl from a PCH was defined. |
| 5819 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5820 | } |
| 5821 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5822 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
| 5823 | assert(!WritingAST && "Already writing the AST!"); |
| 5824 | if (!D->isFromASTFile()) |
| 5825 | return; |
| 5826 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5827 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5828 | } |
| 5829 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5830 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5831 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5832 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5833 | return; |
| 5834 | |
| 5835 | // Since the actual instantiation is delayed, this really means that we need |
| 5836 | // to update the instantiation location. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5837 | DeclUpdates[D].push_back( |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5838 | DeclUpdate(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER, |
| 5839 | D->getMemberSpecializationInfo()->getPointOfInstantiation())); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5842 | void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { |
| 5843 | assert(!WritingAST && "Already writing the AST!"); |
| 5844 | if (!D->isFromASTFile()) |
| 5845 | return; |
| 5846 | |
| 5847 | DeclUpdates[D].push_back( |
| 5848 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D)); |
| 5849 | } |
| 5850 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5851 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 5852 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5853 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5854 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5855 | return; // Declaration not imported from PCH. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5856 | |
| 5857 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 5858 | ObjCClassesWithCategories.insert( |
| 5859 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5860 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 5861 | |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5862 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
| 5863 | assert(!WritingAST && "Already writing the AST!"); |
| 5864 | if (!D->isFromASTFile()) |
| 5865 | return; |
| 5866 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5867 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5868 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5869 | |
| 5870 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
| 5871 | assert(!WritingAST && "Already writing the AST!"); |
| 5872 | if (!D->isFromASTFile()) |
| 5873 | return; |
| 5874 | |
| 5875 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 5876 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5877 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5878 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5879 | assert(!WritingAST && "Already writing the AST!"); |
| 5880 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5881 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5882 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5883 | |
| 5884 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 5885 | const RecordDecl *Record) { |
| 5886 | assert(!WritingAST && "Already writing the AST!"); |
| 5887 | if (!Record->isFromASTFile()) |
| 5888 | return; |
| 5889 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 5890 | } |