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 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 85 | namespace { |
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; |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 88 | ASTWriter::RecordDataImpl &Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 89 | |
| 90 | public: |
| 91 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 92 | TypeCode Code; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 93 | /// \brief Abbreviation to use for the record, if any. |
| 94 | unsigned AbbrevToUse; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 95 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 96 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 97 | : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 98 | |
| 99 | void VisitArrayType(const ArrayType *T); |
| 100 | void VisitFunctionType(const FunctionType *T); |
| 101 | void VisitTagType(const TagType *T); |
| 102 | |
| 103 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 104 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 105 | #include "clang/AST/TypeNodes.def" |
| 106 | }; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 107 | } // end anonymous namespace |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 108 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 109 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 110 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 113 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 114 | Writer.AddTypeRef(T->getElementType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 115 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 118 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 119 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 120 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 123 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
| 124 | Writer.AddTypeRef(T->getOriginalType(), Record); |
| 125 | Code = TYPE_DECAYED; |
| 126 | } |
| 127 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 128 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
| 129 | Writer.AddTypeRef(T->getOriginalType(), Record); |
| 130 | Writer.AddTypeRef(T->getAdjustedType(), Record); |
| 131 | Code = TYPE_ADJUSTED; |
| 132 | } |
| 133 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 134 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 135 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 136 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 139 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 140 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
| 141 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 142 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 145 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 146 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 147 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 150 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 152 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 153 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 156 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 157 | Writer.AddTypeRef(T->getElementType(), Record); |
| 158 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 159 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
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::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 163 | VisitArrayType(T); |
| 164 | Writer.AddAPInt(T->getSize(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 165 | Code = TYPE_CONSTANT_ARRAY; |
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::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 169 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 170 | Code = TYPE_INCOMPLETE_ARRAY; |
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::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 174 | VisitArrayType(T); |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 175 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 176 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 177 | Writer.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 178 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 181 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 182 | Writer.AddTypeRef(T->getElementType(), Record); |
| 183 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 184 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 185 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 188 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 189 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 190 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 193 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 194 | Writer.AddTypeRef(T->getReturnType(), Record); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 195 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 196 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 197 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 198 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 199 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 200 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 201 | Record.push_back(C.getProducesResult()); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 202 | |
| 203 | if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult()) |
| 204 | AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 207 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 208 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 209 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 212 | static void addExceptionSpec(ASTWriter &Writer, const FunctionProtoType *T, |
| 213 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 214 | Record.push_back(T->getExceptionSpecType()); |
| 215 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 216 | Record.push_back(T->getNumExceptions()); |
| 217 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 218 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 219 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 220 | Writer.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 221 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
| 222 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
| 223 | Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 224 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
| 225 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 226 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 230 | VisitFunctionType(T); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 231 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 232 | Record.push_back(T->isVariadic()); |
| 233 | Record.push_back(T->hasTrailingReturn()); |
| 234 | Record.push_back(T->getTypeQuals()); |
| 235 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
| 236 | addExceptionSpec(Writer, T, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 237 | |
| 238 | Record.push_back(T->getNumParams()); |
| 239 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 240 | Writer.AddTypeRef(T->getParamType(I), Record); |
| 241 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 242 | if (T->hasExtParameterInfos()) { |
| 243 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 244 | Record.push_back(T->getExtParameterInfo(I).getOpaqueValue()); |
| 245 | } |
| 246 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 247 | if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 248 | T->getRefQualifier() || T->getExceptionSpecType() != EST_None || |
| 249 | T->hasExtParameterInfos()) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 250 | AbbrevToUse = 0; |
| 251 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 252 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 255 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 256 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 257 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 258 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 259 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 260 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 261 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 262 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 263 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 264 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 267 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 268 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 269 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 272 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 273 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 274 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 277 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 278 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 279 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 280 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 283 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 284 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 285 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 286 | Record.push_back(T->getUTTKind()); |
| 287 | Code = TYPE_UNARY_TRANSFORM; |
| 288 | } |
| 289 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 290 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 291 | Writer.AddTypeRef(T->getDeducedType(), Record); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 292 | Record.push_back((unsigned)T->getKeyword()); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 293 | if (T->getDeducedType().isNull()) |
| 294 | Record.push_back(T->isDependentType()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 295 | Code = TYPE_AUTO; |
| 296 | } |
| 297 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 298 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 299 | Record.push_back(T->isDependentType()); |
Douglas Gregor | f3bccd7 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 300 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 301 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 302 | "Cannot serialize in the middle of a type definition"); |
| 303 | } |
| 304 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 305 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 306 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 307 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 310 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 311 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 312 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 313 | } |
| 314 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 315 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 316 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 317 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 318 | Record.push_back(T->getAttrKind()); |
| 319 | Code = TYPE_ATTRIBUTED; |
| 320 | } |
| 321 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 323 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 324 | const SubstTemplateTypeParmType *T) { |
| 325 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 326 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 327 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 331 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 332 | const SubstTemplateTypeParmPackType *T) { |
| 333 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 334 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 335 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 336 | } |
| 337 | |
| 338 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 339 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 340 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 341 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 342 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 343 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 344 | for (const auto &ArgI : *T) |
| 345 | Writer.AddTemplateArgument(ArgI, Record); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 346 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 347 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 348 | : T->getCanonicalTypeInternal(), |
| 349 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 350 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 354 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 355 | VisitArrayType(T); |
| 356 | Writer.AddStmt(T->getSizeExpr()); |
| 357 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 358 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 362 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 363 | const DependentSizedExtVectorType *T) { |
| 364 | // FIXME: Serialize this type (C++ only) |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 365 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 369 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 370 | Record.push_back(T->getDepth()); |
| 371 | Record.push_back(T->getIndex()); |
| 372 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 373 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 374 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 378 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 379 | Record.push_back(T->getKeyword()); |
| 380 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 381 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 382 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 383 | : T->getCanonicalTypeInternal(), |
| 384 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 385 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 389 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 390 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 391 | Record.push_back(T->getKeyword()); |
| 392 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 393 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 394 | Record.push_back(T->getNumArgs()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 395 | for (const auto &I : *T) |
| 396 | Writer.AddTemplateArgument(I, Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 397 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 400 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 401 | Writer.AddTypeRef(T->getPattern(), Record); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 402 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 403 | Record.push_back(*NumExpansions + 1); |
| 404 | else |
| 405 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 406 | Code = TYPE_PACK_EXPANSION; |
| 407 | } |
| 408 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 409 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 410 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 411 | Code = TYPE_PAREN; |
| 412 | } |
| 413 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 414 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 415 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 416 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 417 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 418 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 421 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Douglas Gregor | 9f21889 | 2012-03-26 15:52:37 +0000 | [diff] [blame] | 422 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
John McCall | 2408e32 | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 423 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 424 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 427 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | f3bccd7 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 428 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 429 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 432 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 433 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 434 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 435 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 436 | Writer.AddTypeRef(TypeArg, Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 437 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 438 | for (const auto *I : T->quals()) |
| 439 | Writer.AddDeclRef(I, Record); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 440 | Record.push_back(T->isKindOfTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 441 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 444 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 445 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 447 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 450 | void |
| 451 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
| 452 | Writer.AddTypeRef(T->getValueType(), Record); |
| 453 | Code = TYPE_ATOMIC; |
| 454 | } |
| 455 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 456 | void |
| 457 | ASTTypeWriter::VisitPipeType(const PipeType *T) { |
| 458 | Writer.AddTypeRef(T->getElementType(), Record); |
| 459 | Code = TYPE_PIPE; |
| 460 | } |
| 461 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 462 | namespace { |
| 463 | |
| 464 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 465 | ASTWriter &Writer; |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 466 | ASTWriter::RecordDataImpl &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 467 | |
| 468 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 469 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 470 | : Writer(Writer), Record(Record) { } |
| 471 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 472 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 473 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 474 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 475 | #include "clang/AST/TypeLocNodes.def" |
| 476 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 477 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 478 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 479 | }; |
| 480 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 481 | } // end anonymous namespace |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 482 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 483 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 484 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 485 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 486 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 487 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 488 | if (TL.needsExtraLocalData()) { |
| 489 | Record.push_back(TL.getWrittenTypeSpec()); |
| 490 | Record.push_back(TL.getWrittenSignSpec()); |
| 491 | Record.push_back(TL.getWrittenWidthSpec()); |
| 492 | Record.push_back(TL.hasModeAttr()); |
| 493 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 494 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 495 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 496 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 497 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 498 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 499 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 500 | } |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 501 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 502 | // nothing to do |
| 503 | } |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 504 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 505 | // nothing to do |
| 506 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 507 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 508 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 509 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 510 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 511 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 512 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 513 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 514 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
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::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 517 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 518 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 519 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 520 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 521 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 522 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 523 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 524 | if (TL.getSizeExpr()) |
| 525 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 526 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 527 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 528 | VisitArrayTypeLoc(TL); |
| 529 | } |
| 530 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 531 | VisitArrayTypeLoc(TL); |
| 532 | } |
| 533 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 534 | VisitArrayTypeLoc(TL); |
| 535 | } |
| 536 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 537 | DependentSizedArrayTypeLoc TL) { |
| 538 | VisitArrayTypeLoc(TL); |
| 539 | } |
| 540 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 541 | DependentSizedExtVectorTypeLoc TL) { |
| 542 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 543 | } |
| 544 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 545 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 546 | } |
| 547 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 548 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 549 | } |
| 550 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 551 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 552 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 553 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 554 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 555 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
| 556 | Writer.AddDeclRef(TL.getParam(i), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 557 | } |
| 558 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 559 | VisitFunctionTypeLoc(TL); |
| 560 | } |
| 561 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 562 | VisitFunctionTypeLoc(TL); |
| 563 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 564 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 565 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 566 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 567 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 568 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 569 | } |
| 570 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 571 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 572 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 573 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 574 | } |
| 575 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 576 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 577 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 578 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 579 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 580 | } |
| 581 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 582 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 583 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 584 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 585 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 586 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 587 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 588 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 589 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 590 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 591 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 592 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 593 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 594 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 595 | } |
| 596 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 597 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 598 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 599 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 600 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 601 | if (TL.hasAttrOperand()) { |
| 602 | SourceRange range = TL.getAttrOperandParensRange(); |
| 603 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 604 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 605 | } |
| 606 | if (TL.hasAttrExprOperand()) { |
| 607 | Expr *operand = TL.getAttrExprOperand(); |
| 608 | Record.push_back(operand ? 1 : 0); |
| 609 | if (operand) Writer.AddStmt(operand); |
| 610 | } else if (TL.hasAttrEnumOperand()) { |
| 611 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 612 | } |
| 613 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 614 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 615 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 616 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 617 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 618 | SubstTemplateTypeParmTypeLoc TL) { |
| 619 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 620 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 621 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 622 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 623 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 624 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 625 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 626 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 627 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 628 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 629 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 630 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 631 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 632 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 633 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 634 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 635 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 636 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 637 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 638 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 639 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 640 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 641 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 642 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 643 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 644 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 645 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 646 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 647 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 648 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 649 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 650 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 651 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 652 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 653 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 654 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 655 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 656 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 657 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 658 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 659 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 660 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 661 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 662 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 663 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 664 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 665 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 666 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 667 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 668 | } |
| 669 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 670 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 671 | Writer.AddSourceLocation(TL.getTypeArgsLAngleLoc(), Record); |
| 672 | Writer.AddSourceLocation(TL.getTypeArgsRAngleLoc(), Record); |
| 673 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
| 674 | Writer.AddTypeSourceInfo(TL.getTypeArgTInfo(i), Record); |
| 675 | Writer.AddSourceLocation(TL.getProtocolLAngleLoc(), Record); |
| 676 | Writer.AddSourceLocation(TL.getProtocolRAngleLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 677 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 678 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 679 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 680 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 681 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 682 | } |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 683 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 684 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 685 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 686 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 687 | } |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 688 | void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { |
| 689 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 690 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 691 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 692 | void ASTWriter::WriteTypeAbbrevs() { |
| 693 | using namespace llvm; |
| 694 | |
| 695 | BitCodeAbbrev *Abv; |
| 696 | |
| 697 | // Abbreviation for TYPE_EXT_QUAL |
| 698 | Abv = new BitCodeAbbrev(); |
| 699 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 700 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 701 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
| 702 | TypeExtQualAbbrev = Stream.EmitAbbrev(Abv); |
| 703 | |
| 704 | // Abbreviation for TYPE_FUNCTION_PROTO |
| 705 | Abv = new BitCodeAbbrev(); |
| 706 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 707 | // FunctionType |
| 708 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 709 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 710 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 711 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 712 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 713 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
| 714 | // FunctionProtoType |
| 715 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 716 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 717 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 718 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 719 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 720 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 721 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 722 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
| 723 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(Abv); |
| 724 | } |
| 725 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 726 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 727 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 728 | //===----------------------------------------------------------------------===// |
| 729 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 730 | static void EmitBlockID(unsigned ID, const char *Name, |
| 731 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 732 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 733 | Record.clear(); |
| 734 | Record.push_back(ID); |
| 735 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 736 | |
| 737 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 738 | if (!Name || Name[0] == 0) |
| 739 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 740 | Record.clear(); |
| 741 | while (*Name) |
| 742 | Record.push_back(*Name++); |
| 743 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 744 | } |
| 745 | |
| 746 | static void EmitRecordID(unsigned ID, const char *Name, |
| 747 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 748 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 749 | Record.clear(); |
| 750 | Record.push_back(ID); |
| 751 | while (*Name) |
| 752 | Record.push_back(*Name++); |
| 753 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 757 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 758 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 759 | RECORD(STMT_STOP); |
| 760 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 761 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 762 | RECORD(STMT_NULL); |
| 763 | RECORD(STMT_COMPOUND); |
| 764 | RECORD(STMT_CASE); |
| 765 | RECORD(STMT_DEFAULT); |
| 766 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 767 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 768 | RECORD(STMT_IF); |
| 769 | RECORD(STMT_SWITCH); |
| 770 | RECORD(STMT_WHILE); |
| 771 | RECORD(STMT_DO); |
| 772 | RECORD(STMT_FOR); |
| 773 | RECORD(STMT_GOTO); |
| 774 | RECORD(STMT_INDIRECT_GOTO); |
| 775 | RECORD(STMT_CONTINUE); |
| 776 | RECORD(STMT_BREAK); |
| 777 | RECORD(STMT_RETURN); |
| 778 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 779 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 780 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 781 | RECORD(EXPR_PREDEFINED); |
| 782 | RECORD(EXPR_DECL_REF); |
| 783 | RECORD(EXPR_INTEGER_LITERAL); |
| 784 | RECORD(EXPR_FLOATING_LITERAL); |
| 785 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 786 | RECORD(EXPR_STRING_LITERAL); |
| 787 | RECORD(EXPR_CHARACTER_LITERAL); |
| 788 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 789 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 790 | RECORD(EXPR_UNARY_OPERATOR); |
| 791 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 792 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 793 | RECORD(EXPR_CALL); |
| 794 | RECORD(EXPR_MEMBER); |
| 795 | RECORD(EXPR_BINARY_OPERATOR); |
| 796 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 797 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 798 | RECORD(EXPR_IMPLICIT_CAST); |
| 799 | RECORD(EXPR_CSTYLE_CAST); |
| 800 | RECORD(EXPR_COMPOUND_LITERAL); |
| 801 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 802 | RECORD(EXPR_INIT_LIST); |
| 803 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 804 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 805 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 806 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 807 | RECORD(EXPR_VA_ARG); |
| 808 | RECORD(EXPR_ADDR_LABEL); |
| 809 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 810 | RECORD(EXPR_CHOOSE); |
| 811 | RECORD(EXPR_GNU_NULL); |
| 812 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 813 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 814 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 815 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 816 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 817 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 818 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 819 | RECORD(EXPR_OBJC_ENCODE); |
| 820 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 821 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 822 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 823 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 824 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 825 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 826 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 827 | RECORD(STMT_OBJC_CATCH); |
| 828 | RECORD(STMT_OBJC_FINALLY); |
| 829 | RECORD(STMT_OBJC_AT_TRY); |
| 830 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 831 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 832 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 833 | RECORD(STMT_CXX_CATCH); |
| 834 | RECORD(STMT_CXX_TRY); |
| 835 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 836 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 837 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 838 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 839 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 840 | RECORD(EXPR_CXX_STATIC_CAST); |
| 841 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 842 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 843 | RECORD(EXPR_CXX_CONST_CAST); |
| 844 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 845 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 846 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 847 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 848 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 849 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 850 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 851 | RECORD(EXPR_CXX_THIS); |
| 852 | RECORD(EXPR_CXX_THROW); |
| 853 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 854 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 855 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 856 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 857 | RECORD(EXPR_CXX_NEW); |
| 858 | RECORD(EXPR_CXX_DELETE); |
| 859 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 860 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 861 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 862 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 863 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 864 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 865 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 866 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 867 | RECORD(EXPR_CXX_NOEXCEPT); |
| 868 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 869 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 870 | RECORD(EXPR_TYPE_TRAIT); |
| 871 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 872 | RECORD(EXPR_PACK_EXPANSION); |
| 873 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 874 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 875 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 876 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 877 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 878 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 879 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 880 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 881 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 882 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 883 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 884 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 885 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 886 | RecordData Record; |
| 887 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 888 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 889 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 890 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 891 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 892 | // Control Block. |
| 893 | BLOCK(CONTROL_BLOCK); |
| 894 | RECORD(METADATA); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 895 | RECORD(SIGNATURE); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 896 | RECORD(MODULE_NAME); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 897 | RECORD(MODULE_DIRECTORY); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 898 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 899 | RECORD(IMPORTS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 900 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 901 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 902 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 903 | RECORD(INPUT_FILE_OFFSETS); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 904 | |
| 905 | BLOCK(OPTIONS_BLOCK); |
| 906 | RECORD(LANGUAGE_OPTIONS); |
| 907 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 908 | RECORD(DIAGNOSTIC_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 909 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 910 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 911 | RECORD(PREPROCESSOR_OPTIONS); |
| 912 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 913 | BLOCK(INPUT_FILES_BLOCK); |
| 914 | RECORD(INPUT_FILE); |
| 915 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 916 | // AST Top-Level Block. |
| 917 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 918 | RECORD(TYPE_OFFSET); |
| 919 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 920 | RECORD(IDENTIFIER_OFFSET); |
| 921 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 922 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 923 | RECORD(SPECIAL_TYPES); |
| 924 | RECORD(STATISTICS); |
| 925 | RECORD(TENTATIVE_DEFINITIONS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 926 | RECORD(SELECTOR_OFFSETS); |
| 927 | RECORD(METHOD_POOL); |
| 928 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 929 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 930 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 931 | RECORD(EXT_VECTOR_DECLS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 932 | RECORD(UNUSED_FILESCOPED_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 933 | RECORD(PPD_ENTITIES_OFFSETS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 934 | RECORD(VTABLE_USES); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 935 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 936 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 937 | RECORD(SEMA_DECL_REFS); |
| 938 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 939 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 940 | RECORD(DECL_REPLACEMENTS); |
| 941 | RECORD(UPDATE_VISIBLE); |
| 942 | RECORD(DECL_UPDATE_OFFSETS); |
| 943 | RECORD(DECL_UPDATES); |
| 944 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 945 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 946 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 947 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 948 | RECORD(FP_PRAGMA_OPTIONS); |
| 949 | RECORD(OPENCL_EXTENSIONS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 950 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 951 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 952 | RECORD(MODULE_OFFSET_MAP); |
| 953 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 954 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 955 | RECORD(FILE_SORTED_DECLS); |
| 956 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 957 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 958 | RECORD(MACRO_OFFSET); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 959 | RECORD(INTERESTING_IDENTIFIERS); |
| 960 | RECORD(UNDEFINED_BUT_USED); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 961 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 962 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 963 | RECORD(MSSTRUCT_PRAGMA_OPTIONS); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 964 | RECORD(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 965 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); |
| 966 | RECORD(CXX_CTOR_INITIALIZERS_OFFSETS); |
| 967 | RECORD(DELETE_EXPRS_TO_ANALYZE); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 968 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 969 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 970 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 971 | RECORD(SM_SLOC_FILE_ENTRY); |
| 972 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 973 | RECORD(SM_SLOC_BUFFER_BLOB); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 974 | RECORD(SM_SLOC_BUFFER_BLOB_COMPRESSED); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 975 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 976 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 977 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 978 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 979 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 980 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 981 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 982 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 983 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 984 | |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 985 | // Submodule Block. |
| 986 | BLOCK(SUBMODULE_BLOCK); |
| 987 | RECORD(SUBMODULE_METADATA); |
| 988 | RECORD(SUBMODULE_DEFINITION); |
| 989 | RECORD(SUBMODULE_UMBRELLA_HEADER); |
| 990 | RECORD(SUBMODULE_HEADER); |
| 991 | RECORD(SUBMODULE_TOPHEADER); |
| 992 | RECORD(SUBMODULE_UMBRELLA_DIR); |
| 993 | RECORD(SUBMODULE_IMPORTS); |
| 994 | RECORD(SUBMODULE_EXPORTS); |
| 995 | RECORD(SUBMODULE_REQUIRES); |
| 996 | RECORD(SUBMODULE_EXCLUDED_HEADER); |
| 997 | RECORD(SUBMODULE_LINK_LIBRARY); |
| 998 | RECORD(SUBMODULE_CONFIG_MACRO); |
| 999 | RECORD(SUBMODULE_CONFLICT); |
| 1000 | RECORD(SUBMODULE_PRIVATE_HEADER); |
| 1001 | RECORD(SUBMODULE_TEXTUAL_HEADER); |
| 1002 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); |
| 1003 | |
| 1004 | // Comments Block. |
| 1005 | BLOCK(COMMENTS_BLOCK); |
| 1006 | RECORD(COMMENTS_RAW_COMMENT); |
| 1007 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 1008 | // Decls and Types block. |
| 1009 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1010 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1011 | RECORD(TYPE_COMPLEX); |
| 1012 | RECORD(TYPE_POINTER); |
| 1013 | RECORD(TYPE_BLOCK_POINTER); |
| 1014 | RECORD(TYPE_LVALUE_REFERENCE); |
| 1015 | RECORD(TYPE_RVALUE_REFERENCE); |
| 1016 | RECORD(TYPE_MEMBER_POINTER); |
| 1017 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1018 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1019 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1020 | RECORD(TYPE_VECTOR); |
| 1021 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1022 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1023 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1024 | RECORD(TYPE_TYPEDEF); |
| 1025 | RECORD(TYPE_TYPEOF_EXPR); |
| 1026 | RECORD(TYPE_TYPEOF); |
| 1027 | RECORD(TYPE_RECORD); |
| 1028 | RECORD(TYPE_ENUM); |
| 1029 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1030 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1031 | RECORD(TYPE_DECLTYPE); |
| 1032 | RECORD(TYPE_ELABORATED); |
| 1033 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 1034 | RECORD(TYPE_UNRESOLVED_USING); |
| 1035 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 1036 | RECORD(TYPE_OBJC_OBJECT); |
| 1037 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 1038 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 1039 | RECORD(TYPE_DEPENDENT_NAME); |
| 1040 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 1041 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 1042 | RECORD(TYPE_PAREN); |
| 1043 | RECORD(TYPE_PACK_EXPANSION); |
| 1044 | RECORD(TYPE_ATTRIBUTED); |
| 1045 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1046 | RECORD(TYPE_AUTO); |
| 1047 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1048 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1049 | RECORD(TYPE_DECAYED); |
| 1050 | RECORD(TYPE_ADJUSTED); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 1051 | RECORD(LOCAL_REDECLARATIONS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1052 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1053 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1054 | RECORD(DECL_ENUM); |
| 1055 | RECORD(DECL_RECORD); |
| 1056 | RECORD(DECL_ENUM_CONSTANT); |
| 1057 | RECORD(DECL_FUNCTION); |
| 1058 | RECORD(DECL_OBJC_METHOD); |
| 1059 | RECORD(DECL_OBJC_INTERFACE); |
| 1060 | RECORD(DECL_OBJC_PROTOCOL); |
| 1061 | RECORD(DECL_OBJC_IVAR); |
| 1062 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1063 | RECORD(DECL_OBJC_CATEGORY); |
| 1064 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1065 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1066 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1067 | RECORD(DECL_OBJC_PROPERTY); |
| 1068 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1069 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1070 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1071 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1072 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1073 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1074 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1075 | RECORD(DECL_BLOCK); |
| 1076 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1077 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1078 | RECORD(DECL_NAMESPACE); |
| 1079 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1080 | RECORD(DECL_USING); |
| 1081 | RECORD(DECL_USING_SHADOW); |
| 1082 | RECORD(DECL_USING_DIRECTIVE); |
| 1083 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1084 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1085 | RECORD(DECL_LINKAGE_SPEC); |
| 1086 | RECORD(DECL_CXX_RECORD); |
| 1087 | RECORD(DECL_CXX_METHOD); |
| 1088 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 1089 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1090 | RECORD(DECL_CXX_CONVERSION); |
| 1091 | RECORD(DECL_ACCESS_SPEC); |
| 1092 | RECORD(DECL_FRIEND); |
| 1093 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1094 | RECORD(DECL_CLASS_TEMPLATE); |
| 1095 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1096 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1097 | RECORD(DECL_VAR_TEMPLATE); |
| 1098 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1099 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1100 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1101 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1102 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1103 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 1104 | RECORD(DECL_STATIC_ASSERT); |
| 1105 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 1106 | RECORD(DECL_INDIRECTFIELD); |
| 1107 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 1108 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1109 | // Statements and Exprs can occur in the Decls and Types block. |
| 1110 | AddStmtsExprs(Stream, Record); |
| 1111 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1112 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1113 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1114 | RECORD(PPD_MACRO_DEFINITION); |
| 1115 | RECORD(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 1116 | |
| 1117 | // Decls and Types block. |
| 1118 | BLOCK(EXTENSION_BLOCK); |
| 1119 | RECORD(EXTENSION_METADATA); |
| 1120 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1121 | #undef RECORD |
| 1122 | #undef BLOCK |
| 1123 | Stream.ExitBlock(); |
| 1124 | } |
| 1125 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1126 | /// \brief Prepares a path for being written to an AST file by converting it |
| 1127 | /// to an absolute path and removing nested './'s. |
| 1128 | /// |
| 1129 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1130 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1131 | SmallVectorImpl<char> &Path) { |
Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 1132 | bool Changed = FileMgr.makeAbsolutePath(Path); |
Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame] | 1133 | return Changed | llvm::sys::path::remove_dots(Path); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1136 | /// \brief Adjusts the given filename to only write out the portion of the |
| 1137 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1139 | /// \param Filename the file name to adjust. |
| 1140 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1141 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1142 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1143 | /// |
| 1144 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1145 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1146 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1147 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1148 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1150 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1151 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1152 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1153 | // Verify that the filename and the system root have the same prefix. |
| 1154 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1155 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1156 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1157 | return Filename; // Prefixes don't match. |
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 | // We hit the end of the filename before we hit the end of the system root. |
| 1160 | if (!Filename[Pos]) |
| 1161 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1163 | // If there's not a path separator at the end of the base directory nor |
| 1164 | // immediately after it, then this isn't within the base directory. |
| 1165 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1166 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1167 | return Filename; |
| 1168 | } else { |
| 1169 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1170 | // We distinguish relative paths from absolute paths by the |
| 1171 | // absence of '/' at the beginning of relative paths. |
| 1172 | // |
| 1173 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1174 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1175 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1176 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1177 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1180 | return Filename + Pos; |
| 1181 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1182 | |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1183 | static ASTFileSignature getSignature() { |
| 1184 | while (1) { |
| 1185 | if (ASTFileSignature S = llvm::sys::Process::GetRandomNumber()) |
| 1186 | return S; |
| 1187 | // Rely on GetRandomNumber to eventually return non-zero... |
| 1188 | } |
| 1189 | } |
| 1190 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1191 | /// \brief Write the control block. |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1192 | uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP, |
| 1193 | ASTContext &Context, |
| 1194 | StringRef isysroot, |
| 1195 | const std::string &OutputFile) { |
| 1196 | ASTFileSignature Signature = 0; |
| 1197 | |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1198 | using namespace llvm; |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1199 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1200 | RecordData Record; |
| 1201 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1202 | // Metadata |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1203 | auto *MetadataAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1204 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1205 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1206 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1207 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1208 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1209 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1210 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1211 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1212 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1213 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1214 | assert((!WritingModule || isysroot.empty()) && |
| 1215 | "writing module as a relocatable PCH?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1216 | { |
| 1217 | RecordData::value_type Record[] = {METADATA, VERSION_MAJOR, VERSION_MINOR, |
| 1218 | CLANG_VERSION_MAJOR, CLANG_VERSION_MINOR, |
| 1219 | !isysroot.empty(), IncludeTimestamps, |
| 1220 | ASTHasCompilerErrors}; |
| 1221 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1222 | getClangFullRepositoryVersion()); |
| 1223 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1224 | if (WritingModule) { |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1225 | // For implicit modules we output a signature that we can use to ensure |
| 1226 | // duplicate module builds don't collide in the cache as their output order |
| 1227 | // is non-deterministic. |
| 1228 | // FIXME: Remove this when output is deterministic. |
| 1229 | if (Context.getLangOpts().ImplicitModules) { |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1230 | Signature = getSignature(); |
| 1231 | RecordData::value_type Record[] = {Signature}; |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1232 | Stream.EmitRecord(SIGNATURE, Record); |
| 1233 | } |
| 1234 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1235 | // Module name |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1236 | auto *Abbrev = new BitCodeAbbrev(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1237 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1238 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1239 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1240 | RecordData::value_type Record[] = {MODULE_NAME}; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1241 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1242 | } |
| 1243 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1244 | if (WritingModule && WritingModule->Directory) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1245 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1246 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1247 | |
| 1248 | // If the home of the module is the current working directory, then we |
| 1249 | // want to pick up the cwd of the build process loading the module, not |
| 1250 | // our cwd, when we load this module. |
| 1251 | if (!PP.getHeaderSearchInfo() |
| 1252 | .getHeaderSearchOpts() |
| 1253 | .ModuleMapFileHomeIsCwd || |
| 1254 | WritingModule->Directory->getName() != StringRef(".")) { |
| 1255 | // Module directory. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1256 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1257 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1258 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
| 1259 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1260 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1261 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1262 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1263 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1264 | |
| 1265 | // Write out all other paths relative to the base directory if possible. |
| 1266 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1267 | } else if (!isysroot.empty()) { |
| 1268 | // Write out paths relative to the sysroot if possible. |
| 1269 | BaseDirectory = isysroot; |
| 1270 | } |
| 1271 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1272 | // Module map file |
| 1273 | if (WritingModule) { |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1274 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1275 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1276 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 1277 | |
| 1278 | // Primary module map file. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1279 | AddPath(Map.getModuleMapFileForUniquing(WritingModule)->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1280 | |
| 1281 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1282 | if (auto *AdditionalModMaps = |
| 1283 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1284 | Record.push_back(AdditionalModMaps->size()); |
| 1285 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1286 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1287 | } else { |
| 1288 | Record.push_back(0); |
| 1289 | } |
| 1290 | |
| 1291 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1294 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1295 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1296 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1297 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1298 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1299 | for (auto *M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1300 | // Skip modules that weren't directly imported. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1301 | if (!M->isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1302 | continue; |
| 1303 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1304 | Record.push_back((unsigned)M->Kind); // FIXME: Stable encoding |
| 1305 | AddSourceLocation(M->ImportLoc, Record); |
| 1306 | Record.push_back(M->File->getSize()); |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1307 | Record.push_back(getTimestampForOutput(M->File)); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1308 | Record.push_back(M->Signature); |
| 1309 | AddPath(M->FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1310 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1311 | Stream.EmitRecord(IMPORTS, Record); |
| 1312 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1314 | // Write the options block. |
| 1315 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); |
| 1316 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1317 | // Language options. |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1318 | Record.clear(); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1319 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1320 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1321 | Record.push_back(LangOpts.Name); |
| 1322 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1323 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1324 | #include "clang/Basic/LangOptions.def" |
| 1325 | #define SANITIZER(NAME, ID) \ |
| 1326 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1327 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1328 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1329 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1330 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1331 | AddString(Feature, Record); |
| 1332 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1333 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1334 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1335 | |
| 1336 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1337 | |
| 1338 | // Comment options. |
| 1339 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1340 | for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) { |
| 1341 | AddString(I, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1342 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1343 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1344 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1345 | // OpenMP offloading options. |
| 1346 | Record.push_back(LangOpts.OMPTargetTriples.size()); |
| 1347 | for (auto &T : LangOpts.OMPTargetTriples) |
| 1348 | AddString(T.getTriple(), Record); |
| 1349 | |
| 1350 | AddString(LangOpts.OMPHostIRFile, Record); |
| 1351 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1352 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1353 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1354 | // Target options. |
| 1355 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1356 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1357 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1358 | AddString(TargetOpts.Triple, Record); |
| 1359 | AddString(TargetOpts.CPU, Record); |
| 1360 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1361 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1362 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1363 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1364 | } |
| 1365 | Record.push_back(TargetOpts.Features.size()); |
| 1366 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1367 | AddString(TargetOpts.Features[I], Record); |
| 1368 | } |
| 1369 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1370 | |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1371 | // Diagnostic options. |
| 1372 | Record.clear(); |
| 1373 | const DiagnosticOptions &DiagOpts |
| 1374 | = Context.getDiagnostics().getDiagnosticOptions(); |
| 1375 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1376 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1377 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1378 | #include "clang/Basic/DiagnosticOptions.def" |
| 1379 | Record.push_back(DiagOpts.Warnings.size()); |
| 1380 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1381 | AddString(DiagOpts.Warnings[I], Record); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 1382 | Record.push_back(DiagOpts.Remarks.size()); |
| 1383 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1384 | AddString(DiagOpts.Remarks[I], Record); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1385 | // Note: we don't serialize the log or serialization file names, because they |
| 1386 | // are generally transient files and will almost always be overridden. |
| 1387 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1388 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1389 | // File system options. |
| 1390 | Record.clear(); |
Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1391 | const FileSystemOptions &FSOpts = |
| 1392 | Context.getSourceManager().getFileManager().getFileSystemOpts(); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1393 | AddString(FSOpts.WorkingDir, Record); |
| 1394 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1395 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1396 | // Header search options. |
| 1397 | Record.clear(); |
| 1398 | const HeaderSearchOptions &HSOpts |
| 1399 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1400 | AddString(HSOpts.Sysroot, Record); |
| 1401 | |
| 1402 | // Include entries. |
| 1403 | Record.push_back(HSOpts.UserEntries.size()); |
| 1404 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1405 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1406 | AddString(Entry.Path, Record); |
| 1407 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1408 | Record.push_back(Entry.IsFramework); |
| 1409 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | // System header prefixes. |
| 1413 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1414 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1415 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1416 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1417 | } |
| 1418 | |
| 1419 | AddString(HSOpts.ResourceDir, Record); |
| 1420 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1421 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1422 | Record.push_back(HSOpts.DisableModuleHash); |
| 1423 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1424 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1425 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1426 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1427 | // Write out the specific module cache path that contains the module files. |
| 1428 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1429 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1430 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1431 | // Preprocessor options. |
| 1432 | Record.clear(); |
| 1433 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1434 | |
| 1435 | // Macro definitions. |
| 1436 | Record.push_back(PPOpts.Macros.size()); |
| 1437 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1438 | AddString(PPOpts.Macros[I].first, Record); |
| 1439 | Record.push_back(PPOpts.Macros[I].second); |
| 1440 | } |
| 1441 | |
| 1442 | // Includes |
| 1443 | Record.push_back(PPOpts.Includes.size()); |
| 1444 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1445 | AddString(PPOpts.Includes[I], Record); |
| 1446 | |
| 1447 | // Macro includes |
| 1448 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1449 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1450 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1451 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1452 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1453 | // Detailed record is important since it is used for the module cache hash. |
| 1454 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1455 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1456 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1457 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1458 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1459 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1460 | // Leave the options block. |
| 1461 | Stream.ExitBlock(); |
| 1462 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1463 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1464 | SourceManager &SM = Context.getSourceManager(); |
| 1465 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1466 | auto *FileAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1467 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1468 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1469 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1470 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1471 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1472 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1473 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1474 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1475 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1476 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1477 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1478 | Record.clear(); |
| 1479 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1480 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1481 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1482 | // Original PCH directory |
| 1483 | if (!OutputFile.empty() && OutputFile != "-") { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1484 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1485 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1486 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1487 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1488 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1489 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1490 | |
Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1491 | SM.getFileManager().makeAbsolutePath(OutputPath); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1492 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1493 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1494 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1495 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1496 | } |
| 1497 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1498 | WriteInputFiles(Context.SourceMgr, |
| 1499 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1500 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1501 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1502 | return Signature; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1505 | namespace { |
| 1506 | /// \brief An input file. |
| 1507 | struct InputFileEntry { |
| 1508 | const FileEntry *File; |
| 1509 | bool IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1510 | bool IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1511 | bool BufferOverridden; |
| 1512 | }; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1513 | } // end anonymous namespace |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1514 | |
| 1515 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1516 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1517 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1518 | using namespace llvm; |
| 1519 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1520 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1521 | // Create input-file abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1522 | auto *IFAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1523 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1524 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1525 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1526 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1527 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1528 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1529 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1530 | unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); |
| 1531 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1532 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1533 | // 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] | 1534 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1535 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1536 | // Get this source location entry. |
| 1537 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1538 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1539 | |
| 1540 | // We only care about file entries that were not overridden. |
| 1541 | if (!SLoc->isFile()) |
| 1542 | continue; |
| 1543 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1544 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1545 | continue; |
| 1546 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1547 | InputFileEntry Entry; |
| 1548 | Entry.File = Cache->OrigEntry; |
| 1549 | Entry.IsSystemFile = Cache->IsSystemFile; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1550 | Entry.IsTransient = Cache->IsTransient; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1551 | Entry.BufferOverridden = Cache->BufferOverridden; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1552 | if (Cache->IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1553 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1554 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1555 | SortedFiles.push_front(Entry); |
| 1556 | } |
| 1557 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1558 | unsigned UserFilesNum = 0; |
| 1559 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1560 | std::vector<uint64_t> InputFileOffsets; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1561 | for (const auto &Entry : SortedFiles) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1562 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1563 | if (InputFileID != 0) |
| 1564 | continue; // already recorded this file. |
| 1565 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1566 | // Record this entry's offset. |
| 1567 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1568 | |
| 1569 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1570 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1571 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1572 | ++UserFilesNum; |
| 1573 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1574 | // Emit size/modification time for this file. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1575 | // And whether this file was overridden. |
| 1576 | RecordData::value_type Record[] = { |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1577 | INPUT_FILE, |
| 1578 | InputFileOffsets.size(), |
| 1579 | (uint64_t)Entry.File->getSize(), |
| 1580 | (uint64_t)getTimestampForOutput(Entry.File), |
| 1581 | Entry.BufferOverridden, |
| 1582 | Entry.IsTransient}; |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1583 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1584 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1585 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1586 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1587 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1588 | |
| 1589 | // Create input file offsets abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1590 | auto *OffsetsAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1591 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1592 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1593 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1594 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1595 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
| 1596 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(OffsetsAbbrev); |
| 1597 | |
| 1598 | // Write input file offsets. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1599 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, |
| 1600 | InputFileOffsets.size(), UserFilesNum}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1601 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1604 | //===----------------------------------------------------------------------===// |
| 1605 | // Source Manager Serialization |
| 1606 | //===----------------------------------------------------------------------===// |
| 1607 | |
| 1608 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1609 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1610 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1611 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1612 | |
| 1613 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1614 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1615 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1616 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1617 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1618 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1619 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1620 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1621 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1622 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1623 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1624 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1628 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1629 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1630 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1631 | |
| 1632 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1633 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1634 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1635 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1636 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1637 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1638 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1639 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1643 | /// buffer's blob. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1644 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, |
| 1645 | bool Compressed) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1646 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1647 | |
| 1648 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1649 | Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED |
| 1650 | : SM_SLOC_BUFFER_BLOB)); |
| 1651 | if (Compressed) |
| 1652 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1653 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1654 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1657 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1658 | /// expansion. |
| 1659 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1660 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1661 | |
| 1662 | auto *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1663 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1664 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1665 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1666 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1667 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1668 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1669 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1672 | namespace { |
| 1673 | // Trait used for the on-disk hash table of header search information. |
| 1674 | class HeaderFileInfoTrait { |
| 1675 | ASTWriter &Writer; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1676 | const HeaderSearch &HS; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1677 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1678 | // Keep track of the framework names we've used during serialization. |
| 1679 | SmallVector<char, 128> FrameworkStringData; |
| 1680 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1681 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1682 | public: |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1683 | HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) |
| 1684 | : Writer(Writer), HS(HS) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1685 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1686 | struct key_type { |
| 1687 | const FileEntry *FE; |
| 1688 | const char *Filename; |
| 1689 | }; |
| 1690 | typedef const key_type &key_type_ref; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1691 | |
| 1692 | typedef HeaderFileInfo data_type; |
| 1693 | typedef const data_type &data_type_ref; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 1694 | typedef unsigned hash_value_type; |
| 1695 | typedef unsigned offset_type; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1696 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1697 | hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1698 | // The hash is based only on size/time of the file, so that the reader can |
| 1699 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1700 | // change the form of the name. However, complete path is still the key. |
| 1701 | return llvm::hash_combine(key.FE->getSize(), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1702 | Writer.getTimestampForOutput(key.FE)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | std::pair<unsigned,unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1706 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1707 | using namespace llvm::support; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1708 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1709 | unsigned KeyLen = strlen(key.Filename) + 1 + 8 + 8; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1710 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1711 | unsigned DataLen = 1 + 2 + 4 + 4; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1712 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) |
| 1713 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) |
| 1714 | DataLen += 4; |
| 1715 | LE.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1716 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1719 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1720 | using namespace llvm::support; |
| 1721 | endian::Writer<little> LE(Out); |
| 1722 | LE.write<uint64_t>(key.FE->getSize()); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1723 | KeyLen -= 8; |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1724 | LE.write<uint64_t>(Writer.getTimestampForOutput(key.FE)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1725 | KeyLen -= 8; |
| 1726 | Out.write(key.Filename, KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1729 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1730 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1731 | using namespace llvm::support; |
| 1732 | endian::Writer<little> LE(Out); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1733 | uint64_t Start = Out.tell(); (void)Start; |
| 1734 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1735 | unsigned char Flags = (Data.isImport << 4) |
| 1736 | | (Data.isPragmaOnce << 3) |
| 1737 | | (Data.DirInfo << 1) |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1738 | | Data.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1739 | LE.write<uint8_t>(Flags); |
| 1740 | LE.write<uint16_t>(Data.NumIncludes); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1741 | |
| 1742 | if (!Data.ControllingMacro) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1743 | LE.write<uint32_t>(Data.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1744 | else |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1745 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1746 | |
| 1747 | unsigned Offset = 0; |
| 1748 | if (!Data.Framework.empty()) { |
| 1749 | // If this header refers into a framework, save the framework name. |
| 1750 | llvm::StringMap<unsigned>::iterator Pos |
| 1751 | = FrameworkNameOffset.find(Data.Framework); |
| 1752 | if (Pos == FrameworkNameOffset.end()) { |
| 1753 | Offset = FrameworkStringData.size() + 1; |
| 1754 | FrameworkStringData.append(Data.Framework.begin(), |
| 1755 | Data.Framework.end()); |
| 1756 | FrameworkStringData.push_back(0); |
| 1757 | |
| 1758 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1759 | } else |
| 1760 | Offset = Pos->second; |
| 1761 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1762 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1763 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1764 | // FIXME: If the header is excluded, we should write out some |
| 1765 | // record of that fact. |
| 1766 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) { |
| 1767 | if (uint32_t ModID = |
| 1768 | Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) { |
| 1769 | uint32_t Value = (ModID << 2) | (unsigned)ModInfo.getRole(); |
| 1770 | assert((Value >> 2) == ModID && "overflow in header module info"); |
| 1771 | LE.write<uint32_t>(Value); |
| 1772 | } |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1775 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1776 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1777 | |
| 1778 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1779 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1780 | }; |
| 1781 | } // end anonymous namespace |
| 1782 | |
| 1783 | /// \brief Write the header search block for the list of files that |
| 1784 | /// |
| 1785 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1786 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1787 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1788 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1789 | |
| 1790 | if (FilesByUID.size() > HS.header_file_size()) |
| 1791 | FilesByUID.resize(HS.header_file_size()); |
| 1792 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1793 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 1794 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1795 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1796 | unsigned NumHeaderSearchEntries = 0; |
| 1797 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1798 | const FileEntry *File = FilesByUID[UID]; |
| 1799 | if (!File) |
| 1800 | continue; |
| 1801 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1802 | // Get the file info. This will load info from the external source if |
| 1803 | // necessary. Skip emitting this file if we have no information on it |
| 1804 | // as a header file (in which case HFI will be null) or if it hasn't |
| 1805 | // changed since it was loaded. Also skip it if it's for a modular header |
| 1806 | // from a different module; in that case, we rely on the module(s) |
| 1807 | // containing the header to provide this information. |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1808 | const HeaderFileInfo *HFI = |
| 1809 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); |
| 1810 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 1811 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1812 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1813 | // Massage the file path into an appropriate form. |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1814 | const char *Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1815 | SmallString<128> FilenameTmp(Filename); |
| 1816 | if (PreparePathForOutput(FilenameTmp)) { |
| 1817 | // If we performed any translation on the file name at all, we need to |
| 1818 | // save this string, since the generator will refer to it later. |
| 1819 | Filename = strdup(FilenameTmp.c_str()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1820 | SavedStrings.push_back(Filename); |
| 1821 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1822 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1823 | HeaderFileInfoTrait::key_type key = { File, Filename }; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1824 | Generator.insert(key, *HFI, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1825 | ++NumHeaderSearchEntries; |
| 1826 | } |
| 1827 | |
| 1828 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1829 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1830 | uint32_t BucketOffset; |
| 1831 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1832 | using namespace llvm::support; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1833 | llvm::raw_svector_ostream Out(TableData); |
| 1834 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1835 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1836 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1837 | } |
| 1838 | |
| 1839 | // Create a blob abbreviation |
| 1840 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1841 | |
| 1842 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1843 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1844 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1845 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1846 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1847 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1848 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1849 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1850 | // Write the header search table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1851 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, |
| 1852 | NumHeaderSearchEntries, TableData.size()}; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1853 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 1854 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1855 | |
| 1856 | // Free all of the strings we had to duplicate. |
| 1857 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1858 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1861 | /// \brief Writes the block containing the serialized form of the |
| 1862 | /// source manager. |
| 1863 | /// |
| 1864 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1865 | /// blob), indexed based on the file name, so that we only create |
| 1866 | /// entries for files that we actually need. In the common case (no |
| 1867 | /// errors), we probably won't have to create file entries for any of |
| 1868 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1869 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1870 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1871 | RecordData Record; |
| 1872 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1873 | // Enter the source manager block. |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1874 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1875 | |
| 1876 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1877 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1878 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1879 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false); |
| 1880 | unsigned SLocBufferBlobCompressedAbbrv = |
| 1881 | CreateSLocBufferBlobAbbrev(Stream, true); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1882 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1883 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1884 | // Write out the source location entry table. We skip the first |
| 1885 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1886 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1887 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1888 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1889 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1890 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1891 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1892 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1893 | FileID FID = FileID::get(I); |
| 1894 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1895 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1896 | // Record the offset of this source-location entry. |
| 1897 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1898 | |
| 1899 | // Figure out which record code to use. |
| 1900 | unsigned Code; |
| 1901 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1902 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1903 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1904 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1905 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1906 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1907 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1908 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1909 | Record.clear(); |
| 1910 | Record.push_back(Code); |
| 1911 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1912 | // Starting offset of this entry within this module, so skip the dummy. |
| 1913 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1914 | if (SLoc->isFile()) { |
| 1915 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1916 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1917 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1918 | Record.push_back(File.hasLineDirectives()); |
| 1919 | |
| 1920 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1921 | bool EmitBlob = false; |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1922 | if (Content->OrigEntry) { |
| 1923 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1924 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1925 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1926 | // The source location entry is a file. Emit input file ID. |
| 1927 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 1928 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1929 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1930 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1931 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1932 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1933 | if (FDI != FileDeclIDs.end()) { |
| 1934 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1935 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1936 | } else { |
| 1937 | Record.push_back(0); |
| 1938 | Record.push_back(0); |
| 1939 | } |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1940 | |
| 1941 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
| 1942 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1943 | if (Content->BufferOverridden || Content->IsTransient) |
| 1944 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1945 | } else { |
| 1946 | // The source location entry is a buffer. The blob associated |
| 1947 | // with this entry contains the contents of the buffer. |
| 1948 | |
| 1949 | // We add one to the size so that we capture the trailing NULL |
| 1950 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1951 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1952 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1953 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1954 | const char *Name = Buffer->getBufferIdentifier(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1955 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1956 | StringRef(Name, strlen(Name) + 1)); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1957 | EmitBlob = true; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1959 | if (strcmp(Name, "<built-in>") == 0) { |
| 1960 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1961 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1962 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1963 | |
| 1964 | if (EmitBlob) { |
| 1965 | // Include the implicit terminating null character in the on-disk buffer |
| 1966 | // if we're writing it uncompressed. |
| 1967 | const llvm::MemoryBuffer *Buffer = |
| 1968 | Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 1969 | StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1); |
| 1970 | |
| 1971 | // Compress the buffer if possible. We expect that almost all PCM |
| 1972 | // consumers will not want its contents. |
| 1973 | SmallString<0> CompressedBuffer; |
| 1974 | if (llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer) == |
| 1975 | llvm::zlib::StatusOK) { |
| 1976 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, |
| 1977 | Blob.size() - 1}; |
| 1978 | Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, |
| 1979 | CompressedBuffer); |
| 1980 | } else { |
| 1981 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB}; |
| 1982 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob); |
| 1983 | } |
| 1984 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1985 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1986 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1987 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 73ee5d7 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1988 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1989 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
Argyrios Kyrtzidis | a1d943a | 2011-08-17 00:31:14 +0000 | [diff] [blame] | 1990 | Record.push_back(Expansion.isMacroArgExpansion() ? 0 |
| 1991 | : Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1992 | |
| 1993 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1994 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1995 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1996 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1997 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1998 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1999 | } |
| 2000 | } |
| 2001 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2002 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2003 | |
| 2004 | if (SLocEntryOffsets.empty()) |
| 2005 | return; |
| 2006 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2007 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2008 | // table is used for lazily loading source-location information. |
| 2009 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2010 | |
| 2011 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2012 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2013 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2014 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2015 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 2016 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2017 | { |
| 2018 | RecordData::value_type Record[] = { |
| 2019 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), |
| 2020 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */}; |
| 2021 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
| 2022 | bytes(SLocEntryOffsets)); |
| 2023 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2024 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2025 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2026 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2027 | |
| 2028 | // Write the line table. It depends on remapping working, so it must come |
| 2029 | // after the source location offsets. |
| 2030 | if (SourceMgr.hasLineTable()) { |
| 2031 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 2032 | |
| 2033 | Record.clear(); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2034 | |
| 2035 | // Emit the needed file names. |
| 2036 | llvm::DenseMap<int, int> FilenameMap; |
| 2037 | for (const auto &L : LineTable) { |
| 2038 | if (L.first.ID < 0) |
| 2039 | continue; |
| 2040 | for (auto &LE : L.second) { |
| 2041 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, |
| 2042 | FilenameMap.size())).second) |
| 2043 | AddPath(LineTable.getFilename(LE.FilenameID), Record); |
| 2044 | } |
| 2045 | } |
| 2046 | Record.push_back(0); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2047 | |
| 2048 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2049 | for (const auto &L : LineTable) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2050 | // Only emit entries for local files. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2051 | if (L.first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2052 | continue; |
| 2053 | |
| 2054 | // Emit the file ID |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2055 | Record.push_back(L.first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2056 | |
| 2057 | // Emit the line entries |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2058 | Record.push_back(L.second.size()); |
| 2059 | for (const auto &LE : L.second) { |
| 2060 | Record.push_back(LE.FileOffset); |
| 2061 | Record.push_back(LE.LineNo); |
| 2062 | Record.push_back(FilenameMap[LE.FilenameID]); |
| 2063 | Record.push_back((unsigned)LE.FileKind); |
| 2064 | Record.push_back(LE.IncludeOffset); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2065 | } |
| 2066 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2067 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2068 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 2069 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2072 | //===----------------------------------------------------------------------===// |
| 2073 | // Preprocessor Serialization |
| 2074 | //===----------------------------------------------------------------------===// |
| 2075 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2076 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 2077 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2078 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 2079 | if (MI->isBuiltinMacro()) |
| 2080 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2081 | |
| 2082 | if (IsModule) { |
| 2083 | SourceLocation Loc = MD->getLocation(); |
| 2084 | if (Loc.isInvalid()) |
| 2085 | return true; |
| 2086 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 2087 | return true; |
| 2088 | } |
| 2089 | |
| 2090 | return false; |
| 2091 | } |
| 2092 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2093 | /// \brief Writes the block containing the serialized form of the |
| 2094 | /// preprocessor. |
| 2095 | /// |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2096 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2097 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2098 | if (PPRec) |
| 2099 | WritePreprocessorDetail(*PPRec); |
| 2100 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2101 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2102 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2103 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2104 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2105 | if (PP.getCounterValue() != 0) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2106 | RecordData::value_type Record[] = {PP.getCounterValue()}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2107 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2111 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2112 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2113 | // 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] | 2114 | // 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] | 2115 | if (PP.SawDateOrTime()) |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2116 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2117 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2118 | // 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] | 2119 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2120 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2121 | // Construct the list of identifiers with macro directives that need to be |
| 2122 | // serialized. |
| 2123 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2124 | for (auto &Id : PP.getIdentifierTable()) |
| 2125 | if (Id.second->hadMacroDefinition() && |
| 2126 | (!Id.second->isFromAST() || |
| 2127 | Id.second->hasChangedSinceDeserialization())) |
| 2128 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2129 | // Sort the set of macro definitions that need to be serialized by the |
| 2130 | // name of the macro, to provide a stable ordering. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2131 | std::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(), |
| 2132 | llvm::less_ptr<IdentifierInfo>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2133 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2134 | // Emit the macro directives as a list and associate the offset with the |
| 2135 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2136 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2137 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2138 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2139 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2140 | // Emit the macro directives in reverse source order. |
| 2141 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2142 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2143 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2144 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2145 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2146 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2147 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2148 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2149 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2150 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2151 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2152 | Record.push_back(VisMD->isPublic()); |
| 2153 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2154 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2155 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2156 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2157 | bool EmittedModuleMacros = false; |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2158 | if (IsModule) { |
| 2159 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2160 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2161 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2162 | while (!Worklist.empty()) { |
| 2163 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2164 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2165 | // Emit a record indicating this submodule exports this macro. |
| 2166 | ModuleMacroRecord.push_back( |
| 2167 | getSubmoduleID(Macro->getOwningModule())); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2168 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2169 | for (auto *M : Macro->overrides()) |
| 2170 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2171 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2172 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2173 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2174 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2175 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2176 | for (auto *M : Macro->overrides()) |
| 2177 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2178 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2179 | |
| 2180 | EmittedModuleMacros = true; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2181 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2182 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2183 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2184 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2185 | continue; |
| 2186 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2187 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2188 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2189 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2190 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2191 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2192 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 2193 | /// the local macro ID |
| 2194 | /// |
| 2195 | /// For each identifier that is associated with a macro, this map |
| 2196 | /// provides the offset into the bitstream where that macro is |
| 2197 | /// defined. |
| 2198 | std::vector<uint32_t> MacroOffsets; |
| 2199 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2200 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2201 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2202 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2203 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2204 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2205 | if (ID < FirstMacroID) { |
| 2206 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2207 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2208 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2209 | |
| 2210 | // Record the local offset of this macro. |
| 2211 | unsigned Index = ID - FirstMacroID; |
| 2212 | if (Index == MacroOffsets.size()) |
| 2213 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2214 | else { |
| 2215 | if (Index > MacroOffsets.size()) |
| 2216 | MacroOffsets.resize(Index + 1); |
| 2217 | |
| 2218 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2219 | } |
| 2220 | |
| 2221 | AddIdentifierRef(Name, Record); |
| 2222 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
| 2223 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2224 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2225 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2226 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2227 | unsigned Code; |
| 2228 | if (MI->isObjectLike()) { |
| 2229 | Code = PP_MACRO_OBJECT_LIKE; |
| 2230 | } else { |
| 2231 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2232 | |
| 2233 | Record.push_back(MI->isC99Varargs()); |
| 2234 | Record.push_back(MI->isGNUVarargs()); |
| 2235 | Record.push_back(MI->hasCommaPasting()); |
| 2236 | Record.push_back(MI->getNumArgs()); |
Daniel Marjamaki | e4770da | 2015-05-29 09:15:24 +0000 | [diff] [blame] | 2237 | for (const IdentifierInfo *Arg : MI->args()) |
| 2238 | AddIdentifierRef(Arg, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | // If we have a detailed preprocessing record, record the macro definition |
| 2242 | // ID that corresponds to this macro. |
| 2243 | if (PPRec) |
| 2244 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2245 | |
| 2246 | Stream.EmitRecord(Code, Record); |
| 2247 | Record.clear(); |
| 2248 | |
| 2249 | // Emit the tokens array. |
| 2250 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2251 | // Note that we know that the preprocessor does not have any annotation |
| 2252 | // tokens in it because they are created by the parser, and thus can't |
| 2253 | // be in a macro definition. |
| 2254 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2255 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2256 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2257 | Record.clear(); |
| 2258 | } |
| 2259 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2260 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2261 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2262 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2263 | |
| 2264 | // Write the offsets table for macro IDs. |
| 2265 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2266 | |
Richard Smith | 13090a2 | 2015-04-10 02:02:24 +0000 | [diff] [blame] | 2267 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2268 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2269 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2270 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2271 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2272 | |
| 2273 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2274 | { |
| 2275 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), |
| 2276 | FirstMacroID - NUM_PREDEF_MACRO_IDS}; |
| 2277 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); |
| 2278 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2282 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2283 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2284 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2285 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2286 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2287 | // Enter the preprocessor block. |
| 2288 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2289 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2290 | // If the preprocessor has a preprocessing record, emit it. |
| 2291 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2292 | using namespace llvm; |
| 2293 | |
| 2294 | // Set up the abbreviation for |
| 2295 | unsigned InclusionAbbrev = 0; |
| 2296 | { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2297 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2298 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2299 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2300 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2301 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2302 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2303 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2304 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2305 | } |
| 2306 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2307 | unsigned FirstPreprocessorEntityID |
| 2308 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 2309 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2310 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2311 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2312 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2313 | EEnd = PPRec.local_end(); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2314 | E != EEnd; |
| 2315 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2316 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2317 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2318 | PreprocessedEntityOffsets.push_back( |
| 2319 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2320 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2321 | if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2322 | // Record this macro definition's ID. |
| 2323 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2324 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2325 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2326 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2327 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2328 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2329 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2330 | if (auto *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2331 | Record.push_back(ME->isBuiltinMacro()); |
| 2332 | if (ME->isBuiltinMacro()) |
| 2333 | AddIdentifierRef(ME->getName(), Record); |
| 2334 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2335 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2336 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2337 | continue; |
| 2338 | } |
| 2339 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2340 | if (auto *ID = dyn_cast<InclusionDirective>(*E)) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2341 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2342 | Record.push_back(ID->getFileName().size()); |
| 2343 | Record.push_back(ID->wasInQuotes()); |
| 2344 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2345 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2346 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2347 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2348 | // Check that the FileEntry is not null because it was not resolved and |
| 2349 | // we create a PCH even with compiler errors. |
| 2350 | if (ID->getFile()) |
| 2351 | Buffer += ID->getFile()->getName(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2352 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2353 | continue; |
| 2354 | } |
| 2355 | |
| 2356 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2357 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2358 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2359 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2360 | // Write the offsets table for the preprocessing record. |
| 2361 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2362 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2363 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2364 | // Write the offsets table for identifier IDs. |
| 2365 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2366 | |
| 2367 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2368 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2369 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2370 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2371 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2372 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2373 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, |
| 2374 | FirstPreprocessorEntityID - |
| 2375 | NUM_PREDEF_PP_ENTITY_IDS}; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2376 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2377 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2378 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2381 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2382 | if (!Mod) |
| 2383 | return 0; |
| 2384 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2385 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2386 | if (Known != SubmoduleIDs.end()) |
| 2387 | return Known->second; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2388 | |
| 2389 | if (Mod->getTopLevelModule() != WritingModule) |
| 2390 | return 0; |
| 2391 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2392 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2393 | } |
| 2394 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2395 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2396 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2397 | // did not result in us loading a module file for that submodule. For |
| 2398 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2399 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); |
| 2400 | assert((ID || !Mod) && |
| 2401 | "asked for module ID for non-local, non-imported module"); |
| 2402 | return ID; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2405 | /// \brief Compute the number of modules within the given tree (including the |
| 2406 | /// given module). |
| 2407 | static unsigned getNumberOfModules(Module *Mod) { |
| 2408 | unsigned ChildModules = 0; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2409 | for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2410 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2411 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2412 | |
| 2413 | return ChildModules + 1; |
| 2414 | } |
| 2415 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2416 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2417 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2418 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2419 | |
| 2420 | // Write the abbreviations needed for the submodules block. |
| 2421 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2422 | |
| 2423 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2424 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2425 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2426 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2427 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2428 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2429 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2430 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2431 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2432 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2433 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2434 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2435 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2436 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2437 | |
| 2438 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2439 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2440 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2441 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2442 | |
| 2443 | Abbrev = new BitCodeAbbrev(); |
| 2444 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2445 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2446 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2447 | |
| 2448 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2449 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2450 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2451 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2452 | |
| 2453 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2454 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2455 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2456 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2457 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2458 | Abbrev = new BitCodeAbbrev(); |
| 2459 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2460 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2461 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2462 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2463 | |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2464 | Abbrev = new BitCodeAbbrev(); |
| 2465 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2466 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2467 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2468 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2469 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2470 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2471 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2472 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2473 | |
| 2474 | Abbrev = new BitCodeAbbrev(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2475 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2476 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2477 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2478 | |
| 2479 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2480 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2481 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2482 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2483 | |
| 2484 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2485 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2486 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2487 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2488 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2489 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2490 | Abbrev = new BitCodeAbbrev(); |
| 2491 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2492 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
| 2493 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2494 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2495 | Abbrev = new BitCodeAbbrev(); |
| 2496 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2497 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2498 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
| 2499 | unsigned ConflictAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2500 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2501 | // Write the submodule metadata block. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2502 | RecordData::value_type Record[] = {getNumberOfModules(WritingModule), |
| 2503 | FirstSubmoduleID - |
| 2504 | NUM_PREDEF_SUBMODULE_IDS}; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2505 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2506 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2507 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2508 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2509 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2510 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2511 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2512 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2513 | unsigned ID = getSubmoduleID(Mod); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2514 | |
| 2515 | uint64_t ParentID = 0; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2516 | if (Mod->Parent) { |
| 2517 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2518 | ParentID = SubmoduleIDs[Mod->Parent]; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2519 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2520 | |
| 2521 | // Emit the definition of the block. |
| 2522 | { |
| 2523 | RecordData::value_type Record[] = { |
| 2524 | SUBMODULE_DEFINITION, ID, ParentID, Mod->IsFramework, Mod->IsExplicit, |
| 2525 | Mod->IsSystem, Mod->IsExternC, Mod->InferSubmodules, |
| 2526 | Mod->InferExplicitSubmodules, Mod->InferExportWildcard, |
| 2527 | Mod->ConfigMacrosExhaustive}; |
| 2528 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2529 | } |
| 2530 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2531 | // Emit the requirements. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2532 | for (const auto &R : Mod->Requirements) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2533 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2534 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2535 | } |
| 2536 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2537 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2538 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2539 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2540 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2541 | UmbrellaHeader.NameAsWritten); |
| 2542 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2543 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; |
| 2544 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2545 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2546 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2547 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2548 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2549 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2550 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2551 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2552 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2553 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2554 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 2555 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 2556 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2557 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2558 | Module::HK_PrivateTextual}, |
| 2559 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2560 | }; |
| 2561 | for (auto &HL : HeaderLists) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2562 | RecordData::value_type Record[] = {HL.RecordKind}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2563 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 2564 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 2565 | } |
| 2566 | |
| 2567 | // Emit the top headers. |
| 2568 | { |
| 2569 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2570 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2571 | for (auto *H : TopHeaders) |
| 2572 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2573 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2574 | |
| 2575 | // Emit the imports. |
| 2576 | if (!Mod->Imports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2577 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2578 | for (auto *I : Mod->Imports) |
| 2579 | Record.push_back(getSubmoduleID(I)); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2580 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2581 | } |
| 2582 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2583 | // Emit the exports. |
| 2584 | if (!Mod->Exports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2585 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2586 | for (const auto &E : Mod->Exports) { |
| 2587 | // FIXME: This may fail; we don't require that all exported modules |
| 2588 | // are local or imported. |
| 2589 | Record.push_back(getSubmoduleID(E.getPointer())); |
| 2590 | Record.push_back(E.getInt()); |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2591 | } |
| 2592 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2593 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2594 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2595 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 2596 | // Might be unnecessary as use declarations are only used to build the |
| 2597 | // module itself. |
| 2598 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2599 | // Emit the link libraries. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2600 | for (const auto &LL : Mod->LinkLibraries) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2601 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, |
| 2602 | LL.IsFramework}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2603 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2606 | // Emit the conflicts. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2607 | for (const auto &C : Mod->Conflicts) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2608 | // FIXME: This may fail; we don't require that all conflicting modules |
| 2609 | // are local or imported. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2610 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, |
| 2611 | getSubmoduleID(C.Other)}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2612 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2613 | } |
| 2614 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2615 | // Emit the configuration macros. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2616 | for (const auto &CM : Mod->ConfigMacros) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2617 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2618 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2621 | // Queue up the submodules of this module. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2622 | for (auto *M : Mod->submodules()) |
| 2623 | Q.push(M); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2627 | |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2628 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 2629 | getNumberOfModules(WritingModule)) && |
| 2630 | "Wrong # of submodules; found a reference to a non-local, " |
| 2631 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2632 | } |
| 2633 | |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2634 | serialization::SubmoduleID |
| 2635 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2636 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2637 | return 0; // No submodule |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2638 | |
| 2639 | // Find the module that owns this location. |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2640 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2641 | Module *OwningMod |
| 2642 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2643 | if (!OwningMod) |
| 2644 | return 0; |
| 2645 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2646 | // Check whether this submodule is part of our own module. |
| 2647 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2648 | return 0; |
| 2649 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2650 | return getSubmoduleID(OwningMod); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 2653 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 2654 | bool isModule) { |
| 2655 | // Make sure set diagnostic pragmas don't affect the translation unit that |
| 2656 | // imports the module. |
| 2657 | // FIXME: Make diagnostic pragma sections work properly with modules. |
| 2658 | if (isModule) |
| 2659 | return; |
| 2660 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2661 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2662 | DiagStateIDMap; |
| 2663 | unsigned CurrID = 0; |
| 2664 | DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2665 | RecordData Record; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2666 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2667 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2668 | I != E; ++I) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2669 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2670 | if (point.Loc.isInvalid()) |
| 2671 | continue; |
| 2672 | |
| 2673 | Record.push_back(point.Loc.getRawEncoding()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2674 | unsigned &DiagStateID = DiagStateIDMap[point.State]; |
| 2675 | Record.push_back(DiagStateID); |
| 2676 | |
| 2677 | if (DiagStateID == 0) { |
| 2678 | DiagStateID = ++CurrID; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2679 | for (const auto &I : *(point.State)) { |
| 2680 | if (I.second.isPragma()) { |
| 2681 | Record.push_back(I.first); |
| 2682 | Record.push_back((unsigned)I.second.getSeverity()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2683 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2684 | } |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2685 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2686 | // location. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2687 | } |
| 2688 | } |
| 2689 | |
Argyrios Kyrtzidis | b0ca9eb | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2690 | if (!Record.empty()) |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2691 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2692 | } |
| 2693 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2694 | void ASTWriter::WriteCXXCtorInitializersOffsets() { |
| 2695 | if (CXXCtorInitializersOffsets.empty()) |
| 2696 | return; |
| 2697 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2698 | // Create a blob abbreviation for the C++ ctor initializer offsets. |
| 2699 | using namespace llvm; |
| 2700 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2701 | auto *Abbrev = new BitCodeAbbrev(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2702 | Abbrev->Add(BitCodeAbbrevOp(CXX_CTOR_INITIALIZERS_OFFSETS)); |
| 2703 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2704 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2705 | unsigned CtorInitializersOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2706 | |
| 2707 | // Write the base specifier offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2708 | RecordData::value_type Record[] = {CXX_CTOR_INITIALIZERS_OFFSETS, |
| 2709 | CXXCtorInitializersOffsets.size()}; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2710 | Stream.EmitRecordWithBlob(CtorInitializersOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2711 | bytes(CXXCtorInitializersOffsets)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2712 | } |
| 2713 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2714 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 2715 | if (CXXBaseSpecifiersOffsets.empty()) |
| 2716 | return; |
| 2717 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2718 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 2719 | using namespace llvm; |
| 2720 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2721 | auto *Abbrev = new BitCodeAbbrev(); |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2722 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 2723 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2724 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2725 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2726 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2727 | // Write the base specifier offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2728 | RecordData::value_type Record[] = {CXX_BASE_SPECIFIER_OFFSETS, |
| 2729 | CXXBaseSpecifiersOffsets.size()}; |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2730 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2731 | bytes(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2734 | //===----------------------------------------------------------------------===// |
| 2735 | // Type Serialization |
| 2736 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2737 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2738 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2739 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | a7fbbb0 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 2740 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2741 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 2742 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2743 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2744 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2745 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2746 | // Record the offset for this type. |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2747 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2748 | if (TypeOffsets.size() == Index) |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2749 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2750 | else if (TypeOffsets.size() < Index) { |
| 2751 | TypeOffsets.resize(Index + 1); |
| 2752 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2756 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2757 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2758 | ASTTypeWriter W(*this, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 2759 | W.AbbrevToUse = 0; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2760 | |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2761 | if (T.hasLocalNonFastQualifiers()) { |
| 2762 | Qualifiers Qs = T.getLocalQualifiers(); |
| 2763 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2764 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2765 | W.Code = TYPE_EXT_QUAL; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 2766 | W.AbbrevToUse = TypeExtQualAbbrev; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2767 | } else { |
| 2768 | switch (T->getTypeClass()) { |
| 2769 | // For all of the concrete, non-dependent types, call the |
| 2770 | // appropriate visitor function. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2771 | #define TYPE(Class, Base) \ |
Mike Stump | 281d6d7 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 2772 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2773 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2774 | #include "clang/AST/TypeNodes.def" |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2775 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | // Emit the serialized record. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 2779 | Stream.EmitRecord(W.Code, Record, W.AbbrevToUse); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2780 | |
| 2781 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2782 | FlushStmts(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2785 | //===----------------------------------------------------------------------===// |
| 2786 | // Declaration Serialization |
| 2787 | //===----------------------------------------------------------------------===// |
| 2788 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2789 | /// \brief Write the block containing all of the declaration IDs |
| 2790 | /// lexically declared within the given DeclContext. |
| 2791 | /// |
| 2792 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2793 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2794 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2795 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2796 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2797 | return 0; |
| 2798 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2799 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2800 | SmallVector<uint32_t, 128> KindDeclPairs; |
| 2801 | for (const auto *D : DC->decls()) { |
| 2802 | KindDeclPairs.push_back(D->getKind()); |
| 2803 | KindDeclPairs.push_back(GetDeclRef(D)); |
| 2804 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2805 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2806 | ++NumLexicalDeclContexts; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2807 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2808 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, |
| 2809 | bytes(KindDeclPairs)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2810 | return Offset; |
| 2811 | } |
| 2812 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2813 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2814 | using namespace llvm; |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2815 | |
| 2816 | // Write the type offsets array |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2817 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2818 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2819 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2820 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2821 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2822 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2823 | { |
| 2824 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), |
| 2825 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; |
| 2826 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
| 2827 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2828 | |
| 2829 | // Write the declaration offsets array |
| 2830 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2831 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2832 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2833 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2834 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2835 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2836 | { |
| 2837 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), |
| 2838 | FirstDeclID - NUM_PREDEF_DECL_IDS}; |
| 2839 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
| 2840 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2843 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2844 | using namespace llvm; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2845 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2846 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 2847 | FileDeclIDs.begin(), FileDeclIDs.end()); |
| 2848 | std::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), |
| 2849 | llvm::less_first()); |
| 2850 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2851 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2852 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 2853 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 2854 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 2855 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 2856 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 2857 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2860 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2861 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2862 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2863 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2864 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2865 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, |
| 2866 | FileGroupedDeclIDs.size()}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2867 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2870 | void ASTWriter::WriteComments() { |
| 2871 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2872 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2873 | RecordData Record; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2874 | for (const auto *I : RawComments) { |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2875 | Record.clear(); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2876 | AddSourceRange(I->getSourceRange(), Record); |
| 2877 | Record.push_back(I->getKind()); |
| 2878 | Record.push_back(I->isTrailingComment()); |
| 2879 | Record.push_back(I->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2880 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2881 | } |
| 2882 | Stream.ExitBlock(); |
| 2883 | } |
| 2884 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2885 | //===----------------------------------------------------------------------===// |
| 2886 | // Global Method Pool and Selector Serialization |
| 2887 | //===----------------------------------------------------------------------===// |
| 2888 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2889 | namespace { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2890 | // 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] | 2891 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2892 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2893 | |
| 2894 | public: |
| 2895 | typedef Selector key_type; |
| 2896 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2897 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2898 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2899 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2900 | ObjCMethodList Instance, Factory; |
| 2901 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2902 | typedef const data_type& data_type_ref; |
| 2903 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2904 | typedef unsigned hash_value_type; |
| 2905 | typedef unsigned offset_type; |
| 2906 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2907 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2908 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2909 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2910 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2911 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2912 | |
| 2913 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2914 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2915 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2916 | using namespace llvm::support; |
| 2917 | endian::Writer<little> LE(Out); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2918 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2919 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2920 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2921 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2922 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2923 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2924 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2925 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2926 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2927 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2928 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2929 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2930 | return std::make_pair(KeyLen, DataLen); |
| 2931 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2932 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2933 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2934 | using namespace llvm::support; |
| 2935 | endian::Writer<little> LE(Out); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2936 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2937 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2938 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2939 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2940 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2941 | if (N == 0) |
| 2942 | N = 1; |
| 2943 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2944 | LE.write<uint32_t>( |
| 2945 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2946 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2947 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2948 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2949 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2950 | using namespace llvm::support; |
| 2951 | endian::Writer<little> LE(Out); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2952 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2953 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2954 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2955 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2956 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2957 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2958 | ++NumInstanceMethods; |
| 2959 | |
| 2960 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2961 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2962 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2963 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2964 | ++NumFactoryMethods; |
| 2965 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2966 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 2967 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2968 | unsigned InstanceHasMoreThanOneDeclBit = |
| 2969 | Methods.Instance.hasMoreThanOneDecl(); |
| 2970 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 2971 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 2972 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2973 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 2974 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2975 | unsigned FactoryHasMoreThanOneDeclBit = |
| 2976 | Methods.Factory.hasMoreThanOneDecl(); |
| 2977 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 2978 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 2979 | FactoryBits; |
| 2980 | LE.write<uint16_t>(FullInstanceBits); |
| 2981 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2982 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2983 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2984 | if (Method->getMethod()) |
| 2985 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2986 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2987 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2988 | if (Method->getMethod()) |
| 2989 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2990 | |
| 2991 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2992 | } |
| 2993 | }; |
| 2994 | } // end anonymous namespace |
| 2995 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2996 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2997 | /// |
| 2998 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2999 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 3000 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3001 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3002 | using namespace llvm; |
| 3003 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3004 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3005 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3006 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3007 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3008 | // 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] | 3009 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3010 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3011 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3012 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3013 | // Create the on-disk hash table representation. We walk through every |
| 3014 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3015 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3016 | for (auto &SelectorAndID : SelectorIDs) { |
| 3017 | Selector S = SelectorAndID.first; |
| 3018 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3019 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3020 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3021 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3022 | ObjCMethodList(), |
| 3023 | ObjCMethodList() |
| 3024 | }; |
| 3025 | if (F != SemaRef.MethodPool.end()) { |
| 3026 | Data.Instance = F->second.first; |
| 3027 | Data.Factory = F->second.second; |
| 3028 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3029 | // 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] | 3030 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3031 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3032 | // Selector already exists. Did it change? |
| 3033 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3034 | for (ObjCMethodList *M = &Data.Instance; |
| 3035 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 3036 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3037 | changed = true; |
| 3038 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3039 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3040 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3041 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3042 | changed = true; |
| 3043 | } |
| 3044 | if (!changed) |
| 3045 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3046 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3047 | // A new method pool entry. |
| 3048 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3049 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3050 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3051 | } |
| 3052 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3053 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3054 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3055 | uint32_t BucketOffset; |
| 3056 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3057 | using namespace llvm::support; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3058 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3059 | llvm::raw_svector_ostream Out(MethodPool); |
| 3060 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3061 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3062 | BucketOffset = Generator.Emit(Out, Trait); |
| 3063 | } |
| 3064 | |
| 3065 | // Create a blob abbreviation |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3066 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3067 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3068 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3069 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3070 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3071 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3072 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3073 | // Write the method pool |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3074 | { |
| 3075 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, |
| 3076 | NumTableEntries}; |
| 3077 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
| 3078 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3079 | |
| 3080 | // Create a blob abbreviation for the selector table offsets. |
| 3081 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3082 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3083 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3084 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3085 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3086 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3087 | |
| 3088 | // Write the selector offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3089 | { |
| 3090 | RecordData::value_type Record[] = { |
| 3091 | SELECTOR_OFFSETS, SelectorOffsets.size(), |
| 3092 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; |
| 3093 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 3094 | bytes(SelectorOffsets)); |
| 3095 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3096 | } |
| 3097 | } |
| 3098 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3099 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3100 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3101 | using namespace llvm; |
| 3102 | if (SemaRef.ReferencedSelectors.empty()) |
| 3103 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3104 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3105 | RecordData Record; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3106 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3107 | // 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] | 3108 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3109 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3110 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3111 | Selector Sel = SelectorAndLocation.first; |
| 3112 | SourceLocation Loc = SelectorAndLocation.second; |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3113 | AddSelectorRef(Sel, Record); |
| 3114 | AddSourceLocation(Loc, Record); |
| 3115 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3116 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3117 | } |
| 3118 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3119 | //===----------------------------------------------------------------------===// |
| 3120 | // Identifier Table Serialization |
| 3121 | //===----------------------------------------------------------------------===// |
| 3122 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3123 | /// Determine the declaration that should be put into the name lookup table to |
| 3124 | /// represent the given declaration in this module. This is usually D itself, |
| 3125 | /// but if D was imported and merged into a local declaration, we want the most |
| 3126 | /// recent local declaration instead. The chosen declaration will be the most |
| 3127 | /// recent declaration in any module that imports this one. |
| 3128 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3129 | NamedDecl *D) { |
| 3130 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3131 | return D; |
| 3132 | |
| 3133 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3134 | // For Redeclarable decls, a prior declaration might be local. |
| 3135 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
| 3136 | if (!Redecl->isFromASTFile()) |
| 3137 | return cast<NamedDecl>(Redecl); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3138 | // 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] | 3139 | // local one. |
| 3140 | if (D->getOwningModuleID() == 0) |
| 3141 | break; |
| 3142 | } |
| 3143 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3144 | // For Mergeable decls, the first decl might be local. |
| 3145 | if (!First->isFromASTFile()) |
| 3146 | return cast<NamedDecl>(First); |
| 3147 | } |
| 3148 | |
| 3149 | // All declarations are imported. Our most recent declaration will also be |
| 3150 | // the most recent one in anyone who imports us. |
| 3151 | return D; |
| 3152 | } |
| 3153 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3154 | namespace { |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3155 | class ASTIdentifierTableTrait { |
| 3156 | ASTWriter &Writer; |
| 3157 | Preprocessor &PP; |
| 3158 | IdentifierResolver &IdResolver; |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3159 | bool IsModule; |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3160 | bool NeedDecls; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3161 | ASTWriter::RecordData *InterestingIdentifierOffsets; |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3162 | |
| 3163 | /// \brief Determines whether this is an "interesting" identifier that needs a |
| 3164 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3165 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3166 | /// to check that. |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3167 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3168 | if (MacroOffset || |
| 3169 | II->isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3170 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3171 | II->hasRevertedTokenIDToIdentifier() || |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3172 | (NeedDecls && II->getFETokenInfo<void>())) |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3173 | return true; |
| 3174 | |
| 3175 | return false; |
| 3176 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3177 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3178 | public: |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3179 | typedef IdentifierInfo* key_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3180 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3181 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3182 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3183 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3184 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3185 | typedef unsigned hash_value_type; |
| 3186 | typedef unsigned offset_type; |
| 3187 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3188 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3189 | IdentifierResolver &IdResolver, bool IsModule, |
| 3190 | ASTWriter::RecordData *InterestingIdentifierOffsets) |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3191 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3192 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), |
| 3193 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3194 | |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3195 | bool needDecls() const { return NeedDecls; } |
| 3196 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3197 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 3198 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3199 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3200 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3201 | bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 3202 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3203 | return isInterestingIdentifier(II, MacroOffset); |
| 3204 | } |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3205 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { |
| 3206 | return isInterestingIdentifier(II, 0); |
| 3207 | } |
| 3208 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3209 | std::pair<unsigned,unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3210 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3211 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3212 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3213 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3214 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3215 | DataLen += 2; // 2 bytes for builtin ID |
| 3216 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3217 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3218 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3219 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3220 | if (NeedDecls) { |
| 3221 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3222 | DEnd = IdResolver.end(); |
| 3223 | D != DEnd; ++D) |
| 3224 | DataLen += 4; |
| 3225 | } |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3226 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3227 | using namespace llvm::support; |
| 3228 | endian::Writer<little> LE(Out); |
| 3229 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3230 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3231 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3232 | // We emit the key length after the data length so that every |
| 3233 | // string is preceded by a 16-bit length. This matches the PTH |
| 3234 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3235 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3236 | return std::make_pair(KeyLen, DataLen); |
| 3237 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3238 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3239 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3240 | unsigned KeyLen) { |
| 3241 | // Record the location of the key data. This is used when generating |
| 3242 | // the mapping from persistent IDs to strings. |
| 3243 | Writer.SetIdentifierOffset(II, Out.tell()); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3244 | |
| 3245 | // Emit the offset of the key/data length information to the interesting |
| 3246 | // identifiers table if necessary. |
| 3247 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) |
| 3248 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); |
| 3249 | |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3250 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3251 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3252 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3253 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3254 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3255 | using namespace llvm::support; |
| 3256 | endian::Writer<little> LE(Out); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3257 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3258 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3259 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3260 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3261 | return; |
| 3262 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3263 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3264 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3265 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3266 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3267 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3268 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3269 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3270 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3271 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3272 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3273 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3274 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3275 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3276 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3277 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3278 | if (HadMacroDefinition) |
| 3279 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3280 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3281 | if (NeedDecls) { |
| 3282 | // Emit the declaration IDs in reverse order, because the |
| 3283 | // IdentifierResolver provides the declarations as they would be |
| 3284 | // visible (e.g., the function "stat" would come before the struct |
| 3285 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3286 | // (so we need to see the struct "stat" before the function "stat"). |
| 3287 | // Only emit declarations that aren't from a chained PCH, though. |
| 3288 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), |
| 3289 | IdResolver.end()); |
| 3290 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3291 | DEnd = Decls.rend(); |
| 3292 | D != DEnd; ++D) |
| 3293 | LE.write<uint32_t>( |
| 3294 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
| 3295 | } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3296 | } |
| 3297 | }; |
| 3298 | } // end anonymous namespace |
| 3299 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3300 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3301 | /// |
| 3302 | /// The identifier table consists of a blob containing string data |
| 3303 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3304 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3305 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 3306 | IdentifierResolver &IdResolver, |
| 3307 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3308 | using namespace llvm; |
| 3309 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3310 | RecordData InterestingIdents; |
| 3311 | |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3312 | // Create and write out the blob that contains the identifier |
| 3313 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3314 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3315 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3316 | ASTIdentifierTableTrait Trait( |
| 3317 | *this, PP, IdResolver, IsModule, |
| 3318 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3319 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3320 | // Look for any identifiers that were named while processing the |
| 3321 | // headers, but are otherwise not needed. We add these to the hash |
| 3322 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3323 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3324 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3325 | SmallVector<const IdentifierInfo *, 128> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3326 | for (const auto &ID : PP.getIdentifierTable()) |
| 3327 | IIs.push_back(ID.second); |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3328 | // Sort the identifiers lexicographically before getting them references so |
| 3329 | // that their order is stable. |
| 3330 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 3331 | for (const IdentifierInfo *II : IIs) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3332 | if (Trait.isInterestingNonMacroIdentifier(II)) |
| 3333 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3334 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3335 | // Create the on-disk hash table representation. We only store offsets |
| 3336 | // for identifiers that appear here for the first time. |
| 3337 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3338 | for (auto IdentIDPair : IdentifierIDs) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3339 | auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3340 | IdentID ID = IdentIDPair.second; |
| 3341 | assert(II && "NULL identifier in identifier table"); |
Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3342 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization() || |
| 3343 | (Trait.needDecls() && |
| 3344 | II->hasFETokenInfoChangedSinceDeserialization())) |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3345 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3346 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3347 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3348 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3349 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3350 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3351 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3352 | using namespace llvm::support; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3353 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3354 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3355 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3356 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | // Create a blob abbreviation |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3360 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3361 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3362 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3363 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3364 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3365 | |
| 3366 | // Write the identifier table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3367 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3368 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | // Write the offsets table for identifier IDs. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3372 | auto *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3373 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3374 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3375 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3376 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3377 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3378 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3379 | #ifndef NDEBUG |
| 3380 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3381 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3382 | #endif |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3383 | |
| 3384 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, |
| 3385 | IdentifierOffsets.size(), |
| 3386 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3387 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3388 | bytes(IdentifierOffsets)); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3389 | |
| 3390 | // In C++, write the list of interesting identifiers (those that are |
| 3391 | // defined as macros, poisoned, or similar unusual things). |
| 3392 | if (!InterestingIdents.empty()) |
| 3393 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3394 | } |
| 3395 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3396 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3397 | // DeclContext's Name Lookup Table Serialization |
| 3398 | //===----------------------------------------------------------------------===// |
| 3399 | |
| 3400 | namespace { |
| 3401 | // Trait used for the on-disk hash table used in the method pool. |
| 3402 | class ASTDeclContextNameLookupTrait { |
| 3403 | ASTWriter &Writer; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3404 | llvm::SmallVector<DeclID, 64> DeclIDs; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3405 | |
| 3406 | public: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3407 | typedef DeclarationNameKey key_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3408 | typedef key_type key_type_ref; |
| 3409 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3410 | /// A start and end index into DeclIDs, representing a sequence of decls. |
| 3411 | typedef std::pair<unsigned, unsigned> data_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3412 | typedef const data_type& data_type_ref; |
| 3413 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3414 | typedef unsigned hash_value_type; |
| 3415 | typedef unsigned offset_type; |
| 3416 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3417 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 3418 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3419 | template<typename Coll> |
| 3420 | data_type getData(const Coll &Decls) { |
| 3421 | unsigned Start = DeclIDs.size(); |
| 3422 | for (NamedDecl *D : Decls) { |
| 3423 | DeclIDs.push_back( |
| 3424 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); |
| 3425 | } |
| 3426 | return std::make_pair(Start, DeclIDs.size()); |
| 3427 | } |
| 3428 | |
| 3429 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { |
| 3430 | unsigned Start = DeclIDs.size(); |
| 3431 | for (auto ID : FromReader) |
| 3432 | DeclIDs.push_back(ID); |
| 3433 | return std::make_pair(Start, DeclIDs.size()); |
| 3434 | } |
| 3435 | |
| 3436 | static bool EqualKey(key_type_ref a, key_type_ref b) { |
| 3437 | return a == b; |
| 3438 | } |
| 3439 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3440 | hash_value_type ComputeHash(DeclarationNameKey Name) { |
| 3441 | return Name.getHash(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3442 | } |
| 3443 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3444 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { |
| 3445 | assert(Writer.hasChain() && |
| 3446 | "have reference to loaded module file but no chain?"); |
| 3447 | |
| 3448 | using namespace llvm::support; |
| 3449 | endian::Writer<little>(Out) |
| 3450 | .write<uint32_t>(Writer.getChain()->getModuleFileID(F)); |
| 3451 | } |
| 3452 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3453 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, |
| 3454 | DeclarationNameKey Name, |
| 3455 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3456 | using namespace llvm::support; |
| 3457 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3458 | unsigned KeyLen = 1; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3459 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3460 | case DeclarationName::Identifier: |
| 3461 | case DeclarationName::ObjCZeroArgSelector: |
| 3462 | case DeclarationName::ObjCOneArgSelector: |
| 3463 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3464 | case DeclarationName::CXXLiteralOperatorName: |
| 3465 | KeyLen += 4; |
| 3466 | break; |
| 3467 | case DeclarationName::CXXOperatorName: |
| 3468 | KeyLen += 1; |
| 3469 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3470 | case DeclarationName::CXXConstructorName: |
| 3471 | case DeclarationName::CXXDestructorName: |
| 3472 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3473 | case DeclarationName::CXXUsingDirective: |
| 3474 | break; |
| 3475 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3476 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3477 | |
Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3478 | // 4 bytes for each DeclID. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3479 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); |
| 3480 | assert(uint16_t(DataLen) == DataLen && |
| 3481 | "too many decls for serialized lookup result"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3482 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3483 | |
| 3484 | return std::make_pair(KeyLen, DataLen); |
| 3485 | } |
| 3486 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3487 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3488 | using namespace llvm::support; |
| 3489 | endian::Writer<little> LE(Out); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3490 | LE.write<uint8_t>(Name.getKind()); |
| 3491 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3492 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3493 | case DeclarationName::CXXLiteralOperatorName: |
| 3494 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3495 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3496 | case DeclarationName::ObjCZeroArgSelector: |
| 3497 | case DeclarationName::ObjCOneArgSelector: |
| 3498 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3499 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); |
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::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3502 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3503 | "Invalid operator?"); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3504 | LE.write<uint8_t>(Name.getOperatorKind()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3505 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3506 | case DeclarationName::CXXConstructorName: |
| 3507 | case DeclarationName::CXXDestructorName: |
| 3508 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3509 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3510 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3511 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3512 | |
| 3513 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3514 | } |
| 3515 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3516 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, |
| 3517 | unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3518 | using namespace llvm::support; |
| 3519 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3520 | uint64_t Start = Out.tell(); (void)Start; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3521 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) |
| 3522 | LE.write<uint32_t>(DeclIDs[I]); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3523 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3524 | } |
| 3525 | }; |
| 3526 | } // end anonymous namespace |
| 3527 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3528 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 3529 | DeclContext *DC) { |
| 3530 | return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage; |
| 3531 | } |
| 3532 | |
| 3533 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 3534 | DeclContext *DC) { |
| 3535 | for (auto *D : Result.getLookupResult()) |
| 3536 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 3537 | return false; |
| 3538 | |
| 3539 | return true; |
| 3540 | } |
| 3541 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3542 | void |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3543 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3544 | llvm::SmallVectorImpl<char> &LookupTable) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3545 | assert(!ConstDC->HasLazyLocalLexicalLookups && |
| 3546 | !ConstDC->HasLazyExternalLexicalLookups && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3547 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3548 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3549 | // FIXME: We need to build the lookups table, which is logically const. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3550 | auto *DC = const_cast<DeclContext*>(ConstDC); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3551 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 3552 | |
| 3553 | // Create the on-disk hash table representation. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3554 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, |
| 3555 | ASTDeclContextNameLookupTrait> Generator; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3556 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3557 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3558 | // The first step is to collect the declaration names which we need to |
| 3559 | // serialize into the name lookup table, and to collect them in a stable |
| 3560 | // order. |
| 3561 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3562 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3563 | // We also build up small sets of the constructor and conversion function |
| 3564 | // names which are visible. |
| 3565 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3566 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3567 | for (auto &Lookup : *DC->buildLookup()) { |
| 3568 | auto &Name = Lookup.first; |
| 3569 | auto &Result = Lookup.second; |
| 3570 | |
Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 3571 | // If there are no local declarations in our lookup result, we |
| 3572 | // don't need to write an entry for the name at all. If we can't |
| 3573 | // write out a lookup set without performing more deserialization, |
| 3574 | // just skip this entry. |
| 3575 | if (isLookupResultExternal(Result, DC) && |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3576 | isLookupResultEntirelyExternal(Result, DC)) |
| 3577 | continue; |
| 3578 | |
| 3579 | // We also skip empty results. If any of the results could be external and |
| 3580 | // the currently available results are empty, then all of the results are |
| 3581 | // external and we skip it above. So the only way we get here with an empty |
| 3582 | // results is when no results could have been external *and* we have |
| 3583 | // external results. |
| 3584 | // |
| 3585 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 3586 | // lookups into a decl context as an optimization, today we *have* to skip |
| 3587 | // them because there are names with empty lookup results in decl contexts |
| 3588 | // which we can't emit in any stable ordering: we lookup constructors and |
| 3589 | // conversion functions in the enclosing namespace scope creating empty |
| 3590 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 3591 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 3592 | // here by omitting lookups with empty results. |
| 3593 | if (Lookup.second.getLookupResult().empty()) |
| 3594 | continue; |
| 3595 | |
| 3596 | switch (Lookup.first.getNameKind()) { |
| 3597 | default: |
| 3598 | Names.push_back(Lookup.first); |
| 3599 | break; |
| 3600 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3601 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3602 | assert(isa<CXXRecordDecl>(DC) && |
| 3603 | "Cannot have a constructor name outside of a class!"); |
| 3604 | ConstructorNameSet.insert(Name); |
| 3605 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3606 | |
| 3607 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3608 | assert(isa<CXXRecordDecl>(DC) && |
| 3609 | "Cannot have a conversion function name outside of a class!"); |
| 3610 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 3611 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3612 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3613 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3614 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3615 | // Sort the names into a stable order. |
| 3616 | std::sort(Names.begin(), Names.end()); |
| 3617 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3618 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3619 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3620 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3621 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3622 | // First we try the easy case by forming the current context's constructor |
| 3623 | // name and adding that name first. This is a very useful optimization to |
| 3624 | // avoid walking the lexical declarations in many cases, and it also |
| 3625 | // handles the only case where a constructor name can come from some other |
| 3626 | // lexical context -- when that name is an implicit constructor merged from |
| 3627 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 3628 | // conversion function which doesn't occur in all the lexical contexts |
| 3629 | // would be an ODR violation. |
| 3630 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 3631 | Context->getCanonicalType(Context->getRecordType(D))); |
| 3632 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 3633 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3634 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3635 | // If we still have constructors or conversion functions, we walk all the |
| 3636 | // names in the decl and add the constructors and conversion functions |
| 3637 | // which are visible in the order they lexically occur within the context. |
| 3638 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 3639 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 3640 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 3641 | auto Name = ChildND->getDeclName(); |
| 3642 | switch (Name.getNameKind()) { |
| 3643 | default: |
| 3644 | continue; |
| 3645 | |
| 3646 | case DeclarationName::CXXConstructorName: |
| 3647 | if (ConstructorNameSet.erase(Name)) |
| 3648 | Names.push_back(Name); |
| 3649 | break; |
| 3650 | |
| 3651 | case DeclarationName::CXXConversionFunctionName: |
| 3652 | if (ConversionNameSet.erase(Name)) |
| 3653 | Names.push_back(Name); |
| 3654 | break; |
| 3655 | } |
| 3656 | |
| 3657 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 3658 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3659 | } |
| 3660 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3661 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 3662 | "constructors by walking all the " |
| 3663 | "lexical members of the context."); |
| 3664 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 3665 | "conversion functions by walking all " |
| 3666 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3669 | // Next we need to do a lookup with each name into this decl context to fully |
| 3670 | // populate any results from external sources. We don't actually use the |
| 3671 | // results of these lookups because we only want to use the results after all |
| 3672 | // results have been loaded and the pointers into them will be stable. |
| 3673 | for (auto &Name : Names) |
| 3674 | DC->lookup(Name); |
| 3675 | |
| 3676 | // Now we need to insert the results for each name into the hash table. For |
| 3677 | // constructor names and conversion function names, we actually need to merge |
| 3678 | // all of the results for them into one list of results each and insert |
| 3679 | // those. |
| 3680 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 3681 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 3682 | |
| 3683 | // Now loop over the names, either inserting them or appending for the two |
| 3684 | // special cases. |
| 3685 | for (auto &Name : Names) { |
| 3686 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 3687 | |
| 3688 | switch (Name.getNameKind()) { |
| 3689 | default: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3690 | Generator.insert(Name, Trait.getData(Result), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3691 | break; |
| 3692 | |
| 3693 | case DeclarationName::CXXConstructorName: |
| 3694 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 3695 | break; |
| 3696 | |
| 3697 | case DeclarationName::CXXConversionFunctionName: |
| 3698 | ConversionDecls.append(Result.begin(), Result.end()); |
| 3699 | break; |
| 3700 | } |
| 3701 | } |
| 3702 | |
| 3703 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 3704 | // the first declaration's name here because the name itself isn't part of |
| 3705 | // the key, only the kind of name is used. |
| 3706 | if (!ConstructorDecls.empty()) |
| 3707 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3708 | Trait.getData(ConstructorDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3709 | if (!ConversionDecls.empty()) |
| 3710 | Generator.insert(ConversionDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3711 | Trait.getData(ConversionDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3712 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3713 | // Create the on-disk hash table. Also emit the existing imported and |
| 3714 | // merged table if there is one. |
| 3715 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; |
| 3716 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3717 | } |
| 3718 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3719 | /// \brief Write the block containing all of the declaration IDs |
| 3720 | /// visible from the given DeclContext. |
| 3721 | /// |
| 3722 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3723 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3724 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 3725 | DeclContext *DC) { |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3726 | // If we imported a key declaration of this namespace, write the visible |
| 3727 | // lookup results as an update record for it rather than including them |
| 3728 | // on this declaration. We will only look at key declarations on reload. |
| 3729 | if (isa<NamespaceDecl>(DC) && Chain && |
| 3730 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { |
| 3731 | // Only do this once, for the first local declaration of the namespace. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3732 | for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3733 | Prev = Prev->getPreviousDecl()) |
| 3734 | if (!Prev->isFromASTFile()) |
| 3735 | return 0; |
| 3736 | |
| 3737 | // Note that we need to emit an update record for the primary context. |
| 3738 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); |
| 3739 | |
| 3740 | // Make sure all visible decls are written. They will be recorded later. We |
| 3741 | // do this using a side data structure so we can sort the names into |
| 3742 | // a deterministic order. |
| 3743 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); |
| 3744 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> |
| 3745 | LookupResults; |
| 3746 | if (Map) { |
| 3747 | LookupResults.reserve(Map->size()); |
| 3748 | for (auto &Entry : *Map) |
| 3749 | LookupResults.push_back( |
| 3750 | std::make_pair(Entry.first, Entry.second.getLookupResult())); |
| 3751 | } |
| 3752 | |
| 3753 | std::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); |
| 3754 | for (auto &NameAndResult : LookupResults) { |
| 3755 | DeclarationName Name = NameAndResult.first; |
| 3756 | DeclContext::lookup_result Result = NameAndResult.second; |
| 3757 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || |
| 3758 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 3759 | // We have to work around a name lookup bug here where negative lookup |
| 3760 | // results for these names get cached in namespace lookup tables (these |
| 3761 | // names should never be looked up in a namespace). |
| 3762 | assert(Result.empty() && "Cannot have a constructor or conversion " |
| 3763 | "function name in a namespace!"); |
| 3764 | continue; |
| 3765 | } |
| 3766 | |
| 3767 | for (NamedDecl *ND : Result) |
| 3768 | if (!ND->isFromASTFile()) |
| 3769 | GetDeclRef(ND); |
| 3770 | } |
| 3771 | |
| 3772 | return 0; |
| 3773 | } |
| 3774 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3775 | if (DC->getPrimaryContext() != DC) |
| 3776 | return 0; |
| 3777 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3778 | // Skip contexts which don't support name lookup. |
| 3779 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3780 | return 0; |
| 3781 | |
| 3782 | // If not in C++, we perform name lookup for the translation unit via the |
| 3783 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3784 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3785 | return 0; |
| 3786 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3787 | // Serialize the contents of the mapping used for lookup. Note that, |
| 3788 | // although we have two very different code paths, the serialized |
| 3789 | // representation is the same for both cases: a declaration name, |
| 3790 | // followed by a size, followed by references to the visible |
| 3791 | // declarations that have that name. |
| 3792 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3793 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3794 | if (!Map || Map->empty()) |
| 3795 | return 0; |
| 3796 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3797 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3798 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3799 | GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3800 | |
| 3801 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3802 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3803 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3804 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3805 | ++NumVisibleDeclContexts; |
| 3806 | return Offset; |
| 3807 | } |
| 3808 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3809 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3810 | /// |
| 3811 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3812 | /// 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] | 3813 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3814 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3815 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3816 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3817 | if (!Map || Map->empty()) |
| 3818 | return; |
| 3819 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3820 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3821 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3822 | GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3823 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3824 | // If we're updating a namespace, select a key declaration as the key for the |
| 3825 | // update record; those are the only ones that will be checked on reload. |
| 3826 | if (isa<NamespaceDecl>(DC)) |
| 3827 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); |
| 3828 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3829 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3830 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3831 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3834 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3835 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3836 | RecordData::value_type Record[] = {Opts.fp_contract}; |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3837 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3838 | } |
| 3839 | |
| 3840 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3841 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3842 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3843 | return; |
| 3844 | |
| 3845 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3846 | RecordData Record; |
| 3847 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3848 | #include "clang/Basic/OpenCLExtensions.def" |
| 3849 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3850 | } |
| 3851 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3852 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3853 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3854 | RecordData Categories; |
| 3855 | |
| 3856 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3857 | unsigned Size = 0; |
| 3858 | unsigned StartIndex = Categories.size(); |
| 3859 | |
| 3860 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3861 | |
| 3862 | // Allocate space for the size. |
| 3863 | Categories.push_back(0); |
| 3864 | |
| 3865 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3866 | for (ObjCInterfaceDecl::known_categories_iterator |
| 3867 | Cat = Class->known_categories_begin(), |
| 3868 | CatEnd = Class->known_categories_end(); |
| 3869 | Cat != CatEnd; ++Cat, ++Size) { |
| 3870 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 3871 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | // Update the size. |
| 3875 | Categories[StartIndex] = Size; |
| 3876 | |
| 3877 | // Record this interface -> category map. |
| 3878 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3879 | CategoriesMap.push_back(CatInfo); |
| 3880 | } |
| 3881 | |
| 3882 | // Sort the categories map by the definition ID, since the reader will be |
| 3883 | // performing binary searches on this information. |
| 3884 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3885 | |
| 3886 | // Emit the categories map. |
| 3887 | using namespace llvm; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3888 | |
| 3889 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3890 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3891 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3892 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3893 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3894 | |
| 3895 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; |
| 3896 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3897 | reinterpret_cast<char *>(CategoriesMap.data()), |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3898 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3899 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3900 | // Emit the category lists. |
| 3901 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3902 | } |
| 3903 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3904 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 3905 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 3906 | |
| 3907 | if (LPTMap.empty()) |
| 3908 | return; |
| 3909 | |
| 3910 | RecordData Record; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 3911 | for (auto LPTMapEntry : LPTMap) { |
| 3912 | const FunctionDecl *FD = LPTMapEntry.first; |
| 3913 | LateParsedTemplate *LPT = LPTMapEntry.second; |
| 3914 | AddDeclRef(FD, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3915 | AddDeclRef(LPT->D, Record); |
| 3916 | Record.push_back(LPT->Toks.size()); |
| 3917 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3918 | for (const auto &Tok : LPT->Toks) { |
| 3919 | AddToken(Tok, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3920 | } |
| 3921 | } |
| 3922 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 3923 | } |
| 3924 | |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3925 | /// \brief Write the state of 'pragma clang optimize' at the end of the module. |
| 3926 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 3927 | RecordData Record; |
| 3928 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 3929 | AddSourceLocation(PragmaLoc, Record); |
| 3930 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 3931 | } |
| 3932 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 3933 | /// \brief Write the state of 'pragma ms_struct' at the end of the module. |
| 3934 | void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) { |
| 3935 | RecordData Record; |
| 3936 | Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF); |
| 3937 | Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record); |
| 3938 | } |
| 3939 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 3940 | /// \brief Write the state of 'pragma pointers_to_members' at the end of the |
| 3941 | //module. |
| 3942 | void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) { |
| 3943 | RecordData Record; |
| 3944 | Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod); |
| 3945 | AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record); |
| 3946 | Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record); |
| 3947 | } |
| 3948 | |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 3949 | void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, |
| 3950 | ModuleFileExtensionWriter &Writer) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3951 | // Enter the extension block. |
| 3952 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); |
| 3953 | |
| 3954 | // Emit the metadata record abbreviation. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3955 | auto *Abv = new llvm::BitCodeAbbrev(); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3956 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); |
| 3957 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3958 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3959 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3960 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3961 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3962 | unsigned Abbrev = Stream.EmitAbbrev(Abv); |
| 3963 | |
| 3964 | // Emit the metadata record. |
| 3965 | RecordData Record; |
| 3966 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); |
| 3967 | Record.push_back(EXTENSION_METADATA); |
| 3968 | Record.push_back(Metadata.MajorVersion); |
| 3969 | Record.push_back(Metadata.MinorVersion); |
| 3970 | Record.push_back(Metadata.BlockName.size()); |
| 3971 | Record.push_back(Metadata.UserInfo.size()); |
| 3972 | SmallString<64> Buffer; |
| 3973 | Buffer += Metadata.BlockName; |
| 3974 | Buffer += Metadata.UserInfo; |
| 3975 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); |
| 3976 | |
| 3977 | // Emit the contents of the extension block. |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 3978 | Writer.writeExtensionContents(SemaRef, Stream); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3979 | |
| 3980 | // Exit the extension block. |
| 3981 | Stream.ExitBlock(); |
| 3982 | } |
| 3983 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3984 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3985 | // General Serialization Routines |
| 3986 | //===----------------------------------------------------------------------===// |
| 3987 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3988 | /// \brief Write a record containing the given attributes. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3989 | void ASTWriter::WriteAttributes(ArrayRef<const Attr*> Attrs, |
| 3990 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3991 | Record.push_back(Attrs.size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3992 | for (const auto *A : Attrs) { |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3993 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Argyrios Kyrtzidis | 309b4c4 | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 3994 | AddSourceRange(A->getRange(), Record); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3995 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3996 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 3997 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3998 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3999 | } |
| 4000 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 4001 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 4002 | AddSourceLocation(Tok.getLocation(), Record); |
| 4003 | Record.push_back(Tok.getLength()); |
| 4004 | |
| 4005 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 4006 | // if it is needed. |
| 4007 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 4008 | // FIXME: Should translate token kind to a stable encoding. |
| 4009 | Record.push_back(Tok.getKind()); |
| 4010 | // FIXME: Should translate token flags to a stable encoding. |
| 4011 | Record.push_back(Tok.getFlags()); |
| 4012 | } |
| 4013 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4014 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4015 | Record.push_back(Str.size()); |
| 4016 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 4017 | } |
| 4018 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4019 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4020 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4021 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4022 | bool Changed = |
| 4023 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4024 | |
| 4025 | // Remove a prefix to make the path relative, if relevant. |
| 4026 | const char *PathBegin = Path.data(); |
| 4027 | const char *PathPtr = |
| 4028 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 4029 | if (PathPtr != PathBegin) { |
| 4030 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 4031 | Changed = true; |
| 4032 | } |
| 4033 | |
| 4034 | return Changed; |
| 4035 | } |
| 4036 | |
| 4037 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 4038 | SmallString<128> FilePath(Path); |
| 4039 | PreparePathForOutput(FilePath); |
| 4040 | AddString(FilePath, Record); |
| 4041 | } |
| 4042 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4043 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4044 | StringRef Path) { |
| 4045 | SmallString<128> FilePath(Path); |
| 4046 | PreparePathForOutput(FilePath); |
| 4047 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 4048 | } |
| 4049 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4050 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 4051 | RecordDataImpl &Record) { |
| 4052 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4053 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4054 | Record.push_back(*Minor + 1); |
| 4055 | else |
| 4056 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4057 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4058 | Record.push_back(*Subminor + 1); |
| 4059 | else |
| 4060 | Record.push_back(0); |
| 4061 | } |
| 4062 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4063 | /// \brief Note that the identifier II occurs at the given offset |
| 4064 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4065 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4066 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4067 | // 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] | 4068 | // up earlier in the chain and thus don't need an offset. |
| 4069 | if (ID >= FirstIdentID) |
| 4070 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4071 | } |
| 4072 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4073 | /// \brief Note that the selector Sel occurs at the given offset |
| 4074 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4075 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4076 | unsigned ID = SelectorIDs[Sel]; |
| 4077 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4078 | // Don't record offsets for selectors that are also available in a different |
| 4079 | // file. |
| 4080 | if (ID < FirstSelectorID) |
| 4081 | return; |
| 4082 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4083 | } |
| 4084 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4085 | ASTWriter::ASTWriter( |
| 4086 | llvm::BitstreamWriter &Stream, |
| 4087 | ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions, |
| 4088 | bool IncludeTimestamps) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4089 | : Stream(Stream), Context(nullptr), PP(nullptr), Chain(nullptr), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4090 | WritingModule(nullptr), IncludeTimestamps(IncludeTimestamps), |
| 4091 | WritingAST(false), DoneWritingDeclsAndTypes(false), |
| 4092 | ASTHasCompilerErrors(false), FirstDeclID(NUM_PREDEF_DECL_IDS), |
| 4093 | NextDeclID(FirstDeclID), FirstTypeID(NUM_PREDEF_TYPE_IDS), |
| 4094 | NextTypeID(FirstTypeID), FirstIdentID(NUM_PREDEF_IDENT_IDS), |
| 4095 | NextIdentID(FirstIdentID), FirstMacroID(NUM_PREDEF_MACRO_IDS), |
| 4096 | NextMacroID(FirstMacroID), FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4097 | NextSubmoduleID(FirstSubmoduleID), |
| 4098 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
| 4099 | CollectedStmts(&StmtsToEmit), NumStatements(0), NumMacros(0), |
| 4100 | NumLexicalDeclContexts(0), NumVisibleDeclContexts(0), |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4101 | NextCXXBaseSpecifiersID(1), NextCXXCtorInitializersID(1), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4102 | TypeExtQualAbbrev(0), TypeFunctionProtoAbbrev(0), DeclParmVarAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4103 | DeclContextLexicalAbbrev(0), DeclContextVisibleLookupAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4104 | UpdateVisibleAbbrev(0), DeclRecordAbbrev(0), DeclTypedefAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4105 | DeclVarAbbrev(0), DeclFieldAbbrev(0), DeclEnumAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4106 | DeclObjCIvarAbbrev(0), DeclCXXMethodAbbrev(0), DeclRefExprAbbrev(0), |
| 4107 | CharacterLiteralAbbrev(0), IntegerLiteralAbbrev(0), |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4108 | ExprImplicitCastAbbrev(0) { |
| 4109 | for (const auto &Ext : Extensions) { |
| 4110 | if (auto Writer = Ext->createExtensionWriter(*this)) |
| 4111 | ModuleFileExtensionWriters.push_back(std::move(Writer)); |
| 4112 | } |
| 4113 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4114 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4115 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 4116 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4119 | const LangOptions &ASTWriter::getLangOpts() const { |
| 4120 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 4121 | return Context->getLangOpts(); |
| 4122 | } |
| 4123 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4124 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { |
| 4125 | return IncludeTimestamps ? E->getModificationTime() : 0; |
| 4126 | } |
| 4127 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4128 | uint64_t ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile, |
| 4129 | Module *WritingModule, StringRef isysroot, |
| 4130 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4131 | WritingAST = true; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4132 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4133 | ASTHasCompilerErrors = hasErrors; |
| 4134 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4135 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4136 | Stream.Emit((unsigned)'C', 8); |
| 4137 | Stream.Emit((unsigned)'P', 8); |
| 4138 | Stream.Emit((unsigned)'C', 8); |
| 4139 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4141 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4142 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4143 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4144 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4145 | this->WritingModule = WritingModule; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4146 | ASTFileSignature Signature = |
| 4147 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4148 | Context = nullptr; |
| 4149 | PP = nullptr; |
| 4150 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4151 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4152 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4153 | WritingAST = false; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4154 | return Signature; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4155 | } |
| 4156 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4157 | template<typename Vector> |
| 4158 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4159 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4160 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4161 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4162 | Writer.AddDeclRef(*I, Record); |
| 4163 | } |
| 4164 | } |
| 4165 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4166 | uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, |
| 4167 | const std::string &OutputFile, |
| 4168 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4169 | using namespace llvm; |
| 4170 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4171 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4172 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4173 | // Make sure that the AST reader knows to finalize itself. |
| 4174 | if (Chain) |
| 4175 | Chain->finalizeForWriting(); |
| 4176 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4177 | ASTContext &Context = SemaRef.Context; |
| 4178 | Preprocessor &PP = SemaRef.PP; |
| 4179 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4180 | // Set up predefined declaration IDs. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4181 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { |
| 4182 | if (D) { |
| 4183 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); |
| 4184 | DeclIDs[D] = ID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4185 | } |
| 4186 | }; |
| 4187 | RegisterPredefDecl(Context.getTranslationUnitDecl(), |
| 4188 | PREDEF_DECL_TRANSLATION_UNIT_ID); |
| 4189 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); |
| 4190 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); |
| 4191 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); |
| 4192 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, |
| 4193 | PREDEF_DECL_OBJC_PROTOCOL_ID); |
| 4194 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); |
| 4195 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); |
| 4196 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, |
| 4197 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); |
| 4198 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4199 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4200 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, |
| 4201 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4202 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4203 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, |
| 4204 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 4205 | RegisterPredefDecl(Context.CFConstantStringTypeDecl, |
| 4206 | PREDEF_DECL_CF_CONSTANT_STRING_ID); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 4207 | RegisterPredefDecl(Context.CFConstantStringTagDecl, |
| 4208 | PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4209 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4210 | // 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] | 4211 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4212 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4213 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4214 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4215 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4216 | // Build a record containing all of the file scoped decls in this file. |
| 4217 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4218 | if (!isModule) |
| 4219 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4220 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4221 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4222 | // Build a record containing all of the delegating constructors we still need |
| 4223 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4224 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4225 | if (!isModule) |
| 4226 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4227 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4228 | // Write the set of weak, undeclared identifiers. We always write the |
| 4229 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4230 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4231 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4232 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4233 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4234 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4235 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4236 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4237 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4238 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4239 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4240 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4241 | // Build a record containing all of the ext_vector declarations. |
| 4242 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4243 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4244 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4245 | // Build a record containing all of the VTable uses information. |
| 4246 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4247 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4248 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4249 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4250 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4251 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4252 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4253 | } |
| 4254 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4255 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4256 | RecordData UnusedLocalTypedefNameCandidates; |
| 4257 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4258 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4259 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4260 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4261 | RecordData PendingInstantiations; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4262 | for (const auto &I : SemaRef.PendingInstantiations) { |
| 4263 | AddDeclRef(I.first, PendingInstantiations); |
| 4264 | AddSourceLocation(I.second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4265 | } |
| 4266 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4267 | "There are local ones at end of translation unit!"); |
| 4268 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4269 | // Build a record containing some declaration references. |
| 4270 | RecordData SemaDeclRefs; |
| 4271 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 4272 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4273 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 4274 | } |
| 4275 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4276 | RecordData CUDASpecialDeclRefs; |
| 4277 | if (Context.getcudaConfigureCallDecl()) { |
| 4278 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4279 | } |
| 4280 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4281 | // Build a record containing all of the known namespaces. |
| 4282 | RecordData KnownNamespaces; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4283 | for (const auto &I : SemaRef.KnownNamespaces) { |
| 4284 | if (!I.second) |
| 4285 | AddDeclRef(I.first, KnownNamespaces); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4286 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4287 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4288 | // Build a record of all used, undefined objects that require definitions. |
| 4289 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4290 | |
| 4291 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4292 | SemaRef.getUndefinedButUsed(Undefined); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4293 | for (const auto &I : Undefined) { |
| 4294 | AddDeclRef(I.first, UndefinedButUsed); |
| 4295 | AddSourceLocation(I.second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4296 | } |
| 4297 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4298 | // Build a record containing all delete-expressions that we would like to |
| 4299 | // analyze later in AST. |
| 4300 | RecordData DeleteExprsToAnalyze; |
| 4301 | |
| 4302 | for (const auto &DeleteExprsInfo : |
| 4303 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4304 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4305 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4306 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4307 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4308 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4309 | } |
| 4310 | } |
| 4311 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4312 | // Write the control block |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4313 | uint64_t Signature = WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4314 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4315 | // Write the remaining AST contents. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4316 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4317 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4318 | // This is so that older clang versions, before the introduction |
| 4319 | // of the control block, can read and reject the newer PCH format. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4320 | { |
| 4321 | RecordData Record = {VERSION_MAJOR}; |
| 4322 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4323 | } |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4324 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4325 | // Create a lexical update block containing all of the declarations in the |
| 4326 | // translation unit that do not come from other AST files. |
| 4327 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4328 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; |
| 4329 | for (const auto *D : TU->noload_decls()) { |
| 4330 | if (!D->isFromASTFile()) { |
| 4331 | NewGlobalKindDeclPairs.push_back(D->getKind()); |
| 4332 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); |
| 4333 | } |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4334 | } |
| 4335 | |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4336 | auto *Abv = new llvm::BitCodeAbbrev(); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4337 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4338 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4339 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4340 | { |
| 4341 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; |
| 4342 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 4343 | bytes(NewGlobalKindDeclPairs)); |
| 4344 | } |
| 4345 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4346 | // And a visible updates block for the translation unit. |
| 4347 | Abv = new llvm::BitCodeAbbrev(); |
| 4348 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4349 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4350 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4351 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 4352 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4353 | |
| 4354 | // If we have any extern "C" names, write out a visible update for them. |
| 4355 | if (Context.ExternCContext) |
| 4356 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4357 | |
| 4358 | // If the translation unit has an anonymous namespace, and we don't already |
| 4359 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4360 | // 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] | 4361 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4362 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4363 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4364 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4365 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4366 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4367 | // Add update records for all mangling numbers and static local numbers. |
| 4368 | // These aren't really update records, but this is a convenient way of |
| 4369 | // tagging this rare extra data onto the declarations. |
| 4370 | for (const auto &Number : Context.MangleNumbers) |
| 4371 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4372 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4373 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4374 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4375 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4376 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4377 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4378 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4379 | // Make sure visible decls, added to DeclContexts previously loaded from |
| 4380 | // an AST file, are registered for serialization. |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4381 | for (const auto *I : UpdatingVisibleDecls) { |
| 4382 | GetDeclRef(I); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4383 | } |
| 4384 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4385 | // Make sure all decls associated with an identifier are registered for |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4386 | // serialization, if we're storing decls with identifiers. |
| 4387 | if (!WritingModule || !getLangOpts().CPlusPlus) { |
| 4388 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4389 | for (const auto &ID : PP.getIdentifierTable()) { |
| 4390 | const IdentifierInfo *II = ID.second; |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4391 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 4392 | IIs.push_back(II); |
| 4393 | } |
| 4394 | // Sort the identifiers to visit based on their name. |
| 4395 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 4396 | for (const IdentifierInfo *II : IIs) { |
| 4397 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4398 | DEnd = SemaRef.IdResolver.end(); |
| 4399 | D != DEnd; ++D) { |
| 4400 | GetDeclRef(*D); |
| 4401 | } |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4402 | } |
| 4403 | } |
| 4404 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4405 | // Form the record of special types. |
| 4406 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4407 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4408 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 4409 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 4410 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 4411 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 4412 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4413 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4414 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4415 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4416 | if (Chain) { |
| 4417 | // Write the mapping information describing our module dependencies and how |
| 4418 | // each of those modules were mapped into our own offset/ID space, so that |
| 4419 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4420 | // The map consists solely of a blob with the following format: |
| 4421 | // *(module-name-len:i16 module-name:len*i8 |
| 4422 | // source-location-offset:i32 |
| 4423 | // identifier-id:i32 |
| 4424 | // preprocessed-entity-id:i32 |
| 4425 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4426 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4427 | // selector-id:i32 |
| 4428 | // declaration-id:i32 |
| 4429 | // c++-base-specifiers-id:i32 |
| 4430 | // type-id:i32) |
| 4431 | // |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4432 | auto *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4433 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4434 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 4435 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4436 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4437 | { |
| 4438 | llvm::raw_svector_ostream Out(Buffer); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4439 | for (ModuleFile *M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4440 | using namespace llvm::support; |
| 4441 | endian::Writer<little> LE(Out); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4442 | StringRef FileName = M->FileName; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4443 | LE.write<uint16_t>(FileName.size()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4444 | Out.write(FileName.data(), FileName.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4445 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4446 | // Note: if a base ID was uint max, it would not be possible to load |
| 4447 | // another module after it or have more than one entity inside it. |
| 4448 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 4449 | |
| 4450 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 4451 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 4452 | if (ShouldWrite) |
| 4453 | LE.write<uint32_t>(BaseID); |
| 4454 | else |
| 4455 | LE.write<uint32_t>(None); |
| 4456 | }; |
| 4457 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4458 | // These values should be unique within a chain, since they will be read |
| 4459 | // as keys into ContinuousRangeMaps. |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4460 | writeBaseIDOrNone(M->SLocEntryBaseOffset, M->LocalNumSLocEntries); |
| 4461 | writeBaseIDOrNone(M->BaseIdentifierID, M->LocalNumIdentifiers); |
| 4462 | writeBaseIDOrNone(M->BaseMacroID, M->LocalNumMacros); |
| 4463 | writeBaseIDOrNone(M->BasePreprocessedEntityID, |
| 4464 | M->NumPreprocessedEntities); |
| 4465 | writeBaseIDOrNone(M->BaseSubmoduleID, M->LocalNumSubmodules); |
| 4466 | writeBaseIDOrNone(M->BaseSelectorID, M->LocalNumSelectors); |
| 4467 | writeBaseIDOrNone(M->BaseDeclID, M->LocalNumDecls); |
| 4468 | writeBaseIDOrNone(M->BaseTypeIndex, M->LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4469 | } |
| 4470 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4471 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4472 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4473 | Buffer.data(), Buffer.size()); |
| 4474 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4475 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4476 | RecordData DeclUpdatesOffsetsRecord; |
| 4477 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4478 | // Keep writing types, declarations, and declaration update records |
| 4479 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4480 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 4481 | WriteTypeAbbrevs(); |
| 4482 | WriteDeclAbbrevs(); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4483 | do { |
| 4484 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 4485 | while (!DeclTypesToEmit.empty()) { |
| 4486 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 4487 | DeclTypesToEmit.pop(); |
| 4488 | if (DOT.isType()) |
| 4489 | WriteType(DOT.getType()); |
| 4490 | else |
| 4491 | WriteDecl(Context, DOT.getDecl()); |
| 4492 | } |
| 4493 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4494 | Stream.ExitBlock(); |
| 4495 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4496 | DoneWritingDeclsAndTypes = true; |
| 4497 | |
| 4498 | // These things can only be done once we've written out decls and types. |
| 4499 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4500 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 4501 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4502 | WriteCXXBaseSpecifiersOffsets(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4503 | WriteCXXCtorInitializersOffsets(); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4504 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4505 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4506 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4507 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4508 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4509 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4510 | WriteReferencedSelectorsPool(SemaRef); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 4511 | WriteLateParsedTemplates(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4512 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4513 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 4514 | WriteOpenCLExtensions(SemaRef); |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 4515 | WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4516 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4517 | // If we're emitting a module, write out the submodule information. |
| 4518 | if (WritingModule) |
| 4519 | WriteSubmodules(WritingModule); |
| 4520 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4521 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 4522 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4523 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 4524 | if (!EagerlyDeserializedDecls.empty()) |
| 4525 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4526 | |
| 4527 | // Write the record containing tentative definitions. |
| 4528 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4529 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4530 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4531 | // Write the record containing unused file scoped decls. |
| 4532 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4533 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4534 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4535 | // Write the record containing weak undeclared identifiers. |
| 4536 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4537 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4538 | WeakUndeclaredIdentifiers); |
| 4539 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4540 | // Write the record containing ext_vector type names. |
| 4541 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4542 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4543 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4544 | // Write the record containing VTable uses information. |
| 4545 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4546 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4547 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4548 | // Write the record containing potentially unused local typedefs. |
| 4549 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 4550 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 4551 | UnusedLocalTypedefNameCandidates); |
| 4552 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4553 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4554 | if (!PendingInstantiations.empty()) |
| 4555 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4556 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4557 | // Write the record containing declaration references of Sema. |
| 4558 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4559 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4560 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4561 | // Write the record containing CUDA-specific declaration references. |
| 4562 | if (!CUDASpecialDeclRefs.empty()) |
| 4563 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4564 | |
| 4565 | // Write the delegating constructors. |
| 4566 | if (!DelegatingCtorDecls.empty()) |
| 4567 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4568 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4569 | // Write the known namespaces. |
| 4570 | if (!KnownNamespaces.empty()) |
| 4571 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4572 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4573 | // Write the undefined internal functions and variables, and inline functions. |
| 4574 | if (!UndefinedButUsed.empty()) |
| 4575 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4576 | |
| 4577 | if (!DeleteExprsToAnalyze.empty()) |
| 4578 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 4579 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4580 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4581 | for (auto *DC : UpdatedDeclContexts) |
| 4582 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4583 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4584 | if (!WritingModule) { |
| 4585 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4586 | struct ModuleInfo { |
| 4587 | uint64_t ID; |
| 4588 | Module *M; |
| 4589 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 4590 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4591 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 4592 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4593 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4594 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 4595 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4596 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4597 | |
| 4598 | if (!Imports.empty()) { |
| 4599 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4600 | return A.ID < B.ID; |
| 4601 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4602 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4603 | return A.ID == B.ID; |
| 4604 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4605 | |
| 4606 | // Sort and deduplicate module IDs. |
| 4607 | std::sort(Imports.begin(), Imports.end(), Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4608 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4609 | Imports.end()); |
| 4610 | |
| 4611 | RecordData ImportedModules; |
| 4612 | for (const auto &Import : Imports) { |
| 4613 | ImportedModules.push_back(Import.ID); |
| 4614 | // FIXME: If the module has macros imported then later has declarations |
| 4615 | // imported, this location won't be the right one as a location for the |
| 4616 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 4617 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4618 | } |
| 4619 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4620 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 4621 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4622 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4623 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4624 | WriteDeclReplacementsBlock(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4625 | WriteObjCCategories(); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4626 | if(!WritingModule) { |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4627 | WriteOptimizePragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4628 | WriteMSStructPragmaOptions(SemaRef); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4629 | WriteMSPointersToMembersPragmaOptions(SemaRef); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4630 | } |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4631 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4632 | // Some simple statistics |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4633 | RecordData::value_type Record[] = { |
| 4634 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4635 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4636 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4637 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4638 | // Write the module file extension blocks. |
| 4639 | for (const auto &ExtWriter : ModuleFileExtensionWriters) |
Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4640 | WriteModuleFileExtension(SemaRef, *ExtWriter); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4641 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4642 | return Signature; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4643 | } |
| 4644 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4645 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4646 | if (DeclUpdates.empty()) |
| 4647 | return; |
| 4648 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4649 | DeclUpdateMap LocalUpdates; |
| 4650 | LocalUpdates.swap(DeclUpdates); |
| 4651 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4652 | for (auto &DeclUpdate : LocalUpdates) { |
| 4653 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 4654 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4655 | bool HasUpdatedBody = false; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4656 | RecordData Record; |
| 4657 | for (auto &Update : DeclUpdate.second) { |
| 4658 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 4659 | |
| 4660 | Record.push_back(Kind); |
| 4661 | switch (Kind) { |
| 4662 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 4663 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 4664 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4665 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4666 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 4667 | break; |
| 4668 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4669 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4670 | // An updated body is emitted last, so that the reader doesn't need |
| 4671 | // to skip over the lazy body to reach statements for other records. |
| 4672 | Record.pop_back(); |
| 4673 | HasUpdatedBody = true; |
| 4674 | break; |
| 4675 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4676 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
| 4677 | AddSourceLocation(Update.getLoc(), Record); |
| 4678 | break; |
| 4679 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4680 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: |
| 4681 | AddStmt(const_cast<Expr*>( |
| 4682 | cast<ParmVarDecl>(Update.getDecl())->getDefaultArg())); |
| 4683 | break; |
| 4684 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4685 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4686 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 4687 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4688 | AddCXXDefinitionData(RD, Record); |
| 4689 | Record.push_back(WriteDeclContextLexicalBlock( |
| 4690 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 4691 | |
| 4692 | // This state is sometimes updated by template instantiation, when we |
| 4693 | // switch from the specialization referring to the template declaration |
| 4694 | // to it referring to the template definition. |
| 4695 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 4696 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
| 4697 | AddSourceLocation(MSInfo->getPointOfInstantiation(), Record); |
| 4698 | } else { |
| 4699 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 4700 | Record.push_back(Spec->getTemplateSpecializationKind()); |
| 4701 | AddSourceLocation(Spec->getPointOfInstantiation(), Record); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4702 | |
| 4703 | // The instantiation might have been resolved to a partial |
| 4704 | // specialization. If so, record which one. |
| 4705 | auto From = Spec->getInstantiatedFrom(); |
| 4706 | if (auto PartialSpec = |
| 4707 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 4708 | Record.push_back(true); |
| 4709 | AddDeclRef(PartialSpec, Record); |
| 4710 | AddTemplateArgumentList(&Spec->getTemplateInstantiationArgs(), |
| 4711 | Record); |
| 4712 | } else { |
| 4713 | Record.push_back(false); |
| 4714 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4715 | } |
| 4716 | Record.push_back(RD->getTagKind()); |
| 4717 | AddSourceLocation(RD->getLocation(), Record); |
| 4718 | AddSourceLocation(RD->getLocStart(), Record); |
| 4719 | AddSourceLocation(RD->getRBraceLoc(), Record); |
| 4720 | |
| 4721 | // Instantiation may change attributes; write them all out afresh. |
| 4722 | Record.push_back(D->hasAttrs()); |
| 4723 | if (Record.back()) |
Craig Topper | 8c2a2a0 | 2014-08-30 16:55:39 +0000 | [diff] [blame] | 4724 | WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(), |
| 4725 | D->getAttrs().size()), Record); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4726 | |
| 4727 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 4728 | break; |
| 4729 | } |
| 4730 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4731 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
| 4732 | AddDeclRef(Update.getDecl(), Record); |
| 4733 | break; |
| 4734 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4735 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 4736 | addExceptionSpec( |
| 4737 | *this, |
| 4738 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 4739 | Record); |
| 4740 | break; |
| 4741 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4742 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 4743 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 4744 | break; |
| 4745 | |
| 4746 | case UPD_DECL_MARKED_USED: |
| 4747 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4748 | |
| 4749 | case UPD_MANGLING_NUMBER: |
| 4750 | case UPD_STATIC_LOCAL_NUMBER: |
| 4751 | Record.push_back(Update.getNumber()); |
| 4752 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4753 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4754 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
| 4755 | AddSourceRange(D->getAttr<OMPThreadPrivateDeclAttr>()->getRange(), |
| 4756 | Record); |
| 4757 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4758 | |
| 4759 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 4760 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4761 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4762 | |
| 4763 | case UPD_ADDED_ATTR_TO_RECORD: |
| 4764 | WriteAttributes(llvm::makeArrayRef(Update.getAttr()), Record); |
| 4765 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4766 | } |
| 4767 | } |
| 4768 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4769 | if (HasUpdatedBody) { |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4770 | const auto *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4771 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4772 | Record.push_back(Def->isInlined()); |
| 4773 | AddSourceLocation(Def->getInnerLocStart(), Record); |
| 4774 | AddFunctionDefinition(Def, Record); |
| 4775 | } |
| 4776 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4777 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 4778 | OffsetsRecord.push_back(Stream.GetCurrentBitNo()); |
| 4779 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4780 | Stream.EmitRecord(DECL_UPDATES, Record); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4781 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4782 | FlushPendingAfterDecl(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4783 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4784 | } |
| 4785 | |
Argyrios Kyrtzidis | 97bfda9 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 4786 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4787 | if (ReplacedDecls.empty()) |
| 4788 | return; |
| 4789 | |
| 4790 | RecordData Record; |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4791 | for (const auto &I : ReplacedDecls) { |
| 4792 | Record.push_back(I.ID); |
| 4793 | Record.push_back(I.Offset); |
| 4794 | Record.push_back(I.Loc); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4795 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4796 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4797 | } |
| 4798 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4799 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4800 | Record.push_back(Loc.getRawEncoding()); |
| 4801 | } |
| 4802 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4803 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4804 | AddSourceLocation(Range.getBegin(), Record); |
| 4805 | AddSourceLocation(Range.getEnd(), Record); |
| 4806 | } |
| 4807 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4808 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4809 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4810 | const uint64_t *Words = Value.getRawData(); |
| 4811 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4812 | } |
| 4813 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4814 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4815 | Record.push_back(Value.isUnsigned()); |
| 4816 | AddAPInt(Value, Record); |
| 4817 | } |
| 4818 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4819 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4820 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 4821 | } |
| 4822 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4823 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4824 | Record.push_back(getIdentifierRef(II)); |
| 4825 | } |
| 4826 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4827 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4828 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4829 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4830 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4831 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4832 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4833 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4834 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4837 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4838 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 4839 | // have been redefined by the header (in which case they are not |
| 4840 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4841 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4842 | return 0; |
| 4843 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4844 | MacroID &ID = MacroIDs[MI]; |
| 4845 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4846 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4847 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 4848 | MacroInfosToEmit.push_back(Info); |
| 4849 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4850 | return ID; |
| 4851 | } |
| 4852 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4853 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4854 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4855 | return 0; |
| 4856 | |
| 4857 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 4858 | return MacroIDs[MI]; |
| 4859 | } |
| 4860 | |
| 4861 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 4862 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4865 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4866 | Record.push_back(getSelectorRef(SelRef)); |
| 4867 | } |
| 4868 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4869 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4870 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4871 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4872 | } |
| 4873 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4874 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4875 | if (SID == 0 && Chain) { |
| 4876 | // This might trigger a ReadSelector callback, which will set the ID for |
| 4877 | // this selector. |
| 4878 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4879 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4880 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4881 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4882 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4883 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4884 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4885 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4886 | } |
| 4887 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4888 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4889 | AddDeclRef(Temp->getDestructor(), Record); |
| 4890 | } |
| 4891 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4892 | void ASTWriter::AddCXXCtorInitializersRef(ArrayRef<CXXCtorInitializer *> Inits, |
| 4893 | RecordDataImpl &Record) { |
| 4894 | assert(!Inits.empty() && "Empty ctor initializer sets are not recorded"); |
| 4895 | CXXCtorInitializersToWrite.push_back( |
| 4896 | QueuedCXXCtorInitializers(NextCXXCtorInitializersID, Inits)); |
| 4897 | Record.push_back(NextCXXCtorInitializersID++); |
| 4898 | } |
| 4899 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4900 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4901 | CXXBaseSpecifier const *BasesEnd, |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4902 | RecordDataImpl &Record) { |
| 4903 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 4904 | CXXBaseSpecifiersToWrite.push_back( |
| 4905 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 4906 | Bases, BasesEnd)); |
| 4907 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 4908 | } |
| 4909 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4910 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4911 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4912 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4913 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4914 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4915 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4916 | break; |
| 4917 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4918 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4919 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4920 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4921 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4922 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4923 | break; |
| 4924 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4925 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4926 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4927 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4928 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4929 | case TemplateArgument::Null: |
| 4930 | case TemplateArgument::Integral: |
| 4931 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4932 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4933 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4934 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4935 | break; |
| 4936 | } |
| 4937 | } |
| 4938 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4939 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4940 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4941 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4942 | |
| 4943 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 4944 | bool InfoHasSameExpr |
| 4945 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 4946 | Record.push_back(InfoHasSameExpr); |
| 4947 | if (InfoHasSameExpr) |
| 4948 | return; // Avoid storing the same expr twice. |
| 4949 | } |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4950 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 4951 | Record); |
| 4952 | } |
| 4953 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4954 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 4955 | RecordDataImpl &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4956 | if (!TInfo) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4957 | AddTypeRef(QualType(), Record); |
| 4958 | return; |
| 4959 | } |
| 4960 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4961 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 4962 | } |
| 4963 | |
| 4964 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 4965 | AddTypeRef(TL.getType(), Record); |
| 4966 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4967 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4968 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4969 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4970 | } |
| 4971 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4972 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 4973 | Record.push_back(GetOrCreateTypeID(T)); |
| 4974 | } |
| 4975 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4976 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4977 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4978 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 4979 | if (T.isNull()) |
| 4980 | return TypeIdx(); |
| 4981 | assert(!T.getLocalFastQualifiers()); |
| 4982 | |
| 4983 | TypeIdx &Idx = TypeIdxs[T]; |
| 4984 | if (Idx.getIndex() == 0) { |
| 4985 | if (DoneWritingDeclsAndTypes) { |
| 4986 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 4987 | return TypeIdx(); |
| 4988 | } |
| 4989 | |
| 4990 | // We haven't seen this type before. Assign it a new ID and put it |
| 4991 | // into the queue of types to emit. |
| 4992 | Idx = TypeIdx(NextTypeID++); |
| 4993 | DeclTypesToEmit.push(T); |
| 4994 | } |
| 4995 | return Idx; |
| 4996 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 4997 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4998 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4999 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5000 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5001 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 5002 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5003 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5004 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5005 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5006 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 5007 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 5008 | return I->second; |
| 5009 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5010 | } |
| 5011 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5012 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5013 | Record.push_back(GetDeclRef(D)); |
| 5014 | } |
| 5015 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5016 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5017 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5018 | |
| 5019 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5020 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5021 | } |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5022 | |
| 5023 | // If D comes from an AST file, its declaration ID is already known and |
| 5024 | // fixed. |
| 5025 | if (D->isFromASTFile()) |
| 5026 | return D->getGlobalID(); |
| 5027 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5028 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5029 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5030 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5031 | if (DoneWritingDeclsAndTypes) { |
| 5032 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 5033 | return 0; |
| 5034 | } |
| 5035 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5036 | // We haven't seen this declaration before. Give it a new ID and |
| 5037 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5038 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5039 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5040 | } |
| 5041 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5042 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5043 | } |
| 5044 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5045 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5046 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5047 | return 0; |
| 5048 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5049 | // If D comes from an AST file, its declaration ID is already known and |
| 5050 | // fixed. |
| 5051 | if (D->isFromASTFile()) |
| 5052 | return D->getGlobalID(); |
| 5053 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5054 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 5055 | return DeclIDs[D]; |
| 5056 | } |
| 5057 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5058 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5059 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5060 | assert(D); |
| 5061 | |
| 5062 | SourceLocation Loc = D->getLocation(); |
| 5063 | if (Loc.isInvalid()) |
| 5064 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5065 | |
| 5066 | // We only keep track of the file-level declarations of each file. |
| 5067 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 5068 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5069 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 5070 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5071 | if (isa<ParmVarDecl>(D)) |
| 5072 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5073 | |
| 5074 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5075 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5076 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5077 | FileID FID; |
| 5078 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5079 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5080 | if (FID.isInvalid()) |
| 5081 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5082 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5083 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5084 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5085 | if (!Info) |
| 5086 | Info = new DeclIDInFileInfo(); |
| 5087 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5088 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5089 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 5090 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5091 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5092 | Decls.push_back(LocDecl); |
| 5093 | return; |
| 5094 | } |
| 5095 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5096 | LocDeclIDsTy::iterator I = |
| 5097 | std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5098 | |
| 5099 | Decls.insert(I, LocDecl); |
| 5100 | } |
| 5101 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5102 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 5103 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5104 | Record.push_back(Name.getNameKind()); |
| 5105 | switch (Name.getNameKind()) { |
| 5106 | case DeclarationName::Identifier: |
| 5107 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 5108 | break; |
| 5109 | |
| 5110 | case DeclarationName::ObjCZeroArgSelector: |
| 5111 | case DeclarationName::ObjCOneArgSelector: |
| 5112 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5113 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5114 | break; |
| 5115 | |
| 5116 | case DeclarationName::CXXConstructorName: |
| 5117 | case DeclarationName::CXXDestructorName: |
| 5118 | case DeclarationName::CXXConversionFunctionName: |
| 5119 | AddTypeRef(Name.getCXXNameType(), Record); |
| 5120 | break; |
| 5121 | |
| 5122 | case DeclarationName::CXXOperatorName: |
| 5123 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 5124 | break; |
| 5125 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5126 | case DeclarationName::CXXLiteralOperatorName: |
| 5127 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 5128 | break; |
| 5129 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5130 | case DeclarationName::CXXUsingDirective: |
| 5131 | // No extra data to emit |
| 5132 | break; |
| 5133 | } |
| 5134 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5135 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5136 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5137 | assert(needsAnonymousDeclarationNumber(D) && |
| 5138 | "expected an anonymous declaration"); |
| 5139 | |
| 5140 | // Number the anonymous declarations within this context, if we've not |
| 5141 | // already done so. |
| 5142 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5143 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5144 | auto *DC = D->getLexicalDeclContext(); |
| 5145 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5146 | AnonymousDeclarationNumbers[ND] = Number; |
| 5147 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5148 | |
| 5149 | It = AnonymousDeclarationNumbers.find(D); |
| 5150 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5151 | "declaration not found within its lexical context"); |
| 5152 | } |
| 5153 | |
| 5154 | return It->second; |
| 5155 | } |
| 5156 | |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5157 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5158 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5159 | switch (Name.getNameKind()) { |
| 5160 | case DeclarationName::CXXConstructorName: |
| 5161 | case DeclarationName::CXXDestructorName: |
| 5162 | case DeclarationName::CXXConversionFunctionName: |
| 5163 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 5164 | break; |
| 5165 | |
| 5166 | case DeclarationName::CXXOperatorName: |
| 5167 | AddSourceLocation( |
| 5168 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 5169 | Record); |
| 5170 | AddSourceLocation( |
| 5171 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 5172 | Record); |
| 5173 | break; |
| 5174 | |
| 5175 | case DeclarationName::CXXLiteralOperatorName: |
| 5176 | AddSourceLocation( |
| 5177 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 5178 | Record); |
| 5179 | break; |
| 5180 | |
| 5181 | case DeclarationName::Identifier: |
| 5182 | case DeclarationName::ObjCZeroArgSelector: |
| 5183 | case DeclarationName::ObjCOneArgSelector: |
| 5184 | case DeclarationName::ObjCMultiArgSelector: |
| 5185 | case DeclarationName::CXXUsingDirective: |
| 5186 | break; |
| 5187 | } |
| 5188 | } |
| 5189 | |
| 5190 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5191 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5192 | AddDeclarationName(NameInfo.getName(), Record); |
| 5193 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 5194 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 5195 | } |
| 5196 | |
| 5197 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5198 | RecordDataImpl &Record) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5199 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5200 | Record.push_back(Info.NumTemplParamLists); |
| 5201 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 5202 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 5203 | } |
| 5204 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5205 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5206 | RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5207 | // 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] | 5208 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5209 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5210 | |
| 5211 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5212 | while (NNS) { |
| 5213 | NestedNames.push_back(NNS); |
| 5214 | NNS = NNS->getPrefix(); |
| 5215 | } |
| 5216 | |
| 5217 | Record.push_back(NestedNames.size()); |
| 5218 | while(!NestedNames.empty()) { |
| 5219 | NNS = NestedNames.pop_back_val(); |
| 5220 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 5221 | Record.push_back(Kind); |
| 5222 | switch (Kind) { |
| 5223 | case NestedNameSpecifier::Identifier: |
| 5224 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 5225 | break; |
| 5226 | |
| 5227 | case NestedNameSpecifier::Namespace: |
| 5228 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 5229 | break; |
| 5230 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5231 | case NestedNameSpecifier::NamespaceAlias: |
| 5232 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 5233 | break; |
| 5234 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5235 | case NestedNameSpecifier::TypeSpec: |
| 5236 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 5237 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 5238 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5239 | break; |
| 5240 | |
| 5241 | case NestedNameSpecifier::Global: |
| 5242 | // Don't need to write an associated value. |
| 5243 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5244 | |
| 5245 | case NestedNameSpecifier::Super: |
| 5246 | AddDeclRef(NNS->getAsRecordDecl(), Record); |
| 5247 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5248 | } |
| 5249 | } |
| 5250 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5251 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5252 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 5253 | RecordDataImpl &Record) { |
| 5254 | // 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] | 5255 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5256 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5257 | |
| 5258 | // Push each of the nested-name-specifiers's onto a stack for |
| 5259 | // serialization in reverse order. |
| 5260 | while (NNS) { |
| 5261 | NestedNames.push_back(NNS); |
| 5262 | NNS = NNS.getPrefix(); |
| 5263 | } |
| 5264 | |
| 5265 | Record.push_back(NestedNames.size()); |
| 5266 | while(!NestedNames.empty()) { |
| 5267 | NNS = NestedNames.pop_back_val(); |
| 5268 | NestedNameSpecifier::SpecifierKind Kind |
| 5269 | = NNS.getNestedNameSpecifier()->getKind(); |
| 5270 | Record.push_back(Kind); |
| 5271 | switch (Kind) { |
| 5272 | case NestedNameSpecifier::Identifier: |
| 5273 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 5274 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5275 | break; |
| 5276 | |
| 5277 | case NestedNameSpecifier::Namespace: |
| 5278 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 5279 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5280 | break; |
| 5281 | |
| 5282 | case NestedNameSpecifier::NamespaceAlias: |
| 5283 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 5284 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5285 | break; |
| 5286 | |
| 5287 | case NestedNameSpecifier::TypeSpec: |
| 5288 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 5289 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5290 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 5291 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 5292 | break; |
| 5293 | |
| 5294 | case NestedNameSpecifier::Global: |
| 5295 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 5296 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5297 | |
| 5298 | case NestedNameSpecifier::Super: |
| 5299 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl(), Record); |
| 5300 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5301 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5302 | } |
| 5303 | } |
| 5304 | } |
| 5305 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5306 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5307 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5308 | Record.push_back(Kind); |
| 5309 | switch (Kind) { |
| 5310 | case TemplateName::Template: |
| 5311 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 5312 | break; |
| 5313 | |
| 5314 | case TemplateName::OverloadedTemplate: { |
| 5315 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 5316 | Record.push_back(OvT->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5317 | for (const auto &I : *OvT) |
| 5318 | AddDeclRef(I, Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5319 | break; |
| 5320 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5321 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5322 | case TemplateName::QualifiedTemplate: { |
| 5323 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 5324 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 5325 | Record.push_back(QualT->hasTemplateKeyword()); |
| 5326 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 5327 | break; |
| 5328 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5329 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5330 | case TemplateName::DependentTemplate: { |
| 5331 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 5332 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 5333 | Record.push_back(DepT->isIdentifier()); |
| 5334 | if (DepT->isIdentifier()) |
| 5335 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 5336 | else |
| 5337 | Record.push_back(DepT->getOperator()); |
| 5338 | break; |
| 5339 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5340 | |
| 5341 | case TemplateName::SubstTemplateTemplateParm: { |
| 5342 | SubstTemplateTemplateParmStorage *subst |
| 5343 | = Name.getAsSubstTemplateTemplateParm(); |
| 5344 | AddDeclRef(subst->getParameter(), Record); |
| 5345 | AddTemplateName(subst->getReplacement(), Record); |
| 5346 | break; |
| 5347 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5348 | |
| 5349 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5350 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5351 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 5352 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 5353 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 5354 | break; |
| 5355 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5356 | } |
| 5357 | } |
| 5358 | |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5359 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5360 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5361 | Record.push_back(Arg.getKind()); |
| 5362 | switch (Arg.getKind()) { |
| 5363 | case TemplateArgument::Null: |
| 5364 | break; |
| 5365 | case TemplateArgument::Type: |
| 5366 | AddTypeRef(Arg.getAsType(), Record); |
| 5367 | break; |
| 5368 | case TemplateArgument::Declaration: |
| 5369 | AddDeclRef(Arg.getAsDecl(), Record); |
David Blaikie | 952a9b1 | 2014-10-17 18:00:12 +0000 | [diff] [blame] | 5370 | AddTypeRef(Arg.getParamTypeForDecl(), Record); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5371 | break; |
| 5372 | case TemplateArgument::NullPtr: |
| 5373 | AddTypeRef(Arg.getNullPtrType(), Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5374 | break; |
| 5375 | case TemplateArgument::Integral: |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 5376 | AddAPSInt(Arg.getAsIntegral(), Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5377 | AddTypeRef(Arg.getIntegralType(), Record); |
| 5378 | break; |
| 5379 | case TemplateArgument::Template: |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5380 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 5381 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5382 | case TemplateArgument::TemplateExpansion: |
| 5383 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5384 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5385 | Record.push_back(*NumExpansions + 1); |
| 5386 | else |
| 5387 | Record.push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5388 | break; |
| 5389 | case TemplateArgument::Expression: |
| 5390 | AddStmt(Arg.getAsExpr()); |
| 5391 | break; |
| 5392 | case TemplateArgument::Pack: |
| 5393 | Record.push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 5394 | for (const auto &P : Arg.pack_elements()) |
| 5395 | AddTemplateArgument(P, Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5396 | break; |
| 5397 | } |
| 5398 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5399 | |
| 5400 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5401 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5402 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5403 | assert(TemplateParams && "No TemplateParams!"); |
| 5404 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 5405 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 5406 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 5407 | Record.push_back(TemplateParams->size()); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5408 | for (const auto &P : *TemplateParams) |
| 5409 | AddDeclRef(P, Record); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | /// \brief Emit a template argument list. |
| 5413 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5414 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5415 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5416 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5417 | Record.push_back(TemplateArgs->size()); |
| 5418 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5419 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 5420 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5421 | |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5422 | void |
| 5423 | ASTWriter::AddASTTemplateArgumentListInfo |
| 5424 | (const ASTTemplateArgumentListInfo *ASTTemplArgList, RecordDataImpl &Record) { |
| 5425 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
| 5426 | AddSourceLocation(ASTTemplArgList->LAngleLoc, Record); |
| 5427 | AddSourceLocation(ASTTemplArgList->RAngleLoc, Record); |
| 5428 | Record.push_back(ASTTemplArgList->NumTemplateArgs); |
| 5429 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
| 5430 | for (int i=0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
| 5431 | AddTemplateArgumentLoc(TemplArgs[i], Record); |
| 5432 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5433 | |
| 5434 | void |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5435 | ASTWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5436 | Record.push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5437 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5438 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 5439 | AddDeclRef(I.getDecl(), Record); |
| 5440 | Record.push_back(I.getAccess()); |
| 5441 | } |
| 5442 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5443 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5444 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5445 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5446 | Record.push_back(Base.isVirtual()); |
| 5447 | Record.push_back(Base.isBaseOfClass()); |
| 5448 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5449 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5450 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5451 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5452 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 5453 | : SourceLocation(), |
| 5454 | Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5455 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5456 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5457 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 5458 | RecordData Record; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5459 | unsigned N = CXXBaseSpecifiersToWrite.size(); |
| 5460 | for (unsigned I = 0; I != N; ++I) { |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5461 | Record.clear(); |
| 5462 | |
| 5463 | // Record the offset of this base-specifier set. |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 5464 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5465 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 5466 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 5467 | else { |
| 5468 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 5469 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 5470 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 5471 | } |
| 5472 | |
| 5473 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 5474 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 5475 | Record.push_back(BEnd - B); |
| 5476 | for (; B != BEnd; ++B) |
| 5477 | AddCXXBaseSpecifier(*B, Record); |
| 5478 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | d585304 | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 5479 | |
| 5480 | // Flush any expressions that were written as part of the base specifiers. |
| 5481 | FlushStmts(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5482 | } |
| 5483 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5484 | assert(N == CXXBaseSpecifiersToWrite.size() && |
| 5485 | "added more base specifiers while writing base specifiers"); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5486 | CXXBaseSpecifiersToWrite.clear(); |
| 5487 | } |
| 5488 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5489 | void ASTWriter::AddCXXCtorInitializers( |
| 5490 | const CXXCtorInitializer * const *CtorInitializers, |
| 5491 | unsigned NumCtorInitializers, |
| 5492 | RecordDataImpl &Record) { |
| 5493 | Record.push_back(NumCtorInitializers); |
| 5494 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 5495 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5496 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5497 | if (Init->isBaseInitializer()) { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5498 | Record.push_back(CTOR_INITIALIZER_BASE); |
Douglas Gregor | d73f3dd | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5499 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5500 | Record.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5501 | } else if (Init->isDelegatingInitializer()) { |
| 5502 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
Douglas Gregor | d73f3dd | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5503 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5504 | } else if (Init->isMemberInitializer()){ |
| 5505 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 5506 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5507 | } else { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5508 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 5509 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5510 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5511 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5512 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 5513 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5514 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 5515 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 5516 | Record.push_back(Init->isWritten()); |
| 5517 | if (Init->isWritten()) { |
| 5518 | Record.push_back(Init->getSourceOrder()); |
| 5519 | } else { |
| 5520 | Record.push_back(Init->getNumArrayIndices()); |
| 5521 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 5522 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 5523 | } |
| 5524 | } |
| 5525 | } |
| 5526 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5527 | void ASTWriter::FlushCXXCtorInitializers() { |
| 5528 | RecordData Record; |
| 5529 | |
| 5530 | unsigned N = CXXCtorInitializersToWrite.size(); |
Daniel Jasper | c77b0a1 | 2015-03-24 08:06:38 +0000 | [diff] [blame] | 5531 | (void)N; // Silence unused warning in non-assert builds. |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5532 | for (auto &Init : CXXCtorInitializersToWrite) { |
| 5533 | Record.clear(); |
| 5534 | |
| 5535 | // Record the offset of this mem-initializer list. |
| 5536 | unsigned Index = Init.ID - 1; |
| 5537 | if (Index == CXXCtorInitializersOffsets.size()) |
| 5538 | CXXCtorInitializersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 5539 | else { |
| 5540 | if (Index > CXXCtorInitializersOffsets.size()) |
| 5541 | CXXCtorInitializersOffsets.resize(Index + 1); |
| 5542 | CXXCtorInitializersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 5543 | } |
| 5544 | |
| 5545 | AddCXXCtorInitializers(Init.Inits.data(), Init.Inits.size(), Record); |
| 5546 | Stream.EmitRecord(serialization::DECL_CXX_CTOR_INITIALIZERS, Record); |
| 5547 | |
| 5548 | // Flush any expressions that were written as part of the initializers. |
| 5549 | FlushStmts(); |
| 5550 | } |
| 5551 | |
| 5552 | assert(N == CXXCtorInitializersToWrite.size() && |
| 5553 | "added more ctor initializers while writing ctor initializers"); |
| 5554 | CXXCtorInitializersToWrite.clear(); |
| 5555 | } |
| 5556 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5557 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5558 | auto &Data = D->data(); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5559 | Record.push_back(Data.IsLambda); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5560 | Record.push_back(Data.UserDeclaredConstructor); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5561 | Record.push_back(Data.UserDeclaredSpecialMembers); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5562 | Record.push_back(Data.Aggregate); |
| 5563 | Record.push_back(Data.PlainOldData); |
| 5564 | Record.push_back(Data.Empty); |
| 5565 | Record.push_back(Data.Polymorphic); |
| 5566 | Record.push_back(Data.Abstract); |
Chandler Carruth | 583edf8 | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 5567 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | b196374 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 5568 | Record.push_back(Data.HasNoNonEmptyBases); |
| 5569 | Record.push_back(Data.HasPrivateFields); |
| 5570 | Record.push_back(Data.HasProtectedFields); |
| 5571 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 61226d3 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 5572 | Record.push_back(Data.HasMutableFields); |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 5573 | Record.push_back(Data.HasVariantMembers); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5574 | Record.push_back(Data.HasOnlyCMembers); |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 5575 | Record.push_back(Data.HasInClassInitializer); |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 5576 | Record.push_back(Data.HasUninitializedReferenceMember); |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 5577 | Record.push_back(Data.HasUninitializedFields); |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 5578 | Record.push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 5579 | Record.push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 5580 | Record.push_back(Data.NeedOverloadResolutionForDestructor); |
| 5581 | Record.push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 5582 | Record.push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 5583 | Record.push_back(Data.DefaultedDestructorIsDeleted); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5584 | Record.push_back(Data.HasTrivialSpecialMembers); |
Richard Smith | b45a6f7 | 2014-04-17 20:33:01 +0000 | [diff] [blame] | 5585 | Record.push_back(Data.DeclaredNonTrivialSpecialMembers); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5586 | Record.push_back(Data.HasIrrelevantDestructor); |
Richard Smith | 111af8d | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 5587 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 5588 | Record.push_back(Data.HasDefaultedDefaultConstructor); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5589 | Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5590 | Record.push_back(Data.HasConstexprDefaultConstructor); |
Chandler Carruth | e71d062 | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 5591 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5592 | Record.push_back(Data.ComputedVisibleConversions); |
Alexis Hunt | ea6f032 | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 5593 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5594 | Record.push_back(Data.DeclaredSpecialMembers); |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 5595 | Record.push_back(Data.ImplicitCopyConstructorHasConstParam); |
| 5596 | Record.push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 5597 | Record.push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 5598 | Record.push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5599 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5600 | |
| 5601 | Record.push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5602 | if (Data.NumBases > 0) |
| 5603 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 5604 | Record); |
| 5605 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5606 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 5607 | Record.push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5608 | if (Data.NumVBases > 0) |
| 5609 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 5610 | Record); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5611 | |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 5612 | AddUnresolvedSet(Data.Conversions.get(*Context), Record); |
| 5613 | AddUnresolvedSet(Data.VisibleConversions.get(*Context), Record); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5614 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 68ad0e7 | 2013-06-26 02:41:25 +0000 | [diff] [blame] | 5615 | AddDeclRef(D->getFirstFriend(), Record); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5616 | |
| 5617 | // Add lambda-specific data. |
| 5618 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5619 | auto &Lambda = D->getLambdaData(); |
Douglas Gregor | 680e9e0 | 2012-02-21 19:11:17 +0000 | [diff] [blame] | 5620 | Record.push_back(Lambda.Dependent); |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 5621 | Record.push_back(Lambda.IsGenericLambda); |
| 5622 | Record.push_back(Lambda.CaptureDefault); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5623 | Record.push_back(Lambda.NumCaptures); |
| 5624 | Record.push_back(Lambda.NumExplicitCaptures); |
Douglas Gregor | 6379854 | 2012-02-20 19:44:39 +0000 | [diff] [blame] | 5625 | Record.push_back(Lambda.ManglingNumber); |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 5626 | AddDeclRef(Lambda.ContextDecl, Record); |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 5627 | AddTypeSourceInfo(Lambda.MethodTyInfo, Record); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5628 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 5629 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5630 | AddSourceLocation(Capture.getLocation(), Record); |
| 5631 | Record.push_back(Capture.isImplicit()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5632 | Record.push_back(Capture.getCaptureKind()); |
| 5633 | switch (Capture.getCaptureKind()) { |
| 5634 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 5635 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5636 | break; |
| 5637 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 5638 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5639 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5640 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5641 | AddDeclRef(Var, Record); |
| 5642 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
| 5643 | : SourceLocation(), |
| 5644 | Record); |
| 5645 | break; |
| 5646 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5647 | } |
| 5648 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5649 | } |
| 5650 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5651 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5652 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5653 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5654 | assert(FirstDeclID == NextDeclID && |
| 5655 | FirstTypeID == NextTypeID && |
| 5656 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5657 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5658 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5659 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5660 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5661 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5662 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5663 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 5664 | // Note, this will get called multiple times, once one the reader starts up |
| 5665 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5666 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 5667 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 5668 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5669 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5670 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5671 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5672 | NextDeclID = FirstDeclID; |
| 5673 | NextTypeID = FirstTypeID; |
| 5674 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5675 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5676 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5677 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5678 | } |
| 5679 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5680 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5681 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5682 | IdentID &StoredID = IdentifierIDs[II]; |
| 5683 | if (ID > StoredID) |
| 5684 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5685 | } |
| 5686 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5687 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5688 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5689 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5690 | if (ID > StoredID) |
| 5691 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5692 | } |
| 5693 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5694 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5695 | // Always take the highest-numbered type index. This copes with an interesting |
| 5696 | // 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] | 5697 | // 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] | 5698 | // keep the higher-numbered entry so that we can properly write it out to |
| 5699 | // the AST file. |
| 5700 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 5701 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 5702 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5703 | } |
| 5704 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5705 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5706 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5707 | SelectorID &StoredID = SelectorIDs[S]; |
| 5708 | if (ID > StoredID) |
| 5709 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5710 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5711 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5712 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5713 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5714 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5715 | MacroDefinitions[MD] = ID; |
| 5716 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5717 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 5718 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 5719 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 5720 | SubmoduleIDs[Mod] = ID; |
| 5721 | } |
| 5722 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5723 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5724 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5725 | assert(!WritingAST && "Already writing the AST!"); |
Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5726 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5727 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5728 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5729 | // A forward reference was mutated into a definition. Rewrite it. |
| 5730 | // FIXME: This happens during template instantiation, should we |
| 5731 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5732 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 5733 | "completed a tag from another module but not by instantiation?"); |
| 5734 | DeclUpdates[RD].push_back( |
| 5735 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5736 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5737 | } |
| 5738 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5739 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5740 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { |
| 5741 | if (D->isFromASTFile()) |
| 5742 | return true; |
| 5743 | |
| 5744 | // If we've not loaded any modules, this can't be imported. |
| 5745 | if (!Chain || !Chain->getModuleManager().size()) |
| 5746 | return false; |
| 5747 | |
| 5748 | // The predefined __va_list_tag struct is imported if we imported any decls. |
| 5749 | // FIXME: This is a gross hack. |
| 5750 | return D == D->getASTContext().getVaListTagDecl(); |
| 5751 | } |
| 5752 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5753 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Vassil Vassilev | 632eac3 | 2016-03-16 11:17:04 +0000 | [diff] [blame^] | 5754 | // TU is handled elsewhere. |
| 5755 | if (isa<TranslationUnitDecl>(DC)) |
| 5756 | return; |
| 5757 | |
| 5758 | // Namespaces are handled elsewhere, except for template instantiations of |
| 5759 | // FunctionTemplateDecls in namespaces. We are interested in cases where the |
| 5760 | // local instantiations are added to an imported context. Only happens when |
| 5761 | // adding ADL lookup candidates, for example templated friends. |
| 5762 | if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && |
| 5763 | !isa<FunctionTemplateDecl>(D)) |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5764 | return; |
| 5765 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5766 | // We're only interested in cases where a local declaration is added to an |
| 5767 | // imported context. |
| 5768 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) |
| 5769 | return; |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5770 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 5771 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5772 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5773 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5774 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { |
| 5775 | // We're adding a visible declaration to a predefined decl context. Ensure |
| 5776 | // that we write out all of its lookup results so we don't get a nasty |
| 5777 | // surprise when we try to emit its lookup table. |
| 5778 | for (auto *Child : DC->decls()) |
| 5779 | UpdatingVisibleDecls.push_back(Child); |
| 5780 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5781 | UpdatingVisibleDecls.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5782 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5783 | |
| 5784 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
| 5785 | assert(D->isImplicit()); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5786 | |
| 5787 | // We're only interested in cases where a local declaration is added to an |
| 5788 | // imported context. |
| 5789 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) |
| 5790 | return; |
| 5791 | |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5792 | if (!isa<CXXMethodDecl>(D)) |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5793 | return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5794 | |
| 5795 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5796 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5797 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5798 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5799 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5800 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5801 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5802 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 5803 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5804 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5805 | // If we don't already know the exception specification for this redecl |
| 5806 | // chain, add an update record for it. |
| 5807 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 5808 | ->getType() |
| 5809 | ->castAs<FunctionProtoType>() |
| 5810 | ->getExceptionSpecType())) |
| 5811 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 5812 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5813 | } |
| 5814 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5815 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
| 5816 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5817 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5818 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5819 | DeclUpdates[D].push_back( |
| 5820 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 5821 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5822 | } |
| 5823 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5824 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
| 5825 | const FunctionDecl *Delete) { |
| 5826 | assert(!WritingAST && "Already writing the AST!"); |
| 5827 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5828 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5829 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5830 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 5831 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5832 | } |
| 5833 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5834 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5835 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5836 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5837 | return; // Declaration not imported from PCH. |
| 5838 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5839 | // Implicit function decl from a PCH was defined. |
| 5840 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5841 | } |
| 5842 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5843 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
| 5844 | assert(!WritingAST && "Already writing the AST!"); |
| 5845 | if (!D->isFromASTFile()) |
| 5846 | return; |
| 5847 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5848 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5851 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5852 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5853 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5854 | return; |
| 5855 | |
| 5856 | // Since the actual instantiation is delayed, this really means that we need |
| 5857 | // to update the instantiation location. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5858 | DeclUpdates[D].push_back( |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5859 | DeclUpdate(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER, |
| 5860 | D->getMemberSpecializationInfo()->getPointOfInstantiation())); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5861 | } |
| 5862 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5863 | void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { |
| 5864 | assert(!WritingAST && "Already writing the AST!"); |
| 5865 | if (!D->isFromASTFile()) |
| 5866 | return; |
| 5867 | |
| 5868 | DeclUpdates[D].push_back( |
| 5869 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D)); |
| 5870 | } |
| 5871 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5872 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 5873 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5874 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5875 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5876 | return; // Declaration not imported from PCH. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5877 | |
| 5878 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 5879 | ObjCClassesWithCategories.insert( |
| 5880 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5881 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 5882 | |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5883 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
| 5884 | assert(!WritingAST && "Already writing the AST!"); |
| 5885 | if (!D->isFromASTFile()) |
| 5886 | return; |
| 5887 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5888 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5889 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5890 | |
| 5891 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
| 5892 | assert(!WritingAST && "Already writing the AST!"); |
| 5893 | if (!D->isFromASTFile()) |
| 5894 | return; |
| 5895 | |
| 5896 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 5897 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5898 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5899 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5900 | assert(!WritingAST && "Already writing the AST!"); |
| 5901 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5902 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5903 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5904 | |
| 5905 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 5906 | const RecordDecl *Record) { |
| 5907 | assert(!WritingAST && "Already writing the AST!"); |
| 5908 | if (!Record->isFromASTFile()) |
| 5909 | return; |
| 5910 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 5911 | } |