Sebastian Redl | d6522cf | 2010-08-18 23:56:31 +0000 | [diff] [blame] | 1 | //===--- ASTWriter.cpp - AST File Writer ----------------------------------===// |
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" |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 53 | #include "llvm/Support/EndianStream.h" |
Michael J. Spencer | 740857f | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 54 | #include "llvm/Support/FileSystem.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 55 | #include "llvm/Support/MemoryBuffer.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 56 | #include "llvm/Support/OnDiskHashTable.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 57 | #include "llvm/Support/Path.h" |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 58 | #include "llvm/Support/Process.h" |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 59 | #include <algorithm> |
Chris Lattner | 225dd6c | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 60 | #include <cstdio> |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 61 | #include <string.h> |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 62 | #include <utility> |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 63 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 64 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 65 | |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 66 | template <typename T, typename Allocator> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 67 | static StringRef bytes(const std::vector<T, Allocator> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 68 | if (v.empty()) return StringRef(); |
| 69 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 70 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 71 | } |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 72 | |
| 73 | template <typename T> |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 74 | static StringRef bytes(const SmallVectorImpl<T> &v) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 75 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 76 | sizeof(T) * v.size()); |
Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 79 | //===----------------------------------------------------------------------===// |
| 80 | // Type serialization |
| 81 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 82 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 83 | namespace { |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 84 | class ASTTypeWriter { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 85 | ASTWriter &Writer; |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 86 | ASTWriter::RecordDataImpl &Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 87 | |
| 88 | public: |
| 89 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 90 | TypeCode Code; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 91 | /// \brief Abbreviation to use for the record, if any. |
| 92 | unsigned AbbrevToUse; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 93 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 94 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 95 | : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 96 | |
| 97 | void VisitArrayType(const ArrayType *T); |
| 98 | void VisitFunctionType(const FunctionType *T); |
| 99 | void VisitTagType(const TagType *T); |
| 100 | |
| 101 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 102 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 103 | #include "clang/AST/TypeNodes.def" |
| 104 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 105 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 106 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 107 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 108 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 111 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 112 | Writer.AddTypeRef(T->getElementType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 113 | Code = TYPE_COMPLEX; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 116 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 117 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 118 | Code = TYPE_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 121 | void ASTTypeWriter::VisitDecayedType(const DecayedType *T) { |
| 122 | Writer.AddTypeRef(T->getOriginalType(), Record); |
| 123 | Code = TYPE_DECAYED; |
| 124 | } |
| 125 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 126 | void ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) { |
| 127 | Writer.AddTypeRef(T->getOriginalType(), Record); |
| 128 | Writer.AddTypeRef(T->getAdjustedType(), Record); |
| 129 | Code = TYPE_ADJUSTED; |
| 130 | } |
| 131 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 132 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 133 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 134 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 137 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 138 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
| 139 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 140 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 143 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 144 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 145 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 148 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 150 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 151 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 154 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 155 | Writer.AddTypeRef(T->getElementType(), Record); |
| 156 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 157 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 160 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 161 | VisitArrayType(T); |
| 162 | Writer.AddAPInt(T->getSize(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 163 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 166 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 167 | VisitArrayType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 168 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 171 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 172 | VisitArrayType(T); |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 173 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 174 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 175 | Writer.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 176 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 179 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 180 | Writer.AddTypeRef(T->getElementType(), Record); |
| 181 | Record.push_back(T->getNumElements()); |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 182 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 183 | Code = TYPE_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 186 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 187 | VisitVectorType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 188 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 191 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 192 | Writer.AddTypeRef(T->getReturnType(), Record); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 193 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 194 | Record.push_back(C.getNoReturn()); |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 195 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 196 | Record.push_back(C.getRegParm()); |
Douglas Gregor | 8c94086 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 197 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 198 | Record.push_back(C.getCC()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 199 | Record.push_back(C.getProducesResult()); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 200 | |
| 201 | if (C.getHasRegParm() || C.getRegParm() || C.getProducesResult()) |
| 202 | AbbrevToUse = 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 205 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 206 | VisitFunctionType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 207 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 210 | static void addExceptionSpec(ASTWriter &Writer, const FunctionProtoType *T, |
| 211 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 212 | Record.push_back(T->getExceptionSpecType()); |
| 213 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 214 | Record.push_back(T->getNumExceptions()); |
| 215 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 216 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 217 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 218 | Writer.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 8b987a9 | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 219 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
| 220 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
| 221 | Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record); |
Richard Smith | d3b5c908 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 222 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
| 223 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 224 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 228 | VisitFunctionType(T); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 229 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 230 | Record.push_back(T->isVariadic()); |
| 231 | Record.push_back(T->hasTrailingReturn()); |
| 232 | Record.push_back(T->getTypeQuals()); |
| 233 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
| 234 | addExceptionSpec(Writer, T, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 235 | |
| 236 | Record.push_back(T->getNumParams()); |
| 237 | for (unsigned I = 0, N = T->getNumParams(); I != N; ++I) |
| 238 | Writer.AddTypeRef(T->getParamType(I), Record); |
| 239 | |
| 240 | if (T->isVariadic() || T->hasTrailingReturn() || T->getTypeQuals() || |
| 241 | T->getRefQualifier() || T->getExceptionSpecType() != EST_None) |
| 242 | AbbrevToUse = 0; |
| 243 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 244 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 247 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 248 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 249 | Code = TYPE_UNRESOLVED_USING; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 250 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 251 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 252 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 253 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 254 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 255 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 256 | Code = TYPE_TYPEDEF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 259 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 260 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 261 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 264 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 265 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 266 | Code = TYPE_TYPEOF; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 269 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 270 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 271 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 272 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 275 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 276 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 277 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 278 | Record.push_back(T->getUTTKind()); |
| 279 | Code = TYPE_UNARY_TRANSFORM; |
| 280 | } |
| 281 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 282 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 283 | Writer.AddTypeRef(T->getDeducedType(), Record); |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 284 | Record.push_back(T->isDecltypeAuto()); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 285 | if (T->getDeducedType().isNull()) |
| 286 | Record.push_back(T->isDependentType()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 287 | Code = TYPE_AUTO; |
| 288 | } |
| 289 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 290 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 291 | Record.push_back(T->isDependentType()); |
Douglas Gregor | f3bccd7 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 292 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | assert(!T->isBeingDefined() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 294 | "Cannot serialize in the middle of a type definition"); |
| 295 | } |
| 296 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 297 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 298 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 299 | Code = TYPE_RECORD; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 302 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 303 | VisitTagType(T); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 304 | Code = TYPE_ENUM; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 305 | } |
| 306 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 307 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 308 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 309 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 310 | Record.push_back(T->getAttrKind()); |
| 311 | Code = TYPE_ATTRIBUTED; |
| 312 | } |
| 313 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 314 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 315 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 316 | const SubstTemplateTypeParmType *T) { |
| 317 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 318 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 319 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | void |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 323 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 324 | const SubstTemplateTypeParmPackType *T) { |
| 325 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 326 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 327 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 328 | } |
| 329 | |
| 330 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 331 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 332 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 333 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 334 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 335 | Record.push_back(T->getNumArgs()); |
| 336 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 337 | ArgI != ArgE; ++ArgI) |
| 338 | Writer.AddTemplateArgument(*ArgI, Record); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 339 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 340 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 341 | : T->getCanonicalTypeInternal(), |
| 342 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 343 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 347 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 348 | VisitArrayType(T); |
| 349 | Writer.AddStmt(T->getSizeExpr()); |
| 350 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 351 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 355 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 356 | const DependentSizedExtVectorType *T) { |
| 357 | // FIXME: Serialize this type (C++ only) |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 358 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
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::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 363 | Record.push_back(T->getDepth()); |
| 364 | Record.push_back(T->getIndex()); |
| 365 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 366 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 367 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 371 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 372 | Record.push_back(T->getKeyword()); |
| 373 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 374 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 375 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 376 | : T->getCanonicalTypeInternal(), |
| 377 | Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 378 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 382 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 383 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 384 | Record.push_back(T->getKeyword()); |
| 385 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 386 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 387 | Record.push_back(T->getNumArgs()); |
| 388 | for (DependentTemplateSpecializationType::iterator |
| 389 | I = T->begin(), E = T->end(); I != E; ++I) |
| 390 | Writer.AddTemplateArgument(*I, Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 391 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 394 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 395 | Writer.AddTypeRef(T->getPattern(), Record); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 396 | if (Optional<unsigned> NumExpansions = T->getNumExpansions()) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 397 | Record.push_back(*NumExpansions + 1); |
| 398 | else |
| 399 | Record.push_back(0); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 400 | Code = TYPE_PACK_EXPANSION; |
| 401 | } |
| 402 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 403 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 404 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 405 | Code = TYPE_PAREN; |
| 406 | } |
| 407 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 408 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 409 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 410 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 411 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 412 | Code = TYPE_ELABORATED; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 415 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Douglas Gregor | 9f21889 | 2012-03-26 15:52:37 +0000 | [diff] [blame] | 416 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
John McCall | 2408e32 | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 417 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 418 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 421 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | f3bccd7 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 422 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 423 | Code = TYPE_OBJC_INTERFACE; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 426 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 427 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 428 | Record.push_back(T->getTypeArgsAsWritten().size()); |
| 429 | for (auto TypeArg : T->getTypeArgsAsWritten()) |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 430 | Writer.AddTypeRef(TypeArg, Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 431 | Record.push_back(T->getNumProtocols()); |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 432 | for (const auto *I : T->quals()) |
| 433 | Writer.AddDeclRef(I, Record); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 434 | Record.push_back(T->isKindOfTypeAsWritten()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 435 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 438 | void |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 439 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 441 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 444 | void |
| 445 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
| 446 | Writer.AddTypeRef(T->getValueType(), Record); |
| 447 | Code = TYPE_ATOMIC; |
| 448 | } |
| 449 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 450 | namespace { |
| 451 | |
| 452 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 453 | ASTWriter &Writer; |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 454 | ASTWriter::RecordDataImpl &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 455 | |
| 456 | public: |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 457 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 458 | : Writer(Writer), Record(Record) { } |
| 459 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 460 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 461 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 462 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 463 | #include "clang/AST/TypeLocNodes.def" |
| 464 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 465 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 466 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 467 | }; |
| 468 | |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 469 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 470 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 471 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 472 | // nothing to do |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 473 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 474 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 475 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 476 | if (TL.needsExtraLocalData()) { |
| 477 | Record.push_back(TL.getWrittenTypeSpec()); |
| 478 | Record.push_back(TL.getWrittenSignSpec()); |
| 479 | Record.push_back(TL.getWrittenWidthSpec()); |
| 480 | Record.push_back(TL.hasModeAttr()); |
| 481 | } |
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::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 484 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
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::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 487 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 488 | } |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 489 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 490 | // nothing to do |
| 491 | } |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 492 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 493 | // nothing to do |
| 494 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 495 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 496 | Writer.AddSourceLocation(TL.getCaretLoc(), 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::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 499 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 500 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 501 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 502 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 503 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 504 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 505 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 506 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 507 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 508 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 509 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 510 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 511 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 512 | if (TL.getSizeExpr()) |
| 513 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 514 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 515 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 516 | VisitArrayTypeLoc(TL); |
| 517 | } |
| 518 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 519 | VisitArrayTypeLoc(TL); |
| 520 | } |
| 521 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 522 | VisitArrayTypeLoc(TL); |
| 523 | } |
| 524 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 525 | DependentSizedArrayTypeLoc TL) { |
| 526 | VisitArrayTypeLoc(TL); |
| 527 | } |
| 528 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 529 | DependentSizedExtVectorTypeLoc TL) { |
| 530 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 531 | } |
| 532 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 533 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 534 | } |
| 535 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 536 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 537 | } |
| 538 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 539 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 540 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 541 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 542 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 543 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) |
| 544 | Writer.AddDeclRef(TL.getParam(i), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 545 | } |
| 546 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 547 | VisitFunctionTypeLoc(TL); |
| 548 | } |
| 549 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 550 | VisitFunctionTypeLoc(TL); |
| 551 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 552 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 553 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 554 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 555 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 556 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 557 | } |
| 558 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 559 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 560 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 561 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 562 | } |
| 563 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 564 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 565 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 566 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 567 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 568 | } |
| 569 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 570 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 571 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 572 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 573 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 574 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 575 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 576 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 577 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 578 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 579 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 580 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 581 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 582 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 583 | } |
| 584 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 585 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 586 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 587 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 588 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 589 | if (TL.hasAttrOperand()) { |
| 590 | SourceRange range = TL.getAttrOperandParensRange(); |
| 591 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 592 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 593 | } |
| 594 | if (TL.hasAttrExprOperand()) { |
| 595 | Expr *operand = TL.getAttrExprOperand(); |
| 596 | Record.push_back(operand ? 1 : 0); |
| 597 | if (operand) Writer.AddStmt(operand); |
| 598 | } else if (TL.hasAttrEnumOperand()) { |
| 599 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 600 | } |
| 601 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 602 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 603 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 604 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 605 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 606 | SubstTemplateTypeParmTypeLoc TL) { |
| 607 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 608 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 609 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 610 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 611 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 612 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 613 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 614 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 615 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 616 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 617 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 618 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 619 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 620 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 621 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 622 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 623 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 624 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 625 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 626 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 627 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 628 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 629 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 630 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 631 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 632 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 633 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 634 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 635 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 636 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 637 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 638 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 639 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 640 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 641 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 642 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 643 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 644 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 645 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 646 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 647 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 648 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 649 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 650 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 651 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 652 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 653 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 654 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 655 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 656 | } |
| 657 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 658 | Record.push_back(TL.hasBaseTypeAsWritten()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 659 | Writer.AddSourceLocation(TL.getTypeArgsLAngleLoc(), Record); |
| 660 | Writer.AddSourceLocation(TL.getTypeArgsRAngleLoc(), Record); |
| 661 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
| 662 | Writer.AddTypeSourceInfo(TL.getTypeArgTInfo(i), Record); |
| 663 | Writer.AddSourceLocation(TL.getProtocolLAngleLoc(), Record); |
| 664 | Writer.AddSourceLocation(TL.getProtocolRAngleLoc(), Record); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 665 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 666 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 667 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 668 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 669 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 670 | } |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 671 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 672 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 673 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 674 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 675 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 676 | |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 677 | void ASTWriter::WriteTypeAbbrevs() { |
| 678 | using namespace llvm; |
| 679 | |
| 680 | BitCodeAbbrev *Abv; |
| 681 | |
| 682 | // Abbreviation for TYPE_EXT_QUAL |
| 683 | Abv = new BitCodeAbbrev(); |
| 684 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); |
| 685 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
| 686 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3)); // Quals |
| 687 | TypeExtQualAbbrev = Stream.EmitAbbrev(Abv); |
| 688 | |
| 689 | // Abbreviation for TYPE_FUNCTION_PROTO |
| 690 | Abv = new BitCodeAbbrev(); |
| 691 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); |
| 692 | // FunctionType |
| 693 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ReturnType |
| 694 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn |
| 695 | Abv->Add(BitCodeAbbrevOp(0)); // HasRegParm |
| 696 | Abv->Add(BitCodeAbbrevOp(0)); // RegParm |
| 697 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC |
| 698 | Abv->Add(BitCodeAbbrevOp(0)); // ProducesResult |
| 699 | // FunctionProtoType |
| 700 | Abv->Add(BitCodeAbbrevOp(0)); // IsVariadic |
| 701 | Abv->Add(BitCodeAbbrevOp(0)); // HasTrailingReturn |
| 702 | Abv->Add(BitCodeAbbrevOp(0)); // TypeQuals |
| 703 | Abv->Add(BitCodeAbbrevOp(0)); // RefQualifier |
| 704 | Abv->Add(BitCodeAbbrevOp(EST_None)); // ExceptionSpec |
| 705 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumParams |
| 706 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 707 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Params |
| 708 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(Abv); |
| 709 | } |
| 710 | |
Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 711 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 712 | // ASTWriter Implementation |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 713 | //===----------------------------------------------------------------------===// |
| 714 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 715 | static void EmitBlockID(unsigned ID, const char *Name, |
| 716 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 717 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 718 | Record.clear(); |
| 719 | Record.push_back(ID); |
| 720 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 721 | |
| 722 | // Emit the block name if present. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 723 | if (!Name || Name[0] == 0) |
| 724 | return; |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 725 | Record.clear(); |
| 726 | while (*Name) |
| 727 | Record.push_back(*Name++); |
| 728 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 729 | } |
| 730 | |
| 731 | static void EmitRecordID(unsigned ID, const char *Name, |
| 732 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 733 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 734 | Record.clear(); |
| 735 | Record.push_back(ID); |
| 736 | while (*Name) |
| 737 | Record.push_back(*Name++); |
| 738 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 742 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 743 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 744 | RECORD(STMT_STOP); |
| 745 | RECORD(STMT_NULL_PTR); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 746 | RECORD(STMT_REF_PTR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 747 | RECORD(STMT_NULL); |
| 748 | RECORD(STMT_COMPOUND); |
| 749 | RECORD(STMT_CASE); |
| 750 | RECORD(STMT_DEFAULT); |
| 751 | RECORD(STMT_LABEL); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 752 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 753 | RECORD(STMT_IF); |
| 754 | RECORD(STMT_SWITCH); |
| 755 | RECORD(STMT_WHILE); |
| 756 | RECORD(STMT_DO); |
| 757 | RECORD(STMT_FOR); |
| 758 | RECORD(STMT_GOTO); |
| 759 | RECORD(STMT_INDIRECT_GOTO); |
| 760 | RECORD(STMT_CONTINUE); |
| 761 | RECORD(STMT_BREAK); |
| 762 | RECORD(STMT_RETURN); |
| 763 | RECORD(STMT_DECL); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 764 | RECORD(STMT_GCCASM); |
Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 765 | RECORD(STMT_MSASM); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 766 | RECORD(EXPR_PREDEFINED); |
| 767 | RECORD(EXPR_DECL_REF); |
| 768 | RECORD(EXPR_INTEGER_LITERAL); |
| 769 | RECORD(EXPR_FLOATING_LITERAL); |
| 770 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 771 | RECORD(EXPR_STRING_LITERAL); |
| 772 | RECORD(EXPR_CHARACTER_LITERAL); |
| 773 | RECORD(EXPR_PAREN); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 774 | RECORD(EXPR_PAREN_LIST); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 775 | RECORD(EXPR_UNARY_OPERATOR); |
| 776 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 777 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 778 | RECORD(EXPR_CALL); |
| 779 | RECORD(EXPR_MEMBER); |
| 780 | RECORD(EXPR_BINARY_OPERATOR); |
| 781 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 782 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 783 | RECORD(EXPR_IMPLICIT_CAST); |
| 784 | RECORD(EXPR_CSTYLE_CAST); |
| 785 | RECORD(EXPR_COMPOUND_LITERAL); |
| 786 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 787 | RECORD(EXPR_INIT_LIST); |
| 788 | RECORD(EXPR_DESIGNATED_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 789 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 790 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 791 | RECORD(EXPR_NO_INIT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 792 | RECORD(EXPR_VA_ARG); |
| 793 | RECORD(EXPR_ADDR_LABEL); |
| 794 | RECORD(EXPR_STMT); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 795 | RECORD(EXPR_CHOOSE); |
| 796 | RECORD(EXPR_GNU_NULL); |
| 797 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 798 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 799 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 800 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 801 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 802 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 803 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 804 | RECORD(EXPR_OBJC_ENCODE); |
| 805 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 806 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 807 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 808 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 809 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 810 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 811 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 812 | RECORD(STMT_OBJC_CATCH); |
| 813 | RECORD(STMT_OBJC_FINALLY); |
| 814 | RECORD(STMT_OBJC_AT_TRY); |
| 815 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 816 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 817 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 818 | RECORD(STMT_CXX_CATCH); |
| 819 | RECORD(STMT_CXX_TRY); |
| 820 | RECORD(STMT_CXX_FOR_RANGE); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 821 | RECORD(EXPR_CXX_OPERATOR_CALL); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 822 | RECORD(EXPR_CXX_MEMBER_CALL); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 823 | RECORD(EXPR_CXX_CONSTRUCT); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 824 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 825 | RECORD(EXPR_CXX_STATIC_CAST); |
| 826 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 827 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 828 | RECORD(EXPR_CXX_CONST_CAST); |
| 829 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 830 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 831 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); |
Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 832 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 833 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 834 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 835 | RECORD(EXPR_CXX_TYPEID_TYPE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 836 | RECORD(EXPR_CXX_THIS); |
| 837 | RECORD(EXPR_CXX_THROW); |
| 838 | RECORD(EXPR_CXX_DEFAULT_ARG); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 839 | RECORD(EXPR_CXX_DEFAULT_INIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 840 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 841 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 842 | RECORD(EXPR_CXX_NEW); |
| 843 | RECORD(EXPR_CXX_DELETE); |
| 844 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 845 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 846 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 847 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 848 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 849 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 850 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 851 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 852 | RECORD(EXPR_CXX_NOEXCEPT); |
| 853 | RECORD(EXPR_OPAQUE_VALUE); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 854 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); |
| 855 | RECORD(EXPR_TYPE_TRAIT); |
| 856 | RECORD(EXPR_ARRAY_TYPE_TRAIT); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 857 | RECORD(EXPR_PACK_EXPANSION); |
| 858 | RECORD(EXPR_SIZEOF_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 859 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 860 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 861 | RECORD(EXPR_FUNCTION_PARM_PACK); |
| 862 | RECORD(EXPR_MATERIALIZE_TEMPORARY); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 863 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 864 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 865 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 866 | RECORD(EXPR_LAMBDA); |
Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 867 | #undef RECORD |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 868 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 870 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 871 | RecordData Record; |
| 872 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 873 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 874 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 875 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 876 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 877 | // Control Block. |
| 878 | BLOCK(CONTROL_BLOCK); |
| 879 | RECORD(METADATA); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 880 | RECORD(SIGNATURE); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 881 | RECORD(MODULE_NAME); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 882 | RECORD(MODULE_DIRECTORY); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 883 | RECORD(MODULE_MAP_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 884 | RECORD(IMPORTS); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 885 | RECORD(ORIGINAL_FILE); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 886 | RECORD(ORIGINAL_PCH_DIR); |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 887 | RECORD(ORIGINAL_FILE_ID); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 888 | RECORD(INPUT_FILE_OFFSETS); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 889 | |
| 890 | BLOCK(OPTIONS_BLOCK); |
| 891 | RECORD(LANGUAGE_OPTIONS); |
| 892 | RECORD(TARGET_OPTIONS); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 893 | RECORD(DIAGNOSTIC_OPTIONS); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 894 | RECORD(FILE_SYSTEM_OPTIONS); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 895 | RECORD(HEADER_SEARCH_OPTIONS); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 896 | RECORD(PREPROCESSOR_OPTIONS); |
| 897 | |
Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 898 | BLOCK(INPUT_FILES_BLOCK); |
| 899 | RECORD(INPUT_FILE); |
| 900 | |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 901 | // AST Top-Level Block. |
| 902 | BLOCK(AST_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 903 | RECORD(TYPE_OFFSET); |
| 904 | RECORD(DECL_OFFSET); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 905 | RECORD(IDENTIFIER_OFFSET); |
| 906 | RECORD(IDENTIFIER_TABLE); |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 907 | RECORD(EAGERLY_DESERIALIZED_DECLS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 908 | RECORD(SPECIAL_TYPES); |
| 909 | RECORD(STATISTICS); |
| 910 | RECORD(TENTATIVE_DEFINITIONS); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 911 | RECORD(SELECTOR_OFFSETS); |
| 912 | RECORD(METHOD_POOL); |
| 913 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 914 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 915 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 916 | RECORD(EXT_VECTOR_DECLS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 917 | RECORD(UNUSED_FILESCOPED_DECLS); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 918 | RECORD(PPD_ENTITIES_OFFSETS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 919 | RECORD(VTABLE_USES); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 920 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 921 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 922 | RECORD(SEMA_DECL_REFS); |
| 923 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 924 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 925 | RECORD(DECL_REPLACEMENTS); |
| 926 | RECORD(UPDATE_VISIBLE); |
| 927 | RECORD(DECL_UPDATE_OFFSETS); |
| 928 | RECORD(DECL_UPDATES); |
| 929 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 930 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 931 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 932 | RECORD(HEADER_SEARCH_TABLE); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 933 | RECORD(FP_PRAGMA_OPTIONS); |
| 934 | RECORD(OPENCL_EXTENSIONS); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 935 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 936 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 937 | RECORD(MODULE_OFFSET_MAP); |
| 938 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 939 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 940 | RECORD(FILE_SORTED_DECLS); |
| 941 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 942 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 943 | RECORD(MACRO_OFFSET); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 944 | RECORD(INTERESTING_IDENTIFIERS); |
| 945 | RECORD(UNDEFINED_BUT_USED); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 946 | RECORD(LATE_PARSED_TEMPLATE); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 947 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 948 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); |
| 949 | RECORD(CXX_CTOR_INITIALIZERS_OFFSETS); |
| 950 | RECORD(DELETE_EXPRS_TO_ANALYZE); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 951 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 952 | // SourceManager Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 953 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 954 | RECORD(SM_SLOC_FILE_ENTRY); |
| 955 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 956 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 957 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 959 | // Preprocessor Block. |
Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 960 | BLOCK(PREPROCESSOR_BLOCK); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 961 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 962 | RECORD(PP_MACRO_FUNCTION_LIKE); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 963 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 964 | RECORD(PP_MODULE_MACRO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 965 | RECORD(PP_TOKEN); |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 966 | |
Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 967 | // Submodule Block. |
| 968 | BLOCK(SUBMODULE_BLOCK); |
| 969 | RECORD(SUBMODULE_METADATA); |
| 970 | RECORD(SUBMODULE_DEFINITION); |
| 971 | RECORD(SUBMODULE_UMBRELLA_HEADER); |
| 972 | RECORD(SUBMODULE_HEADER); |
| 973 | RECORD(SUBMODULE_TOPHEADER); |
| 974 | RECORD(SUBMODULE_UMBRELLA_DIR); |
| 975 | RECORD(SUBMODULE_IMPORTS); |
| 976 | RECORD(SUBMODULE_EXPORTS); |
| 977 | RECORD(SUBMODULE_REQUIRES); |
| 978 | RECORD(SUBMODULE_EXCLUDED_HEADER); |
| 979 | RECORD(SUBMODULE_LINK_LIBRARY); |
| 980 | RECORD(SUBMODULE_CONFIG_MACRO); |
| 981 | RECORD(SUBMODULE_CONFLICT); |
| 982 | RECORD(SUBMODULE_PRIVATE_HEADER); |
| 983 | RECORD(SUBMODULE_TEXTUAL_HEADER); |
| 984 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); |
| 985 | |
| 986 | // Comments Block. |
| 987 | BLOCK(COMMENTS_BLOCK); |
| 988 | RECORD(COMMENTS_RAW_COMMENT); |
| 989 | |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 990 | // Decls and Types block. |
| 991 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 992 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 993 | RECORD(TYPE_COMPLEX); |
| 994 | RECORD(TYPE_POINTER); |
| 995 | RECORD(TYPE_BLOCK_POINTER); |
| 996 | RECORD(TYPE_LVALUE_REFERENCE); |
| 997 | RECORD(TYPE_RVALUE_REFERENCE); |
| 998 | RECORD(TYPE_MEMBER_POINTER); |
| 999 | RECORD(TYPE_CONSTANT_ARRAY); |
| 1000 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 1001 | RECORD(TYPE_VARIABLE_ARRAY); |
| 1002 | RECORD(TYPE_VECTOR); |
| 1003 | RECORD(TYPE_EXT_VECTOR); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1004 | RECORD(TYPE_FUNCTION_NO_PROTO); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1005 | RECORD(TYPE_FUNCTION_PROTO); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1006 | RECORD(TYPE_TYPEDEF); |
| 1007 | RECORD(TYPE_TYPEOF_EXPR); |
| 1008 | RECORD(TYPE_TYPEOF); |
| 1009 | RECORD(TYPE_RECORD); |
| 1010 | RECORD(TYPE_ENUM); |
| 1011 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1012 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1013 | RECORD(TYPE_DECLTYPE); |
| 1014 | RECORD(TYPE_ELABORATED); |
| 1015 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 1016 | RECORD(TYPE_UNRESOLVED_USING); |
| 1017 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 1018 | RECORD(TYPE_OBJC_OBJECT); |
| 1019 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 1020 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 1021 | RECORD(TYPE_DEPENDENT_NAME); |
| 1022 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 1023 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 1024 | RECORD(TYPE_PAREN); |
| 1025 | RECORD(TYPE_PACK_EXPANSION); |
| 1026 | RECORD(TYPE_ATTRIBUTED); |
| 1027 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1028 | RECORD(TYPE_AUTO); |
| 1029 | RECORD(TYPE_UNARY_TRANSFORM); |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1030 | RECORD(TYPE_ATOMIC); |
Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 1031 | RECORD(TYPE_DECAYED); |
| 1032 | RECORD(TYPE_ADJUSTED); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 1033 | RECORD(LOCAL_REDECLARATIONS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1034 | RECORD(DECL_TYPEDEF); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 1035 | RECORD(DECL_TYPEALIAS); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1036 | RECORD(DECL_ENUM); |
| 1037 | RECORD(DECL_RECORD); |
| 1038 | RECORD(DECL_ENUM_CONSTANT); |
| 1039 | RECORD(DECL_FUNCTION); |
| 1040 | RECORD(DECL_OBJC_METHOD); |
| 1041 | RECORD(DECL_OBJC_INTERFACE); |
| 1042 | RECORD(DECL_OBJC_PROTOCOL); |
| 1043 | RECORD(DECL_OBJC_IVAR); |
| 1044 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1045 | RECORD(DECL_OBJC_CATEGORY); |
| 1046 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 1047 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 1048 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 1049 | RECORD(DECL_OBJC_PROPERTY); |
| 1050 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1051 | RECORD(DECL_FIELD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1052 | RECORD(DECL_MS_PROPERTY); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1053 | RECORD(DECL_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1054 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1055 | RECORD(DECL_PARM_VAR); |
Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 1056 | RECORD(DECL_FILE_SCOPE_ASM); |
| 1057 | RECORD(DECL_BLOCK); |
| 1058 | RECORD(DECL_CONTEXT_LEXICAL); |
| 1059 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1060 | RECORD(DECL_NAMESPACE); |
| 1061 | RECORD(DECL_NAMESPACE_ALIAS); |
| 1062 | RECORD(DECL_USING); |
| 1063 | RECORD(DECL_USING_SHADOW); |
| 1064 | RECORD(DECL_USING_DIRECTIVE); |
| 1065 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 1066 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 1067 | RECORD(DECL_LINKAGE_SPEC); |
| 1068 | RECORD(DECL_CXX_RECORD); |
| 1069 | RECORD(DECL_CXX_METHOD); |
| 1070 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 1071 | RECORD(DECL_CXX_DESTRUCTOR); |
| 1072 | RECORD(DECL_CXX_CONVERSION); |
| 1073 | RECORD(DECL_ACCESS_SPEC); |
| 1074 | RECORD(DECL_FRIEND); |
| 1075 | RECORD(DECL_FRIEND_TEMPLATE); |
| 1076 | RECORD(DECL_CLASS_TEMPLATE); |
| 1077 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 1078 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1079 | RECORD(DECL_VAR_TEMPLATE); |
| 1080 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); |
| 1081 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); |
Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 1082 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 1083 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 1084 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 1085 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 1086 | RECORD(DECL_STATIC_ASSERT); |
| 1087 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 1088 | RECORD(DECL_INDIRECTFIELD); |
| 1089 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 1090 | |
Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 1091 | // Statements and Exprs can occur in the Decls and Types block. |
| 1092 | AddStmtsExprs(Stream, Record); |
| 1093 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1094 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1095 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1096 | RECORD(PPD_MACRO_DEFINITION); |
| 1097 | RECORD(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 1098 | |
| 1099 | // Decls and Types block. |
| 1100 | BLOCK(EXTENSION_BLOCK); |
| 1101 | RECORD(EXTENSION_METADATA); |
| 1102 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1103 | #undef RECORD |
| 1104 | #undef BLOCK |
| 1105 | Stream.ExitBlock(); |
| 1106 | } |
| 1107 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1108 | /// \brief Prepares a path for being written to an AST file by converting it |
| 1109 | /// to an absolute path and removing nested './'s. |
| 1110 | /// |
| 1111 | /// \return \c true if the path was changed. |
Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 1112 | static bool cleanPathForOutput(FileManager &FileMgr, |
| 1113 | SmallVectorImpl<char> &Path) { |
Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 1114 | bool Changed = FileMgr.makeAbsolutePath(Path); |
Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame^] | 1115 | return Changed | llvm::sys::path::remove_dots(Path); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1118 | /// \brief Adjusts the given filename to only write out the portion of the |
| 1119 | /// filename that is not part of the system root directory. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1120 | /// |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1121 | /// \param Filename the file name to adjust. |
| 1122 | /// |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1123 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and |
| 1124 | /// the returned filename will be adjusted by this root directory. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1125 | /// |
| 1126 | /// \returns either the original filename (if it needs no adjustment) or the |
| 1127 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | static const char * |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1129 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1130 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1132 | if (BaseDir.empty()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1133 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1134 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1135 | // Verify that the filename and the system root have the same prefix. |
| 1136 | unsigned Pos = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1137 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) |
| 1138 | if (Filename[Pos] != BaseDir[Pos]) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1139 | return Filename; // Prefixes don't match. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1141 | // We hit the end of the filename before we hit the end of the system root. |
| 1142 | if (!Filename[Pos]) |
| 1143 | return Filename; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1145 | // If there's not a path separator at the end of the base directory nor |
| 1146 | // immediately after it, then this isn't within the base directory. |
| 1147 | if (!llvm::sys::path::is_separator(Filename[Pos])) { |
| 1148 | if (!llvm::sys::path::is_separator(BaseDir.back())) |
| 1149 | return Filename; |
| 1150 | } else { |
| 1151 | // If the file name has a '/' at the current position, skip over the '/'. |
| 1152 | // We distinguish relative paths from absolute paths by the |
| 1153 | // absence of '/' at the beginning of relative paths. |
| 1154 | // |
| 1155 | // FIXME: This is wrong. We distinguish them by asking if the path is |
| 1156 | // absolute, which isn't the same thing. And there might be multiple '/'s |
| 1157 | // in a row. Use a better mechanism to indicate whether we have emitted an |
| 1158 | // absolute or relative path. |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1159 | ++Pos; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1160 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1162 | return Filename + Pos; |
| 1163 | } |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1164 | |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1165 | static ASTFileSignature getSignature() { |
| 1166 | while (1) { |
| 1167 | if (ASTFileSignature S = llvm::sys::Process::GetRandomNumber()) |
| 1168 | return S; |
| 1169 | // Rely on GetRandomNumber to eventually return non-zero... |
| 1170 | } |
| 1171 | } |
| 1172 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1173 | /// \brief Write the control block. |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1174 | uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP, |
| 1175 | ASTContext &Context, |
| 1176 | StringRef isysroot, |
| 1177 | const std::string &OutputFile) { |
| 1178 | ASTFileSignature Signature = 0; |
| 1179 | |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1180 | using namespace llvm; |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1181 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1182 | RecordData Record; |
| 1183 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1184 | // Metadata |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1185 | BitCodeAbbrev *MetadataAbbrev = new BitCodeAbbrev(); |
| 1186 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
| 1187 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major |
| 1188 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor |
| 1189 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. |
| 1190 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. |
| 1191 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1192 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1193 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors |
| 1194 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1195 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1196 | assert((!WritingModule || isysroot.empty()) && |
| 1197 | "writing module as a relocatable PCH?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1198 | { |
| 1199 | RecordData::value_type Record[] = {METADATA, VERSION_MAJOR, VERSION_MINOR, |
| 1200 | CLANG_VERSION_MAJOR, CLANG_VERSION_MINOR, |
| 1201 | !isysroot.empty(), IncludeTimestamps, |
| 1202 | ASTHasCompilerErrors}; |
| 1203 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, |
| 1204 | getClangFullRepositoryVersion()); |
| 1205 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1206 | if (WritingModule) { |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1207 | // For implicit modules we output a signature that we can use to ensure |
| 1208 | // duplicate module builds don't collide in the cache as their output order |
| 1209 | // is non-deterministic. |
| 1210 | // FIXME: Remove this when output is deterministic. |
| 1211 | if (Context.getLangOpts().ImplicitModules) { |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1212 | Signature = getSignature(); |
| 1213 | RecordData::value_type Record[] = {Signature}; |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1214 | Stream.EmitRecord(SIGNATURE, Record); |
| 1215 | } |
| 1216 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1217 | // Module name |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1218 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1219 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); |
| 1220 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1221 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1222 | RecordData::value_type Record[] = {MODULE_NAME}; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1223 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); |
| 1224 | } |
| 1225 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1226 | if (WritingModule && WritingModule->Directory) { |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1227 | SmallString<128> BaseDir(WritingModule->Directory->getName()); |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1228 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1229 | |
| 1230 | // If the home of the module is the current working directory, then we |
| 1231 | // want to pick up the cwd of the build process loading the module, not |
| 1232 | // our cwd, when we load this module. |
| 1233 | if (!PP.getHeaderSearchInfo() |
| 1234 | .getHeaderSearchOpts() |
| 1235 | .ModuleMapFileHomeIsCwd || |
| 1236 | WritingModule->Directory->getName() != StringRef(".")) { |
| 1237 | // Module directory. |
| 1238 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1239 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); |
| 1240 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory |
| 1241 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1242 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1243 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; |
Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1244 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); |
| 1245 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1246 | |
| 1247 | // Write out all other paths relative to the base directory if possible. |
| 1248 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); |
| 1249 | } else if (!isysroot.empty()) { |
| 1250 | // Write out paths relative to the sysroot if possible. |
| 1251 | BaseDirectory = isysroot; |
| 1252 | } |
| 1253 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1254 | // Module map file |
| 1255 | if (WritingModule) { |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1256 | Record.clear(); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1257 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1258 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 1259 | |
| 1260 | // Primary module map file. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1261 | AddPath(Map.getModuleMapFileForUniquing(WritingModule)->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1262 | |
| 1263 | // Additional module map files. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1264 | if (auto *AdditionalModMaps = |
| 1265 | Map.getAdditionalModuleMapFiles(WritingModule)) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1266 | Record.push_back(AdditionalModMaps->size()); |
| 1267 | for (const FileEntry *F : *AdditionalModMaps) |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1268 | AddPath(F->getName(), Record); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1269 | } else { |
| 1270 | Record.push_back(0); |
| 1271 | } |
| 1272 | |
| 1273 | Stream.EmitRecord(MODULE_MAP_FILE, Record); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1276 | // Imports |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1277 | if (Chain) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1278 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1279 | Record.clear(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1280 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1281 | for (auto *M : Mgr) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1282 | // Skip modules that weren't directly imported. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1283 | if (!M->isDirectlyImported()) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1284 | continue; |
| 1285 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1286 | Record.push_back((unsigned)M->Kind); // FIXME: Stable encoding |
| 1287 | AddSourceLocation(M->ImportLoc, Record); |
| 1288 | Record.push_back(M->File->getSize()); |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1289 | Record.push_back(getTimestampForOutput(M->File)); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 1290 | Record.push_back(M->Signature); |
| 1291 | AddPath(M->FileName, Record); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1292 | } |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1293 | Stream.EmitRecord(IMPORTS, Record); |
| 1294 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1296 | // Write the options block. |
| 1297 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); |
| 1298 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1299 | // Language options. |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1300 | Record.clear(); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1301 | const LangOptions &LangOpts = Context.getLangOpts(); |
| 1302 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1303 | Record.push_back(LangOpts.Name); |
| 1304 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1305 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1306 | #include "clang/Basic/LangOptions.def" |
| 1307 | #define SANITIZER(NAME, ID) \ |
| 1308 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1309 | #include "clang/Basic/Sanitizers.def" |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1310 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1311 | Record.push_back(LangOpts.ModuleFeatures.size()); |
| 1312 | for (StringRef Feature : LangOpts.ModuleFeatures) |
| 1313 | AddString(Feature, Record); |
| 1314 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1315 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1316 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1317 | |
| 1318 | AddString(LangOpts.CurrentModule, Record); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1319 | |
| 1320 | // Comment options. |
| 1321 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); |
| 1322 | for (CommentOptions::BlockCommandNamesTy::const_iterator |
| 1323 | I = LangOpts.CommentOpts.BlockCommandNames.begin(), |
| 1324 | IEnd = LangOpts.CommentOpts.BlockCommandNames.end(); |
| 1325 | I != IEnd; ++I) { |
| 1326 | AddString(*I, Record); |
| 1327 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1328 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1329 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1330 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
| 1331 | |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1332 | // Target options. |
| 1333 | Record.clear(); |
Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1334 | const TargetInfo &Target = Context.getTargetInfo(); |
| 1335 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1336 | AddString(TargetOpts.Triple, Record); |
| 1337 | AddString(TargetOpts.CPU, Record); |
| 1338 | AddString(TargetOpts.ABI, Record); |
Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1339 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1340 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1341 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1342 | } |
| 1343 | Record.push_back(TargetOpts.Features.size()); |
| 1344 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1345 | AddString(TargetOpts.Features[I], Record); |
| 1346 | } |
| 1347 | Stream.EmitRecord(TARGET_OPTIONS, Record); |
| 1348 | |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1349 | // Diagnostic options. |
| 1350 | Record.clear(); |
| 1351 | const DiagnosticOptions &DiagOpts |
| 1352 | = Context.getDiagnostics().getDiagnosticOptions(); |
| 1353 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); |
| 1354 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 1355 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); |
| 1356 | #include "clang/Basic/DiagnosticOptions.def" |
| 1357 | Record.push_back(DiagOpts.Warnings.size()); |
| 1358 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) |
| 1359 | AddString(DiagOpts.Warnings[I], Record); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 1360 | Record.push_back(DiagOpts.Remarks.size()); |
| 1361 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) |
| 1362 | AddString(DiagOpts.Remarks[I], Record); |
Douglas Gregor | 8263ffb | 2012-10-24 15:17:15 +0000 | [diff] [blame] | 1363 | // Note: we don't serialize the log or serialization file names, because they |
| 1364 | // are generally transient files and will almost always be overridden. |
| 1365 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); |
| 1366 | |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1367 | // File system options. |
| 1368 | Record.clear(); |
Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1369 | const FileSystemOptions &FSOpts = |
| 1370 | Context.getSourceManager().getFileManager().getFileSystemOpts(); |
Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1371 | AddString(FSOpts.WorkingDir, Record); |
| 1372 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); |
| 1373 | |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1374 | // Header search options. |
| 1375 | Record.clear(); |
| 1376 | const HeaderSearchOptions &HSOpts |
| 1377 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 1378 | AddString(HSOpts.Sysroot, Record); |
| 1379 | |
| 1380 | // Include entries. |
| 1381 | Record.push_back(HSOpts.UserEntries.size()); |
| 1382 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { |
| 1383 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; |
| 1384 | AddString(Entry.Path, Record); |
| 1385 | Record.push_back(static_cast<unsigned>(Entry.Group)); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1386 | Record.push_back(Entry.IsFramework); |
| 1387 | Record.push_back(Entry.IgnoreSysRoot); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | // System header prefixes. |
| 1391 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); |
| 1392 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { |
| 1393 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); |
| 1394 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); |
| 1395 | } |
| 1396 | |
| 1397 | AddString(HSOpts.ResourceDir, Record); |
| 1398 | AddString(HSOpts.ModuleCachePath, Record); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1399 | AddString(HSOpts.ModuleUserBuildPath, Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1400 | Record.push_back(HSOpts.DisableModuleHash); |
| 1401 | Record.push_back(HSOpts.UseBuiltinIncludes); |
| 1402 | Record.push_back(HSOpts.UseStandardSystemIncludes); |
| 1403 | Record.push_back(HSOpts.UseStandardCXXIncludes); |
| 1404 | Record.push_back(HSOpts.UseLibcxx); |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1405 | // Write out the specific module cache path that contains the module files. |
| 1406 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); |
Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1407 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); |
| 1408 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1409 | // Preprocessor options. |
| 1410 | Record.clear(); |
| 1411 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); |
| 1412 | |
| 1413 | // Macro definitions. |
| 1414 | Record.push_back(PPOpts.Macros.size()); |
| 1415 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 1416 | AddString(PPOpts.Macros[I].first, Record); |
| 1417 | Record.push_back(PPOpts.Macros[I].second); |
| 1418 | } |
| 1419 | |
| 1420 | // Includes |
| 1421 | Record.push_back(PPOpts.Includes.size()); |
| 1422 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) |
| 1423 | AddString(PPOpts.Includes[I], Record); |
| 1424 | |
| 1425 | // Macro includes |
| 1426 | Record.push_back(PPOpts.MacroIncludes.size()); |
| 1427 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) |
| 1428 | AddString(PPOpts.MacroIncludes[I], Record); |
| 1429 | |
Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1430 | Record.push_back(PPOpts.UsePredefines); |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1431 | // Detailed record is important since it is used for the module cache hash. |
| 1432 | Record.push_back(PPOpts.DetailedRecord); |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1433 | AddString(PPOpts.ImplicitPCHInclude, Record); |
| 1434 | AddString(PPOpts.ImplicitPTHInclude, Record); |
| 1435 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); |
| 1436 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); |
| 1437 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1438 | // Leave the options block. |
| 1439 | Stream.ExitBlock(); |
| 1440 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1441 | // Original file name and file ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1442 | SourceManager &SM = Context.getSourceManager(); |
| 1443 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 1444 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1445 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); |
| 1446 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1447 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1448 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1449 | |
Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1450 | Record.clear(); |
Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1451 | Record.push_back(ORIGINAL_FILE); |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1452 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1453 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1454 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1455 | |
Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1456 | Record.clear(); |
| 1457 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1458 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
| 1459 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1460 | // Original PCH directory |
| 1461 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1462 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1463 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1464 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1465 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1466 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1467 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1468 | |
Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1469 | SM.getFileManager().makeAbsolutePath(OutputPath); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1470 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1471 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1472 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1473 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1474 | } |
| 1475 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1476 | WriteInputFiles(Context.SourceMgr, |
| 1477 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1478 | PP.getLangOpts().Modules); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1479 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 1480 | return Signature; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1483 | namespace { |
| 1484 | /// \brief An input file. |
| 1485 | struct InputFileEntry { |
| 1486 | const FileEntry *File; |
| 1487 | bool IsSystemFile; |
| 1488 | bool BufferOverridden; |
| 1489 | }; |
| 1490 | } |
| 1491 | |
| 1492 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, |
| 1493 | HeaderSearchOptions &HSOpts, |
Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1494 | bool Modules) { |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1495 | using namespace llvm; |
| 1496 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1497 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1498 | // Create input-file abbreviation. |
| 1499 | BitCodeAbbrev *IFAbbrev = new BitCodeAbbrev(); |
| 1500 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1501 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1502 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1503 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1504 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1505 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1506 | unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); |
| 1507 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1508 | // Get all ContentCache objects for files, sorted by whether the file is a |
| 1509 | // 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] | 1510 | std::deque<InputFileEntry> SortedFiles; |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1511 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { |
| 1512 | // Get this source location entry. |
| 1513 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1514 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1515 | |
| 1516 | // We only care about file entries that were not overridden. |
| 1517 | if (!SLoc->isFile()) |
| 1518 | continue; |
| 1519 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1520 | if (!Cache->OrigEntry) |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1521 | continue; |
| 1522 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1523 | InputFileEntry Entry; |
| 1524 | Entry.File = Cache->OrigEntry; |
| 1525 | Entry.IsSystemFile = Cache->IsSystemFile; |
| 1526 | Entry.BufferOverridden = Cache->BufferOverridden; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1527 | if (Cache->IsSystemFile) |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1528 | SortedFiles.push_back(Entry); |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1529 | else |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1530 | SortedFiles.push_front(Entry); |
| 1531 | } |
| 1532 | |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1533 | unsigned UserFilesNum = 0; |
| 1534 | // Write out all of the input files. |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1535 | std::vector<uint64_t> InputFileOffsets; |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1536 | for (std::deque<InputFileEntry>::iterator |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1537 | I = SortedFiles.begin(), E = SortedFiles.end(); I != E; ++I) { |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1538 | const InputFileEntry &Entry = *I; |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1539 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1540 | uint32_t &InputFileID = InputFileIDs[Entry.File]; |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1541 | if (InputFileID != 0) |
| 1542 | continue; // already recorded this file. |
| 1543 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1544 | // Record this entry's offset. |
| 1545 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); |
Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1546 | |
| 1547 | InputFileID = InputFileOffsets.size(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1548 | |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1549 | if (!Entry.IsSystemFile) |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1550 | ++UserFilesNum; |
| 1551 | |
Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1552 | // Emit size/modification time for this file. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1553 | // And whether this file was overridden. |
| 1554 | RecordData::value_type Record[] = { |
| 1555 | INPUT_FILE, InputFileOffsets.size(), (uint64_t)Entry.File->getSize(), |
| 1556 | (uint64_t)getTimestampForOutput(Entry.File), Entry.BufferOverridden}; |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1557 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1558 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); |
| 1559 | } |
Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1560 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1561 | Stream.ExitBlock(); |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1562 | |
| 1563 | // Create input file offsets abbreviation. |
| 1564 | BitCodeAbbrev *OffsetsAbbrev = new BitCodeAbbrev(); |
| 1565 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); |
| 1566 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files |
Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1567 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system |
| 1568 | // input files |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1569 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array |
| 1570 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(OffsetsAbbrev); |
| 1571 | |
| 1572 | // Write input file offsets. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1573 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, |
| 1574 | InputFileOffsets.size(), UserFilesNum}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1575 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1578 | //===----------------------------------------------------------------------===// |
| 1579 | // Source Manager Serialization |
| 1580 | //===----------------------------------------------------------------------===// |
| 1581 | |
| 1582 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1583 | /// file. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1584 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1585 | using namespace llvm; |
| 1586 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1587 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1588 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1589 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1590 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1591 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1592 | // FileEntry fields. |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1593 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1594 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1595 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1596 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1597 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1601 | /// buffer. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1602 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1603 | using namespace llvm; |
| 1604 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1605 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1606 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1607 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1608 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1609 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1610 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1611 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1615 | /// buffer's blob. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1616 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1617 | using namespace llvm; |
| 1618 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1619 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1620 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1621 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1624 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1625 | /// expansion. |
| 1626 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1627 | using namespace llvm; |
| 1628 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1629 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1630 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1631 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1632 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1633 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1634 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1635 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1638 | namespace { |
| 1639 | // Trait used for the on-disk hash table of header search information. |
| 1640 | class HeaderFileInfoTrait { |
| 1641 | ASTWriter &Writer; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1642 | const HeaderSearch &HS; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1643 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1644 | // Keep track of the framework names we've used during serialization. |
| 1645 | SmallVector<char, 128> FrameworkStringData; |
| 1646 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1647 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1648 | public: |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1649 | HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) |
| 1650 | : Writer(Writer), HS(HS) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1651 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1652 | struct key_type { |
| 1653 | const FileEntry *FE; |
| 1654 | const char *Filename; |
| 1655 | }; |
| 1656 | typedef const key_type &key_type_ref; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1657 | |
| 1658 | typedef HeaderFileInfo data_type; |
| 1659 | typedef const data_type &data_type_ref; |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 1660 | typedef unsigned hash_value_type; |
| 1661 | typedef unsigned offset_type; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1662 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1663 | hash_value_type ComputeHash(key_type_ref key) { |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1664 | // The hash is based only on size/time of the file, so that the reader can |
| 1665 | // match even when symlinking or excess path elements ("foo/../", "../") |
| 1666 | // change the form of the name. However, complete path is still the key. |
| 1667 | return llvm::hash_combine(key.FE->getSize(), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1668 | Writer.getTimestampForOutput(key.FE)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | std::pair<unsigned,unsigned> |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1672 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1673 | using namespace llvm::support; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1674 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1675 | unsigned KeyLen = strlen(key.Filename) + 1 + 8 + 8; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1676 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1677 | unsigned DataLen = 1 + 2 + 4 + 4; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1678 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) |
| 1679 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) |
| 1680 | DataLen += 4; |
| 1681 | LE.write<uint8_t>(DataLen); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1682 | return std::make_pair(KeyLen, DataLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1685 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1686 | using namespace llvm::support; |
| 1687 | endian::Writer<little> LE(Out); |
| 1688 | LE.write<uint64_t>(key.FE->getSize()); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1689 | KeyLen -= 8; |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1690 | LE.write<uint64_t>(Writer.getTimestampForOutput(key.FE)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1691 | KeyLen -= 8; |
| 1692 | Out.write(key.Filename, KeyLen); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1695 | void EmitData(raw_ostream &Out, key_type_ref key, |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1696 | data_type_ref Data, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1697 | using namespace llvm::support; |
| 1698 | endian::Writer<little> LE(Out); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1699 | uint64_t Start = Out.tell(); (void)Start; |
| 1700 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1701 | unsigned char Flags = (Data.isImport << 4) |
| 1702 | | (Data.isPragmaOnce << 3) |
| 1703 | | (Data.DirInfo << 1) |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1704 | | Data.IndexHeaderMapHeader; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1705 | LE.write<uint8_t>(Flags); |
| 1706 | LE.write<uint16_t>(Data.NumIncludes); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1707 | |
| 1708 | if (!Data.ControllingMacro) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1709 | LE.write<uint32_t>(Data.ControllingMacroID); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1710 | else |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1711 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1712 | |
| 1713 | unsigned Offset = 0; |
| 1714 | if (!Data.Framework.empty()) { |
| 1715 | // If this header refers into a framework, save the framework name. |
| 1716 | llvm::StringMap<unsigned>::iterator Pos |
| 1717 | = FrameworkNameOffset.find(Data.Framework); |
| 1718 | if (Pos == FrameworkNameOffset.end()) { |
| 1719 | Offset = FrameworkStringData.size() + 1; |
| 1720 | FrameworkStringData.append(Data.Framework.begin(), |
| 1721 | Data.Framework.end()); |
| 1722 | FrameworkStringData.push_back(0); |
| 1723 | |
| 1724 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1725 | } else |
| 1726 | Offset = Pos->second; |
| 1727 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1728 | LE.write<uint32_t>(Offset); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1729 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1730 | // FIXME: If the header is excluded, we should write out some |
| 1731 | // record of that fact. |
| 1732 | for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE)) { |
| 1733 | if (uint32_t ModID = |
| 1734 | Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) { |
| 1735 | uint32_t Value = (ModID << 2) | (unsigned)ModInfo.getRole(); |
| 1736 | assert((Value >> 2) == ModID && "overflow in header module info"); |
| 1737 | LE.write<uint32_t>(Value); |
| 1738 | } |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1741 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1742 | } |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1743 | |
| 1744 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1745 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1746 | }; |
| 1747 | } // end anonymous namespace |
| 1748 | |
| 1749 | /// \brief Write the header search block for the list of files that |
| 1750 | /// |
| 1751 | /// \param HS The header search structure to save. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1752 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1753 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1754 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1755 | |
| 1756 | if (FilesByUID.size() > HS.header_file_size()) |
| 1757 | FilesByUID.resize(HS.header_file_size()); |
| 1758 | |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1759 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 1760 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1761 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1762 | unsigned NumHeaderSearchEntries = 0; |
| 1763 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1764 | const FileEntry *File = FilesByUID[UID]; |
| 1765 | if (!File) |
| 1766 | continue; |
| 1767 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1768 | // Get the file info. This will load info from the external source if |
| 1769 | // necessary. Skip emitting this file if we have no information on it |
| 1770 | // as a header file (in which case HFI will be null) or if it hasn't |
| 1771 | // changed since it was loaded. Also skip it if it's for a modular header |
| 1772 | // from a different module; in that case, we rely on the module(s) |
| 1773 | // containing the header to provide this information. |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1774 | const HeaderFileInfo *HFI = |
| 1775 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); |
| 1776 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) |
Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 1777 | continue; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1778 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1779 | // Massage the file path into an appropriate form. |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1780 | const char *Filename = File->getName(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1781 | SmallString<128> FilenameTmp(Filename); |
| 1782 | if (PreparePathForOutput(FilenameTmp)) { |
| 1783 | // If we performed any translation on the file name at all, we need to |
| 1784 | // save this string, since the generator will refer to it later. |
| 1785 | Filename = strdup(FilenameTmp.c_str()); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1786 | SavedStrings.push_back(Filename); |
| 1787 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1788 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1789 | HeaderFileInfoTrait::key_type key = { File, Filename }; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1790 | Generator.insert(key, *HFI, GeneratorTrait); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1791 | ++NumHeaderSearchEntries; |
| 1792 | } |
| 1793 | |
| 1794 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1795 | SmallString<4096> TableData; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1796 | uint32_t BucketOffset; |
| 1797 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1798 | using namespace llvm::support; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1799 | llvm::raw_svector_ostream Out(TableData); |
| 1800 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1801 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1802 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1803 | } |
| 1804 | |
| 1805 | // Create a blob abbreviation |
| 1806 | using namespace llvm; |
| 1807 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1808 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1809 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1810 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1811 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1812 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1813 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1814 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1815 | // Write the header search table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1816 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, |
| 1817 | NumHeaderSearchEntries, TableData.size()}; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1818 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 1819 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1820 | |
| 1821 | // Free all of the strings we had to duplicate. |
| 1822 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1823 | free(const_cast<char *>(SavedStrings[I])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1826 | /// \brief Writes the block containing the serialized form of the |
| 1827 | /// source manager. |
| 1828 | /// |
| 1829 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1830 | /// blob), indexed based on the file name, so that we only create |
| 1831 | /// entries for files that we actually need. In the common case (no |
| 1832 | /// errors), we probably won't have to create file entries for any of |
| 1833 | /// the files in the AST. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1834 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1835 | const Preprocessor &PP) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1836 | RecordData Record; |
| 1837 | |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1838 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1839 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1840 | |
| 1841 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1842 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1843 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1844 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1845 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1846 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1847 | // Write out the source location entry table. We skip the first |
| 1848 | // entry, which is always the same dummy entry. |
Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1849 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1850 | RecordData PreloadSLocs; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1851 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1852 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1853 | I != N; ++I) { |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1854 | // Get this source location entry. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1855 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1856 | FileID FID = FileID::get(I); |
| 1857 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1858 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1859 | // Record the offset of this source-location entry. |
| 1860 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1861 | |
| 1862 | // Figure out which record code to use. |
| 1863 | unsigned Code; |
| 1864 | if (SLoc->isFile()) { |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1865 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1866 | if (Cache->OrigEntry) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1867 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1868 | } else |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1869 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1870 | } else |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1871 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1872 | Record.clear(); |
| 1873 | Record.push_back(Code); |
| 1874 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1875 | // Starting offset of this entry within this module, so skip the dummy. |
| 1876 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1877 | if (SLoc->isFile()) { |
| 1878 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1879 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1880 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1881 | Record.push_back(File.hasLineDirectives()); |
| 1882 | |
| 1883 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1884 | if (Content->OrigEntry) { |
| 1885 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1886 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1888 | // The source location entry is a file. Emit input file ID. |
| 1889 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); |
| 1890 | Record.push_back(InputFileIDs[Content->OrigEntry]); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1891 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1892 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1893 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1894 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1895 | if (FDI != FileDeclIDs.end()) { |
| 1896 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1897 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1898 | } else { |
| 1899 | Record.push_back(0); |
| 1900 | Record.push_back(0); |
| 1901 | } |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1902 | |
| 1903 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); |
| 1904 | |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1905 | if (Content->BufferOverridden) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1906 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB}; |
Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1907 | const llvm::MemoryBuffer *Buffer |
| 1908 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 1909 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
| 1910 | StringRef(Buffer->getBufferStart(), |
| 1911 | Buffer->getBufferSize() + 1)); |
| 1912 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1913 | } else { |
| 1914 | // The source location entry is a buffer. The blob associated |
| 1915 | // with this entry contains the contents of the buffer. |
| 1916 | |
| 1917 | // We add one to the size so that we capture the trailing NULL |
| 1918 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1919 | // the reader side). |
Douglas Gregor | 874cc62 | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1920 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | fb24a3a | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1921 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1922 | const char *Name = Buffer->getBufferIdentifier(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1923 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1924 | StringRef(Name, strlen(Name) + 1)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1925 | RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB}; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1926 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1927 | StringRef(Buffer->getBufferStart(), |
Daniel Dunbar | 8100d01 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1928 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1929 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1930 | if (strcmp(Name, "<built-in>") == 0) { |
| 1931 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1932 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1933 | } |
| 1934 | } else { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1935 | // The source location entry is a macro expansion. |
Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1936 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 73ee5d7 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1937 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1938 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
Argyrios Kyrtzidis | a1d943a | 2011-08-17 00:31:14 +0000 | [diff] [blame] | 1939 | Record.push_back(Expansion.isMacroArgExpansion() ? 0 |
| 1940 | : Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1941 | |
| 1942 | // Compute the token length for this macro expansion. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1943 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1944 | if (I + 1 != N) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1945 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1946 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1947 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1951 | Stream.ExitBlock(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1952 | |
| 1953 | if (SLocEntryOffsets.empty()) |
| 1954 | return; |
| 1955 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1956 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1957 | // table is used for lazily loading source-location information. |
| 1958 | using namespace llvm; |
| 1959 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1960 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1961 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1962 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1963 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1964 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1965 | { |
| 1966 | RecordData::value_type Record[] = { |
| 1967 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), |
| 1968 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */}; |
| 1969 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
| 1970 | bytes(SLocEntryOffsets)); |
| 1971 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1972 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1973 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1974 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1975 | |
| 1976 | // Write the line table. It depends on remapping working, so it must come |
| 1977 | // after the source location offsets. |
| 1978 | if (SourceMgr.hasLineTable()) { |
| 1979 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1980 | |
| 1981 | Record.clear(); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1982 | |
| 1983 | // Emit the needed file names. |
| 1984 | llvm::DenseMap<int, int> FilenameMap; |
| 1985 | for (const auto &L : LineTable) { |
| 1986 | if (L.first.ID < 0) |
| 1987 | continue; |
| 1988 | for (auto &LE : L.second) { |
| 1989 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, |
| 1990 | FilenameMap.size())).second) |
| 1991 | AddPath(LineTable.getFilename(LE.FilenameID), Record); |
| 1992 | } |
| 1993 | } |
| 1994 | Record.push_back(0); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1995 | |
| 1996 | // Emit the line entries |
| 1997 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1998 | L != LEnd; ++L) { |
| 1999 | // Only emit entries for local files. |
Douglas Gregor | 02c2dbf | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 2000 | if (L->first.ID < 0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2001 | continue; |
| 2002 | |
| 2003 | // Emit the file ID |
Douglas Gregor | 02c2dbf | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 2004 | Record.push_back(L->first.ID); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2005 | |
| 2006 | // Emit the line entries |
| 2007 | Record.push_back(L->second.size()); |
| 2008 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 2009 | LEEnd = L->second.end(); |
| 2010 | LE != LEEnd; ++LE) { |
| 2011 | Record.push_back(LE->FileOffset); |
| 2012 | Record.push_back(LE->LineNo); |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2013 | Record.push_back(FilenameMap[LE->FilenameID]); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2014 | Record.push_back((unsigned)LE->FileKind); |
| 2015 | Record.push_back(LE->IncludeOffset); |
| 2016 | } |
| 2017 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2018 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2019 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 2020 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2023 | //===----------------------------------------------------------------------===// |
| 2024 | // Preprocessor Serialization |
| 2025 | //===----------------------------------------------------------------------===// |
| 2026 | |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2027 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, |
| 2028 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2029 | if (MacroInfo *MI = MD->getMacroInfo()) |
| 2030 | if (MI->isBuiltinMacro()) |
| 2031 | return true; |
Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2032 | |
| 2033 | if (IsModule) { |
| 2034 | SourceLocation Loc = MD->getLocation(); |
| 2035 | if (Loc.isInvalid()) |
| 2036 | return true; |
| 2037 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) |
| 2038 | return true; |
| 2039 | } |
| 2040 | |
| 2041 | return false; |
| 2042 | } |
| 2043 | |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2044 | /// \brief Writes the block containing the serialized form of the |
| 2045 | /// preprocessor. |
| 2046 | /// |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2047 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2048 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 2049 | if (PPRec) |
| 2050 | WritePreprocessorDetail(*PPRec); |
| 2051 | |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2052 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2053 | RecordData ModuleMacroRecord; |
Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2054 | |
Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2055 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 2056 | if (PP.getCounterValue() != 0) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2057 | RecordData::value_type Record[] = {PP.getCounterValue()}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2058 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | // Enter the preprocessor block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2062 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2063 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2064 | // 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] | 2065 | // 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] | 2066 | if (PP.SawDateOrTime()) |
Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2067 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2068 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2069 | // 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] | 2070 | // emitting each to the PP section. |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2071 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2072 | // Construct the list of identifiers with macro directives that need to be |
| 2073 | // serialized. |
| 2074 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; |
| 2075 | for (auto &Id : PP.getIdentifierTable()) |
| 2076 | if (Id.second->hadMacroDefinition() && |
| 2077 | (!Id.second->isFromAST() || |
| 2078 | Id.second->hasChangedSinceDeserialization())) |
| 2079 | MacroIdentifiers.push_back(Id.second); |
Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2080 | // Sort the set of macro definitions that need to be serialized by the |
| 2081 | // name of the macro, to provide a stable ordering. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2082 | std::sort(MacroIdentifiers.begin(), MacroIdentifiers.end(), |
| 2083 | llvm::less_ptr<IdentifierInfo>()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2084 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2085 | // Emit the macro directives as a list and associate the offset with the |
| 2086 | // identifier they belong to. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2087 | for (const IdentifierInfo *Name : MacroIdentifiers) { |
| 2088 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2089 | auto StartOffset = Stream.GetCurrentBitNo(); |
| 2090 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2091 | // Emit the macro directives in reverse source order. |
| 2092 | for (; MD; MD = MD->getPrevious()) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2093 | // Once we hit an ignored macro, we're done: the rest of the chain |
| 2094 | // will all be ignored macros. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2095 | if (shouldIgnoreMacro(MD, IsModule, PP)) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2096 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2097 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2098 | AddSourceLocation(MD->getLocation(), Record); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2099 | Record.push_back(MD->getKind()); |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2100 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2101 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2102 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2103 | Record.push_back(VisMD->isPublic()); |
| 2104 | } |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2105 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2106 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2107 | // Write out any exported module macros. |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2108 | bool EmittedModuleMacros = false; |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2109 | if (IsModule) { |
| 2110 | auto Leafs = PP.getLeafModuleMacros(Name); |
| 2111 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); |
| 2112 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; |
| 2113 | while (!Worklist.empty()) { |
| 2114 | auto *Macro = Worklist.pop_back_val(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2115 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2116 | // Emit a record indicating this submodule exports this macro. |
| 2117 | ModuleMacroRecord.push_back( |
| 2118 | getSubmoduleID(Macro->getOwningModule())); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2119 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2120 | for (auto *M : Macro->overrides()) |
| 2121 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2122 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2123 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); |
| 2124 | ModuleMacroRecord.clear(); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2125 | |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2126 | // Enqueue overridden macros once we've visited all their ancestors. |
| 2127 | for (auto *M : Macro->overrides()) |
| 2128 | if (++Visits[M] == M->getNumOverridingMacros()) |
| 2129 | Worklist.push_back(M); |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2130 | |
| 2131 | EmittedModuleMacros = true; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2132 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2133 | } |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2134 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2135 | if (Record.empty() && !EmittedModuleMacros) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2136 | continue; |
| 2137 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2138 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2139 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); |
| 2140 | Record.clear(); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2141 | } |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2142 | |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2143 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 2144 | /// the local macro ID |
| 2145 | /// |
| 2146 | /// For each identifier that is associated with a macro, this map |
| 2147 | /// provides the offset into the bitstream where that macro is |
| 2148 | /// defined. |
| 2149 | std::vector<uint32_t> MacroOffsets; |
| 2150 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2151 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { |
| 2152 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; |
| 2153 | MacroInfo *MI = MacroInfosToEmit[I].MI; |
| 2154 | MacroID ID = MacroInfosToEmit[I].ID; |
Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2155 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2156 | if (ID < FirstMacroID) { |
| 2157 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); |
| 2158 | continue; |
Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2159 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2160 | |
| 2161 | // Record the local offset of this macro. |
| 2162 | unsigned Index = ID - FirstMacroID; |
| 2163 | if (Index == MacroOffsets.size()) |
| 2164 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 2165 | else { |
| 2166 | if (Index > MacroOffsets.size()) |
| 2167 | MacroOffsets.resize(Index + 1); |
| 2168 | |
| 2169 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 2170 | } |
| 2171 | |
| 2172 | AddIdentifierRef(Name, Record); |
| 2173 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
| 2174 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 2175 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); |
| 2176 | Record.push_back(MI->isUsed()); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2177 | Record.push_back(MI->isUsedForHeaderGuard()); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2178 | unsigned Code; |
| 2179 | if (MI->isObjectLike()) { |
| 2180 | Code = PP_MACRO_OBJECT_LIKE; |
| 2181 | } else { |
| 2182 | Code = PP_MACRO_FUNCTION_LIKE; |
| 2183 | |
| 2184 | Record.push_back(MI->isC99Varargs()); |
| 2185 | Record.push_back(MI->isGNUVarargs()); |
| 2186 | Record.push_back(MI->hasCommaPasting()); |
| 2187 | Record.push_back(MI->getNumArgs()); |
Daniel Marjamaki | e4770da | 2015-05-29 09:15:24 +0000 | [diff] [blame] | 2188 | for (const IdentifierInfo *Arg : MI->args()) |
| 2189 | AddIdentifierRef(Arg, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | // If we have a detailed preprocessing record, record the macro definition |
| 2193 | // ID that corresponds to this macro. |
| 2194 | if (PPRec) |
| 2195 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 2196 | |
| 2197 | Stream.EmitRecord(Code, Record); |
| 2198 | Record.clear(); |
| 2199 | |
| 2200 | // Emit the tokens array. |
| 2201 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 2202 | // Note that we know that the preprocessor does not have any annotation |
| 2203 | // tokens in it because they are created by the parser, and thus can't |
| 2204 | // be in a macro definition. |
| 2205 | const Token &Tok = MI->getReplacementToken(TokNo); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2206 | AddToken(Tok, Record); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2207 | Stream.EmitRecord(PP_TOKEN, Record); |
| 2208 | Record.clear(); |
| 2209 | } |
| 2210 | ++NumMacros; |
Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2211 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2213 | Stream.ExitBlock(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2214 | |
| 2215 | // Write the offsets table for macro IDs. |
| 2216 | using namespace llvm; |
Richard Smith | 13090a2 | 2015-04-10 02:02:24 +0000 | [diff] [blame] | 2217 | auto *Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2218 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 2219 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 2220 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 2221 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2222 | |
| 2223 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2224 | { |
| 2225 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), |
| 2226 | FirstMacroID - NUM_PREDEF_MACRO_IDS}; |
| 2227 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); |
| 2228 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2232 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2233 | return; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2234 | |
Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2235 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2236 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2237 | // Enter the preprocessor block. |
| 2238 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2239 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2240 | // If the preprocessor has a preprocessing record, emit it. |
| 2241 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2242 | using namespace llvm; |
| 2243 | |
| 2244 | // Set up the abbreviation for |
| 2245 | unsigned InclusionAbbrev = 0; |
| 2246 | { |
| 2247 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2248 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2249 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 2250 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 2251 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2252 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2253 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2254 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2255 | } |
| 2256 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2257 | unsigned FirstPreprocessorEntityID |
| 2258 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 2259 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 2260 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2261 | RecordData Record; |
Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2262 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 2263 | EEnd = PPRec.local_end(); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2264 | E != EEnd; |
| 2265 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2266 | Record.clear(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2267 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2268 | PreprocessedEntityOffsets.push_back( |
| 2269 | PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2270 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2271 | if (MacroDefinitionRecord *MD = dyn_cast<MacroDefinitionRecord>(*E)) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2272 | // Record this macro definition's ID. |
| 2273 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2274 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2275 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2276 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 2277 | continue; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2278 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2279 | |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 2280 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2281 | Record.push_back(ME->isBuiltinMacro()); |
| 2282 | if (ME->isBuiltinMacro()) |
| 2283 | AddIdentifierRef(ME->getName(), Record); |
| 2284 | else |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2285 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2286 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2287 | continue; |
| 2288 | } |
| 2289 | |
| 2290 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 2291 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2292 | Record.push_back(ID->getFileName().size()); |
| 2293 | Record.push_back(ID->wasInQuotes()); |
| 2294 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2295 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2296 | SmallString<64> Buffer; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2297 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2298 | // Check that the FileEntry is not null because it was not resolved and |
| 2299 | // we create a PCH even with compiler errors. |
| 2300 | if (ID->getFile()) |
| 2301 | Buffer += ID->getFile()->getName(); |
Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2302 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2303 | continue; |
| 2304 | } |
| 2305 | |
| 2306 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 2307 | } |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2308 | Stream.ExitBlock(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2309 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2310 | // Write the offsets table for the preprocessing record. |
| 2311 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2312 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 2313 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2314 | // Write the offsets table for identifier IDs. |
| 2315 | using namespace llvm; |
| 2316 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2317 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2318 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2319 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2320 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2321 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2322 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, |
| 2323 | FirstPreprocessorEntityID - |
| 2324 | NUM_PREDEF_PP_ENTITY_IDS}; |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2325 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2326 | bytes(PreprocessedEntityOffsets)); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2327 | } |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2330 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2331 | if (!Mod) |
| 2332 | return 0; |
| 2333 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2334 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 2335 | if (Known != SubmoduleIDs.end()) |
| 2336 | return Known->second; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2337 | |
| 2338 | if (Mod->getTopLevelModule() != WritingModule) |
| 2339 | return 0; |
| 2340 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2341 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 2342 | } |
| 2343 | |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2344 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 2345 | // FIXME: This can easily happen, if we have a reference to a submodule that |
| 2346 | // did not result in us loading a module file for that submodule. For |
| 2347 | // instance, a cross-top-level-module 'conflict' declaration will hit this. |
| 2348 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); |
| 2349 | assert((ID || !Mod) && |
| 2350 | "asked for module ID for non-local, non-imported module"); |
| 2351 | return ID; |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2354 | /// \brief Compute the number of modules within the given tree (including the |
| 2355 | /// given module). |
| 2356 | static unsigned getNumberOfModules(Module *Mod) { |
| 2357 | unsigned ChildModules = 0; |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2358 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2359 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2360 | Sub != SubEnd; ++Sub) |
Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2361 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2362 | |
| 2363 | return ChildModules + 1; |
| 2364 | } |
| 2365 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2366 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2367 | // Enter the submodule description block. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2368 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2369 | |
| 2370 | // Write the abbreviations needed for the submodules block. |
| 2371 | using namespace llvm; |
| 2372 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2373 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2374 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2375 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 2376 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2377 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2378 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 2379 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC |
Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2380 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2381 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2382 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2383 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2384 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2385 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2386 | |
| 2387 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2388 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2389 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2390 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2391 | |
| 2392 | Abbrev = new BitCodeAbbrev(); |
| 2393 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 2394 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2395 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2396 | |
| 2397 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2398 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 2399 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2400 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2401 | |
| 2402 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2403 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 2404 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2405 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2406 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2407 | Abbrev = new BitCodeAbbrev(); |
| 2408 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2409 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State |
| 2410 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2411 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2412 | |
Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2413 | Abbrev = new BitCodeAbbrev(); |
| 2414 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 2415 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2416 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2417 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2418 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2419 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); |
| 2420 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2421 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2422 | |
| 2423 | Abbrev = new BitCodeAbbrev(); |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2424 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); |
| 2425 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2426 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2427 | |
| 2428 | Abbrev = new BitCodeAbbrev(); |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2429 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); |
| 2430 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2431 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2432 | |
| 2433 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2434 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); |
| 2435 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 2436 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 2437 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2438 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2439 | Abbrev = new BitCodeAbbrev(); |
| 2440 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); |
| 2441 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Macro name |
| 2442 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2443 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2444 | Abbrev = new BitCodeAbbrev(); |
| 2445 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); |
| 2446 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Other module |
| 2447 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Message |
| 2448 | unsigned ConflictAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2449 | |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2450 | // Write the submodule metadata block. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2451 | RecordData::value_type Record[] = {getNumberOfModules(WritingModule), |
| 2452 | FirstSubmoduleID - |
| 2453 | NUM_PREDEF_SUBMODULE_IDS}; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2454 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 2455 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2456 | // Write all of the submodules. |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2457 | std::queue<Module *> Q; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2458 | Q.push(WritingModule); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2459 | while (!Q.empty()) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2460 | Module *Mod = Q.front(); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2461 | Q.pop(); |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2462 | unsigned ID = getSubmoduleID(Mod); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2463 | |
| 2464 | uint64_t ParentID = 0; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2465 | if (Mod->Parent) { |
| 2466 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2467 | ParentID = SubmoduleIDs[Mod->Parent]; |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2468 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2469 | |
| 2470 | // Emit the definition of the block. |
| 2471 | { |
| 2472 | RecordData::value_type Record[] = { |
| 2473 | SUBMODULE_DEFINITION, ID, ParentID, Mod->IsFramework, Mod->IsExplicit, |
| 2474 | Mod->IsSystem, Mod->IsExternC, Mod->InferSubmodules, |
| 2475 | Mod->InferExplicitSubmodules, Mod->InferExportWildcard, |
| 2476 | Mod->ConfigMacrosExhaustive}; |
| 2477 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2478 | } |
| 2479 | |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2480 | // Emit the requirements. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2481 | for (const auto &R : Mod->Requirements) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2482 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2483 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); |
Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2486 | // Emit the umbrella header, if there is one. |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2487 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2488 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2489 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
| 2490 | UmbrellaHeader.NameAsWritten); |
| 2491 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2492 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; |
| 2493 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2494 | UmbrellaDir.NameAsWritten); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2495 | } |
Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2496 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2497 | // Emit the headers. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2498 | struct { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2499 | unsigned RecordKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2500 | unsigned Abbrev; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2501 | Module::HeaderKind HeaderKind; |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2502 | } HeaderLists[] = { |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2503 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, |
| 2504 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, |
| 2505 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2506 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2507 | Module::HK_PrivateTextual}, |
| 2508 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2509 | }; |
| 2510 | for (auto &HL : HeaderLists) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2511 | RecordData::value_type Record[] = {HL.RecordKind}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2512 | for (auto &H : Mod->Headers[HL.HeaderKind]) |
| 2513 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); |
| 2514 | } |
| 2515 | |
| 2516 | // Emit the top headers. |
| 2517 | { |
| 2518 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2519 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; |
Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2520 | for (auto *H : TopHeaders) |
| 2521 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); |
Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2522 | } |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2523 | |
| 2524 | // Emit the imports. |
| 2525 | if (!Mod->Imports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2526 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2527 | for (auto *I : Mod->Imports) |
| 2528 | Record.push_back(getSubmoduleID(I)); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2529 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2530 | } |
| 2531 | |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2532 | // Emit the exports. |
| 2533 | if (!Mod->Exports.empty()) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2534 | RecordData Record; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2535 | for (const auto &E : Mod->Exports) { |
| 2536 | // FIXME: This may fail; we don't require that all exported modules |
| 2537 | // are local or imported. |
| 2538 | Record.push_back(getSubmoduleID(E.getPointer())); |
| 2539 | Record.push_back(E.getInt()); |
Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2540 | } |
| 2541 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2542 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2543 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2544 | //FIXME: How do we emit the 'use'd modules? They may not be submodules. |
| 2545 | // Might be unnecessary as use declarations are only used to build the |
| 2546 | // module itself. |
| 2547 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2548 | // Emit the link libraries. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2549 | for (const auto &LL : Mod->LinkLibraries) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2550 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, |
| 2551 | LL.IsFramework}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2552 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2555 | // Emit the conflicts. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2556 | for (const auto &C : Mod->Conflicts) { |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2557 | // FIXME: This may fail; we don't require that all conflicting modules |
| 2558 | // are local or imported. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2559 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, |
| 2560 | getSubmoduleID(C.Other)}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2561 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2564 | // Emit the configuration macros. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2565 | for (const auto &CM : Mod->ConfigMacros) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2566 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2567 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2568 | } |
| 2569 | |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2570 | // Queue up the submodules of this module. |
Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2571 | for (auto *M : Mod->submodules()) |
| 2572 | Q.push(M); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | Stream.ExitBlock(); |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2576 | |
Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2577 | assert((NextSubmoduleID - FirstSubmoduleID == |
| 2578 | getNumberOfModules(WritingModule)) && |
| 2579 | "Wrong # of submodules; found a reference to a non-local, " |
| 2580 | "non-imported submodule?"); |
Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2583 | serialization::SubmoduleID |
| 2584 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2585 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2586 | return 0; // No submodule |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2587 | |
| 2588 | // Find the module that owns this location. |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2589 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2590 | Module *OwningMod |
| 2591 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2592 | if (!OwningMod) |
| 2593 | return 0; |
| 2594 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2595 | // Check whether this submodule is part of our own module. |
| 2596 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2597 | return 0; |
| 2598 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2599 | return getSubmoduleID(OwningMod); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 2602 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, |
| 2603 | bool isModule) { |
| 2604 | // Make sure set diagnostic pragmas don't affect the translation unit that |
| 2605 | // imports the module. |
| 2606 | // FIXME: Make diagnostic pragma sections work properly with modules. |
| 2607 | if (isModule) |
| 2608 | return; |
| 2609 | |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2610 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> |
| 2611 | DiagStateIDMap; |
| 2612 | unsigned CurrID = 0; |
| 2613 | DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2614 | RecordData Record; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2615 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2616 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2617 | I != E; ++I) { |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2618 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2619 | if (point.Loc.isInvalid()) |
| 2620 | continue; |
| 2621 | |
| 2622 | Record.push_back(point.Loc.getRawEncoding()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2623 | unsigned &DiagStateID = DiagStateIDMap[point.State]; |
| 2624 | Record.push_back(DiagStateID); |
| 2625 | |
| 2626 | if (DiagStateID == 0) { |
| 2627 | DiagStateID = ++CurrID; |
| 2628 | for (DiagnosticsEngine::DiagState::const_iterator |
| 2629 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
| 2630 | if (I->second.isPragma()) { |
| 2631 | Record.push_back(I->first); |
Alp Toker | 46df1c0 | 2014-06-12 10:15:20 +0000 | [diff] [blame] | 2632 | Record.push_back((unsigned)I->second.getSeverity()); |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2633 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2634 | } |
Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2635 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2636 | // location. |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2637 | } |
| 2638 | } |
| 2639 | |
Argyrios Kyrtzidis | b0ca9eb | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2640 | if (!Record.empty()) |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2641 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2644 | void ASTWriter::WriteCXXCtorInitializersOffsets() { |
| 2645 | if (CXXCtorInitializersOffsets.empty()) |
| 2646 | return; |
| 2647 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2648 | // Create a blob abbreviation for the C++ ctor initializer offsets. |
| 2649 | using namespace llvm; |
| 2650 | |
| 2651 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2652 | Abbrev->Add(BitCodeAbbrevOp(CXX_CTOR_INITIALIZERS_OFFSETS)); |
| 2653 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2654 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2655 | unsigned CtorInitializersOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2656 | |
| 2657 | // Write the base specifier offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2658 | RecordData::value_type Record[] = {CXX_CTOR_INITIALIZERS_OFFSETS, |
| 2659 | CXXCtorInitializersOffsets.size()}; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2660 | Stream.EmitRecordWithBlob(CtorInitializersOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2661 | bytes(CXXCtorInitializersOffsets)); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2664 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 2665 | if (CXXBaseSpecifiersOffsets.empty()) |
| 2666 | return; |
| 2667 | |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2668 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 2669 | using namespace llvm; |
| 2670 | |
| 2671 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2672 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 2673 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2674 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2675 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2676 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2677 | // Write the base specifier offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2678 | RecordData::value_type Record[] = {CXX_BASE_SPECIFIER_OFFSETS, |
| 2679 | CXXBaseSpecifiersOffsets.size()}; |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2680 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2681 | bytes(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | 9bb83e8 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2684 | //===----------------------------------------------------------------------===// |
| 2685 | // Type Serialization |
| 2686 | //===----------------------------------------------------------------------===// |
Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2687 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2688 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2689 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | a7fbbb0 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 2690 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2691 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 2692 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2693 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2694 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2695 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2696 | // Record the offset for this type. |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2697 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2698 | if (TypeOffsets.size() == Index) |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2699 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2700 | else if (TypeOffsets.size() < Index) { |
| 2701 | TypeOffsets.resize(Index + 1); |
| 2702 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | RecordData Record; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2706 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2707 | // Emit the type's representation. |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2708 | ASTTypeWriter W(*this, Record); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 2709 | W.AbbrevToUse = 0; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2710 | |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2711 | if (T.hasLocalNonFastQualifiers()) { |
| 2712 | Qualifiers Qs = T.getLocalQualifiers(); |
| 2713 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2714 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2715 | W.Code = TYPE_EXT_QUAL; |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 2716 | W.AbbrevToUse = TypeExtQualAbbrev; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2717 | } else { |
| 2718 | switch (T->getTypeClass()) { |
| 2719 | // For all of the concrete, non-dependent types, call the |
| 2720 | // appropriate visitor function. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2721 | #define TYPE(Class, Base) \ |
Mike Stump | 281d6d7 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 2722 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2723 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2724 | #include "clang/AST/TypeNodes.def" |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2725 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | // Emit the serialized record. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 2729 | Stream.EmitRecord(W.Code, Record, W.AbbrevToUse); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2730 | |
| 2731 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2732 | FlushStmts(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2735 | //===----------------------------------------------------------------------===// |
| 2736 | // Declaration Serialization |
| 2737 | //===----------------------------------------------------------------------===// |
| 2738 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2739 | /// \brief Write the block containing all of the declaration IDs |
| 2740 | /// lexically declared within the given DeclContext. |
| 2741 | /// |
| 2742 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2743 | /// bistream, or 0 if no block was written. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2744 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2745 | DeclContext *DC) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2746 | if (DC->decls_empty()) |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2747 | return 0; |
| 2748 | |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2749 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2750 | SmallVector<uint32_t, 128> KindDeclPairs; |
| 2751 | for (const auto *D : DC->decls()) { |
| 2752 | KindDeclPairs.push_back(D->getKind()); |
| 2753 | KindDeclPairs.push_back(GetDeclRef(D)); |
| 2754 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2755 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2756 | ++NumLexicalDeclContexts; |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2757 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2758 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, |
| 2759 | bytes(KindDeclPairs)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2760 | return Offset; |
| 2761 | } |
| 2762 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2763 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2764 | using namespace llvm; |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2765 | |
| 2766 | // Write the type offsets array |
| 2767 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2768 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2769 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2770 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2771 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2772 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2773 | { |
| 2774 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), |
| 2775 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; |
| 2776 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); |
| 2777 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2778 | |
| 2779 | // Write the declaration offsets array |
| 2780 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2781 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2782 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2783 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2784 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2785 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2786 | { |
| 2787 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), |
| 2788 | FirstDeclID - NUM_PREDEF_DECL_IDS}; |
| 2789 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); |
| 2790 | } |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2793 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2794 | using namespace llvm; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2795 | |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2796 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs( |
| 2797 | FileDeclIDs.begin(), FileDeclIDs.end()); |
| 2798 | std::sort(SortedFileDeclIDs.begin(), SortedFileDeclIDs.end(), |
| 2799 | llvm::less_first()); |
| 2800 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2801 | // Join the vectors of DeclIDs from all files. |
Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2802 | SmallVector<DeclID, 256> FileGroupedDeclIDs; |
| 2803 | for (auto &FileDeclEntry : SortedFileDeclIDs) { |
| 2804 | DeclIDInFileInfo &Info = *FileDeclEntry.second; |
| 2805 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); |
| 2806 | for (auto &LocDeclEntry : Info.DeclIDs) |
| 2807 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2811 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2812 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2813 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2814 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2815 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, |
| 2816 | FileGroupedDeclIDs.size()}; |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2817 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2820 | void ASTWriter::WriteComments() { |
| 2821 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2822 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2823 | RecordData Record; |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2824 | for (ArrayRef<RawComment *>::iterator I = RawComments.begin(), |
| 2825 | E = RawComments.end(); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2826 | I != E; ++I) { |
| 2827 | Record.clear(); |
Dmitri Gribenko | 7dd29d4 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2828 | AddSourceRange((*I)->getSourceRange(), Record); |
| 2829 | Record.push_back((*I)->getKind()); |
| 2830 | Record.push_back((*I)->isTrailingComment()); |
| 2831 | Record.push_back((*I)->isAlmostTrailingComment()); |
Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2832 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2833 | } |
| 2834 | Stream.ExitBlock(); |
| 2835 | } |
| 2836 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2837 | //===----------------------------------------------------------------------===// |
| 2838 | // Global Method Pool and Selector Serialization |
| 2839 | //===----------------------------------------------------------------------===// |
| 2840 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2841 | namespace { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2842 | // 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] | 2843 | class ASTMethodPoolTrait { |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2844 | ASTWriter &Writer; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2845 | |
| 2846 | public: |
| 2847 | typedef Selector key_type; |
| 2848 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2849 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2850 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2851 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2852 | ObjCMethodList Instance, Factory; |
| 2853 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2854 | typedef const data_type& data_type_ref; |
| 2855 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2856 | typedef unsigned hash_value_type; |
| 2857 | typedef unsigned offset_type; |
| 2858 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2859 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2860 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2861 | static hash_value_type ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2862 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2863 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2864 | |
| 2865 | std::pair<unsigned,unsigned> |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2866 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2867 | data_type_ref Methods) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2868 | using namespace llvm::support; |
| 2869 | endian::Writer<little> LE(Out); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2870 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2871 | LE.write<uint16_t>(KeyLen); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2872 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2873 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2874 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2875 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2876 | DataLen += 4; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2877 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2878 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2879 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2880 | DataLen += 4; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2881 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2882 | return std::make_pair(KeyLen, DataLen); |
| 2883 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2884 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2885 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2886 | using namespace llvm::support; |
| 2887 | endian::Writer<little> LE(Out); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2888 | uint64_t Start = Out.tell(); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2889 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2890 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2891 | unsigned N = Sel.getNumArgs(); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2892 | LE.write<uint16_t>(N); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2893 | if (N == 0) |
| 2894 | N = 1; |
| 2895 | for (unsigned I = 0; I != N; ++I) |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2896 | LE.write<uint32_t>( |
| 2897 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2898 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2899 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2900 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2901 | data_type_ref Methods, unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2902 | using namespace llvm::support; |
| 2903 | endian::Writer<little> LE(Out); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2904 | uint64_t Start = Out.tell(); (void)Start; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2905 | LE.write<uint32_t>(Methods.ID); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2906 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2907 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2908 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2909 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2910 | ++NumInstanceMethods; |
| 2911 | |
| 2912 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2913 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2914 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2915 | if (Method->getMethod()) |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2916 | ++NumFactoryMethods; |
| 2917 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2918 | unsigned InstanceBits = Methods.Instance.getBits(); |
| 2919 | assert(InstanceBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2920 | unsigned InstanceHasMoreThanOneDeclBit = |
| 2921 | Methods.Instance.hasMoreThanOneDecl(); |
| 2922 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | |
| 2923 | (InstanceHasMoreThanOneDeclBit << 2) | |
| 2924 | InstanceBits; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2925 | unsigned FactoryBits = Methods.Factory.getBits(); |
| 2926 | assert(FactoryBits < 4); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 2927 | unsigned FactoryHasMoreThanOneDeclBit = |
| 2928 | Methods.Factory.hasMoreThanOneDecl(); |
| 2929 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | |
| 2930 | (FactoryHasMoreThanOneDeclBit << 2) | |
| 2931 | FactoryBits; |
| 2932 | LE.write<uint16_t>(FullInstanceBits); |
| 2933 | LE.write<uint16_t>(FullFactoryBits); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2934 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2935 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2936 | if (Method->getMethod()) |
| 2937 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2938 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2939 | Method = Method->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2940 | if (Method->getMethod()) |
| 2941 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); |
Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2942 | |
| 2943 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2944 | } |
| 2945 | }; |
| 2946 | } // end anonymous namespace |
| 2947 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2948 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2949 | /// |
| 2950 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2951 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2952 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2953 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2954 | using namespace llvm; |
| 2955 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2956 | // Do we have to do anything at all? |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2957 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2958 | return; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2959 | unsigned NumTableEntries = 0; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2960 | // 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] | 2961 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 2962 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2963 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2964 | |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2965 | // Create the on-disk hash table representation. We walk through every |
| 2966 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2967 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 2968 | for (auto &SelectorAndID : SelectorIDs) { |
| 2969 | Selector S = SelectorAndID.first; |
| 2970 | SelectorID ID = SelectorAndID.second; |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2971 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2972 | ASTMethodPoolTrait::data_type Data = { |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 2973 | ID, |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2974 | ObjCMethodList(), |
| 2975 | ObjCMethodList() |
| 2976 | }; |
| 2977 | if (F != SemaRef.MethodPool.end()) { |
| 2978 | Data.Instance = F->second.first; |
| 2979 | Data.Factory = F->second.second; |
| 2980 | } |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2981 | // 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] | 2982 | // changed. |
Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 2983 | if (Chain && ID < FirstSelectorID) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2984 | // Selector already exists. Did it change? |
| 2985 | bool changed = false; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2986 | for (ObjCMethodList *M = &Data.Instance; |
| 2987 | !changed && M && M->getMethod(); M = M->getNext()) { |
| 2988 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2989 | changed = true; |
| 2990 | } |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2991 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 2992 | M = M->getNext()) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2993 | if (!M->getMethod()->isFromASTFile()) |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2994 | changed = true; |
| 2995 | } |
| 2996 | if (!changed) |
| 2997 | continue; |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 2998 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2999 | // A new method pool entry. |
| 3000 | ++NumTableEntries; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3001 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3002 | Generator.insert(S, Data, Trait); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3005 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3006 | SmallString<4096> MethodPool; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3007 | uint32_t BucketOffset; |
| 3008 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3009 | using namespace llvm::support; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3010 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3011 | llvm::raw_svector_ostream Out(MethodPool); |
| 3012 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3013 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3014 | BucketOffset = Generator.Emit(Out, Trait); |
| 3015 | } |
| 3016 | |
| 3017 | // Create a blob abbreviation |
| 3018 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3019 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3020 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3021 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3022 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3023 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3024 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3025 | // Write the method pool |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3026 | { |
| 3027 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, |
| 3028 | NumTableEntries}; |
| 3029 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); |
| 3030 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3031 | |
| 3032 | // Create a blob abbreviation for the selector table offsets. |
| 3033 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3034 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3035 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3036 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3037 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3038 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3039 | |
| 3040 | // Write the selector offsets table. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3041 | { |
| 3042 | RecordData::value_type Record[] = { |
| 3043 | SELECTOR_OFFSETS, SelectorOffsets.size(), |
| 3044 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; |
| 3045 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 3046 | bytes(SelectorOffsets)); |
| 3047 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3048 | } |
| 3049 | } |
| 3050 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3051 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3052 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3053 | using namespace llvm; |
| 3054 | if (SemaRef.ReferencedSelectors.empty()) |
| 3055 | return; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3056 | |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3057 | RecordData Record; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3058 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3059 | // 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] | 3060 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 3061 | // headers, probably not worth it. It's not a correctness issue. |
Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3062 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { |
| 3063 | Selector Sel = SelectorAndLocation.first; |
| 3064 | SourceLocation Loc = SelectorAndLocation.second; |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3065 | AddSelectorRef(Sel, Record); |
| 3066 | AddSourceLocation(Loc, Record); |
| 3067 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3068 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3071 | //===----------------------------------------------------------------------===// |
| 3072 | // Identifier Table Serialization |
| 3073 | //===----------------------------------------------------------------------===// |
| 3074 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3075 | /// Determine the declaration that should be put into the name lookup table to |
| 3076 | /// represent the given declaration in this module. This is usually D itself, |
| 3077 | /// but if D was imported and merged into a local declaration, we want the most |
| 3078 | /// recent local declaration instead. The chosen declaration will be the most |
| 3079 | /// recent declaration in any module that imports this one. |
| 3080 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, |
| 3081 | NamedDecl *D) { |
| 3082 | if (!LangOpts.Modules || !D->isFromASTFile()) |
| 3083 | return D; |
| 3084 | |
| 3085 | if (Decl *Redecl = D->getPreviousDecl()) { |
| 3086 | // For Redeclarable decls, a prior declaration might be local. |
| 3087 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { |
| 3088 | if (!Redecl->isFromASTFile()) |
| 3089 | return cast<NamedDecl>(Redecl); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3090 | // 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] | 3091 | // local one. |
| 3092 | if (D->getOwningModuleID() == 0) |
| 3093 | break; |
| 3094 | } |
| 3095 | } else if (Decl *First = D->getCanonicalDecl()) { |
| 3096 | // For Mergeable decls, the first decl might be local. |
| 3097 | if (!First->isFromASTFile()) |
| 3098 | return cast<NamedDecl>(First); |
| 3099 | } |
| 3100 | |
| 3101 | // All declarations are imported. Our most recent declaration will also be |
| 3102 | // the most recent one in anyone who imports us. |
| 3103 | return D; |
| 3104 | } |
| 3105 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3106 | namespace { |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3107 | class ASTIdentifierTableTrait { |
| 3108 | ASTWriter &Writer; |
| 3109 | Preprocessor &PP; |
| 3110 | IdentifierResolver &IdResolver; |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3111 | bool IsModule; |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3112 | bool NeedDecls; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3113 | ASTWriter::RecordData *InterestingIdentifierOffsets; |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3114 | |
| 3115 | /// \brief Determines whether this is an "interesting" identifier that needs a |
| 3116 | /// full IdentifierInfo structure written into the hash table. Notably, this |
| 3117 | /// doesn't check whether the name has macros defined; use PublicMacroIterator |
| 3118 | /// to check that. |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3119 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3120 | if (MacroOffset || |
| 3121 | II->isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3122 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3123 | II->hasRevertedTokenIDToIdentifier() || |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3124 | (NeedDecls && II->getFETokenInfo<void>())) |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3125 | return true; |
| 3126 | |
| 3127 | return false; |
| 3128 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3129 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3130 | public: |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3131 | typedef IdentifierInfo* key_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3132 | typedef key_type key_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3134 | typedef IdentID data_type; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3135 | typedef data_type data_type_ref; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3136 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3137 | typedef unsigned hash_value_type; |
| 3138 | typedef unsigned offset_type; |
| 3139 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3140 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3141 | IdentifierResolver &IdResolver, bool IsModule, |
| 3142 | ASTWriter::RecordData *InterestingIdentifierOffsets) |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3143 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3144 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), |
| 3145 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3146 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3147 | static hash_value_type ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 3148 | return llvm::HashString(II->getName()); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3149 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3150 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3151 | bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 3152 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3153 | return isInterestingIdentifier(II, MacroOffset); |
| 3154 | } |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3155 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { |
| 3156 | return isInterestingIdentifier(II, 0); |
| 3157 | } |
| 3158 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3159 | std::pair<unsigned,unsigned> |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3160 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3161 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3162 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3163 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3164 | if (isInterestingIdentifier(II, MacroOffset)) { |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3165 | DataLen += 2; // 2 bytes for builtin ID |
| 3166 | DataLen += 2; // 2 bytes for flags |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3167 | if (MacroOffset) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3168 | DataLen += 4; // MacroDirectives offset. |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3169 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3170 | if (NeedDecls) { |
| 3171 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 3172 | DEnd = IdResolver.end(); |
| 3173 | D != DEnd; ++D) |
| 3174 | DataLen += 4; |
| 3175 | } |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3176 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3177 | using namespace llvm::support; |
| 3178 | endian::Writer<little> LE(Out); |
| 3179 | |
Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3180 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3181 | LE.write<uint16_t>(DataLen); |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3182 | // We emit the key length after the data length so that every |
| 3183 | // string is preceded by a 16-bit length. This matches the PTH |
| 3184 | // format for storing identifiers. |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3185 | LE.write<uint16_t>(KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3186 | return std::make_pair(KeyLen, DataLen); |
| 3187 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3188 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3189 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3190 | unsigned KeyLen) { |
| 3191 | // Record the location of the key data. This is used when generating |
| 3192 | // the mapping from persistent IDs to strings. |
| 3193 | Writer.SetIdentifierOffset(II, Out.tell()); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3194 | |
| 3195 | // Emit the offset of the key/data length information to the interesting |
| 3196 | // identifiers table if necessary. |
| 3197 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) |
| 3198 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); |
| 3199 | |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3200 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3201 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3202 | |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3203 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3204 | IdentID ID, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3205 | using namespace llvm::support; |
| 3206 | endian::Writer<little> LE(Out); |
Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3207 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3208 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); |
| 3209 | if (!isInterestingIdentifier(II, MacroOffset)) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3210 | LE.write<uint32_t>(ID << 1); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3211 | return; |
| 3212 | } |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3213 | |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3214 | LE.write<uint32_t>((ID << 1) | 0x01); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3215 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 3216 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3217 | LE.write<uint16_t>(Bits); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3218 | Bits = 0; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3219 | bool HadMacroDefinition = MacroOffset != 0; |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3220 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3221 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 3222 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3223 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3224 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3225 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3226 | LE.write<uint16_t>(Bits); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3227 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3228 | if (HadMacroDefinition) |
| 3229 | LE.write<uint32_t>(MacroOffset); |
Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3230 | |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3231 | if (NeedDecls) { |
| 3232 | // Emit the declaration IDs in reverse order, because the |
| 3233 | // IdentifierResolver provides the declarations as they would be |
| 3234 | // visible (e.g., the function "stat" would come before the struct |
| 3235 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 3236 | // (so we need to see the struct "stat" before the function "stat"). |
| 3237 | // Only emit declarations that aren't from a chained PCH, though. |
| 3238 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), |
| 3239 | IdResolver.end()); |
| 3240 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), |
| 3241 | DEnd = Decls.rend(); |
| 3242 | D != DEnd; ++D) |
| 3243 | LE.write<uint32_t>( |
| 3244 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); |
| 3245 | } |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3246 | } |
| 3247 | }; |
| 3248 | } // end anonymous namespace |
| 3249 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3250 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3251 | /// |
| 3252 | /// The identifier table consists of a blob containing string data |
| 3253 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 3254 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3255 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 3256 | IdentifierResolver &IdResolver, |
| 3257 | bool IsModule) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3258 | using namespace llvm; |
| 3259 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3260 | RecordData InterestingIdents; |
| 3261 | |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3262 | // Create and write out the blob that contains the identifier |
| 3263 | // strings. |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3264 | { |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3265 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3266 | ASTIdentifierTableTrait Trait( |
| 3267 | *this, PP, IdResolver, IsModule, |
| 3268 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3269 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3270 | // Look for any identifiers that were named while processing the |
| 3271 | // headers, but are otherwise not needed. We add these to the hash |
| 3272 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3273 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3274 | // file. |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3275 | SmallVector<const IdentifierInfo *, 128> IIs; |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3276 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 3277 | IDEnd = PP.getIdentifierTable().end(); |
| 3278 | ID != IDEnd; ++ID) |
Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3279 | IIs.push_back(ID->second); |
| 3280 | // Sort the identifiers lexicographically before getting them references so |
| 3281 | // that their order is stable. |
| 3282 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 3283 | for (const IdentifierInfo *II : IIs) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3284 | if (Trait.isInterestingNonMacroIdentifier(II)) |
| 3285 | getIdentifierRef(II); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3286 | |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3287 | // Create the on-disk hash table representation. We only store offsets |
| 3288 | // for identifiers that appear here for the first time. |
| 3289 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3290 | for (auto IdentIDPair : IdentifierIDs) { |
| 3291 | IdentifierInfo *II = const_cast<IdentifierInfo *>(IdentIDPair.first); |
| 3292 | IdentID ID = IdentIDPair.second; |
| 3293 | assert(II && "NULL identifier in identifier table"); |
| 3294 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 3295 | Generator.insert(II, ID, Trait); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3296 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3297 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3298 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3299 | SmallString<4096> IdentifierTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3300 | uint32_t BucketOffset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3301 | { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3302 | using namespace llvm::support; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3303 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3304 | // Make sure that no bucket is at offset 0 |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3305 | endian::Writer<little>(Out).write<uint32_t>(0); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3306 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | // Create a blob abbreviation |
| 3310 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3311 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3312 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3313 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3314 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3315 | |
| 3316 | // Write the identifier table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3317 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3318 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3322 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3323 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3324 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3325 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3326 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3327 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 3328 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3329 | #ifndef NDEBUG |
| 3330 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) |
| 3331 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); |
| 3332 | #endif |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3333 | |
| 3334 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, |
| 3335 | IdentifierOffsets.size(), |
| 3336 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3337 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3338 | bytes(IdentifierOffsets)); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3339 | |
| 3340 | // In C++, write the list of interesting identifiers (those that are |
| 3341 | // defined as macros, poisoned, or similar unusual things). |
| 3342 | if (!InterestingIdents.empty()) |
| 3343 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3344 | } |
| 3345 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3346 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3347 | // DeclContext's Name Lookup Table Serialization |
| 3348 | //===----------------------------------------------------------------------===// |
| 3349 | |
| 3350 | namespace { |
| 3351 | // Trait used for the on-disk hash table used in the method pool. |
| 3352 | class ASTDeclContextNameLookupTrait { |
| 3353 | ASTWriter &Writer; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3354 | llvm::SmallVector<DeclID, 64> DeclIDs; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3355 | |
| 3356 | public: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3357 | typedef DeclarationNameKey key_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3358 | typedef key_type key_type_ref; |
| 3359 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3360 | /// A start and end index into DeclIDs, representing a sequence of decls. |
| 3361 | typedef std::pair<unsigned, unsigned> data_type; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3362 | typedef const data_type& data_type_ref; |
| 3363 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3364 | typedef unsigned hash_value_type; |
| 3365 | typedef unsigned offset_type; |
| 3366 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3367 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 3368 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3369 | template<typename Coll> |
| 3370 | data_type getData(const Coll &Decls) { |
| 3371 | unsigned Start = DeclIDs.size(); |
| 3372 | for (NamedDecl *D : Decls) { |
| 3373 | DeclIDs.push_back( |
| 3374 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); |
| 3375 | } |
| 3376 | return std::make_pair(Start, DeclIDs.size()); |
| 3377 | } |
| 3378 | |
| 3379 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { |
| 3380 | unsigned Start = DeclIDs.size(); |
| 3381 | for (auto ID : FromReader) |
| 3382 | DeclIDs.push_back(ID); |
| 3383 | return std::make_pair(Start, DeclIDs.size()); |
| 3384 | } |
| 3385 | |
| 3386 | static bool EqualKey(key_type_ref a, key_type_ref b) { |
| 3387 | return a == b; |
| 3388 | } |
| 3389 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3390 | hash_value_type ComputeHash(DeclarationNameKey Name) { |
| 3391 | return Name.getHash(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3392 | } |
| 3393 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3394 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { |
| 3395 | assert(Writer.hasChain() && |
| 3396 | "have reference to loaded module file but no chain?"); |
| 3397 | |
| 3398 | using namespace llvm::support; |
| 3399 | endian::Writer<little>(Out) |
| 3400 | .write<uint32_t>(Writer.getChain()->getModuleFileID(F)); |
| 3401 | } |
| 3402 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3403 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, |
| 3404 | DeclarationNameKey Name, |
| 3405 | data_type_ref Lookup) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3406 | using namespace llvm::support; |
| 3407 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3408 | unsigned KeyLen = 1; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3409 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3410 | case DeclarationName::Identifier: |
| 3411 | case DeclarationName::ObjCZeroArgSelector: |
| 3412 | case DeclarationName::ObjCOneArgSelector: |
| 3413 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3414 | case DeclarationName::CXXLiteralOperatorName: |
| 3415 | KeyLen += 4; |
| 3416 | break; |
| 3417 | case DeclarationName::CXXOperatorName: |
| 3418 | KeyLen += 1; |
| 3419 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3420 | case DeclarationName::CXXConstructorName: |
| 3421 | case DeclarationName::CXXDestructorName: |
| 3422 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3423 | case DeclarationName::CXXUsingDirective: |
| 3424 | break; |
| 3425 | } |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3426 | LE.write<uint16_t>(KeyLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3427 | |
Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3428 | // 4 bytes for each DeclID. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3429 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); |
| 3430 | assert(uint16_t(DataLen) == DataLen && |
| 3431 | "too many decls for serialized lookup result"); |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3432 | LE.write<uint16_t>(DataLen); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3433 | |
| 3434 | return std::make_pair(KeyLen, DataLen); |
| 3435 | } |
| 3436 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3437 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3438 | using namespace llvm::support; |
| 3439 | endian::Writer<little> LE(Out); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3440 | LE.write<uint8_t>(Name.getKind()); |
| 3441 | switch (Name.getKind()) { |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3442 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3443 | case DeclarationName::CXXLiteralOperatorName: |
| 3444 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3445 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3446 | case DeclarationName::ObjCZeroArgSelector: |
| 3447 | case DeclarationName::ObjCOneArgSelector: |
| 3448 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3449 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3450 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3451 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3452 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3453 | "Invalid operator?"); |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3454 | LE.write<uint8_t>(Name.getOperatorKind()); |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3455 | return; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3456 | case DeclarationName::CXXConstructorName: |
| 3457 | case DeclarationName::CXXDestructorName: |
| 3458 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3459 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3460 | return; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3461 | } |
Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3462 | |
| 3463 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3464 | } |
| 3465 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3466 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, |
| 3467 | unsigned DataLen) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3468 | using namespace llvm::support; |
| 3469 | endian::Writer<little> LE(Out); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3470 | uint64_t Start = Out.tell(); (void)Start; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3471 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) |
| 3472 | LE.write<uint32_t>(DeclIDs[I]); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3473 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 3474 | } |
| 3475 | }; |
| 3476 | } // end anonymous namespace |
| 3477 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3478 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, |
| 3479 | DeclContext *DC) { |
| 3480 | return Result.hasExternalDecls() && DC->NeedToReconcileExternalVisibleStorage; |
| 3481 | } |
| 3482 | |
| 3483 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, |
| 3484 | DeclContext *DC) { |
| 3485 | for (auto *D : Result.getLookupResult()) |
| 3486 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) |
| 3487 | return false; |
| 3488 | |
| 3489 | return true; |
| 3490 | } |
| 3491 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3492 | void |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3493 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3494 | llvm::SmallVectorImpl<char> &LookupTable) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3495 | assert(!ConstDC->HasLazyLocalLexicalLookups && |
| 3496 | !ConstDC->HasLazyExternalLexicalLookups && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3497 | "must call buildLookups first"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3498 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3499 | // FIXME: We need to build the lookups table, which is logically const. |
| 3500 | DeclContext *DC = const_cast<DeclContext*>(ConstDC); |
| 3501 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); |
| 3502 | |
| 3503 | // Create the on-disk hash table representation. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3504 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, |
| 3505 | ASTDeclContextNameLookupTrait> Generator; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3506 | ASTDeclContextNameLookupTrait Trait(*this); |
| 3507 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3508 | // The first step is to collect the declaration names which we need to |
| 3509 | // serialize into the name lookup table, and to collect them in a stable |
| 3510 | // order. |
| 3511 | SmallVector<DeclarationName, 16> Names; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3512 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3513 | // We also build up small sets of the constructor and conversion function |
| 3514 | // names which are visible. |
| 3515 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3516 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3517 | for (auto &Lookup : *DC->buildLookup()) { |
| 3518 | auto &Name = Lookup.first; |
| 3519 | auto &Result = Lookup.second; |
| 3520 | |
Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 3521 | // If there are no local declarations in our lookup result, we |
| 3522 | // don't need to write an entry for the name at all. If we can't |
| 3523 | // write out a lookup set without performing more deserialization, |
| 3524 | // just skip this entry. |
| 3525 | if (isLookupResultExternal(Result, DC) && |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3526 | isLookupResultEntirelyExternal(Result, DC)) |
| 3527 | continue; |
| 3528 | |
| 3529 | // We also skip empty results. If any of the results could be external and |
| 3530 | // the currently available results are empty, then all of the results are |
| 3531 | // external and we skip it above. So the only way we get here with an empty |
| 3532 | // results is when no results could have been external *and* we have |
| 3533 | // external results. |
| 3534 | // |
| 3535 | // FIXME: While we might want to start emitting on-disk entries for negative |
| 3536 | // lookups into a decl context as an optimization, today we *have* to skip |
| 3537 | // them because there are names with empty lookup results in decl contexts |
| 3538 | // which we can't emit in any stable ordering: we lookup constructors and |
| 3539 | // conversion functions in the enclosing namespace scope creating empty |
| 3540 | // results for them. This in almost certainly a bug in Clang's name lookup, |
| 3541 | // but that is likely to be hard or impossible to fix and so we tolerate it |
| 3542 | // here by omitting lookups with empty results. |
| 3543 | if (Lookup.second.getLookupResult().empty()) |
| 3544 | continue; |
| 3545 | |
| 3546 | switch (Lookup.first.getNameKind()) { |
| 3547 | default: |
| 3548 | Names.push_back(Lookup.first); |
| 3549 | break; |
| 3550 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3551 | case DeclarationName::CXXConstructorName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3552 | assert(isa<CXXRecordDecl>(DC) && |
| 3553 | "Cannot have a constructor name outside of a class!"); |
| 3554 | ConstructorNameSet.insert(Name); |
| 3555 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3556 | |
| 3557 | case DeclarationName::CXXConversionFunctionName: |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3558 | assert(isa<CXXRecordDecl>(DC) && |
| 3559 | "Cannot have a conversion function name outside of a class!"); |
| 3560 | ConversionNameSet.insert(Name); |
Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 3561 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3562 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3563 | } |
Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3564 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3565 | // Sort the names into a stable order. |
| 3566 | std::sort(Names.begin(), Names.end()); |
| 3567 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3568 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3569 | // We need to establish an ordering of constructor and conversion function |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3570 | // names, and they don't have an intrinsic ordering. |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3571 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3572 | // First we try the easy case by forming the current context's constructor |
| 3573 | // name and adding that name first. This is a very useful optimization to |
| 3574 | // avoid walking the lexical declarations in many cases, and it also |
| 3575 | // handles the only case where a constructor name can come from some other |
| 3576 | // lexical context -- when that name is an implicit constructor merged from |
| 3577 | // another declaration in the redecl chain. Any non-implicit constructor or |
| 3578 | // conversion function which doesn't occur in all the lexical contexts |
| 3579 | // would be an ODR violation. |
| 3580 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( |
| 3581 | Context->getCanonicalType(Context->getRecordType(D))); |
| 3582 | if (ConstructorNameSet.erase(ImplicitCtorName)) |
| 3583 | Names.push_back(ImplicitCtorName); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3584 | |
Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3585 | // If we still have constructors or conversion functions, we walk all the |
| 3586 | // names in the decl and add the constructors and conversion functions |
| 3587 | // which are visible in the order they lexically occur within the context. |
| 3588 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) |
| 3589 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) |
| 3590 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { |
| 3591 | auto Name = ChildND->getDeclName(); |
| 3592 | switch (Name.getNameKind()) { |
| 3593 | default: |
| 3594 | continue; |
| 3595 | |
| 3596 | case DeclarationName::CXXConstructorName: |
| 3597 | if (ConstructorNameSet.erase(Name)) |
| 3598 | Names.push_back(Name); |
| 3599 | break; |
| 3600 | |
| 3601 | case DeclarationName::CXXConversionFunctionName: |
| 3602 | if (ConversionNameSet.erase(Name)) |
| 3603 | Names.push_back(Name); |
| 3604 | break; |
| 3605 | } |
| 3606 | |
| 3607 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) |
| 3608 | break; |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3609 | } |
| 3610 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3611 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " |
| 3612 | "constructors by walking all the " |
| 3613 | "lexical members of the context."); |
| 3614 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " |
| 3615 | "conversion functions by walking all " |
| 3616 | "the lexical members of the context."); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3619 | // Next we need to do a lookup with each name into this decl context to fully |
| 3620 | // populate any results from external sources. We don't actually use the |
| 3621 | // results of these lookups because we only want to use the results after all |
| 3622 | // results have been loaded and the pointers into them will be stable. |
| 3623 | for (auto &Name : Names) |
| 3624 | DC->lookup(Name); |
| 3625 | |
| 3626 | // Now we need to insert the results for each name into the hash table. For |
| 3627 | // constructor names and conversion function names, we actually need to merge |
| 3628 | // all of the results for them into one list of results each and insert |
| 3629 | // those. |
| 3630 | SmallVector<NamedDecl *, 8> ConstructorDecls; |
| 3631 | SmallVector<NamedDecl *, 8> ConversionDecls; |
| 3632 | |
| 3633 | // Now loop over the names, either inserting them or appending for the two |
| 3634 | // special cases. |
| 3635 | for (auto &Name : Names) { |
| 3636 | DeclContext::lookup_result Result = DC->noload_lookup(Name); |
| 3637 | |
| 3638 | switch (Name.getNameKind()) { |
| 3639 | default: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3640 | Generator.insert(Name, Trait.getData(Result), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3641 | break; |
| 3642 | |
| 3643 | case DeclarationName::CXXConstructorName: |
| 3644 | ConstructorDecls.append(Result.begin(), Result.end()); |
| 3645 | break; |
| 3646 | |
| 3647 | case DeclarationName::CXXConversionFunctionName: |
| 3648 | ConversionDecls.append(Result.begin(), Result.end()); |
| 3649 | break; |
| 3650 | } |
| 3651 | } |
| 3652 | |
| 3653 | // Handle our two special cases if we ended up having any. We arbitrarily use |
| 3654 | // the first declaration's name here because the name itself isn't part of |
| 3655 | // the key, only the kind of name is used. |
| 3656 | if (!ConstructorDecls.empty()) |
| 3657 | Generator.insert(ConstructorDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3658 | Trait.getData(ConstructorDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3659 | if (!ConversionDecls.empty()) |
| 3660 | Generator.insert(ConversionDecls.front()->getDeclName(), |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3661 | Trait.getData(ConversionDecls), Trait); |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3662 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3663 | // Create the on-disk hash table. Also emit the existing imported and |
| 3664 | // merged table if there is one. |
| 3665 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; |
| 3666 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3669 | /// \brief Write the block containing all of the declaration IDs |
| 3670 | /// visible from the given DeclContext. |
| 3671 | /// |
| 3672 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3673 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3674 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 3675 | DeclContext *DC) { |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3676 | // If we imported a key declaration of this namespace, write the visible |
| 3677 | // lookup results as an update record for it rather than including them |
| 3678 | // on this declaration. We will only look at key declarations on reload. |
| 3679 | if (isa<NamespaceDecl>(DC) && Chain && |
| 3680 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { |
| 3681 | // Only do this once, for the first local declaration of the namespace. |
| 3682 | for (NamespaceDecl *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; |
| 3683 | Prev = Prev->getPreviousDecl()) |
| 3684 | if (!Prev->isFromASTFile()) |
| 3685 | return 0; |
| 3686 | |
| 3687 | // Note that we need to emit an update record for the primary context. |
| 3688 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); |
| 3689 | |
| 3690 | // Make sure all visible decls are written. They will be recorded later. We |
| 3691 | // do this using a side data structure so we can sort the names into |
| 3692 | // a deterministic order. |
| 3693 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); |
| 3694 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> |
| 3695 | LookupResults; |
| 3696 | if (Map) { |
| 3697 | LookupResults.reserve(Map->size()); |
| 3698 | for (auto &Entry : *Map) |
| 3699 | LookupResults.push_back( |
| 3700 | std::make_pair(Entry.first, Entry.second.getLookupResult())); |
| 3701 | } |
| 3702 | |
| 3703 | std::sort(LookupResults.begin(), LookupResults.end(), llvm::less_first()); |
| 3704 | for (auto &NameAndResult : LookupResults) { |
| 3705 | DeclarationName Name = NameAndResult.first; |
| 3706 | DeclContext::lookup_result Result = NameAndResult.second; |
| 3707 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || |
| 3708 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 3709 | // We have to work around a name lookup bug here where negative lookup |
| 3710 | // results for these names get cached in namespace lookup tables (these |
| 3711 | // names should never be looked up in a namespace). |
| 3712 | assert(Result.empty() && "Cannot have a constructor or conversion " |
| 3713 | "function name in a namespace!"); |
| 3714 | continue; |
| 3715 | } |
| 3716 | |
| 3717 | for (NamedDecl *ND : Result) |
| 3718 | if (!ND->isFromASTFile()) |
| 3719 | GetDeclRef(ND); |
| 3720 | } |
| 3721 | |
| 3722 | return 0; |
| 3723 | } |
| 3724 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3725 | if (DC->getPrimaryContext() != DC) |
| 3726 | return 0; |
| 3727 | |
Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3728 | // Skip contexts which don't support name lookup. |
| 3729 | if (!DC->isLookupContext()) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3730 | return 0; |
| 3731 | |
| 3732 | // If not in C++, we perform name lookup for the translation unit via the |
| 3733 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3734 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3735 | return 0; |
| 3736 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3737 | // Serialize the contents of the mapping used for lookup. Note that, |
| 3738 | // although we have two very different code paths, the serialized |
| 3739 | // representation is the same for both cases: a declaration name, |
| 3740 | // followed by a size, followed by references to the visible |
| 3741 | // declarations that have that name. |
| 3742 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3743 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3744 | if (!Map || Map->empty()) |
| 3745 | return 0; |
| 3746 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3747 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3748 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3749 | GenerateNameLookupTable(DC, LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3750 | |
| 3751 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3752 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3753 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3754 | LookupTable); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3755 | ++NumVisibleDeclContexts; |
| 3756 | return Offset; |
| 3757 | } |
| 3758 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3759 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 3760 | /// |
| 3761 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 3762 | /// 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] | 3763 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 3764 | /// enumeration members (in C++11). |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3765 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3766 | StoredDeclsMap *Map = DC->getLookupPtr(); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3767 | if (!Map || Map->empty()) |
| 3768 | return; |
| 3769 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3770 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3771 | SmallString<4096> LookupTable; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3772 | GenerateNameLookupTable(DC, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3773 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3774 | // If we're updating a namespace, select a key declaration as the key for the |
| 3775 | // update record; those are the only ones that will be checked on reload. |
| 3776 | if (isa<NamespaceDecl>(DC)) |
| 3777 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); |
| 3778 | |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3779 | // Write the lookup table |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3780 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3781 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); |
Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3782 | } |
| 3783 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3784 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3785 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3786 | RecordData::value_type Record[] = {Opts.fp_contract}; |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3787 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3788 | } |
| 3789 | |
| 3790 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3791 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3792 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3793 | return; |
| 3794 | |
| 3795 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3796 | RecordData Record; |
| 3797 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3798 | #include "clang/Basic/OpenCLExtensions.def" |
| 3799 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3800 | } |
| 3801 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3802 | void ASTWriter::WriteObjCCategories() { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3803 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3804 | RecordData Categories; |
| 3805 | |
| 3806 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3807 | unsigned Size = 0; |
| 3808 | unsigned StartIndex = Categories.size(); |
| 3809 | |
| 3810 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3811 | |
| 3812 | // Allocate space for the size. |
| 3813 | Categories.push_back(0); |
| 3814 | |
| 3815 | // Add the categories. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3816 | for (ObjCInterfaceDecl::known_categories_iterator |
| 3817 | Cat = Class->known_categories_begin(), |
| 3818 | CatEnd = Class->known_categories_end(); |
| 3819 | Cat != CatEnd; ++Cat, ++Size) { |
| 3820 | assert(getDeclID(*Cat) != 0 && "Bogus category"); |
| 3821 | AddDeclRef(*Cat, Categories); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | // Update the size. |
| 3825 | Categories[StartIndex] = Size; |
| 3826 | |
| 3827 | // Record this interface -> category map. |
| 3828 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3829 | CategoriesMap.push_back(CatInfo); |
| 3830 | } |
| 3831 | |
| 3832 | // Sort the categories map by the definition ID, since the reader will be |
| 3833 | // performing binary searches on this information. |
| 3834 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3835 | |
| 3836 | // Emit the categories map. |
| 3837 | using namespace llvm; |
| 3838 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3839 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3840 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3841 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3842 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3843 | |
| 3844 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; |
| 3845 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3846 | reinterpret_cast<char *>(CategoriesMap.data()), |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3847 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3848 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3849 | // Emit the category lists. |
| 3850 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3851 | } |
| 3852 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3853 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { |
| 3854 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; |
| 3855 | |
| 3856 | if (LPTMap.empty()) |
| 3857 | return; |
| 3858 | |
| 3859 | RecordData Record; |
Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 3860 | for (auto LPTMapEntry : LPTMap) { |
| 3861 | const FunctionDecl *FD = LPTMapEntry.first; |
| 3862 | LateParsedTemplate *LPT = LPTMapEntry.second; |
| 3863 | AddDeclRef(FD, Record); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3864 | AddDeclRef(LPT->D, Record); |
| 3865 | Record.push_back(LPT->Toks.size()); |
| 3866 | |
| 3867 | for (CachedTokens::iterator TokIt = LPT->Toks.begin(), |
| 3868 | TokEnd = LPT->Toks.end(); |
| 3869 | TokIt != TokEnd; ++TokIt) { |
| 3870 | AddToken(*TokIt, Record); |
| 3871 | } |
| 3872 | } |
| 3873 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); |
| 3874 | } |
| 3875 | |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3876 | /// \brief Write the state of 'pragma clang optimize' at the end of the module. |
| 3877 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { |
| 3878 | RecordData Record; |
| 3879 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); |
| 3880 | AddSourceLocation(PragmaLoc, Record); |
| 3881 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); |
| 3882 | } |
| 3883 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3884 | void ASTWriter::WriteModuleFileExtension(ModuleFileExtensionWriter &Writer) { |
| 3885 | // Enter the extension block. |
| 3886 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); |
| 3887 | |
| 3888 | // Emit the metadata record abbreviation. |
| 3889 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 3890 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); |
| 3891 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3892 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3893 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3894 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3895 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3896 | unsigned Abbrev = Stream.EmitAbbrev(Abv); |
| 3897 | |
| 3898 | // Emit the metadata record. |
| 3899 | RecordData Record; |
| 3900 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); |
| 3901 | Record.push_back(EXTENSION_METADATA); |
| 3902 | Record.push_back(Metadata.MajorVersion); |
| 3903 | Record.push_back(Metadata.MinorVersion); |
| 3904 | Record.push_back(Metadata.BlockName.size()); |
| 3905 | Record.push_back(Metadata.UserInfo.size()); |
| 3906 | SmallString<64> Buffer; |
| 3907 | Buffer += Metadata.BlockName; |
| 3908 | Buffer += Metadata.UserInfo; |
| 3909 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); |
| 3910 | |
| 3911 | // Emit the contents of the extension block. |
| 3912 | Writer.writeExtensionContents(Stream); |
| 3913 | |
| 3914 | // Exit the extension block. |
| 3915 | Stream.ExitBlock(); |
| 3916 | } |
| 3917 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3918 | //===----------------------------------------------------------------------===// |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3919 | // General Serialization Routines |
| 3920 | //===----------------------------------------------------------------------===// |
| 3921 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3922 | /// \brief Write a record containing the given attributes. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3923 | void ASTWriter::WriteAttributes(ArrayRef<const Attr*> Attrs, |
| 3924 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9beef8e | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3925 | Record.push_back(Attrs.size()); |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3926 | for (ArrayRef<const Attr *>::iterator i = Attrs.begin(), |
| 3927 | e = Attrs.end(); i != e; ++i){ |
| 3928 | const Attr *A = *i; |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3929 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Argyrios Kyrtzidis | 309b4c4 | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 3930 | AddSourceRange(A->getRange(), Record); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3931 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3932 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | fc6507e | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 3933 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3934 | } |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3935 | } |
| 3936 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 3937 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { |
| 3938 | AddSourceLocation(Tok.getLocation(), Record); |
| 3939 | Record.push_back(Tok.getLength()); |
| 3940 | |
| 3941 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 3942 | // if it is needed. |
| 3943 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 3944 | // FIXME: Should translate token kind to a stable encoding. |
| 3945 | Record.push_back(Tok.getKind()); |
| 3946 | // FIXME: Should translate token flags to a stable encoding. |
| 3947 | Record.push_back(Tok.getFlags()); |
| 3948 | } |
| 3949 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3950 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3951 | Record.push_back(Str.size()); |
| 3952 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 3953 | } |
| 3954 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3955 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 3956 | assert(Context && "should have context when outputting path"); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3957 | |
Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 3958 | bool Changed = |
| 3959 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3960 | |
| 3961 | // Remove a prefix to make the path relative, if relevant. |
| 3962 | const char *PathBegin = Path.data(); |
| 3963 | const char *PathPtr = |
| 3964 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); |
| 3965 | if (PathPtr != PathBegin) { |
| 3966 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); |
| 3967 | Changed = true; |
| 3968 | } |
| 3969 | |
| 3970 | return Changed; |
| 3971 | } |
| 3972 | |
| 3973 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { |
| 3974 | SmallString<128> FilePath(Path); |
| 3975 | PreparePathForOutput(FilePath); |
| 3976 | AddString(FilePath, Record); |
| 3977 | } |
| 3978 | |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3979 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3980 | StringRef Path) { |
| 3981 | SmallString<128> FilePath(Path); |
| 3982 | PreparePathForOutput(FilePath); |
| 3983 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); |
| 3984 | } |
| 3985 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3986 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 3987 | RecordDataImpl &Record) { |
| 3988 | Record.push_back(Version.getMajor()); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3989 | if (Optional<unsigned> Minor = Version.getMinor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3990 | Record.push_back(*Minor + 1); |
| 3991 | else |
| 3992 | Record.push_back(0); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3993 | if (Optional<unsigned> Subminor = Version.getSubminor()) |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3994 | Record.push_back(*Subminor + 1); |
| 3995 | else |
| 3996 | Record.push_back(0); |
| 3997 | } |
| 3998 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3999 | /// \brief Note that the identifier II occurs at the given offset |
| 4000 | /// within the identifier table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4001 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4002 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4003 | // 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] | 4004 | // up earlier in the chain and thus don't need an offset. |
| 4005 | if (ID >= FirstIdentID) |
| 4006 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4007 | } |
| 4008 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4009 | /// \brief Note that the selector Sel occurs at the given offset |
| 4010 | /// within the method pool/selector table. |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4011 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4012 | unsigned ID = SelectorIDs[Sel]; |
| 4013 | assert(ID && "Unknown selector"); |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4014 | // Don't record offsets for selectors that are also available in a different |
| 4015 | // file. |
| 4016 | if (ID < FirstSelectorID) |
| 4017 | return; |
| 4018 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4019 | } |
| 4020 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4021 | ASTWriter::ASTWriter( |
| 4022 | llvm::BitstreamWriter &Stream, |
| 4023 | ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions, |
| 4024 | bool IncludeTimestamps) |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4025 | : Stream(Stream), Context(nullptr), PP(nullptr), Chain(nullptr), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4026 | WritingModule(nullptr), IncludeTimestamps(IncludeTimestamps), |
| 4027 | WritingAST(false), DoneWritingDeclsAndTypes(false), |
| 4028 | ASTHasCompilerErrors(false), FirstDeclID(NUM_PREDEF_DECL_IDS), |
| 4029 | NextDeclID(FirstDeclID), FirstTypeID(NUM_PREDEF_TYPE_IDS), |
| 4030 | NextTypeID(FirstTypeID), FirstIdentID(NUM_PREDEF_IDENT_IDS), |
| 4031 | NextIdentID(FirstIdentID), FirstMacroID(NUM_PREDEF_MACRO_IDS), |
| 4032 | NextMacroID(FirstMacroID), FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4033 | NextSubmoduleID(FirstSubmoduleID), |
| 4034 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
| 4035 | CollectedStmts(&StmtsToEmit), NumStatements(0), NumMacros(0), |
| 4036 | NumLexicalDeclContexts(0), NumVisibleDeclContexts(0), |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4037 | NextCXXBaseSpecifiersID(1), NextCXXCtorInitializersID(1), |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4038 | TypeExtQualAbbrev(0), TypeFunctionProtoAbbrev(0), DeclParmVarAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4039 | DeclContextLexicalAbbrev(0), DeclContextVisibleLookupAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4040 | UpdateVisibleAbbrev(0), DeclRecordAbbrev(0), DeclTypedefAbbrev(0), |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4041 | DeclVarAbbrev(0), DeclFieldAbbrev(0), DeclEnumAbbrev(0), |
Richard Smith | a27c26e | 2014-07-27 04:19:32 +0000 | [diff] [blame] | 4042 | DeclObjCIvarAbbrev(0), DeclCXXMethodAbbrev(0), DeclRefExprAbbrev(0), |
| 4043 | CharacterLiteralAbbrev(0), IntegerLiteralAbbrev(0), |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4044 | ExprImplicitCastAbbrev(0) { |
| 4045 | for (const auto &Ext : Extensions) { |
| 4046 | if (auto Writer = Ext->createExtensionWriter(*this)) |
| 4047 | ModuleFileExtensionWriters.push_back(std::move(Writer)); |
| 4048 | } |
| 4049 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4050 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4051 | ASTWriter::~ASTWriter() { |
Reid Kleckner | 588c937 | 2014-02-19 23:44:52 +0000 | [diff] [blame] | 4052 | llvm::DeleteContainerSeconds(FileDeclIDs); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4053 | } |
| 4054 | |
Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4055 | const LangOptions &ASTWriter::getLangOpts() const { |
| 4056 | assert(WritingAST && "can't determine lang opts when not writing AST"); |
| 4057 | return Context->getLangOpts(); |
| 4058 | } |
| 4059 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4060 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { |
| 4061 | return IncludeTimestamps ? E->getModificationTime() : 0; |
| 4062 | } |
| 4063 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4064 | uint64_t ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile, |
| 4065 | Module *WritingModule, StringRef isysroot, |
| 4066 | bool hasErrors) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4067 | WritingAST = true; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4068 | |
Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4069 | ASTHasCompilerErrors = hasErrors; |
| 4070 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4071 | // Emit the file header. |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4072 | Stream.Emit((unsigned)'C', 8); |
| 4073 | Stream.Emit((unsigned)'P', 8); |
| 4074 | Stream.Emit((unsigned)'C', 8); |
| 4075 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | |
Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4077 | WriteBlockInfoBlock(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4078 | |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4079 | Context = &SemaRef.Context; |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4080 | PP = &SemaRef.PP; |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4081 | this->WritingModule = WritingModule; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4082 | ASTFileSignature Signature = |
| 4083 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4084 | Context = nullptr; |
| 4085 | PP = nullptr; |
| 4086 | this->WritingModule = nullptr; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4087 | this->BaseDirectory.clear(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4088 | |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4089 | WritingAST = false; |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4090 | return Signature; |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4091 | } |
| 4092 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4093 | template<typename Vector> |
| 4094 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 4095 | ASTWriter::RecordData &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4096 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); |
| 4097 | I != E; ++I) { |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4098 | Writer.AddDeclRef(*I, Record); |
| 4099 | } |
| 4100 | } |
| 4101 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4102 | uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, |
| 4103 | const std::string &OutputFile, |
| 4104 | Module *WritingModule) { |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4105 | using namespace llvm; |
| 4106 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4107 | bool isModule = WritingModule != nullptr; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4108 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4109 | // Make sure that the AST reader knows to finalize itself. |
| 4110 | if (Chain) |
| 4111 | Chain->finalizeForWriting(); |
| 4112 | |
Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4113 | ASTContext &Context = SemaRef.Context; |
| 4114 | Preprocessor &PP = SemaRef.PP; |
| 4115 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4116 | // Set up predefined declaration IDs. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4117 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { |
| 4118 | if (D) { |
| 4119 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); |
| 4120 | DeclIDs[D] = ID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4121 | } |
| 4122 | }; |
| 4123 | RegisterPredefDecl(Context.getTranslationUnitDecl(), |
| 4124 | PREDEF_DECL_TRANSLATION_UNIT_ID); |
| 4125 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); |
| 4126 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); |
| 4127 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); |
| 4128 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, |
| 4129 | PREDEF_DECL_OBJC_PROTOCOL_ID); |
| 4130 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); |
| 4131 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); |
| 4132 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, |
| 4133 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); |
| 4134 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4135 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4136 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, |
| 4137 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4138 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4139 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, |
| 4140 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); |
Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4141 | |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4142 | // 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] | 4143 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4144 | // headers. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4145 | RecordData TentativeDefinitions; |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4146 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4147 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4148 | // Build a record containing all of the file scoped decls in this file. |
| 4149 | RecordData UnusedFileScopedDecls; |
Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4150 | if (!isModule) |
| 4151 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 4152 | UnusedFileScopedDecls); |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4154 | // Build a record containing all of the delegating constructors we still need |
| 4155 | // to resolve. |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4156 | RecordData DelegatingCtorDecls; |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4157 | if (!isModule) |
| 4158 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4159 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4160 | // Write the set of weak, undeclared identifiers. We always write the |
| 4161 | // entire table, since later PCH files in a PCH chain are only interested in |
| 4162 | // the results at the end of the chain. |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4163 | RecordData WeakUndeclaredIdentifiers; |
Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4164 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { |
| 4165 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; |
| 4166 | WeakInfo &WI = WeakUndeclaredIdentifier.second; |
| 4167 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); |
| 4168 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); |
| 4169 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); |
| 4170 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4171 | } |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4172 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4173 | // Build a record containing all of the ext_vector declarations. |
| 4174 | RecordData ExtVectorDecls; |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4175 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4176 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4177 | // Build a record containing all of the VTable uses information. |
| 4178 | RecordData VTableUses; |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4179 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4180 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 4181 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 4182 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 4183 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 4184 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4185 | } |
| 4186 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4187 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. |
| 4188 | RecordData UnusedLocalTypedefNameCandidates; |
| 4189 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) |
| 4190 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); |
| 4191 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4192 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4193 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4194 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4195 | I = SemaRef.PendingInstantiations.begin(), |
| 4196 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 4197 | AddDeclRef(I->first, PendingInstantiations); |
| 4198 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4199 | } |
| 4200 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 4201 | "There are local ones at end of translation unit!"); |
| 4202 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4203 | // Build a record containing some declaration references. |
| 4204 | RecordData SemaDeclRefs; |
| 4205 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 4206 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 4207 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 4208 | } |
| 4209 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4210 | RecordData CUDASpecialDeclRefs; |
| 4211 | if (Context.getcudaConfigureCallDecl()) { |
| 4212 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 4213 | } |
| 4214 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4215 | // Build a record containing all of the known namespaces. |
| 4216 | RecordData KnownNamespaces; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4217 | for (llvm::MapVector<NamespaceDecl*, bool>::iterator |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4218 | I = SemaRef.KnownNamespaces.begin(), |
| 4219 | IEnd = SemaRef.KnownNamespaces.end(); |
| 4220 | I != IEnd; ++I) { |
| 4221 | if (!I->second) |
| 4222 | AddDeclRef(I->first, KnownNamespaces); |
| 4223 | } |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4224 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4225 | // Build a record of all used, undefined objects that require definitions. |
| 4226 | RecordData UndefinedButUsed; |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4227 | |
| 4228 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4229 | SemaRef.getUndefinedButUsed(Undefined); |
Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4230 | for (SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> >::iterator |
| 4231 | I = Undefined.begin(), E = Undefined.end(); I != E; ++I) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4232 | AddDeclRef(I->first, UndefinedButUsed); |
| 4233 | AddSourceLocation(I->second, UndefinedButUsed); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4234 | } |
| 4235 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4236 | // Build a record containing all delete-expressions that we would like to |
| 4237 | // analyze later in AST. |
| 4238 | RecordData DeleteExprsToAnalyze; |
| 4239 | |
| 4240 | for (const auto &DeleteExprsInfo : |
| 4241 | SemaRef.getMismatchingDeleteExpressions()) { |
| 4242 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); |
| 4243 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); |
| 4244 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { |
| 4245 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); |
| 4246 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); |
| 4247 | } |
| 4248 | } |
| 4249 | |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4250 | // Write the control block |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4251 | uint64_t Signature = WriteControlBlock(PP, Context, isysroot, OutputFile); |
Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4252 | |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4253 | // Write the remaining AST contents. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4254 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4255 | |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4256 | // This is so that older clang versions, before the introduction |
| 4257 | // of the control block, can read and reject the newer PCH format. |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4258 | { |
| 4259 | RecordData Record = {VERSION_MAJOR}; |
| 4260 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); |
| 4261 | } |
Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4262 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4263 | // Create a lexical update block containing all of the declarations in the |
| 4264 | // translation unit that do not come from other AST files. |
| 4265 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4266 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; |
| 4267 | for (const auto *D : TU->noload_decls()) { |
| 4268 | if (!D->isFromASTFile()) { |
| 4269 | NewGlobalKindDeclPairs.push_back(D->getKind()); |
| 4270 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); |
| 4271 | } |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 4275 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 4276 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4277 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4278 | { |
| 4279 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; |
| 4280 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 4281 | bytes(NewGlobalKindDeclPairs)); |
| 4282 | } |
| 4283 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4284 | // And a visible updates block for the translation unit. |
| 4285 | Abv = new llvm::BitCodeAbbrev(); |
| 4286 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 4287 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4288 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 4289 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 4290 | WriteDeclContextVisibleUpdate(TU); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4291 | |
| 4292 | // If we have any extern "C" names, write out a visible update for them. |
| 4293 | if (Context.ExternCContext) |
| 4294 | WriteDeclContextVisibleUpdate(Context.ExternCContext); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4295 | |
| 4296 | // If the translation unit has an anonymous namespace, and we don't already |
| 4297 | // have an update block for it, write it as an update block. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4298 | // 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] | 4299 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 4300 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4301 | if (Record.empty()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4302 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4303 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4304 | |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4305 | // Add update records for all mangling numbers and static local numbers. |
| 4306 | // These aren't really update records, but this is a convenient way of |
| 4307 | // tagging this rare extra data onto the declarations. |
| 4308 | for (const auto &Number : Context.MangleNumbers) |
| 4309 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4310 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, |
| 4311 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4312 | for (const auto &Number : Context.StaticLocalNumbers) |
| 4313 | if (!Number.first->isFromASTFile()) |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4314 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, |
| 4315 | Number.second)); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4316 | |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4317 | // Make sure visible decls, added to DeclContexts previously loaded from |
| 4318 | // an AST file, are registered for serialization. |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 4319 | for (SmallVectorImpl<const Decl *>::iterator |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4320 | I = UpdatingVisibleDecls.begin(), |
| 4321 | E = UpdatingVisibleDecls.end(); I != E; ++I) { |
| 4322 | GetDeclRef(*I); |
| 4323 | } |
| 4324 | |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4325 | // Make sure all decls associated with an identifier are registered for |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4326 | // serialization, if we're storing decls with identifiers. |
| 4327 | if (!WritingModule || !getLangOpts().CPlusPlus) { |
| 4328 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; |
| 4329 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 4330 | IDEnd = PP.getIdentifierTable().end(); |
| 4331 | ID != IDEnd; ++ID) { |
| 4332 | const IdentifierInfo *II = ID->second; |
| 4333 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) |
| 4334 | IIs.push_back(II); |
| 4335 | } |
| 4336 | // Sort the identifiers to visit based on their name. |
| 4337 | std::sort(IIs.begin(), IIs.end(), llvm::less_ptr<IdentifierInfo>()); |
| 4338 | for (const IdentifierInfo *II : IIs) { |
| 4339 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), |
| 4340 | DEnd = SemaRef.IdResolver.end(); |
| 4341 | D != DEnd; ++D) { |
| 4342 | GetDeclRef(*D); |
| 4343 | } |
Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4344 | } |
| 4345 | } |
| 4346 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4347 | // Form the record of special types. |
| 4348 | RecordData SpecialTypes; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4349 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4350 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 4351 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 4352 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 4353 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 4354 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4355 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4356 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4357 | |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4358 | if (Chain) { |
| 4359 | // Write the mapping information describing our module dependencies and how |
| 4360 | // each of those modules were mapped into our own offset/ID space, so that |
| 4361 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 4362 | // The map consists solely of a blob with the following format: |
| 4363 | // *(module-name-len:i16 module-name:len*i8 |
| 4364 | // source-location-offset:i32 |
| 4365 | // identifier-id:i32 |
| 4366 | // preprocessed-entity-id:i32 |
| 4367 | // macro-definition-id:i32 |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4368 | // submodule-id:i32 |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4369 | // selector-id:i32 |
| 4370 | // declaration-id:i32 |
| 4371 | // c++-base-specifiers-id:i32 |
| 4372 | // type-id:i32) |
| 4373 | // |
| 4374 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 4375 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 4376 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 4377 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4378 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4379 | { |
| 4380 | llvm::raw_svector_ostream Out(Buffer); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4381 | for (ModuleFile *M : Chain->ModuleMgr) { |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4382 | using namespace llvm::support; |
| 4383 | endian::Writer<little> LE(Out); |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4384 | StringRef FileName = M->FileName; |
Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4385 | LE.write<uint16_t>(FileName.size()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4386 | Out.write(FileName.data(), FileName.size()); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4387 | |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4388 | // Note: if a base ID was uint max, it would not be possible to load |
| 4389 | // another module after it or have more than one entity inside it. |
| 4390 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 4391 | |
| 4392 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { |
| 4393 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); |
| 4394 | if (ShouldWrite) |
| 4395 | LE.write<uint32_t>(BaseID); |
| 4396 | else |
| 4397 | LE.write<uint32_t>(None); |
| 4398 | }; |
| 4399 | |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4400 | // These values should be unique within a chain, since they will be read |
| 4401 | // as keys into ContinuousRangeMaps. |
Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4402 | writeBaseIDOrNone(M->SLocEntryBaseOffset, M->LocalNumSLocEntries); |
| 4403 | writeBaseIDOrNone(M->BaseIdentifierID, M->LocalNumIdentifiers); |
| 4404 | writeBaseIDOrNone(M->BaseMacroID, M->LocalNumMacros); |
| 4405 | writeBaseIDOrNone(M->BasePreprocessedEntityID, |
| 4406 | M->NumPreprocessedEntities); |
| 4407 | writeBaseIDOrNone(M->BaseSubmoduleID, M->LocalNumSubmodules); |
| 4408 | writeBaseIDOrNone(M->BaseSelectorID, M->LocalNumSelectors); |
| 4409 | writeBaseIDOrNone(M->BaseDeclID, M->LocalNumDecls); |
| 4410 | writeBaseIDOrNone(M->BaseTypeIndex, M->LocalNumTypes); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4411 | } |
| 4412 | } |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4413 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4414 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 4415 | Buffer.data(), Buffer.size()); |
| 4416 | } |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4417 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4418 | RecordData DeclUpdatesOffsetsRecord; |
| 4419 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4420 | // Keep writing types, declarations, and declaration update records |
| 4421 | // until we've emitted all of them. |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4422 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); |
| 4423 | WriteTypeAbbrevs(); |
| 4424 | WriteDeclAbbrevs(); |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4425 | do { |
| 4426 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); |
| 4427 | while (!DeclTypesToEmit.empty()) { |
| 4428 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 4429 | DeclTypesToEmit.pop(); |
| 4430 | if (DOT.isType()) |
| 4431 | WriteType(DOT.getType()); |
| 4432 | else |
| 4433 | WriteDecl(Context, DOT.getDecl()); |
| 4434 | } |
| 4435 | } while (!DeclUpdates.empty()); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4436 | Stream.ExitBlock(); |
| 4437 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4438 | DoneWritingDeclsAndTypes = true; |
| 4439 | |
| 4440 | // These things can only be done once we've written out decls and types. |
| 4441 | WriteTypeDeclOffsets(); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4442 | if (!DeclUpdatesOffsetsRecord.empty()) |
| 4443 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4444 | WriteCXXBaseSpecifiersOffsets(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4445 | WriteCXXCtorInitializersOffsets(); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4446 | WriteFileDeclIDsMap(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4447 | WriteSourceManagerBlock(Context.getSourceManager(), PP); |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4448 | WriteComments(); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4449 | WritePreprocessor(PP, isModule); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4450 | WriteHeaderSearch(PP.getHeaderSearchInfo()); |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4451 | WriteSelectors(SemaRef); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4452 | WriteReferencedSelectorsPool(SemaRef); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 4453 | WriteLateParsedTemplates(SemaRef); |
Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4454 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4455 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 4456 | WriteOpenCLExtensions(SemaRef); |
Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 4457 | WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4458 | |
Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4459 | // If we're emitting a module, write out the submodule information. |
| 4460 | if (WritingModule) |
| 4461 | WriteSubmodules(WritingModule); |
| 4462 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4463 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 4464 | |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4465 | // Write the record containing external, unnamed definitions. |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 4466 | if (!EagerlyDeserializedDecls.empty()) |
| 4467 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4468 | |
| 4469 | // Write the record containing tentative definitions. |
| 4470 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4471 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4472 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4473 | // Write the record containing unused file scoped decls. |
| 4474 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4475 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4476 | |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4477 | // Write the record containing weak undeclared identifiers. |
| 4478 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4479 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4480 | WeakUndeclaredIdentifiers); |
| 4481 | |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4482 | // Write the record containing ext_vector type names. |
| 4483 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4484 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4485 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4486 | // Write the record containing VTable uses information. |
| 4487 | if (!VTableUses.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4488 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4489 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4490 | // Write the record containing potentially unused local typedefs. |
| 4491 | if (!UnusedLocalTypedefNameCandidates.empty()) |
| 4492 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, |
| 4493 | UnusedLocalTypedefNameCandidates); |
| 4494 | |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4495 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4496 | if (!PendingInstantiations.empty()) |
| 4497 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4498 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4499 | // Write the record containing declaration references of Sema. |
| 4500 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4501 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4502 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4503 | // Write the record containing CUDA-specific declaration references. |
| 4504 | if (!CUDASpecialDeclRefs.empty()) |
| 4505 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4506 | |
| 4507 | // Write the delegating constructors. |
| 4508 | if (!DelegatingCtorDecls.empty()) |
| 4509 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4510 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4511 | // Write the known namespaces. |
| 4512 | if (!KnownNamespaces.empty()) |
| 4513 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4514 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4515 | // Write the undefined internal functions and variables, and inline functions. |
| 4516 | if (!UndefinedButUsed.empty()) |
| 4517 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4518 | |
| 4519 | if (!DeleteExprsToAnalyze.empty()) |
| 4520 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); |
| 4521 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4522 | // Write the visible updates to DeclContexts. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4523 | for (auto *DC : UpdatedDeclContexts) |
| 4524 | WriteDeclContextVisibleUpdate(DC); |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4525 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4526 | if (!WritingModule) { |
| 4527 | // Write the submodules that were imported, if any. |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4528 | struct ModuleInfo { |
| 4529 | uint64_t ID; |
| 4530 | Module *M; |
| 4531 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} |
| 4532 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4533 | llvm::SmallVector<ModuleInfo, 64> Imports; |
Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 4534 | for (const auto *I : Context.local_imports()) { |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4535 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4536 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], |
| 4537 | I->getImportedModule())); |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4538 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4539 | |
| 4540 | if (!Imports.empty()) { |
| 4541 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4542 | return A.ID < B.ID; |
| 4543 | }; |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4544 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { |
| 4545 | return A.ID == B.ID; |
| 4546 | }; |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4547 | |
| 4548 | // Sort and deduplicate module IDs. |
| 4549 | std::sort(Imports.begin(), Imports.end(), Cmp); |
Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4550 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4551 | Imports.end()); |
| 4552 | |
| 4553 | RecordData ImportedModules; |
| 4554 | for (const auto &Import : Imports) { |
| 4555 | ImportedModules.push_back(Import.ID); |
| 4556 | // FIXME: If the module has macros imported then later has declarations |
| 4557 | // imported, this location won't be the right one as a location for the |
| 4558 | // declaration imports. |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 4559 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4560 | } |
| 4561 | |
Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4562 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 4563 | } |
Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4564 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4565 | |
Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4566 | WriteDeclReplacementsBlock(); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4567 | WriteObjCCategories(); |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4568 | if(!WritingModule) |
| 4569 | WriteOptimizePragmaOptions(SemaRef); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4570 | |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4571 | // Some simple statistics |
Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4572 | RecordData::value_type Record[] = { |
| 4573 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4574 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4575 | Stream.ExitBlock(); |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4576 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4577 | // Write the module file extension blocks. |
| 4578 | for (const auto &ExtWriter : ModuleFileExtensionWriters) |
| 4579 | WriteModuleFileExtension(*ExtWriter); |
| 4580 | |
Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4581 | return Signature; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4582 | } |
| 4583 | |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4584 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4585 | if (DeclUpdates.empty()) |
| 4586 | return; |
| 4587 | |
Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4588 | DeclUpdateMap LocalUpdates; |
| 4589 | LocalUpdates.swap(DeclUpdates); |
| 4590 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4591 | for (auto &DeclUpdate : LocalUpdates) { |
| 4592 | const Decl *D = DeclUpdate.first; |
Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 4593 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4594 | bool HasUpdatedBody = false; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4595 | RecordData Record; |
| 4596 | for (auto &Update : DeclUpdate.second) { |
| 4597 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); |
| 4598 | |
| 4599 | Record.push_back(Kind); |
| 4600 | switch (Kind) { |
| 4601 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 4602 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 4603 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4604 | assert(Update.getDecl() && "no decl to add?"); |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4605 | Record.push_back(GetDeclRef(Update.getDecl())); |
| 4606 | break; |
| 4607 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4608 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4609 | // An updated body is emitted last, so that the reader doesn't need |
| 4610 | // to skip over the lazy body to reach statements for other records. |
| 4611 | Record.pop_back(); |
| 4612 | HasUpdatedBody = true; |
| 4613 | break; |
| 4614 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4615 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
| 4616 | AddSourceLocation(Update.getLoc(), Record); |
| 4617 | break; |
| 4618 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4619 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4620 | auto *RD = cast<CXXRecordDecl>(D); |
Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 4621 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4622 | AddCXXDefinitionData(RD, Record); |
| 4623 | Record.push_back(WriteDeclContextLexicalBlock( |
| 4624 | *Context, const_cast<CXXRecordDecl *>(RD))); |
| 4625 | |
| 4626 | // This state is sometimes updated by template instantiation, when we |
| 4627 | // switch from the specialization referring to the template declaration |
| 4628 | // to it referring to the template definition. |
| 4629 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { |
| 4630 | Record.push_back(MSInfo->getTemplateSpecializationKind()); |
| 4631 | AddSourceLocation(MSInfo->getPointOfInstantiation(), Record); |
| 4632 | } else { |
| 4633 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
| 4634 | Record.push_back(Spec->getTemplateSpecializationKind()); |
| 4635 | AddSourceLocation(Spec->getPointOfInstantiation(), Record); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4636 | |
| 4637 | // The instantiation might have been resolved to a partial |
| 4638 | // specialization. If so, record which one. |
| 4639 | auto From = Spec->getInstantiatedFrom(); |
| 4640 | if (auto PartialSpec = |
| 4641 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { |
| 4642 | Record.push_back(true); |
| 4643 | AddDeclRef(PartialSpec, Record); |
| 4644 | AddTemplateArgumentList(&Spec->getTemplateInstantiationArgs(), |
| 4645 | Record); |
| 4646 | } else { |
| 4647 | Record.push_back(false); |
| 4648 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4649 | } |
| 4650 | Record.push_back(RD->getTagKind()); |
| 4651 | AddSourceLocation(RD->getLocation(), Record); |
| 4652 | AddSourceLocation(RD->getLocStart(), Record); |
| 4653 | AddSourceLocation(RD->getRBraceLoc(), Record); |
| 4654 | |
| 4655 | // Instantiation may change attributes; write them all out afresh. |
| 4656 | Record.push_back(D->hasAttrs()); |
| 4657 | if (Record.back()) |
Craig Topper | 8c2a2a0 | 2014-08-30 16:55:39 +0000 | [diff] [blame] | 4658 | WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(), |
| 4659 | D->getAttrs().size()), Record); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4660 | |
| 4661 | // FIXME: Ensure we don't get here for explicit instantiations. |
| 4662 | break; |
| 4663 | } |
| 4664 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4665 | case UPD_CXX_RESOLVED_DTOR_DELETE: |
| 4666 | AddDeclRef(Update.getDecl(), Record); |
| 4667 | break; |
| 4668 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4669 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: |
| 4670 | addExceptionSpec( |
| 4671 | *this, |
| 4672 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(), |
| 4673 | Record); |
| 4674 | break; |
| 4675 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4676 | case UPD_CXX_DEDUCED_RETURN_TYPE: |
| 4677 | Record.push_back(GetOrCreateTypeID(Update.getType())); |
| 4678 | break; |
| 4679 | |
| 4680 | case UPD_DECL_MARKED_USED: |
| 4681 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4682 | |
| 4683 | case UPD_MANGLING_NUMBER: |
| 4684 | case UPD_STATIC_LOCAL_NUMBER: |
| 4685 | Record.push_back(Update.getNumber()); |
| 4686 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4687 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4688 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
| 4689 | AddSourceRange(D->getAttr<OMPThreadPrivateDeclAttr>()->getRange(), |
| 4690 | Record); |
| 4691 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4692 | |
| 4693 | case UPD_DECL_EXPORTED: |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 4694 | Record.push_back(getSubmoduleID(Update.getModule())); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4695 | break; |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4696 | |
| 4697 | case UPD_ADDED_ATTR_TO_RECORD: |
| 4698 | WriteAttributes(llvm::makeArrayRef(Update.getAttr()), Record); |
| 4699 | break; |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4700 | } |
| 4701 | } |
| 4702 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4703 | if (HasUpdatedBody) { |
| 4704 | const FunctionDecl *Def = cast<FunctionDecl>(D); |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4705 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4706 | Record.push_back(Def->isInlined()); |
| 4707 | AddSourceLocation(Def->getInnerLocStart(), Record); |
| 4708 | AddFunctionDefinition(Def, Record); |
| 4709 | } |
| 4710 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4711 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 4712 | OffsetsRecord.push_back(Stream.GetCurrentBitNo()); |
| 4713 | |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4714 | Stream.EmitRecord(DECL_UPDATES, Record); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4715 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4716 | FlushPendingAfterDecl(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4717 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4718 | } |
| 4719 | |
Argyrios Kyrtzidis | 97bfda9 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 4720 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4721 | if (ReplacedDecls.empty()) |
| 4722 | return; |
| 4723 | |
| 4724 | RecordData Record; |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 4725 | for (SmallVectorImpl<ReplacedDeclInfo>::iterator |
| 4726 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
Argyrios Kyrtzidis | 6fb6003 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 4727 | Record.push_back(I->ID); |
| 4728 | Record.push_back(I->Offset); |
| 4729 | Record.push_back(I->Loc); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4730 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4731 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4734 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4735 | Record.push_back(Loc.getRawEncoding()); |
| 4736 | } |
| 4737 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4738 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4739 | AddSourceLocation(Range.getBegin(), Record); |
| 4740 | AddSourceLocation(Range.getEnd(), Record); |
| 4741 | } |
| 4742 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4743 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4744 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4745 | const uint64_t *Words = Value.getRawData(); |
| 4746 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4747 | } |
| 4748 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4749 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4750 | Record.push_back(Value.isUnsigned()); |
| 4751 | AddAPInt(Value, Record); |
| 4752 | } |
| 4753 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4754 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4755 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 4756 | } |
| 4757 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4758 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4759 | Record.push_back(getIdentifierRef(II)); |
| 4760 | } |
| 4761 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4762 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4763 | if (!II) |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4764 | return 0; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4765 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4766 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4767 | if (ID == 0) |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4768 | ID = NextIdentID++; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 4769 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4770 | } |
| 4771 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4772 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4773 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 4774 | // have been redefined by the header (in which case they are not |
| 4775 | // isBuiltinMacro). |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4776 | if (!MI || MI->isBuiltinMacro()) |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4777 | return 0; |
| 4778 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4779 | MacroID &ID = MacroIDs[MI]; |
| 4780 | if (ID == 0) { |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4781 | ID = NextMacroID++; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4782 | MacroInfoToEmitData Info = { Name, MI, ID }; |
| 4783 | MacroInfosToEmit.push_back(Info); |
| 4784 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4785 | return ID; |
| 4786 | } |
| 4787 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4788 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4789 | if (!MI || MI->isBuiltinMacro()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4790 | return 0; |
| 4791 | |
| 4792 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); |
| 4793 | return MacroIDs[MI]; |
| 4794 | } |
| 4795 | |
| 4796 | uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 4797 | return IdentMacroDirectivesOffsetMap.lookup(Name); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 4798 | } |
| 4799 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4800 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4801 | Record.push_back(getSelectorRef(SelRef)); |
| 4802 | } |
| 4803 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4804 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4805 | if (Sel.getAsOpaquePtr() == nullptr) { |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4806 | return 0; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4807 | } |
| 4808 | |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4809 | SelectorID SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4810 | if (SID == 0 && Chain) { |
| 4811 | // This might trigger a ReadSelector callback, which will set the ID for |
| 4812 | // this selector. |
| 4813 | Chain->LoadSelector(Sel); |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4814 | SID = SelectorIDs[Sel]; |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4815 | } |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4816 | if (SID == 0) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4817 | SID = NextSelectorID++; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 4818 | SelectorIDs[Sel] = SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4819 | } |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4820 | return SID; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4821 | } |
| 4822 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4823 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4824 | AddDeclRef(Temp->getDestructor(), Record); |
| 4825 | } |
| 4826 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4827 | void ASTWriter::AddCXXCtorInitializersRef(ArrayRef<CXXCtorInitializer *> Inits, |
| 4828 | RecordDataImpl &Record) { |
| 4829 | assert(!Inits.empty() && "Empty ctor initializer sets are not recorded"); |
| 4830 | CXXCtorInitializersToWrite.push_back( |
| 4831 | QueuedCXXCtorInitializers(NextCXXCtorInitializersID, Inits)); |
| 4832 | Record.push_back(NextCXXCtorInitializersID++); |
| 4833 | } |
| 4834 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4835 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 4836 | CXXBaseSpecifier const *BasesEnd, |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4837 | RecordDataImpl &Record) { |
| 4838 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 4839 | CXXBaseSpecifiersToWrite.push_back( |
| 4840 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 4841 | Bases, BasesEnd)); |
| 4842 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 4843 | } |
| 4844 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4845 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4846 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4847 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4848 | switch (Kind) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4849 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4850 | AddStmt(Arg.getAsExpr()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4851 | break; |
| 4852 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4853 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4854 | break; |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4855 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4856 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4857 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4858 | break; |
| 4859 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4860 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4861 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4862 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4863 | break; |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4864 | case TemplateArgument::Null: |
| 4865 | case TemplateArgument::Integral: |
| 4866 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4867 | case TemplateArgument::NullPtr: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4868 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4869 | // FIXME: Is this right? |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4870 | break; |
| 4871 | } |
| 4872 | } |
| 4873 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4874 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4875 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4876 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4877 | |
| 4878 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 4879 | bool InfoHasSameExpr |
| 4880 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 4881 | Record.push_back(InfoHasSameExpr); |
| 4882 | if (InfoHasSameExpr) |
| 4883 | return; // Avoid storing the same expr twice. |
| 4884 | } |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4885 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 4886 | Record); |
| 4887 | } |
| 4888 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4889 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 4890 | RecordDataImpl &Record) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4891 | if (!TInfo) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4892 | AddTypeRef(QualType(), Record); |
| 4893 | return; |
| 4894 | } |
| 4895 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4896 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 4897 | } |
| 4898 | |
| 4899 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 4900 | AddTypeRef(TL.getType(), Record); |
| 4901 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4902 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4903 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4904 | TLW.Visit(TL); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4907 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 4908 | Record.push_back(GetOrCreateTypeID(T)); |
| 4909 | } |
| 4910 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4911 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4912 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4913 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 4914 | if (T.isNull()) |
| 4915 | return TypeIdx(); |
| 4916 | assert(!T.getLocalFastQualifiers()); |
| 4917 | |
| 4918 | TypeIdx &Idx = TypeIdxs[T]; |
| 4919 | if (Idx.getIndex() == 0) { |
| 4920 | if (DoneWritingDeclsAndTypes) { |
| 4921 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 4922 | return TypeIdx(); |
| 4923 | } |
| 4924 | |
| 4925 | // We haven't seen this type before. Assign it a new ID and put it |
| 4926 | // into the queue of types to emit. |
| 4927 | Idx = TypeIdx(NextTypeID++); |
| 4928 | DeclTypesToEmit.push(T); |
| 4929 | } |
| 4930 | return Idx; |
| 4931 | }); |
Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 4932 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4933 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4934 | TypeID ASTWriter::getTypeID(QualType T) const { |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4935 | assert(Context); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4936 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { |
| 4937 | if (T.isNull()) |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4938 | return TypeIdx(); |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4939 | assert(!T.getLocalFastQualifiers()); |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4940 | |
Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 4941 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 4942 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 4943 | return I->second; |
| 4944 | }); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4947 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4948 | Record.push_back(GetDeclRef(D)); |
| 4949 | } |
| 4950 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4951 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4952 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4953 | |
| 4954 | if (!D) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4955 | return 0; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4956 | } |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4957 | |
| 4958 | // If D comes from an AST file, its declaration ID is already known and |
| 4959 | // fixed. |
| 4960 | if (D->isFromASTFile()) |
| 4961 | return D->getGlobalID(); |
| 4962 | |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4963 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4964 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4965 | if (ID == 0) { |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4966 | if (DoneWritingDeclsAndTypes) { |
| 4967 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 4968 | return 0; |
| 4969 | } |
| 4970 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4971 | // We haven't seen this declaration before. Give it a new ID and |
| 4972 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4973 | ID = NextDeclID++; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4974 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4975 | } |
| 4976 | |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4977 | return ID; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4978 | } |
| 4979 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4980 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4981 | if (!D) |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4982 | return 0; |
| 4983 | |
Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4984 | // If D comes from an AST file, its declaration ID is already known and |
| 4985 | // fixed. |
| 4986 | if (D->isFromASTFile()) |
| 4987 | return D->getGlobalID(); |
| 4988 | |
Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4989 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 4990 | return DeclIDs[D]; |
| 4991 | } |
| 4992 | |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4993 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4994 | assert(ID); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4995 | assert(D); |
| 4996 | |
| 4997 | SourceLocation Loc = D->getLocation(); |
| 4998 | if (Loc.isInvalid()) |
| 4999 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5000 | |
| 5001 | // We only keep track of the file-level declarations of each file. |
| 5002 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 5003 | return; |
Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5004 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 5005 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5006 | if (isa<ParmVarDecl>(D)) |
| 5007 | return; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5008 | |
| 5009 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5010 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5011 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5012 | FileID FID; |
| 5013 | unsigned Offset; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5014 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5015 | if (FID.isInvalid()) |
| 5016 | return; |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5017 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5018 | |
Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5019 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5020 | if (!Info) |
| 5021 | Info = new DeclIDInFileInfo(); |
| 5022 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5023 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5024 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 5025 | |
Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5026 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5027 | Decls.push_back(LocDecl); |
| 5028 | return; |
| 5029 | } |
| 5030 | |
Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5031 | LocDeclIDsTy::iterator I = |
| 5032 | std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first()); |
Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5033 | |
| 5034 | Decls.insert(I, LocDecl); |
| 5035 | } |
| 5036 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5037 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | 258172e | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 5038 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5039 | Record.push_back(Name.getNameKind()); |
| 5040 | switch (Name.getNameKind()) { |
| 5041 | case DeclarationName::Identifier: |
| 5042 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 5043 | break; |
| 5044 | |
| 5045 | case DeclarationName::ObjCZeroArgSelector: |
| 5046 | case DeclarationName::ObjCOneArgSelector: |
| 5047 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5048 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5049 | break; |
| 5050 | |
| 5051 | case DeclarationName::CXXConstructorName: |
| 5052 | case DeclarationName::CXXDestructorName: |
| 5053 | case DeclarationName::CXXConversionFunctionName: |
| 5054 | AddTypeRef(Name.getCXXNameType(), Record); |
| 5055 | break; |
| 5056 | |
| 5057 | case DeclarationName::CXXOperatorName: |
| 5058 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 5059 | break; |
| 5060 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5061 | case DeclarationName::CXXLiteralOperatorName: |
| 5062 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 5063 | break; |
| 5064 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5065 | case DeclarationName::CXXUsingDirective: |
| 5066 | // No extra data to emit |
| 5067 | break; |
| 5068 | } |
| 5069 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5070 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5071 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { |
| 5072 | assert(needsAnonymousDeclarationNumber(D) && |
| 5073 | "expected an anonymous declaration"); |
| 5074 | |
| 5075 | // Number the anonymous declarations within this context, if we've not |
| 5076 | // already done so. |
| 5077 | auto It = AnonymousDeclarationNumbers.find(D); |
| 5078 | if (It == AnonymousDeclarationNumbers.end()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5079 | auto *DC = D->getLexicalDeclContext(); |
| 5080 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { |
| 5081 | AnonymousDeclarationNumbers[ND] = Number; |
| 5082 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5083 | |
| 5084 | It = AnonymousDeclarationNumbers.find(D); |
| 5085 | assert(It != AnonymousDeclarationNumbers.end() && |
| 5086 | "declaration not found within its lexical context"); |
| 5087 | } |
| 5088 | |
| 5089 | return It->second; |
| 5090 | } |
| 5091 | |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5092 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5093 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5094 | switch (Name.getNameKind()) { |
| 5095 | case DeclarationName::CXXConstructorName: |
| 5096 | case DeclarationName::CXXDestructorName: |
| 5097 | case DeclarationName::CXXConversionFunctionName: |
| 5098 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 5099 | break; |
| 5100 | |
| 5101 | case DeclarationName::CXXOperatorName: |
| 5102 | AddSourceLocation( |
| 5103 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 5104 | Record); |
| 5105 | AddSourceLocation( |
| 5106 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 5107 | Record); |
| 5108 | break; |
| 5109 | |
| 5110 | case DeclarationName::CXXLiteralOperatorName: |
| 5111 | AddSourceLocation( |
| 5112 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 5113 | Record); |
| 5114 | break; |
| 5115 | |
| 5116 | case DeclarationName::Identifier: |
| 5117 | case DeclarationName::ObjCZeroArgSelector: |
| 5118 | case DeclarationName::ObjCOneArgSelector: |
| 5119 | case DeclarationName::ObjCMultiArgSelector: |
| 5120 | case DeclarationName::CXXUsingDirective: |
| 5121 | break; |
| 5122 | } |
| 5123 | } |
| 5124 | |
| 5125 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5126 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5127 | AddDeclarationName(NameInfo.getName(), Record); |
| 5128 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 5129 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 5130 | } |
| 5131 | |
| 5132 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5133 | RecordDataImpl &Record) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5134 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5135 | Record.push_back(Info.NumTemplParamLists); |
| 5136 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 5137 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 5138 | } |
| 5139 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5140 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5141 | RecordDataImpl &Record) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5142 | // 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] | 5143 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5144 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5145 | |
| 5146 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 5147 | while (NNS) { |
| 5148 | NestedNames.push_back(NNS); |
| 5149 | NNS = NNS->getPrefix(); |
| 5150 | } |
| 5151 | |
| 5152 | Record.push_back(NestedNames.size()); |
| 5153 | while(!NestedNames.empty()) { |
| 5154 | NNS = NestedNames.pop_back_val(); |
| 5155 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 5156 | Record.push_back(Kind); |
| 5157 | switch (Kind) { |
| 5158 | case NestedNameSpecifier::Identifier: |
| 5159 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 5160 | break; |
| 5161 | |
| 5162 | case NestedNameSpecifier::Namespace: |
| 5163 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 5164 | break; |
| 5165 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5166 | case NestedNameSpecifier::NamespaceAlias: |
| 5167 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 5168 | break; |
| 5169 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5170 | case NestedNameSpecifier::TypeSpec: |
| 5171 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 5172 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 5173 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5174 | break; |
| 5175 | |
| 5176 | case NestedNameSpecifier::Global: |
| 5177 | // Don't need to write an associated value. |
| 5178 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5179 | |
| 5180 | case NestedNameSpecifier::Super: |
| 5181 | AddDeclRef(NNS->getAsRecordDecl(), Record); |
| 5182 | break; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5183 | } |
| 5184 | } |
| 5185 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5187 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 5188 | RecordDataImpl &Record) { |
| 5189 | // 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] | 5190 | // typically accommodate the vast majority. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5191 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5192 | |
| 5193 | // Push each of the nested-name-specifiers's onto a stack for |
| 5194 | // serialization in reverse order. |
| 5195 | while (NNS) { |
| 5196 | NestedNames.push_back(NNS); |
| 5197 | NNS = NNS.getPrefix(); |
| 5198 | } |
| 5199 | |
| 5200 | Record.push_back(NestedNames.size()); |
| 5201 | while(!NestedNames.empty()) { |
| 5202 | NNS = NestedNames.pop_back_val(); |
| 5203 | NestedNameSpecifier::SpecifierKind Kind |
| 5204 | = NNS.getNestedNameSpecifier()->getKind(); |
| 5205 | Record.push_back(Kind); |
| 5206 | switch (Kind) { |
| 5207 | case NestedNameSpecifier::Identifier: |
| 5208 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 5209 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5210 | break; |
| 5211 | |
| 5212 | case NestedNameSpecifier::Namespace: |
| 5213 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 5214 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5215 | break; |
| 5216 | |
| 5217 | case NestedNameSpecifier::NamespaceAlias: |
| 5218 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 5219 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5220 | break; |
| 5221 | |
| 5222 | case NestedNameSpecifier::TypeSpec: |
| 5223 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 5224 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 5225 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 5226 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 5227 | break; |
| 5228 | |
| 5229 | case NestedNameSpecifier::Global: |
| 5230 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 5231 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5232 | |
| 5233 | case NestedNameSpecifier::Super: |
| 5234 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl(), Record); |
| 5235 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 5236 | break; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5237 | } |
| 5238 | } |
| 5239 | } |
| 5240 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5241 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5242 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5243 | Record.push_back(Kind); |
| 5244 | switch (Kind) { |
| 5245 | case TemplateName::Template: |
| 5246 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 5247 | break; |
| 5248 | |
| 5249 | case TemplateName::OverloadedTemplate: { |
| 5250 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 5251 | Record.push_back(OvT->size()); |
| 5252 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 5253 | I != E; ++I) |
| 5254 | AddDeclRef(*I, Record); |
| 5255 | break; |
| 5256 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5257 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5258 | case TemplateName::QualifiedTemplate: { |
| 5259 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 5260 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 5261 | Record.push_back(QualT->hasTemplateKeyword()); |
| 5262 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 5263 | break; |
| 5264 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5265 | |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5266 | case TemplateName::DependentTemplate: { |
| 5267 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 5268 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 5269 | Record.push_back(DepT->isIdentifier()); |
| 5270 | if (DepT->isIdentifier()) |
| 5271 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 5272 | else |
| 5273 | Record.push_back(DepT->getOperator()); |
| 5274 | break; |
| 5275 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5276 | |
| 5277 | case TemplateName::SubstTemplateTemplateParm: { |
| 5278 | SubstTemplateTemplateParmStorage *subst |
| 5279 | = Name.getAsSubstTemplateTemplateParm(); |
| 5280 | AddDeclRef(subst->getParameter(), Record); |
| 5281 | AddTemplateName(subst->getReplacement(), Record); |
| 5282 | break; |
| 5283 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5284 | |
| 5285 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5286 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 5287 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 5288 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 5289 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 5290 | break; |
| 5291 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5292 | } |
| 5293 | } |
| 5294 | |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5295 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5296 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5297 | Record.push_back(Arg.getKind()); |
| 5298 | switch (Arg.getKind()) { |
| 5299 | case TemplateArgument::Null: |
| 5300 | break; |
| 5301 | case TemplateArgument::Type: |
| 5302 | AddTypeRef(Arg.getAsType(), Record); |
| 5303 | break; |
| 5304 | case TemplateArgument::Declaration: |
| 5305 | AddDeclRef(Arg.getAsDecl(), Record); |
David Blaikie | 952a9b1 | 2014-10-17 18:00:12 +0000 | [diff] [blame] | 5306 | AddTypeRef(Arg.getParamTypeForDecl(), Record); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5307 | break; |
| 5308 | case TemplateArgument::NullPtr: |
| 5309 | AddTypeRef(Arg.getNullPtrType(), Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5310 | break; |
| 5311 | case TemplateArgument::Integral: |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 5312 | AddAPSInt(Arg.getAsIntegral(), Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5313 | AddTypeRef(Arg.getIntegralType(), Record); |
| 5314 | break; |
| 5315 | case TemplateArgument::Template: |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5316 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 5317 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5318 | case TemplateArgument::TemplateExpansion: |
| 5319 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5320 | if (Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5321 | Record.push_back(*NumExpansions + 1); |
| 5322 | else |
| 5323 | Record.push_back(0); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5324 | break; |
| 5325 | case TemplateArgument::Expression: |
| 5326 | AddStmt(Arg.getAsExpr()); |
| 5327 | break; |
| 5328 | case TemplateArgument::Pack: |
| 5329 | Record.push_back(Arg.pack_size()); |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 5330 | for (const auto &P : Arg.pack_elements()) |
| 5331 | AddTemplateArgument(P, Record); |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 5332 | break; |
| 5333 | } |
| 5334 | } |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5335 | |
| 5336 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5337 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5338 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5339 | assert(TemplateParams && "No TemplateParams!"); |
| 5340 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 5341 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 5342 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 5343 | Record.push_back(TemplateParams->size()); |
| 5344 | for (TemplateParameterList::const_iterator |
| 5345 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 5346 | P != PEnd; ++P) |
| 5347 | AddDeclRef(*P, Record); |
| 5348 | } |
| 5349 | |
| 5350 | /// \brief Emit a template argument list. |
| 5351 | void |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5352 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5353 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5354 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5355 | Record.push_back(TemplateArgs->size()); |
| 5356 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5357 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 5358 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5359 | |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5360 | void |
| 5361 | ASTWriter::AddASTTemplateArgumentListInfo |
| 5362 | (const ASTTemplateArgumentListInfo *ASTTemplArgList, RecordDataImpl &Record) { |
| 5363 | assert(ASTTemplArgList && "No ASTTemplArgList!"); |
| 5364 | AddSourceLocation(ASTTemplArgList->LAngleLoc, Record); |
| 5365 | AddSourceLocation(ASTTemplArgList->RAngleLoc, Record); |
| 5366 | Record.push_back(ASTTemplArgList->NumTemplateArgs); |
| 5367 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); |
| 5368 | for (int i=0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) |
| 5369 | AddTemplateArgumentLoc(TemplArgs[i], Record); |
| 5370 | } |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5371 | |
| 5372 | void |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5373 | ASTWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5374 | Record.push_back(Set.size()); |
Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5375 | for (ASTUnresolvedSet::const_iterator |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5376 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 5377 | AddDeclRef(I.getDecl(), Record); |
| 5378 | Record.push_back(I.getAccess()); |
| 5379 | } |
| 5380 | } |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5381 | |
Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 5382 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5383 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5384 | Record.push_back(Base.isVirtual()); |
| 5385 | Record.push_back(Base.isBaseOfClass()); |
| 5386 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5387 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5388 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5389 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5390 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 5391 | : SourceLocation(), |
| 5392 | Record); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5393 | } |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5394 | |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5395 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 5396 | RecordData Record; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5397 | unsigned N = CXXBaseSpecifiersToWrite.size(); |
| 5398 | for (unsigned I = 0; I != N; ++I) { |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5399 | Record.clear(); |
| 5400 | |
| 5401 | // Record the offset of this base-specifier set. |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 5402 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5403 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 5404 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 5405 | else { |
| 5406 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 5407 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 5408 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 5409 | } |
| 5410 | |
| 5411 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 5412 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 5413 | Record.push_back(BEnd - B); |
| 5414 | for (; B != BEnd; ++B) |
| 5415 | AddCXXBaseSpecifier(*B, Record); |
| 5416 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | d585304 | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 5417 | |
| 5418 | // Flush any expressions that were written as part of the base specifiers. |
| 5419 | FlushStmts(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5420 | } |
| 5421 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5422 | assert(N == CXXBaseSpecifiersToWrite.size() && |
| 5423 | "added more base specifiers while writing base specifiers"); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5424 | CXXBaseSpecifiersToWrite.clear(); |
| 5425 | } |
| 5426 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5427 | void ASTWriter::AddCXXCtorInitializers( |
| 5428 | const CXXCtorInitializer * const *CtorInitializers, |
| 5429 | unsigned NumCtorInitializers, |
| 5430 | RecordDataImpl &Record) { |
| 5431 | Record.push_back(NumCtorInitializers); |
| 5432 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 5433 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5434 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5435 | if (Init->isBaseInitializer()) { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5436 | Record.push_back(CTOR_INITIALIZER_BASE); |
Douglas Gregor | d73f3dd | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5437 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5438 | Record.push_back(Init->isBaseVirtual()); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5439 | } else if (Init->isDelegatingInitializer()) { |
| 5440 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
Douglas Gregor | d73f3dd | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5441 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5442 | } else if (Init->isMemberInitializer()){ |
| 5443 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 5444 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5445 | } else { |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5446 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 5447 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5448 | } |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5449 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5450 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 5451 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5452 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 5453 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 5454 | Record.push_back(Init->isWritten()); |
| 5455 | if (Init->isWritten()) { |
| 5456 | Record.push_back(Init->getSourceOrder()); |
| 5457 | } else { |
| 5458 | Record.push_back(Init->getNumArrayIndices()); |
| 5459 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 5460 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 5461 | } |
| 5462 | } |
| 5463 | } |
| 5464 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5465 | void ASTWriter::FlushCXXCtorInitializers() { |
| 5466 | RecordData Record; |
| 5467 | |
| 5468 | unsigned N = CXXCtorInitializersToWrite.size(); |
Daniel Jasper | c77b0a1 | 2015-03-24 08:06:38 +0000 | [diff] [blame] | 5469 | (void)N; // Silence unused warning in non-assert builds. |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5470 | for (auto &Init : CXXCtorInitializersToWrite) { |
| 5471 | Record.clear(); |
| 5472 | |
| 5473 | // Record the offset of this mem-initializer list. |
| 5474 | unsigned Index = Init.ID - 1; |
| 5475 | if (Index == CXXCtorInitializersOffsets.size()) |
| 5476 | CXXCtorInitializersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 5477 | else { |
| 5478 | if (Index > CXXCtorInitializersOffsets.size()) |
| 5479 | CXXCtorInitializersOffsets.resize(Index + 1); |
| 5480 | CXXCtorInitializersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 5481 | } |
| 5482 | |
| 5483 | AddCXXCtorInitializers(Init.Inits.data(), Init.Inits.size(), Record); |
| 5484 | Stream.EmitRecord(serialization::DECL_CXX_CTOR_INITIALIZERS, Record); |
| 5485 | |
| 5486 | // Flush any expressions that were written as part of the initializers. |
| 5487 | FlushStmts(); |
| 5488 | } |
| 5489 | |
| 5490 | assert(N == CXXCtorInitializersToWrite.size() && |
| 5491 | "added more ctor initializers while writing ctor initializers"); |
| 5492 | CXXCtorInitializersToWrite.clear(); |
| 5493 | } |
| 5494 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5495 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5496 | auto &Data = D->data(); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5497 | Record.push_back(Data.IsLambda); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5498 | Record.push_back(Data.UserDeclaredConstructor); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5499 | Record.push_back(Data.UserDeclaredSpecialMembers); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5500 | Record.push_back(Data.Aggregate); |
| 5501 | Record.push_back(Data.PlainOldData); |
| 5502 | Record.push_back(Data.Empty); |
| 5503 | Record.push_back(Data.Polymorphic); |
| 5504 | Record.push_back(Data.Abstract); |
Chandler Carruth | 583edf8 | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 5505 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | b196374 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 5506 | Record.push_back(Data.HasNoNonEmptyBases); |
| 5507 | Record.push_back(Data.HasPrivateFields); |
| 5508 | Record.push_back(Data.HasProtectedFields); |
| 5509 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 61226d3 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 5510 | Record.push_back(Data.HasMutableFields); |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 5511 | Record.push_back(Data.HasVariantMembers); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5512 | Record.push_back(Data.HasOnlyCMembers); |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 5513 | Record.push_back(Data.HasInClassInitializer); |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 5514 | Record.push_back(Data.HasUninitializedReferenceMember); |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 5515 | Record.push_back(Data.NeedOverloadResolutionForMoveConstructor); |
| 5516 | Record.push_back(Data.NeedOverloadResolutionForMoveAssignment); |
| 5517 | Record.push_back(Data.NeedOverloadResolutionForDestructor); |
| 5518 | Record.push_back(Data.DefaultedMoveConstructorIsDeleted); |
| 5519 | Record.push_back(Data.DefaultedMoveAssignmentIsDeleted); |
| 5520 | Record.push_back(Data.DefaultedDestructorIsDeleted); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5521 | Record.push_back(Data.HasTrivialSpecialMembers); |
Richard Smith | b45a6f7 | 2014-04-17 20:33:01 +0000 | [diff] [blame] | 5522 | Record.push_back(Data.DeclaredNonTrivialSpecialMembers); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5523 | Record.push_back(Data.HasIrrelevantDestructor); |
Richard Smith | 111af8d | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 5524 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5525 | Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5526 | Record.push_back(Data.HasConstexprDefaultConstructor); |
Chandler Carruth | e71d062 | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 5527 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5528 | Record.push_back(Data.ComputedVisibleConversions); |
Alexis Hunt | ea6f032 | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 5529 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 5530 | Record.push_back(Data.DeclaredSpecialMembers); |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 5531 | Record.push_back(Data.ImplicitCopyConstructorHasConstParam); |
| 5532 | Record.push_back(Data.ImplicitCopyAssignmentHasConstParam); |
| 5533 | Record.push_back(Data.HasDeclaredCopyConstructorWithConstParam); |
| 5534 | Record.push_back(Data.HasDeclaredCopyAssignmentWithConstParam); |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5535 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5536 | |
| 5537 | Record.push_back(Data.NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5538 | if (Data.NumBases > 0) |
| 5539 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 5540 | Record); |
| 5541 | |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5542 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 5543 | Record.push_back(Data.NumVBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5544 | if (Data.NumVBases > 0) |
| 5545 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 5546 | Record); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5547 | |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 5548 | AddUnresolvedSet(Data.Conversions.get(*Context), Record); |
| 5549 | AddUnresolvedSet(Data.VisibleConversions.get(*Context), Record); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5550 | // Data.Definition is the owning decl, no need to write it. |
Richard Smith | 68ad0e7 | 2013-06-26 02:41:25 +0000 | [diff] [blame] | 5551 | AddDeclRef(D->getFirstFriend(), Record); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5552 | |
| 5553 | // Add lambda-specific data. |
| 5554 | if (Data.IsLambda) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5555 | auto &Lambda = D->getLambdaData(); |
Douglas Gregor | 680e9e0 | 2012-02-21 19:11:17 +0000 | [diff] [blame] | 5556 | Record.push_back(Lambda.Dependent); |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 5557 | Record.push_back(Lambda.IsGenericLambda); |
| 5558 | Record.push_back(Lambda.CaptureDefault); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5559 | Record.push_back(Lambda.NumCaptures); |
| 5560 | Record.push_back(Lambda.NumExplicitCaptures); |
Douglas Gregor | 6379854 | 2012-02-20 19:44:39 +0000 | [diff] [blame] | 5561 | Record.push_back(Lambda.ManglingNumber); |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 5562 | AddDeclRef(Lambda.ContextDecl, Record); |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 5563 | AddTypeSourceInfo(Lambda.MethodTyInfo, Record); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5564 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 5565 | const LambdaCapture &Capture = Lambda.Captures[I]; |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5566 | AddSourceLocation(Capture.getLocation(), Record); |
| 5567 | Record.push_back(Capture.isImplicit()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5568 | Record.push_back(Capture.getCaptureKind()); |
| 5569 | switch (Capture.getCaptureKind()) { |
| 5570 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 5571 | case LCK_VLAType: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5572 | break; |
| 5573 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 5574 | case LCK_ByRef: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5575 | VarDecl *Var = |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5576 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5577 | AddDeclRef(Var, Record); |
| 5578 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() |
| 5579 | : SourceLocation(), |
| 5580 | Record); |
| 5581 | break; |
| 5582 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5583 | } |
| 5584 | } |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5585 | } |
| 5586 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5587 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5588 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5589 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5590 | assert(FirstDeclID == NextDeclID && |
| 5591 | FirstTypeID == NextTypeID && |
| 5592 | FirstIdentID == NextIdentID && |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5593 | FirstMacroID == NextMacroID && |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5594 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5595 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5596 | "Setting chain after writing has started."); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5597 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5598 | Chain = Reader; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5599 | |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 5600 | // Note, this will get called multiple times, once one the reader starts up |
| 5601 | // and again each time it's done reading a PCH or module. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5602 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 5603 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 5604 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5605 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5606 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5607 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5608 | NextDeclID = FirstDeclID; |
| 5609 | NextTypeID = FirstTypeID; |
| 5610 | NextIdentID = FirstIdentID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5611 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5612 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5613 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5614 | } |
| 5615 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5616 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5617 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5618 | IdentID &StoredID = IdentifierIDs[II]; |
| 5619 | if (ID > StoredID) |
| 5620 | StoredID = ID; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5621 | } |
| 5622 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5623 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5624 | // Always keep the highest ID. See \p TypeRead() for more information. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5625 | MacroID &StoredID = MacroIDs[MI]; |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5626 | if (ID > StoredID) |
| 5627 | StoredID = ID; |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5628 | } |
| 5629 | |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5630 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5631 | // Always take the highest-numbered type index. This copes with an interesting |
| 5632 | // 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] | 5633 | // 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] | 5634 | // keep the higher-numbered entry so that we can properly write it out to |
| 5635 | // the AST file. |
| 5636 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 5637 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 5638 | StoredIdx = Idx; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5639 | } |
| 5640 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5641 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5642 | // Always keep the highest ID. See \p TypeRead() for more information. |
| 5643 | SelectorID &StoredID = SelectorIDs[S]; |
| 5644 | if (ID > StoredID) |
| 5645 | StoredID = ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5646 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5647 | |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5648 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5649 | MacroDefinitionRecord *MD) { |
Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5650 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5651 | MacroDefinitions[MD] = ID; |
| 5652 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5653 | |
Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 5654 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 5655 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 5656 | SubmoduleIDs[Mod] = ID; |
| 5657 | } |
| 5658 | |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5659 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5660 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5661 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5662 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 5663 | // We are interested when a PCH decl is modified. |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5664 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5665 | // A forward reference was mutated into a definition. Rewrite it. |
| 5666 | // FIXME: This happens during template instantiation, should we |
| 5667 | // have created a new definition decl instead ? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5668 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && |
| 5669 | "completed a tag from another module but not by instantiation?"); |
| 5670 | DeclUpdates[RD].push_back( |
| 5671 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5672 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5673 | } |
| 5674 | } |
Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5675 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5676 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { |
| 5677 | if (D->isFromASTFile()) |
| 5678 | return true; |
| 5679 | |
| 5680 | // If we've not loaded any modules, this can't be imported. |
| 5681 | if (!Chain || !Chain->getModuleManager().size()) |
| 5682 | return false; |
| 5683 | |
| 5684 | // The predefined __va_list_tag struct is imported if we imported any decls. |
| 5685 | // FIXME: This is a gross hack. |
| 5686 | return D == D->getASTContext().getVaListTagDecl(); |
| 5687 | } |
| 5688 | |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5689 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
| 5690 | // TU and namespaces are handled elsewhere. |
| 5691 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 5692 | return; |
| 5693 | |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5694 | // We're only interested in cases where a local declaration is added to an |
| 5695 | // imported context. |
| 5696 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) |
| 5697 | return; |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5698 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 5699 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5700 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5701 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5702 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { |
| 5703 | // We're adding a visible declaration to a predefined decl context. Ensure |
| 5704 | // that we write out all of its lookup results so we don't get a nasty |
| 5705 | // surprise when we try to emit its lookup table. |
| 5706 | for (auto *Child : DC->decls()) |
| 5707 | UpdatingVisibleDecls.push_back(Child); |
| 5708 | } |
Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5709 | UpdatingVisibleDecls.push_back(D); |
Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5710 | } |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5711 | |
| 5712 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
| 5713 | assert(D->isImplicit()); |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5714 | |
| 5715 | // We're only interested in cases where a local declaration is added to an |
| 5716 | // imported context. |
| 5717 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) |
| 5718 | return; |
| 5719 | |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5720 | if (!isa<CXXMethodDecl>(D)) |
Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5721 | return; |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5722 | |
| 5723 | // A decl coming from PCH was modified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5724 | assert(RD->isCompleteDefinition()); |
Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5725 | assert(!WritingAST && "Already writing the AST!"); |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5726 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5727 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5728 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5729 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5730 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); |
| 5731 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5732 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5733 | // If we don't already know the exception specification for this redecl |
| 5734 | // chain, add an update record for it. |
| 5735 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) |
| 5736 | ->getType() |
| 5737 | ->castAs<FunctionProtoType>() |
| 5738 | ->getExceptionSpecType())) |
| 5739 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); |
| 5740 | }); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5741 | } |
| 5742 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5743 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { |
| 5744 | assert(!WritingAST && "Already writing the AST!"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5745 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5746 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5747 | DeclUpdates[D].push_back( |
| 5748 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); |
| 5749 | }); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5750 | } |
| 5751 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5752 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, |
| 5753 | const FunctionDecl *Delete) { |
| 5754 | assert(!WritingAST && "Already writing the AST!"); |
| 5755 | assert(Delete && "Not given an operator delete"); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5756 | if (!Chain) return; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5757 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5758 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); |
| 5759 | }); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5760 | } |
| 5761 | |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5762 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5763 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5764 | if (!D->isFromASTFile()) |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5765 | return; // Declaration not imported from PCH. |
| 5766 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5767 | // Implicit function decl from a PCH was defined. |
| 5768 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5769 | } |
| 5770 | |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5771 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { |
| 5772 | assert(!WritingAST && "Already writing the AST!"); |
| 5773 | if (!D->isFromASTFile()) |
| 5774 | return; |
| 5775 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5776 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5777 | } |
| 5778 | |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5779 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5780 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5781 | if (!D->isFromASTFile()) |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5782 | return; |
| 5783 | |
| 5784 | // Since the actual instantiation is delayed, this really means that we need |
| 5785 | // to update the instantiation location. |
Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5786 | DeclUpdates[D].push_back( |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5787 | DeclUpdate(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER, |
| 5788 | D->getMemberSpecializationInfo()->getPointOfInstantiation())); |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5789 | } |
| 5790 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5791 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 5792 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5793 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5794 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5795 | return; // Declaration not imported from PCH. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5796 | |
| 5797 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 5798 | ObjCClassesWithCategories.insert( |
| 5799 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5800 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 5801 | |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5802 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { |
| 5803 | assert(!WritingAST && "Already writing the AST!"); |
| 5804 | if (!D->isFromASTFile()) |
| 5805 | return; |
| 5806 | |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5807 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5808 | } |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5809 | |
| 5810 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { |
| 5811 | assert(!WritingAST && "Already writing the AST!"); |
| 5812 | if (!D->isFromASTFile()) |
| 5813 | return; |
| 5814 | |
| 5815 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); |
| 5816 | } |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5817 | |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5818 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5819 | assert(!WritingAST && "Already writing the AST!"); |
| 5820 | assert(D->isHidden() && "expected a hidden declaration"); |
Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5821 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5822 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5823 | |
| 5824 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, |
| 5825 | const RecordDecl *Record) { |
| 5826 | assert(!WritingAST && "Already writing the AST!"); |
| 5827 | if (!Record->isFromASTFile()) |
| 5828 | return; |
| 5829 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); |
| 5830 | } |