Sebastian Redl | 4ee2ad0 | 2010-08-18 23:56:31 +0000 | [diff] [blame] | 1 | //===--- ASTWriter.cpp - AST File Writer ----------------------------------===// |
Douglas Gregor | 2cf2634 | 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 | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 10 | // This file defines the ASTWriter class, which writes AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sebastian Redl | 7faa2ec | 2010-08-18 23:56:37 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTWriter.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 16 | #include "clang/Sema/Sema.h" |
| 17 | #include "clang/Sema/IdentifierResolver.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
| 19 | #include "clang/AST/Decl.h" |
| 20 | #include "clang/AST/DeclContextInternals.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclTemplate.h" |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclFriend.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 23 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 24 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 25 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocVisitor.h" |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 27 | #include "clang/Serialization/ASTReader.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 28 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 29 | #include "clang/Lex/PreprocessingRecord.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 30 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 31 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 33 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 34 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 36 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 37 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 38 | #include "clang/Basic/TargetOptions.h" |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 39 | #include "clang/Basic/Version.h" |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 40 | #include "clang/Basic/VersionTuple.h" |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/APFloat.h" |
| 42 | #include "llvm/ADT/APInt.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 43 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 44 | #include "llvm/Bitcode/BitstreamWriter.h" |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 45 | #include "llvm/Support/FileSystem.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 46 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 47 | #include "llvm/Support/Path.h" |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 48 | #include <algorithm> |
Chris Lattner | 3c304bd | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 49 | #include <cstdio> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 50 | #include <string.h> |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 51 | #include <utility> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 52 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 53 | using namespace clang::serialization; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 54 | |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 55 | template <typename T, typename Allocator> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 56 | static StringRef data(const std::vector<T, Allocator> &v) { |
| 57 | if (v.empty()) return StringRef(); |
| 58 | return StringRef(reinterpret_cast<const char*>(&v[0]), |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 59 | sizeof(T) * v.size()); |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 60 | } |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 61 | |
| 62 | template <typename T> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 63 | static StringRef data(const SmallVectorImpl<T> &v) { |
| 64 | return StringRef(reinterpret_cast<const char*>(v.data()), |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 65 | sizeof(T) * v.size()); |
Sebastian Redl | ade5000 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 68 | //===----------------------------------------------------------------------===// |
| 69 | // Type serialization |
| 70 | //===----------------------------------------------------------------------===// |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 71 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 72 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 73 | class ASTTypeWriter { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 74 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 75 | ASTWriter::RecordDataImpl &Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 76 | |
| 77 | public: |
| 78 | /// \brief Type code that corresponds to the record generated. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 79 | TypeCode Code; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 80 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 81 | ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 82 | : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 83 | |
| 84 | void VisitArrayType(const ArrayType *T); |
| 85 | void VisitFunctionType(const FunctionType *T); |
| 86 | void VisitTagType(const TagType *T); |
| 87 | |
| 88 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 89 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 90 | #include "clang/AST/TypeNodes.def" |
| 91 | }; |
| 92 | } |
| 93 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 94 | void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 95 | llvm_unreachable("Built-in types are never serialized"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 98 | void ASTTypeWriter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 99 | Writer.AddTypeRef(T->getElementType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 100 | Code = TYPE_COMPLEX; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 103 | void ASTTypeWriter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 104 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 105 | Code = TYPE_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 108 | void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 109 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 110 | Code = TYPE_BLOCK_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 113 | void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 114 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
| 115 | Record.push_back(T->isSpelledAsLValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 116 | Code = TYPE_LVALUE_REFERENCE; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 119 | void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 120 | Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 121 | Code = TYPE_RVALUE_REFERENCE; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 124 | void ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 126 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 127 | Code = TYPE_MEMBER_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 130 | void ASTTypeWriter::VisitArrayType(const ArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 131 | Writer.AddTypeRef(T->getElementType(), Record); |
| 132 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 133 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 136 | void ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 137 | VisitArrayType(T); |
| 138 | Writer.AddAPInt(T->getSize(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 139 | Code = TYPE_CONSTANT_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 142 | void ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 143 | VisitArrayType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 144 | Code = TYPE_INCOMPLETE_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 147 | void ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 148 | VisitArrayType(T); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 149 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 150 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 151 | Writer.AddStmt(T->getSizeExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 152 | Code = TYPE_VARIABLE_ARRAY; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 155 | void ASTTypeWriter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 156 | Writer.AddTypeRef(T->getElementType(), Record); |
| 157 | Record.push_back(T->getNumElements()); |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 158 | Record.push_back(T->getVectorKind()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 159 | Code = TYPE_VECTOR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 162 | void ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 163 | VisitVectorType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 164 | Code = TYPE_EXT_VECTOR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 167 | void ASTTypeWriter::VisitFunctionType(const FunctionType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 168 | Writer.AddTypeRef(T->getResultType(), Record); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 169 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 170 | Record.push_back(C.getNoReturn()); |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 171 | Record.push_back(C.getHasRegParm()); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 172 | Record.push_back(C.getRegParm()); |
Douglas Gregor | ab8bbf4 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 173 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 174 | Record.push_back(C.getCC()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 175 | Record.push_back(C.getProducesResult()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 178 | void ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 179 | VisitFunctionType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 180 | Code = TYPE_FUNCTION_NO_PROTO; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 183 | void ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 184 | VisitFunctionType(T); |
| 185 | Record.push_back(T->getNumArgs()); |
| 186 | for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) |
| 187 | Writer.AddTypeRef(T->getArgType(I), Record); |
| 188 | Record.push_back(T->isVariadic()); |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 189 | Record.push_back(T->hasTrailingReturn()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 190 | Record.push_back(T->getTypeQuals()); |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 191 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 192 | Record.push_back(T->getExceptionSpecType()); |
| 193 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 194 | Record.push_back(T->getNumExceptions()); |
| 195 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 196 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 197 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 198 | Writer.AddStmt(T->getNoexceptExpr()); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 199 | } else if (T->getExceptionSpecType() == EST_Uninstantiated) { |
| 200 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
| 201 | Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record); |
Richard Smith | b9d0b76 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 202 | } else if (T->getExceptionSpecType() == EST_Unevaluated) { |
| 203 | Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 204 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 205 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 208 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 209 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 210 | Code = TYPE_UNRESOLVED_USING; |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 211 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 212 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 213 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 214 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 215 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 216 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 217 | Code = TYPE_TYPEDEF; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 220 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 221 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 222 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 225 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 226 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 227 | Code = TYPE_TYPEOF; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 230 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 231 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 232 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 233 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 236 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 237 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 238 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 239 | Record.push_back(T->getUTTKind()); |
| 240 | Code = TYPE_UNARY_TRANSFORM; |
| 241 | } |
| 242 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 243 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 244 | Writer.AddTypeRef(T->getDeducedType(), Record); |
| 245 | Code = TYPE_AUTO; |
| 246 | } |
| 247 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 248 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 249 | Record.push_back(T->isDependentType()); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 250 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 251 | assert(!T->isBeingDefined() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 252 | "Cannot serialize in the middle of a type definition"); |
| 253 | } |
| 254 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 255 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 256 | VisitTagType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 257 | Code = TYPE_RECORD; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 260 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 261 | VisitTagType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 262 | Code = TYPE_ENUM; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 263 | } |
| 264 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 265 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 266 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 267 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 268 | Record.push_back(T->getAttrKind()); |
| 269 | Code = TYPE_ATTRIBUTED; |
| 270 | } |
| 271 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 273 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 274 | const SubstTemplateTypeParmType *T) { |
| 275 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 276 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 277 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 281 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 282 | const SubstTemplateTypeParmPackType *T) { |
| 283 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 284 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 285 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 286 | } |
| 287 | |
| 288 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 289 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 290 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 291 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 292 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 293 | Record.push_back(T->getNumArgs()); |
| 294 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 295 | ArgI != ArgE; ++ArgI) |
| 296 | Writer.AddTemplateArgument(*ArgI, Record); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 297 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 298 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 299 | : T->getCanonicalTypeInternal(), |
| 300 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 301 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 305 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 306 | VisitArrayType(T); |
| 307 | Writer.AddStmt(T->getSizeExpr()); |
| 308 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 309 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 313 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 314 | const DependentSizedExtVectorType *T) { |
| 315 | // FIXME: Serialize this type (C++ only) |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 316 | llvm_unreachable("Cannot serialize dependent sized extended vector types"); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 320 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 321 | Record.push_back(T->getDepth()); |
| 322 | Record.push_back(T->getIndex()); |
| 323 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 324 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 325 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 329 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 330 | Record.push_back(T->getKeyword()); |
| 331 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 332 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 333 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 334 | : T->getCanonicalTypeInternal(), |
| 335 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 336 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 340 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 341 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 342 | Record.push_back(T->getKeyword()); |
| 343 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 344 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 345 | Record.push_back(T->getNumArgs()); |
| 346 | for (DependentTemplateSpecializationType::iterator |
| 347 | I = T->begin(), E = T->end(); I != E; ++I) |
| 348 | Writer.AddTemplateArgument(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 349 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 352 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 353 | Writer.AddTypeRef(T->getPattern(), Record); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 354 | if (llvm::Optional<unsigned> NumExpansions = T->getNumExpansions()) |
| 355 | Record.push_back(*NumExpansions + 1); |
| 356 | else |
| 357 | Record.push_back(0); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 358 | Code = TYPE_PACK_EXPANSION; |
| 359 | } |
| 360 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 361 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 362 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 363 | Code = TYPE_PAREN; |
| 364 | } |
| 365 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 366 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 367 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 368 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 369 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 370 | Code = TYPE_ELABORATED; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 373 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
Douglas Gregor | a8e0b97 | 2012-03-26 15:52:37 +0000 | [diff] [blame] | 374 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 375 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 376 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 379 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 380 | Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 381 | Code = TYPE_OBJC_INTERFACE; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 384 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 385 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 386 | Record.push_back(T->getNumProtocols()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 387 | for (ObjCObjectType::qual_iterator I = T->qual_begin(), |
Steve Naroff | 446ee4e | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 388 | E = T->qual_end(); I != E; ++I) |
| 389 | Writer.AddDeclRef(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 390 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 393 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 394 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 396 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 399 | void |
| 400 | ASTTypeWriter::VisitAtomicType(const AtomicType *T) { |
| 401 | Writer.AddTypeRef(T->getValueType(), Record); |
| 402 | Code = TYPE_ATOMIC; |
| 403 | } |
| 404 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 405 | namespace { |
| 406 | |
| 407 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 408 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 409 | ASTWriter::RecordDataImpl &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 410 | |
| 411 | public: |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 412 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 413 | : Writer(Writer), Record(Record) { } |
| 414 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 415 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 416 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 417 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 418 | #include "clang/AST/TypeLocNodes.def" |
| 419 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 420 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 421 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 422 | }; |
| 423 | |
| 424 | } |
| 425 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 426 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 427 | // nothing to do |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 428 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 429 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 430 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 431 | if (TL.needsExtraLocalData()) { |
| 432 | Record.push_back(TL.getWrittenTypeSpec()); |
| 433 | Record.push_back(TL.getWrittenSignSpec()); |
| 434 | Record.push_back(TL.getWrittenWidthSpec()); |
| 435 | Record.push_back(TL.hasModeAttr()); |
| 436 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 437 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 438 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 439 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 440 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 441 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 442 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 443 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 444 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 445 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 446 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 447 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 448 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 449 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 450 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 451 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 452 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 453 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 454 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 455 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 456 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 457 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 458 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 459 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 460 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 461 | if (TL.getSizeExpr()) |
| 462 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 463 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 464 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 465 | VisitArrayTypeLoc(TL); |
| 466 | } |
| 467 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 468 | VisitArrayTypeLoc(TL); |
| 469 | } |
| 470 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 471 | VisitArrayTypeLoc(TL); |
| 472 | } |
| 473 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 474 | DependentSizedArrayTypeLoc TL) { |
| 475 | VisitArrayTypeLoc(TL); |
| 476 | } |
| 477 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 478 | DependentSizedExtVectorTypeLoc TL) { |
| 479 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 480 | } |
| 481 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 482 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 483 | } |
| 484 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 485 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 486 | } |
| 487 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 488 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 489 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 490 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 491 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 492 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 493 | Writer.AddDeclRef(TL.getArg(i), Record); |
| 494 | } |
| 495 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 496 | VisitFunctionTypeLoc(TL); |
| 497 | } |
| 498 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 499 | VisitFunctionTypeLoc(TL); |
| 500 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 501 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 502 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 503 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 504 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 505 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 506 | } |
| 507 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 508 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 509 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 510 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 511 | } |
| 512 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 513 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 514 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 515 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 516 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 517 | } |
| 518 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 519 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 520 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 521 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 522 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 523 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 524 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 525 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 526 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 527 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 528 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 529 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 530 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 531 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 532 | } |
| 533 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 534 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 535 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 536 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 537 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 538 | if (TL.hasAttrOperand()) { |
| 539 | SourceRange range = TL.getAttrOperandParensRange(); |
| 540 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 541 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 542 | } |
| 543 | if (TL.hasAttrExprOperand()) { |
| 544 | Expr *operand = TL.getAttrExprOperand(); |
| 545 | Record.push_back(operand ? 1 : 0); |
| 546 | if (operand) Writer.AddStmt(operand); |
| 547 | } else if (TL.hasAttrEnumOperand()) { |
| 548 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 549 | } |
| 550 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 551 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 552 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 553 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 554 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 555 | SubstTemplateTypeParmTypeLoc TL) { |
| 556 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 557 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 558 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 559 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 560 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 561 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 562 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 563 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 564 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 565 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 566 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 567 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 568 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 569 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 570 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 571 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 572 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 573 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 574 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 575 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 576 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 577 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 578 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 579 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 580 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 581 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 582 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 583 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 584 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 585 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 586 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 587 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 588 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 589 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 590 | Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 591 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 592 | Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 593 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 594 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 595 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 596 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 597 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 598 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 599 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 600 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 601 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 602 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 603 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 604 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 605 | } |
| 606 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 607 | Record.push_back(TL.hasBaseTypeAsWritten()); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 608 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 609 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 610 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 611 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 612 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 613 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 614 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 615 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 616 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 617 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 618 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 619 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 620 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 621 | |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 622 | //===----------------------------------------------------------------------===// |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 623 | // ASTWriter Implementation |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 624 | //===----------------------------------------------------------------------===// |
| 625 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 626 | static void EmitBlockID(unsigned ID, const char *Name, |
| 627 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 628 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 629 | Record.clear(); |
| 630 | Record.push_back(ID); |
| 631 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 632 | |
| 633 | // Emit the block name if present. |
| 634 | if (Name == 0 || Name[0] == 0) return; |
| 635 | Record.clear(); |
| 636 | while (*Name) |
| 637 | Record.push_back(*Name++); |
| 638 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 639 | } |
| 640 | |
| 641 | static void EmitRecordID(unsigned ID, const char *Name, |
| 642 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 643 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 644 | Record.clear(); |
| 645 | Record.push_back(ID); |
| 646 | while (*Name) |
| 647 | Record.push_back(*Name++); |
| 648 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 652 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 653 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 654 | RECORD(STMT_STOP); |
| 655 | RECORD(STMT_NULL_PTR); |
| 656 | RECORD(STMT_NULL); |
| 657 | RECORD(STMT_COMPOUND); |
| 658 | RECORD(STMT_CASE); |
| 659 | RECORD(STMT_DEFAULT); |
| 660 | RECORD(STMT_LABEL); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 661 | RECORD(STMT_ATTRIBUTED); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 662 | RECORD(STMT_IF); |
| 663 | RECORD(STMT_SWITCH); |
| 664 | RECORD(STMT_WHILE); |
| 665 | RECORD(STMT_DO); |
| 666 | RECORD(STMT_FOR); |
| 667 | RECORD(STMT_GOTO); |
| 668 | RECORD(STMT_INDIRECT_GOTO); |
| 669 | RECORD(STMT_CONTINUE); |
| 670 | RECORD(STMT_BREAK); |
| 671 | RECORD(STMT_RETURN); |
| 672 | RECORD(STMT_DECL); |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 673 | RECORD(STMT_GCCASM); |
Chad Rosier | cd518a0 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 674 | RECORD(STMT_MSASM); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 675 | RECORD(EXPR_PREDEFINED); |
| 676 | RECORD(EXPR_DECL_REF); |
| 677 | RECORD(EXPR_INTEGER_LITERAL); |
| 678 | RECORD(EXPR_FLOATING_LITERAL); |
| 679 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 680 | RECORD(EXPR_STRING_LITERAL); |
| 681 | RECORD(EXPR_CHARACTER_LITERAL); |
| 682 | RECORD(EXPR_PAREN); |
| 683 | RECORD(EXPR_UNARY_OPERATOR); |
| 684 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 685 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 686 | RECORD(EXPR_CALL); |
| 687 | RECORD(EXPR_MEMBER); |
| 688 | RECORD(EXPR_BINARY_OPERATOR); |
| 689 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 690 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 691 | RECORD(EXPR_IMPLICIT_CAST); |
| 692 | RECORD(EXPR_CSTYLE_CAST); |
| 693 | RECORD(EXPR_COMPOUND_LITERAL); |
| 694 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 695 | RECORD(EXPR_INIT_LIST); |
| 696 | RECORD(EXPR_DESIGNATED_INIT); |
| 697 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 698 | RECORD(EXPR_VA_ARG); |
| 699 | RECORD(EXPR_ADDR_LABEL); |
| 700 | RECORD(EXPR_STMT); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 701 | RECORD(EXPR_CHOOSE); |
| 702 | RECORD(EXPR_GNU_NULL); |
| 703 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 704 | RECORD(EXPR_BLOCK); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 705 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 706 | RECORD(EXPR_OBJC_STRING_LITERAL); |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 707 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 708 | RECORD(EXPR_OBJC_ARRAY_LITERAL); |
| 709 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 710 | RECORD(EXPR_OBJC_ENCODE); |
| 711 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 712 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 713 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 714 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 715 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 716 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 717 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 718 | RECORD(STMT_OBJC_CATCH); |
| 719 | RECORD(STMT_OBJC_FINALLY); |
| 720 | RECORD(STMT_OBJC_AT_TRY); |
| 721 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 722 | RECORD(STMT_OBJC_AT_THROW); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 723 | RECORD(EXPR_OBJC_BOOL_LITERAL); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 724 | RECORD(EXPR_CXX_OPERATOR_CALL); |
| 725 | RECORD(EXPR_CXX_CONSTRUCT); |
| 726 | RECORD(EXPR_CXX_STATIC_CAST); |
| 727 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 728 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 729 | RECORD(EXPR_CXX_CONST_CAST); |
| 730 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 731 | RECORD(EXPR_USER_DEFINED_LITERAL); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 732 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 733 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 734 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 735 | RECORD(EXPR_CXX_TYPEID_TYPE); |
| 736 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 737 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 738 | RECORD(EXPR_CXX_THIS); |
| 739 | RECORD(EXPR_CXX_THROW); |
| 740 | RECORD(EXPR_CXX_DEFAULT_ARG); |
| 741 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 742 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 743 | RECORD(EXPR_CXX_NEW); |
| 744 | RECORD(EXPR_CXX_DELETE); |
| 745 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 746 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 747 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 748 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 749 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 750 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 751 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
| 752 | RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); |
| 753 | RECORD(EXPR_CXX_NOEXCEPT); |
| 754 | RECORD(EXPR_OPAQUE_VALUE); |
| 755 | RECORD(EXPR_BINARY_TYPE_TRAIT); |
| 756 | RECORD(EXPR_PACK_EXPANSION); |
| 757 | RECORD(EXPR_SIZEOF_PACK); |
| 758 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 759 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 760 | #undef RECORD |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 761 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 763 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 764 | RecordData Record; |
| 765 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 767 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 768 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 770 | // AST Top-Level Block. |
Sebastian Redl | f29f0a2 | 2010-08-18 23:57:22 +0000 | [diff] [blame] | 771 | BLOCK(AST_BLOCK); |
Zhongxing Xu | 51e774d | 2009-06-03 09:23:28 +0000 | [diff] [blame] | 772 | RECORD(ORIGINAL_FILE_NAME); |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 773 | RECORD(ORIGINAL_FILE_ID); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 774 | RECORD(TYPE_OFFSET); |
| 775 | RECORD(DECL_OFFSET); |
| 776 | RECORD(LANGUAGE_OPTIONS); |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 777 | RECORD(METADATA); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 778 | RECORD(IDENTIFIER_OFFSET); |
| 779 | RECORD(IDENTIFIER_TABLE); |
| 780 | RECORD(EXTERNAL_DEFINITIONS); |
| 781 | RECORD(SPECIAL_TYPES); |
| 782 | RECORD(STATISTICS); |
| 783 | RECORD(TENTATIVE_DEFINITIONS); |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 784 | RECORD(UNUSED_FILESCOPED_DECLS); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 785 | RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); |
| 786 | RECORD(SELECTOR_OFFSETS); |
| 787 | RECORD(METHOD_POOL); |
| 788 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 789 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 790 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 791 | RECORD(STAT_CACHE); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 792 | RECORD(EXT_VECTOR_DECLS); |
Ted Kremenek | 5b4ec63 | 2010-01-22 20:59:36 +0000 | [diff] [blame] | 793 | RECORD(VERSION_CONTROL_BRANCH_REVISION); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 794 | RECORD(PPD_ENTITIES_OFFSETS); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 795 | RECORD(IMPORTS); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 796 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 797 | RECORD(TU_UPDATE_LEXICAL); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 798 | RECORD(LOCAL_REDECLARATIONS_MAP); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 799 | RECORD(SEMA_DECL_REFS); |
| 800 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 801 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 802 | RECORD(DECL_REPLACEMENTS); |
| 803 | RECORD(UPDATE_VISIBLE); |
| 804 | RECORD(DECL_UPDATE_OFFSETS); |
| 805 | RECORD(DECL_UPDATES); |
| 806 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 807 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 808 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 809 | RECORD(HEADER_SEARCH_TABLE); |
Douglas Gregor | 837593f | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 810 | RECORD(ORIGINAL_PCH_DIR); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 811 | RECORD(FP_PRAGMA_OPTIONS); |
| 812 | RECORD(OPENCL_EXTENSIONS); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 813 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 814 | RECORD(FILE_SOURCE_LOCATION_OFFSETS); |
| 815 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 837593f | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 816 | RECORD(MODULE_OFFSET_MAP); |
| 817 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 818 | RECORD(OBJC_CATEGORIES_MAP); |
Douglas Gregor | a126651 | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 819 | RECORD(FILE_SORTED_DECLS); |
| 820 | RECORD(IMPORTED_MODULES); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 821 | RECORD(MERGED_DECLARATIONS); |
| 822 | RECORD(LOCAL_REDECLARATIONS); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 823 | RECORD(OBJC_CATEGORIES); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 824 | RECORD(MACRO_OFFSET); |
| 825 | RECORD(MACRO_UPDATES); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 826 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 827 | // SourceManager Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 828 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 829 | RECORD(SM_SLOC_FILE_ENTRY); |
| 830 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 831 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 832 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 834 | // Preprocessor Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 835 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 836 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 837 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 838 | RECORD(PP_TOKEN); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 839 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 840 | // Decls and Types block. |
| 841 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 842 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 843 | RECORD(TYPE_COMPLEX); |
| 844 | RECORD(TYPE_POINTER); |
| 845 | RECORD(TYPE_BLOCK_POINTER); |
| 846 | RECORD(TYPE_LVALUE_REFERENCE); |
| 847 | RECORD(TYPE_RVALUE_REFERENCE); |
| 848 | RECORD(TYPE_MEMBER_POINTER); |
| 849 | RECORD(TYPE_CONSTANT_ARRAY); |
| 850 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 851 | RECORD(TYPE_VARIABLE_ARRAY); |
| 852 | RECORD(TYPE_VECTOR); |
| 853 | RECORD(TYPE_EXT_VECTOR); |
| 854 | RECORD(TYPE_FUNCTION_PROTO); |
| 855 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 856 | RECORD(TYPE_TYPEDEF); |
| 857 | RECORD(TYPE_TYPEOF_EXPR); |
| 858 | RECORD(TYPE_TYPEOF); |
| 859 | RECORD(TYPE_RECORD); |
| 860 | RECORD(TYPE_ENUM); |
| 861 | RECORD(TYPE_OBJC_INTERFACE); |
John McCall | a53d2cb | 2010-05-16 02:12:35 +0000 | [diff] [blame] | 862 | RECORD(TYPE_OBJC_OBJECT); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 863 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 864 | RECORD(TYPE_DECLTYPE); |
| 865 | RECORD(TYPE_ELABORATED); |
| 866 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 867 | RECORD(TYPE_UNRESOLVED_USING); |
| 868 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 869 | RECORD(TYPE_OBJC_OBJECT); |
| 870 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 871 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 872 | RECORD(TYPE_DEPENDENT_NAME); |
| 873 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 874 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 875 | RECORD(TYPE_PAREN); |
| 876 | RECORD(TYPE_PACK_EXPANSION); |
| 877 | RECORD(TYPE_ATTRIBUTED); |
| 878 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 879 | RECORD(TYPE_ATOMIC); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 880 | RECORD(DECL_TYPEDEF); |
| 881 | RECORD(DECL_ENUM); |
| 882 | RECORD(DECL_RECORD); |
| 883 | RECORD(DECL_ENUM_CONSTANT); |
| 884 | RECORD(DECL_FUNCTION); |
| 885 | RECORD(DECL_OBJC_METHOD); |
| 886 | RECORD(DECL_OBJC_INTERFACE); |
| 887 | RECORD(DECL_OBJC_PROTOCOL); |
| 888 | RECORD(DECL_OBJC_IVAR); |
| 889 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 890 | RECORD(DECL_OBJC_CATEGORY); |
| 891 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 892 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 893 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 894 | RECORD(DECL_OBJC_PROPERTY); |
| 895 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 896 | RECORD(DECL_FIELD); |
| 897 | RECORD(DECL_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 898 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 899 | RECORD(DECL_PARM_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 900 | RECORD(DECL_FILE_SCOPE_ASM); |
| 901 | RECORD(DECL_BLOCK); |
| 902 | RECORD(DECL_CONTEXT_LEXICAL); |
| 903 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 904 | RECORD(DECL_NAMESPACE); |
| 905 | RECORD(DECL_NAMESPACE_ALIAS); |
| 906 | RECORD(DECL_USING); |
| 907 | RECORD(DECL_USING_SHADOW); |
| 908 | RECORD(DECL_USING_DIRECTIVE); |
| 909 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 910 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 911 | RECORD(DECL_LINKAGE_SPEC); |
| 912 | RECORD(DECL_CXX_RECORD); |
| 913 | RECORD(DECL_CXX_METHOD); |
| 914 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 915 | RECORD(DECL_CXX_DESTRUCTOR); |
| 916 | RECORD(DECL_CXX_CONVERSION); |
| 917 | RECORD(DECL_ACCESS_SPEC); |
| 918 | RECORD(DECL_FRIEND); |
| 919 | RECORD(DECL_FRIEND_TEMPLATE); |
| 920 | RECORD(DECL_CLASS_TEMPLATE); |
| 921 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 922 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
| 923 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 924 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 925 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 926 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 927 | RECORD(DECL_STATIC_ASSERT); |
| 928 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 929 | RECORD(DECL_INDIRECTFIELD); |
| 930 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 931 | |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 932 | // Statements and Exprs can occur in the Decls and Types block. |
| 933 | AddStmtsExprs(Stream, Record); |
| 934 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 935 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 936 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 937 | RECORD(PPD_MACRO_DEFINITION); |
| 938 | RECORD(PPD_INCLUSION_DIRECTIVE); |
| 939 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 940 | #undef RECORD |
| 941 | #undef BLOCK |
| 942 | Stream.ExitBlock(); |
| 943 | } |
| 944 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 945 | /// \brief Adjusts the given filename to only write out the portion of the |
| 946 | /// filename that is not part of the system root directory. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 947 | /// |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 948 | /// \param Filename the file name to adjust. |
| 949 | /// |
| 950 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 951 | /// the returned filename will be adjusted by this system root. |
| 952 | /// |
| 953 | /// \returns either the original filename (if it needs no adjustment) or the |
| 954 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 | static const char * |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 956 | adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 957 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 959 | if (isysroot.empty()) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 960 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 961 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 962 | // Verify that the filename and the system root have the same prefix. |
| 963 | unsigned Pos = 0; |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 964 | for (; Filename[Pos] && Pos < isysroot.size(); ++Pos) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 965 | if (Filename[Pos] != isysroot[Pos]) |
| 966 | return Filename; // Prefixes don't match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 967 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 968 | // We hit the end of the filename before we hit the end of the system root. |
| 969 | if (!Filename[Pos]) |
| 970 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 972 | // If the file name has a '/' at the current position, skip over the '/'. |
| 973 | // We distinguish sysroot-based includes from absolute includes by the |
| 974 | // absence of '/' at the beginning of sysroot-based includes. |
| 975 | if (Filename[Pos] == '/') |
| 976 | ++Pos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 977 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 978 | return Filename + Pos; |
| 979 | } |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 980 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 981 | /// \brief Write the AST metadata (e.g., i686-apple-darwin9). |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 982 | void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 983 | const std::string &OutputFile) { |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 984 | using namespace llvm; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 985 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 986 | // Metadata |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 987 | const TargetInfo &Target = Context.getTargetInfo(); |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 988 | const TargetOptions &TargetOpts = Target.getTargetOpts(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 989 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 990 | Record.push_back(VERSION_MAJOR); |
| 991 | Record.push_back(VERSION_MINOR); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 992 | Record.push_back(CLANG_VERSION_MAJOR); |
| 993 | Record.push_back(CLANG_VERSION_MINOR); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 994 | Record.push_back(!isysroot.empty()); |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 995 | Record.push_back(ASTHasCompilerErrors); |
Douglas Gregor | 57016dd | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 996 | AddString(TargetOpts.Triple, Record); |
| 997 | AddString(TargetOpts.CPU, Record); |
| 998 | AddString(TargetOpts.ABI, Record); |
| 999 | AddString(TargetOpts.CXXABI, Record); |
| 1000 | AddString(TargetOpts.LinkerVersion, Record); |
| 1001 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); |
| 1002 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { |
| 1003 | AddString(TargetOpts.FeaturesAsWritten[I], Record); |
| 1004 | } |
| 1005 | Record.push_back(TargetOpts.Features.size()); |
| 1006 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { |
| 1007 | AddString(TargetOpts.Features[I], Record); |
| 1008 | } |
| 1009 | Stream.EmitRecord(METADATA, Record); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1010 | |
| 1011 | if (Chain) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1012 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
| 1013 | llvm::SmallVector<char, 128> ModulePaths; |
| 1014 | Record.clear(); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1015 | |
| 1016 | for (ModuleManager::ModuleIterator M = Mgr.begin(), MEnd = Mgr.end(); |
| 1017 | M != MEnd; ++M) { |
| 1018 | // Skip modules that weren't directly imported. |
| 1019 | if (!(*M)->isDirectlyImported()) |
| 1020 | continue; |
| 1021 | |
| 1022 | Record.push_back((unsigned)(*M)->Kind); // FIXME: Stable encoding |
| 1023 | // FIXME: Write import location, once it matters. |
| 1024 | // FIXME: This writes the absolute path for AST files we depend on. |
| 1025 | const std::string &FileName = (*M)->FileName; |
| 1026 | Record.push_back(FileName.size()); |
| 1027 | Record.append(FileName.begin(), FileName.end()); |
| 1028 | } |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1029 | Stream.EmitRecord(IMPORTS, Record); |
| 1030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1031 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1032 | // Original file name and file ID |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1033 | SourceManager &SM = Context.getSourceManager(); |
| 1034 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 1035 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1036 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE_NAME)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1037 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1038 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1039 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1040 | SmallString<128> MainFilePath(MainFile->getName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1042 | llvm::sys::fs::make_absolute(MainFilePath); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1043 | |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1044 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1045 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1046 | isysroot); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1047 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1048 | Record.push_back(ORIGINAL_FILE_NAME); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1049 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1050 | |
| 1051 | Record.clear(); |
| 1052 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1053 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1054 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1055 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1056 | // Original PCH directory |
| 1057 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1058 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1059 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1060 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1061 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1062 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1063 | SmallString<128> OutputPath(OutputFile); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1064 | |
| 1065 | llvm::sys::fs::make_absolute(OutputPath); |
| 1066 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1067 | |
| 1068 | RecordData Record; |
| 1069 | Record.push_back(ORIGINAL_PCH_DIR); |
| 1070 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1071 | } |
| 1072 | |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1073 | // Repository branch/version information. |
| 1074 | BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1075 | RepoAbbrev->Add(BitCodeAbbrevOp(VERSION_CONTROL_BRANCH_REVISION)); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1076 | RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1077 | unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 1078 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1079 | Record.push_back(VERSION_CONTROL_BRANCH_REVISION); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1080 | Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, |
| 1081 | getClangFullRepositoryVersion()); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | /// \brief Write the LangOptions structure. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1085 | void ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1086 | RecordData Record; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 1087 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1088 | Record.push_back(LangOpts.Name); |
| 1089 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1090 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
| 1091 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1092 | |
| 1093 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); |
| 1094 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 1095 | |
| 1096 | Record.push_back(LangOpts.CurrentModule.size()); |
| 1097 | Record.append(LangOpts.CurrentModule.begin(), LangOpts.CurrentModule.end()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1098 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1101 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1102 | // stat cache Serialization |
| 1103 | //===----------------------------------------------------------------------===// |
| 1104 | |
| 1105 | namespace { |
| 1106 | // Trait used for the on-disk hash table of stat cache results. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1107 | class ASTStatCacheTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1108 | public: |
| 1109 | typedef const char * key_type; |
| 1110 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1112 | typedef struct stat data_type; |
| 1113 | typedef const data_type &data_type_ref; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1114 | |
| 1115 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1116 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1117 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | |
| 1119 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1120 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1121 | data_type_ref Data) { |
| 1122 | unsigned StrLen = strlen(path); |
| 1123 | clang::io::Emit16(Out, StrLen); |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1124 | unsigned DataLen = 4 + 4 + 2 + 8 + 8; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1125 | clang::io::Emit8(Out, DataLen); |
| 1126 | return std::make_pair(StrLen + 1, DataLen); |
| 1127 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1129 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1130 | Out.write(path, KeyLen); |
| 1131 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1132 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1133 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1134 | data_type_ref Data, unsigned DataLen) { |
| 1135 | using namespace clang::io; |
| 1136 | uint64_t Start = Out.tell(); (void)Start; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1138 | Emit32(Out, (uint32_t) Data.st_ino); |
| 1139 | Emit32(Out, (uint32_t) Data.st_dev); |
| 1140 | Emit16(Out, (uint16_t) Data.st_mode); |
| 1141 | Emit64(Out, (uint64_t) Data.st_mtime); |
| 1142 | Emit64(Out, (uint64_t) Data.st_size); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1143 | |
| 1144 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1145 | } |
| 1146 | }; |
| 1147 | } // end anonymous namespace |
| 1148 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1149 | /// \brief Write the stat() system call cache to the AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1150 | void ASTWriter::WriteStatCache(MemorizeStatCalls &StatCalls) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1151 | // Build the on-disk hash table containing information about every |
| 1152 | // stat() call. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1153 | OnDiskChainedHashTableGenerator<ASTStatCacheTrait> Generator; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1154 | unsigned NumStatEntries = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1155 | for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1156 | StatEnd = StatCalls.end(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1157 | Stat != StatEnd; ++Stat, ++NumStatEntries) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1158 | StringRef Filename = Stat->first(); |
Chris Lattner | 1e5f83b | 2011-07-14 18:24:21 +0000 | [diff] [blame] | 1159 | Generator.insert(Filename.data(), Stat->second); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1160 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1162 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1163 | SmallString<4096> StatCacheData; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1164 | uint32_t BucketOffset; |
| 1165 | { |
| 1166 | llvm::raw_svector_ostream Out(StatCacheData); |
| 1167 | // Make sure that no bucket is at offset 0 |
| 1168 | clang::io::Emit32(Out, 0); |
| 1169 | BucketOffset = Generator.Emit(Out); |
| 1170 | } |
| 1171 | |
| 1172 | // Create a blob abbreviation |
| 1173 | using namespace llvm; |
| 1174 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1175 | Abbrev->Add(BitCodeAbbrevOp(STAT_CACHE)); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1176 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1177 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1178 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1179 | unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1180 | |
| 1181 | // Write the stat cache |
| 1182 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1183 | Record.push_back(STAT_CACHE); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1184 | Record.push_back(BucketOffset); |
| 1185 | Record.push_back(NumStatEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1186 | Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1190 | // Source Manager Serialization |
| 1191 | //===----------------------------------------------------------------------===// |
| 1192 | |
| 1193 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1194 | /// file. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1195 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1196 | using namespace llvm; |
| 1197 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1198 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1199 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1200 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1201 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1202 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1203 | // FileEntry fields. |
| 1204 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1205 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1206 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // BufferOverridden |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1207 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1208 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex |
| 1209 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1210 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1211 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1215 | /// buffer. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1216 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1217 | using namespace llvm; |
| 1218 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1219 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1220 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1221 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1222 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1223 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1224 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1225 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1229 | /// buffer's blob. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1230 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1231 | using namespace llvm; |
| 1232 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1233 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1234 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1235 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1238 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1239 | /// expansion. |
| 1240 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1241 | using namespace llvm; |
| 1242 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1243 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1244 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1245 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1246 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1247 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | f60e991 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1248 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1249 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1252 | namespace { |
| 1253 | // Trait used for the on-disk hash table of header search information. |
| 1254 | class HeaderFileInfoTrait { |
| 1255 | ASTWriter &Writer; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1256 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1257 | // Keep track of the framework names we've used during serialization. |
| 1258 | SmallVector<char, 128> FrameworkStringData; |
| 1259 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1260 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1261 | public: |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 1262 | HeaderFileInfoTrait(ASTWriter &Writer) |
| 1263 | : Writer(Writer) { } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1264 | |
| 1265 | typedef const char *key_type; |
| 1266 | typedef key_type key_type_ref; |
| 1267 | |
| 1268 | typedef HeaderFileInfo data_type; |
| 1269 | typedef const data_type &data_type_ref; |
| 1270 | |
| 1271 | static unsigned ComputeHash(const char *path) { |
| 1272 | // The hash is based only on the filename portion of the key, so that the |
| 1273 | // reader can match based on filenames when symlinking or excess path |
| 1274 | // elements ("foo/../", "../") change the form of the name. However, |
| 1275 | // complete path is still the key. |
| 1276 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1277 | } |
| 1278 | |
| 1279 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1280 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1281 | data_type_ref Data) { |
| 1282 | unsigned StrLen = strlen(path); |
| 1283 | clang::io::Emit16(Out, StrLen); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1284 | unsigned DataLen = 1 + 2 + 4 + 4; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1285 | clang::io::Emit8(Out, DataLen); |
| 1286 | return std::make_pair(StrLen + 1, DataLen); |
| 1287 | } |
| 1288 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1289 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1290 | Out.write(path, KeyLen); |
| 1291 | } |
| 1292 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1293 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1294 | data_type_ref Data, unsigned DataLen) { |
| 1295 | using namespace clang::io; |
| 1296 | uint64_t Start = Out.tell(); (void)Start; |
| 1297 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1298 | unsigned char Flags = (Data.isImport << 5) |
| 1299 | | (Data.isPragmaOnce << 4) |
| 1300 | | (Data.DirInfo << 2) |
| 1301 | | (Data.Resolved << 1) |
| 1302 | | Data.IndexHeaderMapHeader; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1303 | Emit8(Out, (uint8_t)Flags); |
| 1304 | Emit16(Out, (uint16_t) Data.NumIncludes); |
| 1305 | |
| 1306 | if (!Data.ControllingMacro) |
| 1307 | Emit32(Out, (uint32_t)Data.ControllingMacroID); |
| 1308 | else |
| 1309 | Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1310 | |
| 1311 | unsigned Offset = 0; |
| 1312 | if (!Data.Framework.empty()) { |
| 1313 | // If this header refers into a framework, save the framework name. |
| 1314 | llvm::StringMap<unsigned>::iterator Pos |
| 1315 | = FrameworkNameOffset.find(Data.Framework); |
| 1316 | if (Pos == FrameworkNameOffset.end()) { |
| 1317 | Offset = FrameworkStringData.size() + 1; |
| 1318 | FrameworkStringData.append(Data.Framework.begin(), |
| 1319 | Data.Framework.end()); |
| 1320 | FrameworkStringData.push_back(0); |
| 1321 | |
| 1322 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1323 | } else |
| 1324 | Offset = Pos->second; |
| 1325 | } |
| 1326 | Emit32(Out, Offset); |
| 1327 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1328 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1329 | } |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1330 | |
| 1331 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1332 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1333 | }; |
| 1334 | } // end anonymous namespace |
| 1335 | |
| 1336 | /// \brief Write the header search block for the list of files that |
| 1337 | /// |
| 1338 | /// \param HS The header search structure to save. |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1339 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1340 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1341 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1342 | |
| 1343 | if (FilesByUID.size() > HS.header_file_size()) |
| 1344 | FilesByUID.resize(HS.header_file_size()); |
| 1345 | |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 1346 | HeaderFileInfoTrait GeneratorTrait(*this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1347 | OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1348 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1349 | unsigned NumHeaderSearchEntries = 0; |
| 1350 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1351 | const FileEntry *File = FilesByUID[UID]; |
| 1352 | if (!File) |
| 1353 | continue; |
| 1354 | |
Argyrios Kyrtzidis | 590ad93 | 2011-11-13 22:08:39 +0000 | [diff] [blame] | 1355 | // Use HeaderSearch's getFileInfo to make sure we get the HeaderFileInfo |
| 1356 | // from the external source if it was not provided already. |
| 1357 | const HeaderFileInfo &HFI = HS.getFileInfo(File); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1358 | if (HFI.External && Chain) |
| 1359 | continue; |
| 1360 | |
| 1361 | // Turn the file name into an absolute path, if it isn't already. |
| 1362 | const char *Filename = File->getName(); |
| 1363 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1364 | |
| 1365 | // If we performed any translation on the file name at all, we need to |
| 1366 | // save this string, since the generator will refer to it later. |
| 1367 | if (Filename != File->getName()) { |
| 1368 | Filename = strdup(Filename); |
| 1369 | SavedStrings.push_back(Filename); |
| 1370 | } |
| 1371 | |
| 1372 | Generator.insert(Filename, HFI, GeneratorTrait); |
| 1373 | ++NumHeaderSearchEntries; |
| 1374 | } |
| 1375 | |
| 1376 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1377 | SmallString<4096> TableData; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1378 | uint32_t BucketOffset; |
| 1379 | { |
| 1380 | llvm::raw_svector_ostream Out(TableData); |
| 1381 | // Make sure that no bucket is at offset 0 |
| 1382 | clang::io::Emit32(Out, 0); |
| 1383 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1384 | } |
| 1385 | |
| 1386 | // Create a blob abbreviation |
| 1387 | using namespace llvm; |
| 1388 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1389 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1390 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1391 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1392 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1393 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1394 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1395 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1396 | // Write the header search table |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1397 | RecordData Record; |
| 1398 | Record.push_back(HEADER_SEARCH_TABLE); |
| 1399 | Record.push_back(BucketOffset); |
| 1400 | Record.push_back(NumHeaderSearchEntries); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1401 | Record.push_back(TableData.size()); |
| 1402 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1403 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); |
| 1404 | |
| 1405 | // Free all of the strings we had to duplicate. |
| 1406 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
| 1407 | free((void*)SavedStrings[I]); |
| 1408 | } |
| 1409 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1410 | /// \brief Writes the block containing the serialized form of the |
| 1411 | /// source manager. |
| 1412 | /// |
| 1413 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1414 | /// blob), indexed based on the file name, so that we only create |
| 1415 | /// entries for files that we actually need. In the common case (no |
| 1416 | /// errors), we probably won't have to create file entries for any of |
| 1417 | /// the files in the AST. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1418 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1419 | const Preprocessor &PP, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1420 | StringRef isysroot) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1421 | RecordData Record; |
| 1422 | |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1423 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1424 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1425 | |
| 1426 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | 828e18c | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1427 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1428 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1429 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1430 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1431 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1432 | // Write out the source location entry table. We skip the first |
| 1433 | // entry, which is always the same dummy entry. |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1434 | std::vector<uint32_t> SLocEntryOffsets; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1435 | // Write out the offsets of only source location file entries. |
| 1436 | // We will go through them in ASTReader::validateFileEntries(). |
| 1437 | std::vector<uint32_t> SLocFileEntryOffsets; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1438 | RecordData PreloadSLocs; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1439 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1440 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1441 | I != N; ++I) { |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1442 | // Get this source location entry. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1443 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1444 | FileID FID = FileID::get(I); |
| 1445 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1446 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1447 | // Record the offset of this source-location entry. |
| 1448 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1449 | |
| 1450 | // Figure out which record code to use. |
| 1451 | unsigned Code; |
| 1452 | if (SLoc->isFile()) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1453 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); |
| 1454 | if (Cache->OrigEntry) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1455 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1456 | SLocFileEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1457 | } else |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1458 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1459 | } else |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1460 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1461 | Record.clear(); |
| 1462 | Record.push_back(Code); |
| 1463 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1464 | // Starting offset of this entry within this module, so skip the dummy. |
| 1465 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1466 | if (SLoc->isFile()) { |
| 1467 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1468 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1469 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1470 | Record.push_back(File.hasLineDirectives()); |
| 1471 | |
| 1472 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1473 | if (Content->OrigEntry) { |
| 1474 | assert(Content->OrigEntry == Content->ContentsEntry && |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1475 | "Writing to AST an overridden file is not supported"); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1476 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1477 | // The source location entry is a file. The blob associated |
| 1478 | // with this entry is the file name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1479 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1480 | // Emit size/modification time for this file. |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1481 | Record.push_back(Content->OrigEntry->getSize()); |
| 1482 | Record.push_back(Content->OrigEntry->getModificationTime()); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1483 | Record.push_back(Content->BufferOverridden); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1484 | Record.push_back(File.NumCreatedFIDs); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1485 | |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1486 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1487 | if (FDI != FileDeclIDs.end()) { |
| 1488 | Record.push_back(FDI->second->FirstDeclIndex); |
| 1489 | Record.push_back(FDI->second->DeclIDs.size()); |
| 1490 | } else { |
| 1491 | Record.push_back(0); |
| 1492 | Record.push_back(0); |
| 1493 | } |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1494 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1495 | // Turn the file name into an absolute path, if it isn't already. |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1496 | const char *Filename = Content->OrigEntry->getName(); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1497 | SmallString<128> FilePath(Filename); |
Anders Carlsson | 2c10c80 | 2011-03-08 16:04:35 +0000 | [diff] [blame] | 1498 | |
| 1499 | // Ask the file manager to fixup the relative path for us. This will |
| 1500 | // honor the working directory. |
| 1501 | SourceMgr.getFileManager().FixupRelativePath(FilePath); |
| 1502 | |
| 1503 | // FIXME: This call to make_absolute shouldn't be necessary, the |
| 1504 | // call to FixupRelativePath should always return an absolute path. |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1505 | llvm::sys::fs::make_absolute(FilePath); |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1506 | Filename = FilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1507 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1508 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1509 | Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1510 | |
| 1511 | if (Content->BufferOverridden) { |
| 1512 | Record.clear(); |
| 1513 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
| 1514 | const llvm::MemoryBuffer *Buffer |
| 1515 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
| 1516 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
| 1517 | StringRef(Buffer->getBufferStart(), |
| 1518 | Buffer->getBufferSize() + 1)); |
| 1519 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1520 | } else { |
| 1521 | // The source location entry is a buffer. The blob associated |
| 1522 | // with this entry contains the contents of the buffer. |
| 1523 | |
| 1524 | // We add one to the size so that we capture the trailing NULL |
| 1525 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1526 | // the reader side). |
Douglas Gregor | 36c35ba | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1527 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1528 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1529 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1530 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1531 | StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1532 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1533 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1534 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1535 | StringRef(Buffer->getBufferStart(), |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1536 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1537 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1538 | if (strcmp(Name, "<built-in>") == 0) { |
| 1539 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1540 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1541 | } |
| 1542 | } else { |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1543 | // The source location entry is a macro expansion. |
Chandler Carruth | 1728762 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1544 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 78df836 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1545 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1546 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
Argyrios Kyrtzidis | d21683c | 2011-08-17 00:31:14 +0000 | [diff] [blame] | 1547 | Record.push_back(Expansion.isMacroArgExpansion() ? 0 |
| 1548 | : Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1549 | |
| 1550 | // Compute the token length for this macro expansion. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1551 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1552 | if (I + 1 != N) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1553 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1554 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1555 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1559 | Stream.ExitBlock(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1560 | |
| 1561 | if (SLocEntryOffsets.empty()) |
| 1562 | return; |
| 1563 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1564 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1565 | // table is used for lazily loading source-location information. |
| 1566 | using namespace llvm; |
| 1567 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1568 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1569 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1570 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1571 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1572 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1574 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1575 | Record.push_back(SOURCE_LOCATION_OFFSETS); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1576 | Record.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1577 | Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1578 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1579 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1580 | Abbrev = new BitCodeAbbrev(); |
| 1581 | Abbrev->Add(BitCodeAbbrevOp(FILE_SOURCE_LOCATION_OFFSETS)); |
| 1582 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
| 1583 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1584 | unsigned SLocFileOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1585 | |
| 1586 | Record.clear(); |
| 1587 | Record.push_back(FILE_SOURCE_LOCATION_OFFSETS); |
| 1588 | Record.push_back(SLocFileEntryOffsets.size()); |
| 1589 | Stream.EmitRecordWithBlob(SLocFileOffsetsAbbrev, Record, |
| 1590 | data(SLocFileEntryOffsets)); |
| 1591 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1592 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1593 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1594 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1595 | |
| 1596 | // Write the line table. It depends on remapping working, so it must come |
| 1597 | // after the source location offsets. |
| 1598 | if (SourceMgr.hasLineTable()) { |
| 1599 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1600 | |
| 1601 | Record.clear(); |
| 1602 | // Emit the file names |
| 1603 | Record.push_back(LineTable.getNumFilenames()); |
| 1604 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1605 | // Emit the file name |
| 1606 | const char *Filename = LineTable.getFilename(I); |
| 1607 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1608 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1609 | Record.push_back(FilenameLen); |
| 1610 | if (FilenameLen) |
| 1611 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1612 | } |
| 1613 | |
| 1614 | // Emit the line entries |
| 1615 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1616 | L != LEnd; ++L) { |
| 1617 | // Only emit entries for local files. |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1618 | if (L->first.ID < 0) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1619 | continue; |
| 1620 | |
| 1621 | // Emit the file ID |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 1622 | Record.push_back(L->first.ID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1623 | |
| 1624 | // Emit the line entries |
| 1625 | Record.push_back(L->second.size()); |
| 1626 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1627 | LEEnd = L->second.end(); |
| 1628 | LE != LEEnd; ++LE) { |
| 1629 | Record.push_back(LE->FileOffset); |
| 1630 | Record.push_back(LE->LineNo); |
| 1631 | Record.push_back(LE->FilenameID); |
| 1632 | Record.push_back((unsigned)LE->FileKind); |
| 1633 | Record.push_back(LE->IncludeOffset); |
| 1634 | } |
| 1635 | } |
| 1636 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 1637 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1640 | //===----------------------------------------------------------------------===// |
| 1641 | // Preprocessor Serialization |
| 1642 | //===----------------------------------------------------------------------===// |
| 1643 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1644 | static int compareMacroDefinitions(const void *XPtr, const void *YPtr) { |
| 1645 | const std::pair<const IdentifierInfo *, MacroInfo *> &X = |
| 1646 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; |
| 1647 | const std::pair<const IdentifierInfo *, MacroInfo *> &Y = |
| 1648 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; |
| 1649 | return X.first->getName().compare(Y.first->getName()); |
| 1650 | } |
| 1651 | |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1652 | /// \brief Writes the block containing the serialized form of the |
| 1653 | /// preprocessor. |
| 1654 | /// |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1655 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1656 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 1657 | if (PPRec) |
| 1658 | WritePreprocessorDetail(*PPRec); |
| 1659 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1660 | RecordData Record; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1661 | |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1662 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1663 | if (PP.getCounterValue() != 0) { |
| 1664 | Record.push_back(PP.getCounterValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1665 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1666 | Record.clear(); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | // Enter the preprocessor block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1670 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1671 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1672 | // If the AST file contains __DATE__ or __TIME__ emit a warning about this. |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1673 | // FIXME: use diagnostics subsystem for localization etc. |
| 1674 | if (PP.SawDateOrTime()) |
| 1675 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1677 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1678 | // Loop over all the macro definitions that are live at the end of the file, |
| 1679 | // emitting each to the PP section. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1680 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1681 | // Construct the list of macro definitions that need to be serialized. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1682 | SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1683 | MacrosToEmit; |
| 1684 | llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1685 | for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1686 | E = PP.macro_end(Chain == 0); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1687 | I != E; ++I) { |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1688 | if (!IsModule || I->second->isPublic()) { |
| 1689 | MacroDefinitionsSeen.insert(I->first); |
| 1690 | MacrosToEmit.push_back(std::make_pair(I->first, I->second)); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1691 | } |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1692 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1693 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1694 | // Sort the set of macro definitions that need to be serialized by the |
| 1695 | // name of the macro, to provide a stable ordering. |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1696 | llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1697 | &compareMacroDefinitions); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1698 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1699 | /// \brief Offsets of each of the macros into the bitstream, indexed by |
| 1700 | /// the local macro ID |
| 1701 | /// |
| 1702 | /// For each identifier that is associated with a macro, this map |
| 1703 | /// provides the offset into the bitstream where that macro is |
| 1704 | /// defined. |
| 1705 | std::vector<uint32_t> MacroOffsets; |
| 1706 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1707 | for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { |
| 1708 | const IdentifierInfo *Name = MacrosToEmit[I].first; |
Douglas Gregor | ee9b0ba | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 1709 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1710 | for (MacroInfo *MI = MacrosToEmit[I].second; MI; |
| 1711 | MI = MI->getPreviousDefinition()) { |
| 1712 | MacroID ID = getMacroRef(MI); |
| 1713 | if (!ID) |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1714 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1715 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1716 | // Skip macros from a AST file if we're chaining. |
| 1717 | if (Chain && MI->isFromAST() && !MI->hasChangedAfterLoad()) |
| 1718 | continue; |
| 1719 | |
| 1720 | if (ID < FirstMacroID) { |
| 1721 | // This will have been dealt with via an update record. |
| 1722 | assert(MacroUpdates.count(MI) > 0 && "Missing macro update"); |
| 1723 | continue; |
| 1724 | } |
| 1725 | |
| 1726 | // Record the local offset of this macro. |
| 1727 | unsigned Index = ID - FirstMacroID; |
| 1728 | if (Index == MacroOffsets.size()) |
| 1729 | MacroOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1730 | else { |
| 1731 | if (Index > MacroOffsets.size()) |
| 1732 | MacroOffsets.resize(Index + 1); |
| 1733 | |
| 1734 | MacroOffsets[Index] = Stream.GetCurrentBitNo(); |
| 1735 | } |
| 1736 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1737 | AddIdentifierRef(Name, Record); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1738 | addMacroRef(MI, Record); |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 1739 | Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1740 | AddSourceLocation(MI->getDefinitionLoc(), Record); |
| 1741 | AddSourceLocation(MI->getUndefLoc(), Record); |
| 1742 | Record.push_back(MI->isUsed()); |
| 1743 | Record.push_back(MI->isPublic()); |
| 1744 | AddSourceLocation(MI->getVisibilityLocation(), Record); |
| 1745 | unsigned Code; |
| 1746 | if (MI->isObjectLike()) { |
| 1747 | Code = PP_MACRO_OBJECT_LIKE; |
| 1748 | } else { |
| 1749 | Code = PP_MACRO_FUNCTION_LIKE; |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1750 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1751 | Record.push_back(MI->isC99Varargs()); |
| 1752 | Record.push_back(MI->isGNUVarargs()); |
| 1753 | Record.push_back(MI->getNumArgs()); |
| 1754 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1755 | I != E; ++I) |
| 1756 | AddIdentifierRef(*I, Record); |
| 1757 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1759 | // If we have a detailed preprocessing record, record the macro definition |
| 1760 | // ID that corresponds to this macro. |
| 1761 | if (PPRec) |
| 1762 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); |
| 1763 | |
| 1764 | Stream.EmitRecord(Code, Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1765 | Record.clear(); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1766 | |
| 1767 | // Emit the tokens array. |
| 1768 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1769 | // Note that we know that the preprocessor does not have any annotation |
| 1770 | // tokens in it because they are created by the parser, and thus can't |
| 1771 | // be in a macro definition. |
| 1772 | const Token &Tok = MI->getReplacementToken(TokNo); |
| 1773 | |
| 1774 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1775 | Record.push_back(Tok.getLength()); |
| 1776 | |
| 1777 | // FIXME: When reading literal tokens, reconstruct the literal pointer |
| 1778 | // if it is needed. |
| 1779 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
| 1780 | // FIXME: Should translate token kind to a stable encoding. |
| 1781 | Record.push_back(Tok.getKind()); |
| 1782 | // FIXME: Should translate token flags to a stable encoding. |
| 1783 | Record.push_back(Tok.getFlags()); |
| 1784 | |
| 1785 | Stream.EmitRecord(PP_TOKEN, Record); |
| 1786 | Record.clear(); |
| 1787 | } |
| 1788 | ++NumMacros; |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1789 | } |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1790 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1791 | Stream.ExitBlock(); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 1792 | |
| 1793 | // Write the offsets table for macro IDs. |
| 1794 | using namespace llvm; |
| 1795 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1796 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); |
| 1797 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros |
| 1798 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
| 1799 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1800 | |
| 1801 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1802 | Record.clear(); |
| 1803 | Record.push_back(MACRO_OFFSET); |
| 1804 | Record.push_back(MacroOffsets.size()); |
| 1805 | Record.push_back(FirstMacroID - NUM_PREDEF_MACRO_IDS); |
| 1806 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, |
| 1807 | data(MacroOffsets)); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
Argyrios Kyrtzidis | b6441ef | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 1811 | if (PPRec.local_begin() == PPRec.local_end()) |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1812 | return; |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1813 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1814 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1815 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1816 | // Enter the preprocessor block. |
| 1817 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1818 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1819 | // If the preprocessor has a preprocessing record, emit it. |
| 1820 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1821 | using namespace llvm; |
| 1822 | |
| 1823 | // Set up the abbreviation for |
| 1824 | unsigned InclusionAbbrev = 0; |
| 1825 | { |
| 1826 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1827 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1828 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 1829 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 1830 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 1831 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1832 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1833 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1834 | } |
| 1835 | |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1836 | unsigned FirstPreprocessorEntityID |
| 1837 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 1838 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 1839 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1840 | RecordData Record; |
Argyrios Kyrtzidis | b6441ef | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 1841 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), |
| 1842 | EEnd = PPRec.local_end(); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1843 | E != EEnd; |
| 1844 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1845 | Record.clear(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1846 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1847 | PreprocessedEntityOffsets.push_back(PPEntityOffset((*E)->getSourceRange(), |
| 1848 | Stream.GetCurrentBitNo())); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1850 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1851 | // Record this macro definition's ID. |
| 1852 | MacroDefinitions[MD] = NextPreprocessorEntityID; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1853 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1854 | AddIdentifierRef(MD->getName(), Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1855 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 1856 | continue; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1857 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1858 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1859 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Argyrios Kyrtzidis | 8f7c540 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 1860 | Record.push_back(ME->isBuiltinMacro()); |
| 1861 | if (ME->isBuiltinMacro()) |
| 1862 | AddIdentifierRef(ME->getName(), Record); |
| 1863 | else |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1864 | Record.push_back(MacroDefinitions[ME->getDefinition()]); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1865 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1866 | continue; |
| 1867 | } |
| 1868 | |
| 1869 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 1870 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1871 | Record.push_back(ID->getFileName().size()); |
| 1872 | Record.push_back(ID->wasInQuotes()); |
| 1873 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 1874 | Record.push_back(ID->importedModule()); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1875 | SmallString<64> Buffer; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1876 | Buffer += ID->getFileName(); |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 1877 | // Check that the FileEntry is not null because it was not resolved and |
| 1878 | // we create a PCH even with compiler errors. |
| 1879 | if (ID->getFile()) |
| 1880 | Buffer += ID->getFile()->getName(); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1881 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
| 1882 | continue; |
| 1883 | } |
| 1884 | |
| 1885 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 1886 | } |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1887 | Stream.ExitBlock(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1888 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1889 | // Write the offsets table for the preprocessing record. |
| 1890 | if (NumPreprocessingRecords > 0) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1891 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); |
| 1892 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1893 | // Write the offsets table for identifier IDs. |
| 1894 | using namespace llvm; |
| 1895 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1896 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1897 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1898 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1899 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1900 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1901 | Record.clear(); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1902 | Record.push_back(PPD_ENTITIES_OFFSETS); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1903 | Record.push_back(FirstPreprocessorEntityID - NUM_PREDEF_PP_ENTITY_IDS); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1904 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, |
| 1905 | data(PreprocessedEntityOffsets)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1906 | } |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 1909 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { |
| 1910 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); |
| 1911 | if (Known != SubmoduleIDs.end()) |
| 1912 | return Known->second; |
| 1913 | |
| 1914 | return SubmoduleIDs[Mod] = NextSubmoduleID++; |
| 1915 | } |
| 1916 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1917 | /// \brief Compute the number of modules within the given tree (including the |
| 1918 | /// given module). |
| 1919 | static unsigned getNumberOfModules(Module *Mod) { |
| 1920 | unsigned ChildModules = 0; |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 1921 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 1922 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1923 | Sub != SubEnd; ++Sub) |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 1924 | ChildModules += getNumberOfModules(*Sub); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1925 | |
| 1926 | return ChildModules + 1; |
| 1927 | } |
| 1928 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1929 | void ASTWriter::WriteSubmodules(Module *WritingModule) { |
Douglas Gregor | 4bc8738d | 2011-12-05 16:35:23 +0000 | [diff] [blame] | 1930 | // Determine the dependencies of our module and each of it's submodules. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 1931 | // FIXME: This feels like it belongs somewhere else, but there are no |
| 1932 | // other consumers of this information. |
| 1933 | SourceManager &SrcMgr = PP->getSourceManager(); |
| 1934 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
| 1935 | for (ASTContext::import_iterator I = Context->local_import_begin(), |
| 1936 | IEnd = Context->local_import_end(); |
| 1937 | I != IEnd; ++I) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 1938 | if (Module *ImportedFrom |
| 1939 | = ModMap.inferModuleFromLocation(FullSourceLoc(I->getLocation(), |
| 1940 | SrcMgr))) { |
| 1941 | ImportedFrom->Imports.push_back(I->getImportedModule()); |
| 1942 | } |
| 1943 | } |
| 1944 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1945 | // Enter the submodule description block. |
| 1946 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
| 1947 | |
| 1948 | // Write the abbreviations needed for the submodules block. |
| 1949 | using namespace llvm; |
| 1950 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1951 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 1952 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1953 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent |
| 1954 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework |
| 1955 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 1956 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem |
| 1957 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 1958 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 1959 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1960 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1961 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1962 | |
| 1963 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 1964 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1965 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1966 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1967 | |
| 1968 | Abbrev = new BitCodeAbbrev(); |
| 1969 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); |
| 1970 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1971 | unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 1972 | |
| 1973 | Abbrev = new BitCodeAbbrev(); |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 1974 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); |
| 1975 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1976 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1977 | |
| 1978 | Abbrev = new BitCodeAbbrev(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 1979 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); |
| 1980 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1981 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1982 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 1983 | Abbrev = new BitCodeAbbrev(); |
| 1984 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); |
| 1985 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature |
| 1986 | unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1987 | |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 1988 | Abbrev = new BitCodeAbbrev(); |
| 1989 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); |
| 1990 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name |
| 1991 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1992 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 1993 | // Write the submodule metadata block. |
| 1994 | RecordData Record; |
| 1995 | Record.push_back(getNumberOfModules(WritingModule)); |
| 1996 | Record.push_back(FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS); |
| 1997 | Stream.EmitRecord(SUBMODULE_METADATA, Record); |
| 1998 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1999 | // Write all of the submodules. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2000 | std::queue<Module *> Q; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2001 | Q.push(WritingModule); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2002 | while (!Q.empty()) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2003 | Module *Mod = Q.front(); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2004 | Q.pop(); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2005 | unsigned ID = getSubmoduleID(Mod); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2006 | |
| 2007 | // Emit the definition of the block. |
| 2008 | Record.clear(); |
| 2009 | Record.push_back(SUBMODULE_DEFINITION); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2010 | Record.push_back(ID); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2011 | if (Mod->Parent) { |
| 2012 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); |
| 2013 | Record.push_back(SubmoduleIDs[Mod->Parent]); |
| 2014 | } else { |
| 2015 | Record.push_back(0); |
| 2016 | } |
| 2017 | Record.push_back(Mod->IsFramework); |
| 2018 | Record.push_back(Mod->IsExplicit); |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2019 | Record.push_back(Mod->IsSystem); |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2020 | Record.push_back(Mod->InferSubmodules); |
| 2021 | Record.push_back(Mod->InferExplicitSubmodules); |
| 2022 | Record.push_back(Mod->InferExportWildcard); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2023 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); |
| 2024 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2025 | // Emit the requirements. |
| 2026 | for (unsigned I = 0, N = Mod->Requires.size(); I != N; ++I) { |
| 2027 | Record.clear(); |
| 2028 | Record.push_back(SUBMODULE_REQUIRES); |
| 2029 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, |
| 2030 | Mod->Requires[I].data(), |
| 2031 | Mod->Requires[I].size()); |
| 2032 | } |
| 2033 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2034 | // Emit the umbrella header, if there is one. |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 2035 | if (const FileEntry *UmbrellaHeader = Mod->getUmbrellaHeader()) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2036 | Record.clear(); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2037 | Record.push_back(SUBMODULE_UMBRELLA_HEADER); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2038 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 2039 | UmbrellaHeader->getName()); |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2040 | } else if (const DirectoryEntry *UmbrellaDir = Mod->getUmbrellaDir()) { |
| 2041 | Record.clear(); |
| 2042 | Record.push_back(SUBMODULE_UMBRELLA_DIR); |
| 2043 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, |
| 2044 | UmbrellaDir->getName()); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | // Emit the headers. |
| 2048 | for (unsigned I = 0, N = Mod->Headers.size(); I != N; ++I) { |
| 2049 | Record.clear(); |
| 2050 | Record.push_back(SUBMODULE_HEADER); |
| 2051 | Stream.EmitRecordWithBlob(HeaderAbbrev, Record, |
| 2052 | Mod->Headers[I]->getName()); |
| 2053 | } |
Douglas Gregor | 2b49d1f | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2054 | // Emit the excluded headers. |
| 2055 | for (unsigned I = 0, N = Mod->ExcludedHeaders.size(); I != N; ++I) { |
| 2056 | Record.clear(); |
| 2057 | Record.push_back(SUBMODULE_EXCLUDED_HEADER); |
| 2058 | Stream.EmitRecordWithBlob(ExcludedHeaderAbbrev, Record, |
| 2059 | Mod->ExcludedHeaders[I]->getName()); |
| 2060 | } |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2061 | for (unsigned I = 0, N = Mod->TopHeaders.size(); I != N; ++I) { |
| 2062 | Record.clear(); |
| 2063 | Record.push_back(SUBMODULE_TOPHEADER); |
| 2064 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, |
| 2065 | Mod->TopHeaders[I]->getName()); |
| 2066 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2067 | |
| 2068 | // Emit the imports. |
| 2069 | if (!Mod->Imports.empty()) { |
| 2070 | Record.clear(); |
| 2071 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
Douglas Gregor | bab9f4a | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2072 | unsigned ImportedID = getSubmoduleID(Mod->Imports[I]); |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2073 | assert(ImportedID && "Unknown submodule!"); |
| 2074 | Record.push_back(ImportedID); |
| 2075 | } |
| 2076 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); |
| 2077 | } |
| 2078 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2079 | // Emit the exports. |
| 2080 | if (!Mod->Exports.empty()) { |
| 2081 | Record.clear(); |
| 2082 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
Douglas Gregor | bab9f4a | 2011-12-12 23:17:57 +0000 | [diff] [blame] | 2083 | if (Module *Exported = Mod->Exports[I].getPointer()) { |
| 2084 | unsigned ExportedID = SubmoduleIDs[Exported]; |
| 2085 | assert(ExportedID > 0 && "Unknown submodule ID?"); |
| 2086 | Record.push_back(ExportedID); |
| 2087 | } else { |
| 2088 | Record.push_back(0); |
| 2089 | } |
| 2090 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2091 | Record.push_back(Mod->Exports[I].getInt()); |
| 2092 | } |
| 2093 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); |
| 2094 | } |
| 2095 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2096 | // Queue up the submodules of this module. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2097 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2098 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2099 | Sub != SubEnd; ++Sub) |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2100 | Q.push(*Sub); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | Stream.ExitBlock(); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2104 | |
| 2105 | assert((NextSubmoduleID - FirstSubmoduleID |
| 2106 | == getNumberOfModules(WritingModule)) && "Wrong # of submodules"); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2109 | serialization::SubmoduleID |
| 2110 | ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2111 | if (Loc.isInvalid() || !WritingModule) |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2112 | return 0; // No submodule |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2113 | |
| 2114 | // Find the module that owns this location. |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2115 | ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2116 | Module *OwningMod |
| 2117 | = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2118 | if (!OwningMod) |
| 2119 | return 0; |
| 2120 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2121 | // Check whether this submodule is part of our own module. |
| 2122 | if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2123 | return 0; |
| 2124 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2125 | return getSubmoduleID(OwningMod); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2128 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2129 | RecordData Record; |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2130 | for (DiagnosticsEngine::DiagStatePointsTy::const_iterator |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2131 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 2132 | I != E; ++I) { |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2133 | const DiagnosticsEngine::DiagStatePoint &point = *I; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2134 | if (point.Loc.isInvalid()) |
| 2135 | continue; |
| 2136 | |
| 2137 | Record.push_back(point.Loc.getRawEncoding()); |
Daniel Dunbar | ba494c6 | 2011-09-29 01:42:25 +0000 | [diff] [blame] | 2138 | for (DiagnosticsEngine::DiagState::const_iterator |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2139 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
Daniel Dunbar | b1c99c6 | 2011-09-29 01:30:00 +0000 | [diff] [blame] | 2140 | if (I->second.isPragma()) { |
| 2141 | Record.push_back(I->first); |
| 2142 | Record.push_back(I->second.getMapping()); |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2143 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2144 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2145 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 2146 | // location. |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
Argyrios Kyrtzidis | 60f7684 | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 2149 | if (!Record.empty()) |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2150 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2153 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 2154 | if (CXXBaseSpecifiersOffsets.empty()) |
| 2155 | return; |
| 2156 | |
| 2157 | RecordData Record; |
| 2158 | |
| 2159 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 2160 | using namespace llvm; |
| 2161 | |
| 2162 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2163 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 2164 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 2165 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2166 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2167 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2168 | // Write the base specifier offsets table. |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2169 | Record.clear(); |
| 2170 | Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); |
| 2171 | Record.push_back(CXXBaseSpecifiersOffsets.size()); |
| 2172 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2173 | data(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2176 | //===----------------------------------------------------------------------===// |
| 2177 | // Type Serialization |
| 2178 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2179 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2180 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2181 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 2182 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2183 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 2184 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2185 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2186 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | 55f48de | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2187 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2188 | // Record the offset for this type. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 2189 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2190 | if (TypeOffsets.size() == Index) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2191 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 2192 | else if (TypeOffsets.size() < Index) { |
| 2193 | TypeOffsets.resize(Index + 1); |
| 2194 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | RecordData Record; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2198 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2199 | // Emit the type's representation. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2200 | ASTTypeWriter W(*this, Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2201 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2202 | if (T.hasLocalNonFastQualifiers()) { |
| 2203 | Qualifiers Qs = T.getLocalQualifiers(); |
| 2204 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2205 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2206 | W.Code = TYPE_EXT_QUAL; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2207 | } else { |
| 2208 | switch (T->getTypeClass()) { |
| 2209 | // For all of the concrete, non-dependent types, call the |
| 2210 | // appropriate visitor function. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2211 | #define TYPE(Class, Base) \ |
Mike Stump | b716633 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 2212 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2213 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2214 | #include "clang/AST/TypeNodes.def" |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2215 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | // Emit the serialized record. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2219 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2220 | |
| 2221 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2222 | FlushStmts(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2225 | //===----------------------------------------------------------------------===// |
| 2226 | // Declaration Serialization |
| 2227 | //===----------------------------------------------------------------------===// |
| 2228 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2229 | /// \brief Write the block containing all of the declaration IDs |
| 2230 | /// lexically declared within the given DeclContext. |
| 2231 | /// |
| 2232 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2233 | /// bistream, or 0 if no block was written. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2234 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2235 | DeclContext *DC) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2236 | if (DC->decls_empty()) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2237 | return 0; |
| 2238 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2239 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2240 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2241 | Record.push_back(DECL_CONTEXT_LEXICAL); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2242 | SmallVector<KindDeclIDPair, 64> Decls; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2243 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 2244 | D != DEnd; ++D) |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2245 | Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2246 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2247 | ++NumLexicalDeclContexts; |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2248 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, data(Decls)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2249 | return Offset; |
| 2250 | } |
| 2251 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2252 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2253 | using namespace llvm; |
| 2254 | RecordData Record; |
| 2255 | |
| 2256 | // Write the type offsets array |
| 2257 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2258 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2259 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2260 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2261 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2262 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2263 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2264 | Record.push_back(TYPE_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2265 | Record.push_back(TypeOffsets.size()); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2266 | Record.push_back(FirstTypeID - NUM_PREDEF_TYPE_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2267 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, data(TypeOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2268 | |
| 2269 | // Write the declaration offsets array |
| 2270 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2271 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2272 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2273 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2274 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2275 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2276 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2277 | Record.push_back(DECL_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2278 | Record.push_back(DeclOffsets.size()); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 2279 | Record.push_back(FirstDeclID - NUM_PREDEF_DECL_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2280 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, data(DeclOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2283 | void ASTWriter::WriteFileDeclIDsMap() { |
| 2284 | using namespace llvm; |
| 2285 | RecordData Record; |
| 2286 | |
| 2287 | // Join the vectors of DeclIDs from all files. |
| 2288 | SmallVector<DeclID, 256> FileSortedIDs; |
| 2289 | for (FileDeclIDsTy::iterator |
| 2290 | FI = FileDeclIDs.begin(), FE = FileDeclIDs.end(); FI != FE; ++FI) { |
| 2291 | DeclIDInFileInfo &Info = *FI->second; |
| 2292 | Info.FirstDeclIndex = FileSortedIDs.size(); |
| 2293 | for (LocDeclIDsTy::iterator |
| 2294 | DI = Info.DeclIDs.begin(), DE = Info.DeclIDs.end(); DI != DE; ++DI) |
| 2295 | FileSortedIDs.push_back(DI->second); |
| 2296 | } |
| 2297 | |
| 2298 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2299 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2300 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2301 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2302 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 2303 | Record.push_back(FILE_SORTED_DECLS); |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2304 | Record.push_back(FileSortedIDs.size()); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2305 | Stream.EmitRecordWithBlob(AbbrevCode, Record, data(FileSortedIDs)); |
| 2306 | } |
| 2307 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2308 | void ASTWriter::WriteComments() { |
| 2309 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2310 | ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2311 | RecordData Record; |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2312 | for (ArrayRef<RawComment *>::iterator I = RawComments.begin(), |
| 2313 | E = RawComments.end(); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2314 | I != E; ++I) { |
| 2315 | Record.clear(); |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 2316 | AddSourceRange((*I)->getSourceRange(), Record); |
| 2317 | Record.push_back((*I)->getKind()); |
| 2318 | Record.push_back((*I)->isTrailingComment()); |
| 2319 | Record.push_back((*I)->isAlmostTrailingComment()); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2320 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); |
| 2321 | } |
| 2322 | Stream.ExitBlock(); |
| 2323 | } |
| 2324 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2325 | //===----------------------------------------------------------------------===// |
| 2326 | // Global Method Pool and Selector Serialization |
| 2327 | //===----------------------------------------------------------------------===// |
| 2328 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2329 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2330 | // Trait used for the on-disk hash table used in the method pool. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2331 | class ASTMethodPoolTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2332 | ASTWriter &Writer; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2333 | |
| 2334 | public: |
| 2335 | typedef Selector key_type; |
| 2336 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2337 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2338 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2339 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2340 | ObjCMethodList Instance, Factory; |
| 2341 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2342 | typedef const data_type& data_type_ref; |
| 2343 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2344 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2345 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2346 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2347 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2348 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2349 | |
| 2350 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2351 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2352 | data_type_ref Methods) { |
| 2353 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 2354 | clang::io::Emit16(Out, KeyLen); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2355 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2356 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2357 | Method = Method->Next) |
| 2358 | if (Method->Method) |
| 2359 | DataLen += 4; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2360 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2361 | Method = Method->Next) |
| 2362 | if (Method->Method) |
| 2363 | DataLen += 4; |
| 2364 | clang::io::Emit16(Out, DataLen); |
| 2365 | return std::make_pair(KeyLen, DataLen); |
| 2366 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2367 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2368 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2369 | uint64_t Start = Out.tell(); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2370 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2371 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2372 | unsigned N = Sel.getNumArgs(); |
| 2373 | clang::io::Emit16(Out, N); |
| 2374 | if (N == 0) |
| 2375 | N = 1; |
| 2376 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2377 | clang::io::Emit32(Out, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2378 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 2379 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2380 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2381 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2382 | data_type_ref Methods, unsigned DataLen) { |
| 2383 | uint64_t Start = Out.tell(); (void)Start; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2384 | clang::io::Emit32(Out, Methods.ID); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2385 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2386 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2387 | Method = Method->Next) |
| 2388 | if (Method->Method) |
| 2389 | ++NumInstanceMethods; |
| 2390 | |
| 2391 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2392 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2393 | Method = Method->Next) |
| 2394 | if (Method->Method) |
| 2395 | ++NumFactoryMethods; |
| 2396 | |
| 2397 | clang::io::Emit16(Out, NumInstanceMethods); |
| 2398 | clang::io::Emit16(Out, NumFactoryMethods); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2399 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2400 | Method = Method->Next) |
| 2401 | if (Method->Method) |
| 2402 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2403 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2404 | Method = Method->Next) |
| 2405 | if (Method->Method) |
| 2406 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2407 | |
| 2408 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2409 | } |
| 2410 | }; |
| 2411 | } // end anonymous namespace |
| 2412 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2413 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2414 | /// |
| 2415 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2416 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2417 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2418 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2419 | using namespace llvm; |
| 2420 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2421 | // Do we have to do anything at all? |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2422 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2423 | return; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2424 | unsigned NumTableEntries = 0; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2425 | // Create and write out the blob that contains selectors and the method pool. |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2426 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2427 | OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2428 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2429 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2430 | // Create the on-disk hash table representation. We walk through every |
| 2431 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2432 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2433 | for (llvm::DenseMap<Selector, SelectorID>::iterator |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2434 | I = SelectorIDs.begin(), E = SelectorIDs.end(); |
| 2435 | I != E; ++I) { |
| 2436 | Selector S = I->first; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2437 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2438 | ASTMethodPoolTrait::data_type Data = { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2439 | I->second, |
| 2440 | ObjCMethodList(), |
| 2441 | ObjCMethodList() |
| 2442 | }; |
| 2443 | if (F != SemaRef.MethodPool.end()) { |
| 2444 | Data.Instance = F->second.first; |
| 2445 | Data.Factory = F->second.second; |
| 2446 | } |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2447 | // Only write this selector if it's not in an existing AST or something |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2448 | // changed. |
| 2449 | if (Chain && I->second < FirstSelectorID) { |
| 2450 | // Selector already exists. Did it change? |
| 2451 | bool changed = false; |
| 2452 | for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; |
| 2453 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2454 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2455 | changed = true; |
| 2456 | } |
| 2457 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; |
| 2458 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2459 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2460 | changed = true; |
| 2461 | } |
| 2462 | if (!changed) |
| 2463 | continue; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2464 | } else if (Data.Instance.Method || Data.Factory.Method) { |
| 2465 | // A new method pool entry. |
| 2466 | ++NumTableEntries; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2467 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2468 | Generator.insert(S, Data, Trait); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2471 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2472 | SmallString<4096> MethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2473 | uint32_t BucketOffset; |
| 2474 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2475 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2476 | llvm::raw_svector_ostream Out(MethodPool); |
| 2477 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2478 | clang::io::Emit32(Out, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2479 | BucketOffset = Generator.Emit(Out, Trait); |
| 2480 | } |
| 2481 | |
| 2482 | // Create a blob abbreviation |
| 2483 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2484 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2485 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2486 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2487 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2488 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2489 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2490 | // Write the method pool |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2491 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2492 | Record.push_back(METHOD_POOL); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2493 | Record.push_back(BucketOffset); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2494 | Record.push_back(NumTableEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2495 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2496 | |
| 2497 | // Create a blob abbreviation for the selector table offsets. |
| 2498 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2499 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2500 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2501 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2502 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2503 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2504 | |
| 2505 | // Write the selector offsets table. |
| 2506 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2507 | Record.push_back(SELECTOR_OFFSETS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2508 | Record.push_back(SelectorOffsets.size()); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2509 | Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2510 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2511 | data(SelectorOffsets)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2512 | } |
| 2513 | } |
| 2514 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2515 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2516 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2517 | using namespace llvm; |
| 2518 | if (SemaRef.ReferencedSelectors.empty()) |
| 2519 | return; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2520 | |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2521 | RecordData Record; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2522 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2523 | // Note: this writes out all references even for a dependent AST. But it is |
Sebastian Redl | a68340f | 2010-08-04 22:21:29 +0000 | [diff] [blame] | 2524 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 2525 | // headers, probably not worth it. It's not a correctness issue. |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2526 | for (DenseMap<Selector, SourceLocation>::iterator S = |
| 2527 | SemaRef.ReferencedSelectors.begin(), |
| 2528 | E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { |
| 2529 | Selector Sel = (*S).first; |
| 2530 | SourceLocation Loc = (*S).second; |
| 2531 | AddSelectorRef(Sel, Record); |
| 2532 | AddSourceLocation(Loc, Record); |
| 2533 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2534 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2535 | } |
| 2536 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2537 | //===----------------------------------------------------------------------===// |
| 2538 | // Identifier Table Serialization |
| 2539 | //===----------------------------------------------------------------------===// |
| 2540 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2541 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2542 | class ASTIdentifierTableTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2543 | ASTWriter &Writer; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2544 | Preprocessor &PP; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2545 | IdentifierResolver &IdResolver; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2546 | bool IsModule; |
| 2547 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2548 | /// \brief Determines whether this is an "interesting" identifier |
| 2549 | /// that needs a full IdentifierInfo structure written into the hash |
| 2550 | /// table. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2551 | bool isInterestingIdentifier(IdentifierInfo *II, MacroInfo *&Macro) { |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2552 | if (II->isPoisoned() || |
| 2553 | II->isExtensionToken() || |
| 2554 | II->getObjCOrBuiltinID() || |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2555 | II->hasRevertedTokenIDToIdentifier() || |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2556 | II->getFETokenInfo<void>()) |
| 2557 | return true; |
| 2558 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2559 | return hadMacroDefinition(II, Macro); |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2560 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2561 | |
| 2562 | bool hadMacroDefinition(IdentifierInfo *II, MacroInfo *&Macro) { |
| 2563 | if (!II->hadMacroDefinition()) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2564 | return false; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2565 | |
| 2566 | if (Macro || (Macro = PP.getMacroInfoHistory(II))) |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 2567 | return !Macro->isBuiltinMacro() && (!IsModule || Macro->isPublic()); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2568 | |
| 2569 | return false; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2570 | } |
| 2571 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2572 | public: |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2573 | typedef IdentifierInfo* key_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2574 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2575 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2576 | typedef IdentID data_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2577 | typedef data_type data_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2578 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2579 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, |
| 2580 | IdentifierResolver &IdResolver, bool IsModule) |
| 2581 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule) { } |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2582 | |
| 2583 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 2584 | return llvm::HashString(II->getName()); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2585 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2586 | |
| 2587 | std::pair<unsigned,unsigned> |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2588 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2589 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2590 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2591 | MacroInfo *Macro = 0; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2592 | if (isInterestingIdentifier(II, Macro)) { |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2593 | DataLen += 2; // 2 bytes for builtin ID |
| 2594 | DataLen += 2; // 2 bytes for flags |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2595 | if (hadMacroDefinition(II, Macro)) { |
| 2596 | for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { |
| 2597 | if (Writer.getMacroRef(M) != 0) |
| 2598 | DataLen += 4; |
| 2599 | } |
| 2600 | |
| 2601 | DataLen += 4; |
| 2602 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2603 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2604 | for (IdentifierResolver::iterator D = IdResolver.begin(II), |
| 2605 | DEnd = IdResolver.end(); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2606 | D != DEnd; ++D) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2607 | DataLen += sizeof(DeclID); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2608 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2609 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 2610 | // We emit the key length after the data length so that every |
| 2611 | // string is preceded by a 16-bit length. This matches the PTH |
| 2612 | // format for storing identifiers. |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2613 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2614 | return std::make_pair(KeyLen, DataLen); |
| 2615 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2616 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2617 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2618 | unsigned KeyLen) { |
| 2619 | // Record the location of the key data. This is used when generating |
| 2620 | // the mapping from persistent IDs to strings. |
| 2621 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2622 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2623 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2624 | |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2625 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2626 | IdentID ID, unsigned) { |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 2627 | MacroInfo *Macro = 0; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2628 | if (!isInterestingIdentifier(II, Macro)) { |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2629 | clang::io::Emit32(Out, ID << 1); |
| 2630 | return; |
| 2631 | } |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2632 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2633 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2634 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); |
| 2635 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); |
| 2636 | clang::io::Emit16(Out, Bits); |
| 2637 | Bits = 0; |
| 2638 | bool HadMacroDefinition = hadMacroDefinition(II, Macro); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2639 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2640 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 2641 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 2642 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2643 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2644 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2645 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2646 | if (HadMacroDefinition) { |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2647 | // Write all of the macro IDs associated with this identifier. |
| 2648 | for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { |
| 2649 | if (MacroID ID = Writer.getMacroRef(M)) |
| 2650 | clang::io::Emit32(Out, ID); |
| 2651 | } |
| 2652 | |
| 2653 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2654 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2655 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2656 | // Emit the declaration IDs in reverse order, because the |
| 2657 | // IdentifierResolver provides the declarations as they would be |
| 2658 | // visible (e.g., the function "stat" would come before the struct |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2659 | // "stat"), but the ASTReader adds declarations to the end of the list |
| 2660 | // (so we need to see the struct "status" before the function "status"). |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2661 | // Only emit declarations that aren't from a chained PCH, though. |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2662 | SmallVector<Decl *, 16> Decls(IdResolver.begin(II), |
| 2663 | IdResolver.end()); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2664 | for (SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2665 | DEnd = Decls.rend(); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2666 | D != DEnd; ++D) |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 2667 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2668 | } |
| 2669 | }; |
| 2670 | } // end anonymous namespace |
| 2671 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2672 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2673 | /// |
| 2674 | /// The identifier table consists of a blob containing string data |
| 2675 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 2676 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2677 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, |
| 2678 | IdentifierResolver &IdResolver, |
| 2679 | bool IsModule) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2680 | using namespace llvm; |
| 2681 | |
| 2682 | // Create and write out the blob that contains the identifier |
| 2683 | // strings. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2684 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2685 | OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2686 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2687 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2688 | // Look for any identifiers that were named while processing the |
| 2689 | // headers, but are otherwise not needed. We add these to the hash |
| 2690 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2691 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2692 | // file. |
| 2693 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 2694 | IDEnd = PP.getIdentifierTable().end(); |
| 2695 | ID != IDEnd; ++ID) |
| 2696 | getIdentifierRef(ID->second); |
| 2697 | |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2698 | // Create the on-disk hash table representation. We only store offsets |
| 2699 | // for identifiers that appear here for the first time. |
| 2700 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2701 | for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2702 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 2703 | ID != IDEnd; ++ID) { |
| 2704 | assert(ID->first && "NULL identifier in identifier table"); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2705 | if (!Chain || !ID->first->isFromAST() || |
| 2706 | ID->first->hasChangedSinceDeserialization()) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2707 | Generator.insert(const_cast<IdentifierInfo *>(ID->first), ID->second, |
| 2708 | Trait); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2709 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2710 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2711 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2712 | SmallString<4096> IdentifierTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2713 | uint32_t BucketOffset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2714 | { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2715 | ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2716 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2717 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2718 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2719 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | // Create a blob abbreviation |
| 2723 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2724 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2725 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2726 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2727 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2728 | |
| 2729 | // Write the identifier table |
| 2730 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2731 | Record.push_back(IDENTIFIER_TABLE); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2732 | Record.push_back(BucketOffset); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2733 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2737 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2738 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2739 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2740 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2741 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2742 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2743 | |
| 2744 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2745 | Record.push_back(IDENTIFIER_OFFSET); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2746 | Record.push_back(IdentifierOffsets.size()); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2747 | Record.push_back(FirstIdentID - NUM_PREDEF_IDENT_IDS); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2748 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2749 | data(IdentifierOffsets)); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2752 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2753 | // DeclContext's Name Lookup Table Serialization |
| 2754 | //===----------------------------------------------------------------------===// |
| 2755 | |
| 2756 | namespace { |
| 2757 | // Trait used for the on-disk hash table used in the method pool. |
| 2758 | class ASTDeclContextNameLookupTrait { |
| 2759 | ASTWriter &Writer; |
| 2760 | |
| 2761 | public: |
| 2762 | typedef DeclarationName key_type; |
| 2763 | typedef key_type key_type_ref; |
| 2764 | |
| 2765 | typedef DeclContext::lookup_result data_type; |
| 2766 | typedef const data_type& data_type_ref; |
| 2767 | |
| 2768 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 2769 | |
| 2770 | unsigned ComputeHash(DeclarationName Name) { |
| 2771 | llvm::FoldingSetNodeID ID; |
| 2772 | ID.AddInteger(Name.getNameKind()); |
| 2773 | |
| 2774 | switch (Name.getNameKind()) { |
| 2775 | case DeclarationName::Identifier: |
| 2776 | ID.AddString(Name.getAsIdentifierInfo()->getName()); |
| 2777 | break; |
| 2778 | case DeclarationName::ObjCZeroArgSelector: |
| 2779 | case DeclarationName::ObjCOneArgSelector: |
| 2780 | case DeclarationName::ObjCMultiArgSelector: |
| 2781 | ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); |
| 2782 | break; |
| 2783 | case DeclarationName::CXXConstructorName: |
| 2784 | case DeclarationName::CXXDestructorName: |
| 2785 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2786 | break; |
| 2787 | case DeclarationName::CXXOperatorName: |
| 2788 | ID.AddInteger(Name.getCXXOverloadedOperator()); |
| 2789 | break; |
| 2790 | case DeclarationName::CXXLiteralOperatorName: |
| 2791 | ID.AddString(Name.getCXXLiteralIdentifier()->getName()); |
| 2792 | case DeclarationName::CXXUsingDirective: |
| 2793 | break; |
| 2794 | } |
| 2795 | |
| 2796 | return ID.ComputeHash(); |
| 2797 | } |
| 2798 | |
| 2799 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2800 | EmitKeyDataLength(raw_ostream& Out, DeclarationName Name, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2801 | data_type_ref Lookup) { |
| 2802 | unsigned KeyLen = 1; |
| 2803 | switch (Name.getNameKind()) { |
| 2804 | case DeclarationName::Identifier: |
| 2805 | case DeclarationName::ObjCZeroArgSelector: |
| 2806 | case DeclarationName::ObjCOneArgSelector: |
| 2807 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2808 | case DeclarationName::CXXLiteralOperatorName: |
| 2809 | KeyLen += 4; |
| 2810 | break; |
| 2811 | case DeclarationName::CXXOperatorName: |
| 2812 | KeyLen += 1; |
| 2813 | break; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2814 | case DeclarationName::CXXConstructorName: |
| 2815 | case DeclarationName::CXXDestructorName: |
| 2816 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2817 | case DeclarationName::CXXUsingDirective: |
| 2818 | break; |
| 2819 | } |
| 2820 | clang::io::Emit16(Out, KeyLen); |
| 2821 | |
| 2822 | // 2 bytes for num of decls and 4 for each DeclID. |
| 2823 | unsigned DataLen = 2 + 4 * (Lookup.second - Lookup.first); |
| 2824 | clang::io::Emit16(Out, DataLen); |
| 2825 | |
| 2826 | return std::make_pair(KeyLen, DataLen); |
| 2827 | } |
| 2828 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2829 | void EmitKey(raw_ostream& Out, DeclarationName Name, unsigned) { |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2830 | using namespace clang::io; |
| 2831 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2832 | Emit8(Out, Name.getNameKind()); |
| 2833 | switch (Name.getNameKind()) { |
| 2834 | case DeclarationName::Identifier: |
| 2835 | Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2836 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2837 | case DeclarationName::ObjCZeroArgSelector: |
| 2838 | case DeclarationName::ObjCOneArgSelector: |
| 2839 | case DeclarationName::ObjCMultiArgSelector: |
| 2840 | Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2841 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2842 | case DeclarationName::CXXOperatorName: |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2843 | assert(Name.getCXXOverloadedOperator() < NUM_OVERLOADED_OPERATORS && |
| 2844 | "Invalid operator?"); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2845 | Emit8(Out, Name.getCXXOverloadedOperator()); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2846 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2847 | case DeclarationName::CXXLiteralOperatorName: |
| 2848 | Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2849 | return; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2850 | case DeclarationName::CXXConstructorName: |
| 2851 | case DeclarationName::CXXDestructorName: |
| 2852 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2853 | case DeclarationName::CXXUsingDirective: |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2854 | return; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2855 | } |
Benjamin Kramer | 5931331 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 2856 | |
| 2857 | llvm_unreachable("Invalid name kind?"); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2860 | void EmitData(raw_ostream& Out, key_type_ref, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2861 | data_type Lookup, unsigned DataLen) { |
| 2862 | uint64_t Start = Out.tell(); (void)Start; |
| 2863 | clang::io::Emit16(Out, Lookup.second - Lookup.first); |
| 2864 | for (; Lookup.first != Lookup.second; ++Lookup.first) |
| 2865 | clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first)); |
| 2866 | |
| 2867 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 2868 | } |
| 2869 | }; |
| 2870 | } // end anonymous namespace |
| 2871 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2872 | /// \brief Write the block containing all of the declaration IDs |
| 2873 | /// visible from the given DeclContext. |
| 2874 | /// |
| 2875 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2876 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2877 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 2878 | DeclContext *DC) { |
| 2879 | if (DC->getPrimaryContext() != DC) |
| 2880 | return 0; |
| 2881 | |
| 2882 | // Since there is no name lookup into functions or methods, don't bother to |
| 2883 | // build a visible-declarations table for these entities. |
| 2884 | if (DC->isFunctionOrMethod()) |
| 2885 | return 0; |
| 2886 | |
| 2887 | // If not in C++, we perform name lookup for the translation unit via the |
| 2888 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
| 2889 | // FIXME: In C++ we need the visible declarations in order to "see" the |
| 2890 | // friend declarations, is there a way to do this without writing the table ? |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2891 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2892 | return 0; |
| 2893 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2894 | // Serialize the contents of the mapping used for lookup. Note that, |
| 2895 | // although we have two very different code paths, the serialized |
| 2896 | // representation is the same for both cases: a declaration name, |
| 2897 | // followed by a size, followed by references to the visible |
| 2898 | // declarations that have that name. |
| 2899 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Richard Smith | c5d3e80 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 2900 | StoredDeclsMap *Map = DC->buildLookup(); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2901 | if (!Map || Map->empty()) |
| 2902 | return 0; |
| 2903 | |
| 2904 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2905 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2906 | |
| 2907 | // Create the on-disk hash table representation. |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2908 | DeclarationName ConversionName; |
| 2909 | llvm::SmallVector<NamedDecl *, 4> ConversionDecls; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2910 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2911 | D != DEnd; ++D) { |
| 2912 | DeclarationName Name = D->first; |
| 2913 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2914 | if (Result.first != Result.second) { |
| 2915 | if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 2916 | // Hash all conversion function names to the same name. The actual |
| 2917 | // type information in conversion function name is not used in the |
| 2918 | // key (since such type information is not stable across different |
| 2919 | // modules), so the intended effect is to coalesce all of the conversion |
| 2920 | // functions under a single key. |
| 2921 | if (!ConversionName) |
| 2922 | ConversionName = Name; |
| 2923 | ConversionDecls.append(Result.first, Result.second); |
| 2924 | continue; |
| 2925 | } |
| 2926 | |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 2927 | Generator.insert(Name, Result, Trait); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2928 | } |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2931 | // Add the conversion functions |
| 2932 | if (!ConversionDecls.empty()) { |
| 2933 | Generator.insert(ConversionName, |
| 2934 | DeclContext::lookup_result(ConversionDecls.begin(), |
| 2935 | ConversionDecls.end()), |
| 2936 | Trait); |
| 2937 | } |
| 2938 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2939 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2940 | SmallString<4096> LookupTable; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2941 | uint32_t BucketOffset; |
| 2942 | { |
| 2943 | llvm::raw_svector_ostream Out(LookupTable); |
| 2944 | // Make sure that no bucket is at offset 0 |
| 2945 | clang::io::Emit32(Out, 0); |
| 2946 | BucketOffset = Generator.Emit(Out, Trait); |
| 2947 | } |
| 2948 | |
| 2949 | // Write the lookup table |
| 2950 | RecordData Record; |
| 2951 | Record.push_back(DECL_CONTEXT_VISIBLE); |
| 2952 | Record.push_back(BucketOffset); |
| 2953 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
| 2954 | LookupTable.str()); |
| 2955 | |
| 2956 | Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); |
| 2957 | ++NumVisibleDeclContexts; |
| 2958 | return Offset; |
| 2959 | } |
| 2960 | |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2961 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 2962 | /// |
| 2963 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 2964 | /// DeclContext in a dependent AST file. As such, they only exist for the TU |
Richard Smith | c5d3e80 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 2965 | /// (in C++), for namespaces, and for classes with forward-declared unscoped |
| 2966 | /// enumeration members (in C++11). |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2967 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2968 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 2969 | if (!Map || Map->empty()) |
| 2970 | return; |
| 2971 | |
| 2972 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2973 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2974 | |
| 2975 | // Create the hash table. |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2976 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2977 | D != DEnd; ++D) { |
| 2978 | DeclarationName Name = D->first; |
| 2979 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 2980 | // For any name that appears in this table, the results are complete, i.e. |
| 2981 | // they overwrite results from previous PCHs. Merging is always a mess. |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 2982 | if (Result.first != Result.second) |
| 2983 | Generator.insert(Name, Result, Trait); |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | // Create the on-disk hash table in a buffer. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2987 | SmallString<4096> LookupTable; |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2988 | uint32_t BucketOffset; |
| 2989 | { |
| 2990 | llvm::raw_svector_ostream Out(LookupTable); |
| 2991 | // Make sure that no bucket is at offset 0 |
| 2992 | clang::io::Emit32(Out, 0); |
| 2993 | BucketOffset = Generator.Emit(Out, Trait); |
| 2994 | } |
| 2995 | |
| 2996 | // Write the lookup table |
| 2997 | RecordData Record; |
| 2998 | Record.push_back(UPDATE_VISIBLE); |
| 2999 | Record.push_back(getDeclID(cast<Decl>(DC))); |
| 3000 | Record.push_back(BucketOffset); |
| 3001 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); |
| 3002 | } |
| 3003 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3004 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 3005 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
| 3006 | RecordData Record; |
| 3007 | Record.push_back(Opts.fp_contract); |
| 3008 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 3009 | } |
| 3010 | |
| 3011 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 3012 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3013 | if (!SemaRef.Context.getLangOpts().OpenCL) |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3014 | return; |
| 3015 | |
| 3016 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 3017 | RecordData Record; |
| 3018 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 3019 | #include "clang/Basic/OpenCLExtensions.def" |
| 3020 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 3021 | } |
| 3022 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3023 | void ASTWriter::WriteRedeclarations() { |
| 3024 | RecordData LocalRedeclChains; |
| 3025 | SmallVector<serialization::LocalRedeclarationsInfo, 2> LocalRedeclsMap; |
| 3026 | |
| 3027 | for (unsigned I = 0, N = Redeclarations.size(); I != N; ++I) { |
| 3028 | Decl *First = Redeclarations[I]; |
| 3029 | assert(First->getPreviousDecl() == 0 && "Not the first declaration?"); |
| 3030 | |
| 3031 | Decl *MostRecent = First->getMostRecentDecl(); |
| 3032 | |
| 3033 | // If we only have a single declaration, there is no point in storing |
| 3034 | // a redeclaration chain. |
| 3035 | if (First == MostRecent) |
| 3036 | continue; |
| 3037 | |
| 3038 | unsigned Offset = LocalRedeclChains.size(); |
| 3039 | unsigned Size = 0; |
| 3040 | LocalRedeclChains.push_back(0); // Placeholder for the size. |
| 3041 | |
| 3042 | // Collect the set of local redeclarations of this declaration. |
| 3043 | for (Decl *Prev = MostRecent; Prev != First; |
| 3044 | Prev = Prev->getPreviousDecl()) { |
| 3045 | if (!Prev->isFromASTFile()) { |
| 3046 | AddDeclRef(Prev, LocalRedeclChains); |
| 3047 | ++Size; |
| 3048 | } |
| 3049 | } |
| 3050 | LocalRedeclChains[Offset] = Size; |
| 3051 | |
| 3052 | // Reverse the set of local redeclarations, so that we store them in |
| 3053 | // order (since we found them in reverse order). |
| 3054 | std::reverse(LocalRedeclChains.end() - Size, LocalRedeclChains.end()); |
| 3055 | |
| 3056 | // Add the mapping from the first ID to the set of local declarations. |
| 3057 | LocalRedeclarationsInfo Info = { getDeclID(First), Offset }; |
| 3058 | LocalRedeclsMap.push_back(Info); |
| 3059 | |
| 3060 | assert(N == Redeclarations.size() && |
| 3061 | "Deserialized a declaration we shouldn't have"); |
| 3062 | } |
| 3063 | |
| 3064 | if (LocalRedeclChains.empty()) |
| 3065 | return; |
| 3066 | |
| 3067 | // Sort the local redeclarations map by the first declaration ID, |
| 3068 | // since the reader will be performing binary searches on this information. |
| 3069 | llvm::array_pod_sort(LocalRedeclsMap.begin(), LocalRedeclsMap.end()); |
| 3070 | |
| 3071 | // Emit the local redeclarations map. |
| 3072 | using namespace llvm; |
| 3073 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3074 | Abbrev->Add(BitCodeAbbrevOp(LOCAL_REDECLARATIONS_MAP)); |
| 3075 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3076 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3077 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3078 | |
| 3079 | RecordData Record; |
| 3080 | Record.push_back(LOCAL_REDECLARATIONS_MAP); |
| 3081 | Record.push_back(LocalRedeclsMap.size()); |
| 3082 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3083 | reinterpret_cast<char*>(LocalRedeclsMap.data()), |
| 3084 | LocalRedeclsMap.size() * sizeof(LocalRedeclarationsInfo)); |
| 3085 | |
| 3086 | // Emit the redeclaration chains. |
| 3087 | Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedeclChains); |
| 3088 | } |
| 3089 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3090 | void ASTWriter::WriteObjCCategories() { |
| 3091 | llvm::SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; |
| 3092 | RecordData Categories; |
| 3093 | |
| 3094 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { |
| 3095 | unsigned Size = 0; |
| 3096 | unsigned StartIndex = Categories.size(); |
| 3097 | |
| 3098 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; |
| 3099 | |
| 3100 | // Allocate space for the size. |
| 3101 | Categories.push_back(0); |
| 3102 | |
| 3103 | // Add the categories. |
| 3104 | for (ObjCCategoryDecl *Cat = Class->getCategoryList(); |
| 3105 | Cat; Cat = Cat->getNextClassCategory(), ++Size) { |
| 3106 | assert(getDeclID(Cat) != 0 && "Bogus category"); |
| 3107 | AddDeclRef(Cat, Categories); |
| 3108 | } |
| 3109 | |
| 3110 | // Update the size. |
| 3111 | Categories[StartIndex] = Size; |
| 3112 | |
| 3113 | // Record this interface -> category map. |
| 3114 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; |
| 3115 | CategoriesMap.push_back(CatInfo); |
| 3116 | } |
| 3117 | |
| 3118 | // Sort the categories map by the definition ID, since the reader will be |
| 3119 | // performing binary searches on this information. |
| 3120 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); |
| 3121 | |
| 3122 | // Emit the categories map. |
| 3123 | using namespace llvm; |
| 3124 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3125 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); |
| 3126 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries |
| 3127 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3128 | unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); |
| 3129 | |
| 3130 | RecordData Record; |
| 3131 | Record.push_back(OBJC_CATEGORIES_MAP); |
| 3132 | Record.push_back(CategoriesMap.size()); |
| 3133 | Stream.EmitRecordWithBlob(AbbrevID, Record, |
| 3134 | reinterpret_cast<char*>(CategoriesMap.data()), |
| 3135 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); |
| 3136 | |
| 3137 | // Emit the category lists. |
| 3138 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); |
| 3139 | } |
| 3140 | |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3141 | void ASTWriter::WriteMergedDecls() { |
| 3142 | if (!Chain || Chain->MergedDecls.empty()) |
| 3143 | return; |
| 3144 | |
| 3145 | RecordData Record; |
| 3146 | for (ASTReader::MergedDeclsMap::iterator I = Chain->MergedDecls.begin(), |
| 3147 | IEnd = Chain->MergedDecls.end(); |
| 3148 | I != IEnd; ++I) { |
Douglas Gregor | b6b60c1 | 2012-01-05 22:27:05 +0000 | [diff] [blame] | 3149 | DeclID CanonID = I->first->isFromASTFile()? I->first->getGlobalID() |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3150 | : getDeclID(I->first); |
| 3151 | assert(CanonID && "Merged declaration not known?"); |
| 3152 | |
| 3153 | Record.push_back(CanonID); |
| 3154 | Record.push_back(I->second.size()); |
| 3155 | Record.append(I->second.begin(), I->second.end()); |
| 3156 | } |
| 3157 | Stream.EmitRecord(MERGED_DECLARATIONS, Record); |
| 3158 | } |
| 3159 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3160 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3161 | // General Serialization Routines |
| 3162 | //===----------------------------------------------------------------------===// |
| 3163 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3164 | /// \brief Write a record containing the given attributes. |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3165 | void ASTWriter::WriteAttributes(ArrayRef<const Attr*> Attrs, |
| 3166 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4eb9fc0 | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 3167 | Record.push_back(Attrs.size()); |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 3168 | for (ArrayRef<const Attr *>::iterator i = Attrs.begin(), |
| 3169 | e = Attrs.end(); i != e; ++i){ |
| 3170 | const Attr *A = *i; |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3171 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Argyrios Kyrtzidis | 768d6ca | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 3172 | AddSourceRange(A->getRange(), Record); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3173 | |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 3174 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | 4e9255f | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 3175 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3176 | } |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3179 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 3180 | Record.push_back(Str.size()); |
| 3181 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 3182 | } |
| 3183 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3184 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 3185 | RecordDataImpl &Record) { |
| 3186 | Record.push_back(Version.getMajor()); |
| 3187 | if (llvm::Optional<unsigned> Minor = Version.getMinor()) |
| 3188 | Record.push_back(*Minor + 1); |
| 3189 | else |
| 3190 | Record.push_back(0); |
| 3191 | if (llvm::Optional<unsigned> Subminor = Version.getSubminor()) |
| 3192 | Record.push_back(*Subminor + 1); |
| 3193 | else |
| 3194 | Record.push_back(0); |
| 3195 | } |
| 3196 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3197 | /// \brief Note that the identifier II occurs at the given offset |
| 3198 | /// within the identifier table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3199 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3200 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3201 | // Only store offsets new to this AST file. Other identifier names are looked |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3202 | // up earlier in the chain and thus don't need an offset. |
| 3203 | if (ID >= FirstIdentID) |
| 3204 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3205 | } |
| 3206 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3207 | /// \brief Note that the selector Sel occurs at the given offset |
| 3208 | /// within the method pool/selector table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3209 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3210 | unsigned ID = SelectorIDs[Sel]; |
| 3211 | assert(ID && "Unknown selector"); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3212 | // Don't record offsets for selectors that are also available in a different |
| 3213 | // file. |
| 3214 | if (ID < FirstSelectorID) |
| 3215 | return; |
| 3216 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3219 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3220 | : Stream(Stream), Context(0), PP(0), Chain(0), WritingModule(0), |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3221 | WritingAST(false), DoneWritingDeclsAndTypes(false), |
| 3222 | ASTHasCompilerErrors(false), |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3223 | FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3224 | FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3225 | FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), |
| 3226 | FirstMacroID(NUM_PREDEF_MACRO_IDS), NextMacroID(FirstMacroID), |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3227 | FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), |
| 3228 | NextSubmoduleID(FirstSubmoduleID), |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3229 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3230 | CollectedStmts(&StmtsToEmit), |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3231 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3232 | NumVisibleDeclContexts(0), |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3233 | NextCXXBaseSpecifiersID(1), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3234 | DeclParmVarAbbrev(0), DeclContextLexicalAbbrev(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3235 | DeclContextVisibleLookupAbbrev(0), UpdateVisibleAbbrev(0), |
| 3236 | DeclRefExprAbbrev(0), CharacterLiteralAbbrev(0), |
| 3237 | DeclRecordAbbrev(0), IntegerLiteralAbbrev(0), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 3238 | DeclTypedefAbbrev(0), |
| 3239 | DeclVarAbbrev(0), DeclFieldAbbrev(0), |
| 3240 | DeclEnumAbbrev(0), DeclObjCIvarAbbrev(0) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3241 | { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3242 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3243 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3244 | ASTWriter::~ASTWriter() { |
| 3245 | for (FileDeclIDsTy::iterator |
| 3246 | I = FileDeclIDs.begin(), E = FileDeclIDs.end(); I != E; ++I) |
| 3247 | delete I->second; |
| 3248 | } |
| 3249 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3250 | void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 3251 | const std::string &OutputFile, |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3252 | Module *WritingModule, StringRef isysroot, |
| 3253 | bool hasErrors) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3254 | WritingAST = true; |
| 3255 | |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 3256 | ASTHasCompilerErrors = hasErrors; |
| 3257 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3258 | // Emit the file header. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3259 | Stream.Emit((unsigned)'C', 8); |
| 3260 | Stream.Emit((unsigned)'P', 8); |
| 3261 | Stream.Emit((unsigned)'C', 8); |
| 3262 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3263 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 3264 | WriteBlockInfoBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3265 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3266 | Context = &SemaRef.Context; |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3267 | PP = &SemaRef.PP; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3268 | this->WritingModule = WritingModule; |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3269 | WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile, WritingModule); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3270 | Context = 0; |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3271 | PP = 0; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3272 | this->WritingModule = 0; |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3273 | |
| 3274 | WritingAST = false; |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3277 | template<typename Vector> |
| 3278 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 3279 | ASTWriter::RecordData &Record) { |
| 3280 | for (typename Vector::iterator I = Vec.begin(0, true), E = Vec.end(); |
| 3281 | I != E; ++I) { |
| 3282 | Writer.AddDeclRef(*I, Record); |
| 3283 | } |
| 3284 | } |
| 3285 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3286 | void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3287 | StringRef isysroot, |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3288 | const std::string &OutputFile, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3289 | Module *WritingModule) { |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3290 | using namespace llvm; |
| 3291 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3292 | // Make sure that the AST reader knows to finalize itself. |
| 3293 | if (Chain) |
| 3294 | Chain->finalizeForWriting(); |
| 3295 | |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3296 | ASTContext &Context = SemaRef.Context; |
| 3297 | Preprocessor &PP = SemaRef.PP; |
| 3298 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3299 | // Set up predefined declaration IDs. |
| 3300 | DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 3301 | if (Context.ObjCIdDecl) |
| 3302 | DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID; |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 3303 | if (Context.ObjCSelDecl) |
| 3304 | DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID; |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 3305 | if (Context.ObjCClassDecl) |
| 3306 | DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID; |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 3307 | if (Context.ObjCProtocolClassDecl) |
| 3308 | DeclIDs[Context.ObjCProtocolClassDecl] = PREDEF_DECL_OBJC_PROTOCOL_ID; |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 3309 | if (Context.Int128Decl) |
| 3310 | DeclIDs[Context.Int128Decl] = PREDEF_DECL_INT_128_ID; |
| 3311 | if (Context.UInt128Decl) |
| 3312 | DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID; |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 3313 | if (Context.ObjCInstanceTypeDecl) |
| 3314 | DeclIDs[Context.ObjCInstanceTypeDecl] = PREDEF_DECL_OBJC_INSTANCETYPE_ID; |
Meador Inge | c5613b2 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 3315 | if (Context.BuiltinVaListDecl) |
| 3316 | DeclIDs[Context.getBuiltinVaListDecl()] = PREDEF_DECL_BUILTIN_VA_LIST_ID; |
| 3317 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3318 | if (!Chain) { |
| 3319 | // Make sure that we emit IdentifierInfos (and any attached |
| 3320 | // declarations) for builtins. We don't need to do this when we're |
| 3321 | // emitting chained PCH files, because all of the builtins will be |
| 3322 | // in the original PCH file. |
| 3323 | // FIXME: Modules won't like this at all. |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3324 | IdentifierTable &Table = PP.getIdentifierTable(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3325 | SmallVector<const char *, 32> BuiltinNames; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3326 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3327 | Context.getLangOpts().NoBuiltin); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3328 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 3329 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 3330 | } |
| 3331 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3332 | // If there are any out-of-date identifiers, bring them up to date. |
| 3333 | if (ExternalPreprocessorSource *ExtSource = PP.getExternalSource()) { |
| 3334 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 3335 | IDEnd = PP.getIdentifierTable().end(); |
| 3336 | ID != IDEnd; ++ID) |
| 3337 | if (ID->second->isOutOfDate()) |
| 3338 | ExtSource->updateOutOfDateIdentifier(*ID->second); |
| 3339 | } |
| 3340 | |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3341 | // Build a record containing all of the tentative definitions in this file, in |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3342 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3343 | // headers. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3344 | RecordData TentativeDefinitions; |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3345 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 3346 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3347 | // Build a record containing all of the file scoped decls in this file. |
| 3348 | RecordData UnusedFileScopedDecls; |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 3349 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 3350 | UnusedFileScopedDecls); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3351 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3352 | // Build a record containing all of the delegating constructors we still need |
| 3353 | // to resolve. |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3354 | RecordData DelegatingCtorDecls; |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 3355 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3356 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3357 | // Write the set of weak, undeclared identifiers. We always write the |
| 3358 | // entire table, since later PCH files in a PCH chain are only interested in |
| 3359 | // the results at the end of the chain. |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3360 | RecordData WeakUndeclaredIdentifiers; |
| 3361 | if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 3362 | for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3363 | I = SemaRef.WeakUndeclaredIdentifiers.begin(), |
| 3364 | E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { |
| 3365 | AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); |
| 3366 | AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); |
| 3367 | AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); |
| 3368 | WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); |
| 3369 | } |
| 3370 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3371 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3372 | // Build a record containing all of the locally-scoped external |
| 3373 | // declarations in this header file. Generally, this record will be |
| 3374 | // empty. |
| 3375 | RecordData LocallyScopedExternalDecls; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3376 | // FIXME: This is filling in the AST file in densemap order which is |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 3377 | // nondeterminstic! |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3378 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3379 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 3380 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3381 | TD != TDEnd; ++TD) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3382 | if (!TD->second->isFromASTFile()) |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 3383 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 3384 | } |
| 3385 | |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3386 | // Build a record containing all of the ext_vector declarations. |
| 3387 | RecordData ExtVectorDecls; |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 3388 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3389 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3390 | // Build a record containing all of the VTable uses information. |
| 3391 | RecordData VTableUses; |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3392 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 3393 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 3394 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 3395 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 3396 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 3397 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | // Build a record containing all of dynamic classes declarations. |
| 3401 | RecordData DynamicClasses; |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 3402 | AddLazyVectorDecls(*this, SemaRef.DynamicClasses, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3403 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3404 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3405 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3406 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3407 | I = SemaRef.PendingInstantiations.begin(), |
| 3408 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 3409 | AddDeclRef(I->first, PendingInstantiations); |
| 3410 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3411 | } |
| 3412 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 3413 | "There are local ones at end of translation unit!"); |
| 3414 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3415 | // Build a record containing some declaration references. |
| 3416 | RecordData SemaDeclRefs; |
| 3417 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 3418 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 3419 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 3420 | } |
| 3421 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3422 | RecordData CUDASpecialDeclRefs; |
| 3423 | if (Context.getcudaConfigureCallDecl()) { |
| 3424 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 3425 | } |
| 3426 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3427 | // Build a record containing all of the known namespaces. |
| 3428 | RecordData KnownNamespaces; |
| 3429 | for (llvm::DenseMap<NamespaceDecl*, bool>::iterator |
| 3430 | I = SemaRef.KnownNamespaces.begin(), |
| 3431 | IEnd = SemaRef.KnownNamespaces.end(); |
| 3432 | I != IEnd; ++I) { |
| 3433 | if (!I->second) |
| 3434 | AddDeclRef(I->first, KnownNamespaces); |
| 3435 | } |
| 3436 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3437 | // Write the remaining AST contents. |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3438 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3439 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3440 | WriteLanguageOptions(Context.getLangOpts()); |
Argyrios Kyrtzidis | 900ab95 | 2012-10-11 16:05:00 +0000 | [diff] [blame] | 3441 | WriteMetadata(Context, isysroot, OutputFile); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3442 | if (StatCalls && isysroot.empty()) |
Douglas Gregor | dd41ed5 | 2010-07-12 23:48:14 +0000 | [diff] [blame] | 3443 | WriteStatCache(*StatCalls); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3444 | |
| 3445 | // Create a lexical update block containing all of the declarations in the |
| 3446 | // translation unit that do not come from other AST files. |
| 3447 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
| 3448 | SmallVector<KindDeclIDPair, 64> NewGlobalDecls; |
| 3449 | for (DeclContext::decl_iterator I = TU->noload_decls_begin(), |
| 3450 | E = TU->noload_decls_end(); |
| 3451 | I != E; ++I) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3452 | if (!(*I)->isFromASTFile()) |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3453 | NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 3457 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 3458 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3459 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
| 3460 | Record.clear(); |
| 3461 | Record.push_back(TU_UPDATE_LEXICAL); |
| 3462 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 3463 | data(NewGlobalDecls)); |
| 3464 | |
| 3465 | // And a visible updates block for the translation unit. |
| 3466 | Abv = new llvm::BitCodeAbbrev(); |
| 3467 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 3468 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3469 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); |
| 3470 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3471 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 3472 | WriteDeclContextVisibleUpdate(TU); |
| 3473 | |
| 3474 | // If the translation unit has an anonymous namespace, and we don't already |
| 3475 | // have an update block for it, write it as an update block. |
| 3476 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 3477 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
| 3478 | if (Record.empty()) { |
| 3479 | Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3480 | Record.push_back(reinterpret_cast<uint64_t>(NS)); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3481 | } |
| 3482 | } |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3483 | |
| 3484 | // Make sure visible decls, added to DeclContexts previously loaded from |
| 3485 | // an AST file, are registered for serialization. |
| 3486 | for (SmallVector<const Decl *, 16>::iterator |
| 3487 | I = UpdatingVisibleDecls.begin(), |
| 3488 | E = UpdatingVisibleDecls.end(); I != E; ++I) { |
| 3489 | GetDeclRef(*I); |
| 3490 | } |
| 3491 | |
Argyrios Kyrtzidis | 67bc4ba | 2011-11-14 04:52:24 +0000 | [diff] [blame] | 3492 | // Resolve any declaration pointers within the declaration updates block. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3493 | ResolveDeclUpdatesBlocks(); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3494 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3495 | // Form the record of special types. |
| 3496 | RecordData SpecialTypes; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3497 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3498 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 3499 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 3500 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 3501 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 3502 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3503 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 3504 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); |
Douglas Gregor | 185dbd7 | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 3505 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3506 | // Keep writing types and declarations until all types and |
| 3507 | // declarations have been written. |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3508 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3509 | WriteDeclsBlockAbbrevs(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3510 | for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), |
| 3511 | E = DeclsToRewrite.end(); |
| 3512 | I != E; ++I) |
| 3513 | DeclTypesToEmit.push(const_cast<Decl*>(*I)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3514 | while (!DeclTypesToEmit.empty()) { |
| 3515 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 3516 | DeclTypesToEmit.pop(); |
| 3517 | if (DOT.isType()) |
| 3518 | WriteType(DOT.getType()); |
| 3519 | else |
| 3520 | WriteDecl(Context, DOT.getDecl()); |
| 3521 | } |
| 3522 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3523 | |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3524 | DoneWritingDeclsAndTypes = true; |
| 3525 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3526 | WriteFileDeclIDsMap(); |
| 3527 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 3528 | WriteComments(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3529 | |
| 3530 | if (Chain) { |
| 3531 | // Write the mapping information describing our module dependencies and how |
| 3532 | // each of those modules were mapped into our own offset/ID space, so that |
| 3533 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 3534 | // The map consists solely of a blob with the following format: |
| 3535 | // *(module-name-len:i16 module-name:len*i8 |
| 3536 | // source-location-offset:i32 |
| 3537 | // identifier-id:i32 |
| 3538 | // preprocessed-entity-id:i32 |
| 3539 | // macro-definition-id:i32 |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3540 | // submodule-id:i32 |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3541 | // selector-id:i32 |
| 3542 | // declaration-id:i32 |
| 3543 | // c++-base-specifiers-id:i32 |
| 3544 | // type-id:i32) |
| 3545 | // |
| 3546 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 3547 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 3548 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 3549 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3550 | SmallString<2048> Buffer; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3551 | { |
| 3552 | llvm::raw_svector_ostream Out(Buffer); |
| 3553 | for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3554 | MEnd = Chain->ModuleMgr.end(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3555 | M != MEnd; ++M) { |
| 3556 | StringRef FileName = (*M)->FileName; |
| 3557 | io::Emit16(Out, FileName.size()); |
| 3558 | Out.write(FileName.data(), FileName.size()); |
| 3559 | io::Emit32(Out, (*M)->SLocEntryBaseOffset); |
| 3560 | io::Emit32(Out, (*M)->BaseIdentifierID); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3561 | io::Emit32(Out, (*M)->BaseMacroID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3562 | io::Emit32(Out, (*M)->BasePreprocessedEntityID); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3563 | io::Emit32(Out, (*M)->BaseSubmoduleID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 3564 | io::Emit32(Out, (*M)->BaseSelectorID); |
| 3565 | io::Emit32(Out, (*M)->BaseDeclID); |
| 3566 | io::Emit32(Out, (*M)->BaseTypeIndex); |
| 3567 | } |
| 3568 | } |
| 3569 | Record.clear(); |
| 3570 | Record.push_back(MODULE_OFFSET_MAP); |
| 3571 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 3572 | Buffer.data(), Buffer.size()); |
| 3573 | } |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3574 | WritePreprocessor(PP, WritingModule != 0); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3575 | WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3576 | WriteSelectors(SemaRef); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3577 | WriteReferencedSelectorsPool(SemaRef); |
Douglas Gregor | a8cc6ce | 2011-11-30 04:39:39 +0000 | [diff] [blame] | 3578 | WriteIdentifierTable(PP, SemaRef.IdResolver, WritingModule != 0); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3579 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 3580 | WriteOpenCLExtensions(SemaRef); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3581 | |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3582 | WriteTypeDeclOffsets(); |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3583 | WritePragmaDiagnosticMappings(Context.getDiagnostics()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3584 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 3585 | WriteCXXBaseSpecifiersOffsets(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3586 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3587 | // If we're emitting a module, write out the submodule information. |
| 3588 | if (WritingModule) |
| 3589 | WriteSubmodules(WritingModule); |
| 3590 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3591 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 3592 | |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3593 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3594 | if (!ExternalDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3595 | Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3596 | |
| 3597 | // Write the record containing tentative definitions. |
| 3598 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3599 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3600 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3601 | // Write the record containing unused file scoped decls. |
| 3602 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3603 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3604 | |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3605 | // Write the record containing weak undeclared identifiers. |
| 3606 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3607 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3608 | WeakUndeclaredIdentifiers); |
| 3609 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3610 | // Write the record containing locally-scoped external definitions. |
| 3611 | if (!LocallyScopedExternalDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3612 | Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3613 | LocallyScopedExternalDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3614 | |
| 3615 | // Write the record containing ext_vector type names. |
| 3616 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3617 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3618 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3619 | // Write the record containing VTable uses information. |
| 3620 | if (!VTableUses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3621 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3622 | |
| 3623 | // Write the record containing dynamic classes declarations. |
| 3624 | if (!DynamicClasses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3625 | Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3626 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3627 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3628 | if (!PendingInstantiations.empty()) |
| 3629 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3630 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3631 | // Write the record containing declaration references of Sema. |
| 3632 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3633 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3634 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3635 | // Write the record containing CUDA-specific declaration references. |
| 3636 | if (!CUDASpecialDeclRefs.empty()) |
| 3637 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3638 | |
| 3639 | // Write the delegating constructors. |
| 3640 | if (!DelegatingCtorDecls.empty()) |
| 3641 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3642 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3643 | // Write the known namespaces. |
| 3644 | if (!KnownNamespaces.empty()) |
| 3645 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
| 3646 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3647 | // Write the visible updates to DeclContexts. |
| 3648 | for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator |
| 3649 | I = UpdatedDeclContexts.begin(), |
| 3650 | E = UpdatedDeclContexts.end(); |
| 3651 | I != E; ++I) |
| 3652 | WriteDeclContextVisibleUpdate(*I); |
| 3653 | |
Douglas Gregor | c5e0f9b | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 3654 | if (!WritingModule) { |
| 3655 | // Write the submodules that were imported, if any. |
| 3656 | RecordData ImportedModules; |
| 3657 | for (ASTContext::import_iterator I = Context.local_import_begin(), |
| 3658 | IEnd = Context.local_import_end(); |
| 3659 | I != IEnd; ++I) { |
| 3660 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); |
| 3661 | ImportedModules.push_back(SubmoduleIDs[I->getImportedModule()]); |
| 3662 | } |
| 3663 | if (!ImportedModules.empty()) { |
| 3664 | // Sort module IDs. |
| 3665 | llvm::array_pod_sort(ImportedModules.begin(), ImportedModules.end()); |
| 3666 | |
| 3667 | // Unique module IDs. |
| 3668 | ImportedModules.erase(std::unique(ImportedModules.begin(), |
| 3669 | ImportedModules.end()), |
| 3670 | ImportedModules.end()); |
| 3671 | |
| 3672 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); |
| 3673 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 3674 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3675 | |
| 3676 | WriteMacroUpdates(); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3677 | WriteDeclUpdatesBlocks(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3678 | WriteDeclReplacementsBlock(); |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 3679 | WriteMergedDecls(); |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 3680 | WriteRedeclarations(); |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3681 | WriteObjCCategories(); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3682 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3683 | // Some simple statistics |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3684 | Record.clear(); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3685 | Record.push_back(NumStatements); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 3686 | Record.push_back(NumMacros); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3687 | Record.push_back(NumLexicalDeclContexts); |
| 3688 | Record.push_back(NumVisibleDeclContexts); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3689 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3690 | Stream.ExitBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3691 | } |
| 3692 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3693 | void ASTWriter::WriteMacroUpdates() { |
| 3694 | if (MacroUpdates.empty()) |
| 3695 | return; |
| 3696 | |
| 3697 | RecordData Record; |
| 3698 | for (MacroUpdatesMap::iterator I = MacroUpdates.begin(), |
| 3699 | E = MacroUpdates.end(); |
| 3700 | I != E; ++I) { |
| 3701 | addMacroRef(I->first, Record); |
| 3702 | AddSourceLocation(I->second.UndefLoc, Record); |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 3703 | Record.push_back(inferSubmoduleIDFromLocation(I->second.UndefLoc)); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3704 | } |
| 3705 | Stream.EmitRecord(MACRO_UPDATES, Record); |
| 3706 | } |
| 3707 | |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3708 | /// \brief Go through the declaration update blocks and resolve declaration |
| 3709 | /// pointers into declaration IDs. |
| 3710 | void ASTWriter::ResolveDeclUpdatesBlocks() { |
| 3711 | for (DeclUpdateMap::iterator |
| 3712 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3713 | const Decl *D = I->first; |
| 3714 | UpdateRecord &URec = I->second; |
| 3715 | |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 3716 | if (isRewritten(D)) |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3717 | continue; // The decl will be written completely |
| 3718 | |
| 3719 | unsigned Idx = 0, N = URec.size(); |
| 3720 | while (Idx < N) { |
| 3721 | switch ((DeclUpdateKind)URec[Idx++]) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3722 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: |
| 3723 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
| 3724 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: |
| 3725 | URec[Idx] = GetDeclRef(reinterpret_cast<Decl *>(URec[Idx])); |
| 3726 | ++Idx; |
| 3727 | break; |
| 3728 | |
| 3729 | case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: |
| 3730 | ++Idx; |
| 3731 | break; |
| 3732 | } |
| 3733 | } |
| 3734 | } |
| 3735 | } |
| 3736 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3737 | void ASTWriter::WriteDeclUpdatesBlocks() { |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3738 | if (DeclUpdates.empty()) |
| 3739 | return; |
| 3740 | |
| 3741 | RecordData OffsetsRecord; |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3742 | Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3743 | for (DeclUpdateMap::iterator |
| 3744 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3745 | const Decl *D = I->first; |
| 3746 | UpdateRecord &URec = I->second; |
| 3747 | |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 3748 | if (isRewritten(D)) |
Argyrios Kyrtzidis | ba901b5 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 3749 | continue; // The decl will be written completely,no need to store updates. |
| 3750 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3751 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 3752 | Stream.EmitRecord(DECL_UPDATES, URec); |
| 3753 | |
| 3754 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 3755 | OffsetsRecord.push_back(Offset); |
| 3756 | } |
| 3757 | Stream.ExitBlock(); |
| 3758 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); |
| 3759 | } |
| 3760 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3761 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3762 | if (ReplacedDecls.empty()) |
| 3763 | return; |
| 3764 | |
| 3765 | RecordData Record; |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 3766 | for (SmallVector<ReplacedDeclInfo, 16>::iterator |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3767 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 3768 | Record.push_back(I->ID); |
| 3769 | Record.push_back(I->Offset); |
| 3770 | Record.push_back(I->Loc); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3771 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3772 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3775 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3776 | Record.push_back(Loc.getRawEncoding()); |
| 3777 | } |
| 3778 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3779 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3780 | AddSourceLocation(Range.getBegin(), Record); |
| 3781 | AddSourceLocation(Range.getEnd(), Record); |
| 3782 | } |
| 3783 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3784 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3785 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3786 | const uint64_t *Words = Value.getRawData(); |
| 3787 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3790 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3791 | Record.push_back(Value.isUnsigned()); |
| 3792 | AddAPInt(Value, Record); |
| 3793 | } |
| 3794 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3795 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 3796 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 3797 | } |
| 3798 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3799 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3800 | Record.push_back(getIdentifierRef(II)); |
| 3801 | } |
| 3802 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3803 | void ASTWriter::addMacroRef(MacroInfo *MI, RecordDataImpl &Record) { |
| 3804 | Record.push_back(getMacroRef(MI)); |
| 3805 | } |
| 3806 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3807 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3808 | if (II == 0) |
| 3809 | return 0; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3810 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3811 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3812 | if (ID == 0) |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3813 | ID = NextIdentID++; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3814 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3815 | } |
| 3816 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 3817 | MacroID ASTWriter::getMacroRef(MacroInfo *MI) { |
| 3818 | // Don't emit builtin macros like __LINE__ to the AST file unless they |
| 3819 | // have been redefined by the header (in which case they are not |
| 3820 | // isBuiltinMacro). |
| 3821 | if (MI == 0 || MI->isBuiltinMacro()) |
| 3822 | return 0; |
| 3823 | |
| 3824 | MacroID &ID = MacroIDs[MI]; |
| 3825 | if (ID == 0) |
| 3826 | ID = NextMacroID++; |
| 3827 | return ID; |
| 3828 | } |
| 3829 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3830 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3831 | Record.push_back(getSelectorRef(SelRef)); |
| 3832 | } |
| 3833 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3834 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3835 | if (Sel.getAsOpaquePtr() == 0) { |
| 3836 | return 0; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3837 | } |
| 3838 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3839 | SelectorID &SID = SelectorIDs[Sel]; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3840 | if (SID == 0 && Chain) { |
| 3841 | // This might trigger a ReadSelector callback, which will set the ID for |
| 3842 | // this selector. |
| 3843 | Chain->LoadSelector(Sel); |
| 3844 | } |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3845 | if (SID == 0) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3846 | SID = NextSelectorID++; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3847 | } |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3848 | return SID; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3851 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 3852 | AddDeclRef(Temp->getDestructor(), Record); |
| 3853 | } |
| 3854 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3855 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
| 3856 | CXXBaseSpecifier const *BasesEnd, |
| 3857 | RecordDataImpl &Record) { |
| 3858 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 3859 | CXXBaseSpecifiersToWrite.push_back( |
| 3860 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 3861 | Bases, BasesEnd)); |
| 3862 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 3863 | } |
| 3864 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3865 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3866 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3867 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3868 | switch (Kind) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3869 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3870 | AddStmt(Arg.getAsExpr()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3871 | break; |
| 3872 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3873 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3874 | break; |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3875 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3876 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3877 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3878 | break; |
| 3879 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3880 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3881 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3882 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3883 | break; |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3884 | case TemplateArgument::Null: |
| 3885 | case TemplateArgument::Integral: |
| 3886 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3887 | case TemplateArgument::NullPtr: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3888 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3889 | // FIXME: Is this right? |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3890 | break; |
| 3891 | } |
| 3892 | } |
| 3893 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3894 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3895 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3896 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3897 | |
| 3898 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 3899 | bool InfoHasSameExpr |
| 3900 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 3901 | Record.push_back(InfoHasSameExpr); |
| 3902 | if (InfoHasSameExpr) |
| 3903 | return; // Avoid storing the same expr twice. |
| 3904 | } |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3905 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 3906 | Record); |
| 3907 | } |
| 3908 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3909 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 3910 | RecordDataImpl &Record) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3911 | if (TInfo == 0) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3912 | AddTypeRef(QualType(), Record); |
| 3913 | return; |
| 3914 | } |
| 3915 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3916 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 3917 | } |
| 3918 | |
| 3919 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 3920 | AddTypeRef(TL.getType(), Record); |
| 3921 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3922 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3923 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3924 | TLW.Visit(TL); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3925 | } |
| 3926 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3927 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 7fb3518 | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 3928 | Record.push_back(GetOrCreateTypeID(T)); |
| 3929 | } |
| 3930 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3931 | TypeID ASTWriter::GetOrCreateTypeID( QualType T) { |
| 3932 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3933 | std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); |
| 3934 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3935 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3936 | TypeID ASTWriter::getTypeID(QualType T) const { |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3937 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3938 | std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | TypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { |
| 3942 | if (T.isNull()) |
| 3943 | return TypeIdx(); |
| 3944 | assert(!T.getLocalFastQualifiers()); |
| 3945 | |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 3946 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3947 | if (Idx.getIndex() == 0) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3948 | if (DoneWritingDeclsAndTypes) { |
| 3949 | assert(0 && "New type seen after serializing all the types to emit!"); |
| 3950 | return TypeIdx(); |
| 3951 | } |
| 3952 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3953 | // We haven't seen this type before. Assign it a new ID and put it |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3954 | // into the queue of types to emit. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3955 | Idx = TypeIdx(NextTypeID++); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3956 | DeclTypesToEmit.push(T); |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3957 | } |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3958 | return Idx; |
| 3959 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3960 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3961 | TypeIdx ASTWriter::getTypeIdx(QualType T) const { |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3962 | if (T.isNull()) |
| 3963 | return TypeIdx(); |
| 3964 | assert(!T.getLocalFastQualifiers()); |
| 3965 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3966 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3967 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 3968 | return I->second; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3969 | } |
| 3970 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3971 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3972 | Record.push_back(GetDeclRef(D)); |
| 3973 | } |
| 3974 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3975 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 3976 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); |
| 3977 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3978 | if (D == 0) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3979 | return 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3980 | } |
Douglas Gregor | 1c7946a | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 3981 | |
| 3982 | // If D comes from an AST file, its declaration ID is already known and |
| 3983 | // fixed. |
| 3984 | if (D->isFromASTFile()) |
| 3985 | return D->getGlobalID(); |
| 3986 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3987 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3988 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3989 | if (ID == 0) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 3990 | if (DoneWritingDeclsAndTypes) { |
| 3991 | assert(0 && "New decl seen after serializing all the decls to emit!"); |
| 3992 | return 0; |
| 3993 | } |
| 3994 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3995 | // We haven't seen this declaration before. Give it a new ID and |
| 3996 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3997 | ID = NextDeclID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3998 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3999 | } |
| 4000 | |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 4001 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4004 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4005 | if (D == 0) |
| 4006 | return 0; |
| 4007 | |
Douglas Gregor | 1c7946a | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 4008 | // If D comes from an AST file, its declaration ID is already known and |
| 4009 | // fixed. |
| 4010 | if (D->isFromASTFile()) |
| 4011 | return D->getGlobalID(); |
| 4012 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4013 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 4014 | return DeclIDs[D]; |
| 4015 | } |
| 4016 | |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4017 | static inline bool compLocDecl(std::pair<unsigned, serialization::DeclID> L, |
| 4018 | std::pair<unsigned, serialization::DeclID> R) { |
| 4019 | return L.first < R.first; |
| 4020 | } |
| 4021 | |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4022 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4023 | assert(ID); |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4024 | assert(D); |
| 4025 | |
| 4026 | SourceLocation Loc = D->getLocation(); |
| 4027 | if (Loc.isInvalid()) |
| 4028 | return; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4029 | |
| 4030 | // We only keep track of the file-level declarations of each file. |
| 4031 | if (!D->getLexicalDeclContext()->isFileContext()) |
| 4032 | return; |
Argyrios Kyrtzidis | 69015c2 | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 4033 | // FIXME: ParmVarDecls that are part of a function type of a parameter of |
| 4034 | // a function/objc method, should not have TU as lexical context. |
Argyrios Kyrtzidis | 8cceefa | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 4035 | if (isa<ParmVarDecl>(D)) |
| 4036 | return; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4037 | |
| 4038 | SourceManager &SM = Context->getSourceManager(); |
Argyrios Kyrtzidis | 19645d2 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 4039 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4040 | assert(SM.isLocalSourceLocation(FileLoc)); |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4041 | FileID FID; |
| 4042 | unsigned Offset; |
| 4043 | llvm::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4044 | if (FID.isInvalid()) |
| 4045 | return; |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4046 | assert(SM.getSLocEntry(FID).isFile()); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4047 | |
Argyrios Kyrtzidis | a2ea4d9 | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 4048 | DeclIDInFileInfo *&Info = FileDeclIDs[FID]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4049 | if (!Info) |
| 4050 | Info = new DeclIDInFileInfo(); |
| 4051 | |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4052 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4053 | LocDeclIDsTy &Decls = Info->DeclIDs; |
| 4054 | |
Argyrios Kyrtzidis | fab8d5b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 4055 | if (Decls.empty() || Decls.back().first <= Offset) { |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4056 | Decls.push_back(LocDecl); |
| 4057 | return; |
| 4058 | } |
| 4059 | |
| 4060 | LocDeclIDsTy::iterator |
| 4061 | I = std::upper_bound(Decls.begin(), Decls.end(), LocDecl, compLocDecl); |
| 4062 | |
| 4063 | Decls.insert(I, LocDecl); |
| 4064 | } |
| 4065 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4066 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 4067 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4068 | Record.push_back(Name.getNameKind()); |
| 4069 | switch (Name.getNameKind()) { |
| 4070 | case DeclarationName::Identifier: |
| 4071 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 4072 | break; |
| 4073 | |
| 4074 | case DeclarationName::ObjCZeroArgSelector: |
| 4075 | case DeclarationName::ObjCOneArgSelector: |
| 4076 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4077 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4078 | break; |
| 4079 | |
| 4080 | case DeclarationName::CXXConstructorName: |
| 4081 | case DeclarationName::CXXDestructorName: |
| 4082 | case DeclarationName::CXXConversionFunctionName: |
| 4083 | AddTypeRef(Name.getCXXNameType(), Record); |
| 4084 | break; |
| 4085 | |
| 4086 | case DeclarationName::CXXOperatorName: |
| 4087 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 4088 | break; |
| 4089 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4090 | case DeclarationName::CXXLiteralOperatorName: |
| 4091 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 4092 | break; |
| 4093 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4094 | case DeclarationName::CXXUsingDirective: |
| 4095 | // No extra data to emit |
| 4096 | break; |
| 4097 | } |
| 4098 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4099 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4100 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4101 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4102 | switch (Name.getNameKind()) { |
| 4103 | case DeclarationName::CXXConstructorName: |
| 4104 | case DeclarationName::CXXDestructorName: |
| 4105 | case DeclarationName::CXXConversionFunctionName: |
| 4106 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 4107 | break; |
| 4108 | |
| 4109 | case DeclarationName::CXXOperatorName: |
| 4110 | AddSourceLocation( |
| 4111 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 4112 | Record); |
| 4113 | AddSourceLocation( |
| 4114 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 4115 | Record); |
| 4116 | break; |
| 4117 | |
| 4118 | case DeclarationName::CXXLiteralOperatorName: |
| 4119 | AddSourceLocation( |
| 4120 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 4121 | Record); |
| 4122 | break; |
| 4123 | |
| 4124 | case DeclarationName::Identifier: |
| 4125 | case DeclarationName::ObjCZeroArgSelector: |
| 4126 | case DeclarationName::ObjCOneArgSelector: |
| 4127 | case DeclarationName::ObjCMultiArgSelector: |
| 4128 | case DeclarationName::CXXUsingDirective: |
| 4129 | break; |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4134 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4135 | AddDeclarationName(NameInfo.getName(), Record); |
| 4136 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 4137 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 4138 | } |
| 4139 | |
| 4140 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4141 | RecordDataImpl &Record) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4142 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4143 | Record.push_back(Info.NumTemplParamLists); |
| 4144 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 4145 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 4146 | } |
| 4147 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4148 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4149 | RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4150 | // Nested name specifiers usually aren't too long. I think that 8 would |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 4151 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4152 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4153 | |
| 4154 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 4155 | while (NNS) { |
| 4156 | NestedNames.push_back(NNS); |
| 4157 | NNS = NNS->getPrefix(); |
| 4158 | } |
| 4159 | |
| 4160 | Record.push_back(NestedNames.size()); |
| 4161 | while(!NestedNames.empty()) { |
| 4162 | NNS = NestedNames.pop_back_val(); |
| 4163 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 4164 | Record.push_back(Kind); |
| 4165 | switch (Kind) { |
| 4166 | case NestedNameSpecifier::Identifier: |
| 4167 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 4168 | break; |
| 4169 | |
| 4170 | case NestedNameSpecifier::Namespace: |
| 4171 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 4172 | break; |
| 4173 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 4174 | case NestedNameSpecifier::NamespaceAlias: |
| 4175 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 4176 | break; |
| 4177 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4178 | case NestedNameSpecifier::TypeSpec: |
| 4179 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4180 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 4181 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4182 | break; |
| 4183 | |
| 4184 | case NestedNameSpecifier::Global: |
| 4185 | // Don't need to write an associated value. |
| 4186 | break; |
| 4187 | } |
| 4188 | } |
| 4189 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4190 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4191 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 4192 | RecordDataImpl &Record) { |
| 4193 | // Nested name specifiers usually aren't too long. I think that 8 would |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 4194 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4195 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 4196 | |
| 4197 | // Push each of the nested-name-specifiers's onto a stack for |
| 4198 | // serialization in reverse order. |
| 4199 | while (NNS) { |
| 4200 | NestedNames.push_back(NNS); |
| 4201 | NNS = NNS.getPrefix(); |
| 4202 | } |
| 4203 | |
| 4204 | Record.push_back(NestedNames.size()); |
| 4205 | while(!NestedNames.empty()) { |
| 4206 | NNS = NestedNames.pop_back_val(); |
| 4207 | NestedNameSpecifier::SpecifierKind Kind |
| 4208 | = NNS.getNestedNameSpecifier()->getKind(); |
| 4209 | Record.push_back(Kind); |
| 4210 | switch (Kind) { |
| 4211 | case NestedNameSpecifier::Identifier: |
| 4212 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 4213 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4214 | break; |
| 4215 | |
| 4216 | case NestedNameSpecifier::Namespace: |
| 4217 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 4218 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4219 | break; |
| 4220 | |
| 4221 | case NestedNameSpecifier::NamespaceAlias: |
| 4222 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 4223 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 4224 | break; |
| 4225 | |
| 4226 | case NestedNameSpecifier::TypeSpec: |
| 4227 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4228 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 4229 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 4230 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4231 | break; |
| 4232 | |
| 4233 | case NestedNameSpecifier::Global: |
| 4234 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 4235 | break; |
| 4236 | } |
| 4237 | } |
| 4238 | } |
| 4239 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4240 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4241 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4242 | Record.push_back(Kind); |
| 4243 | switch (Kind) { |
| 4244 | case TemplateName::Template: |
| 4245 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 4246 | break; |
| 4247 | |
| 4248 | case TemplateName::OverloadedTemplate: { |
| 4249 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 4250 | Record.push_back(OvT->size()); |
| 4251 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 4252 | I != E; ++I) |
| 4253 | AddDeclRef(*I, Record); |
| 4254 | break; |
| 4255 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4256 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4257 | case TemplateName::QualifiedTemplate: { |
| 4258 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 4259 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 4260 | Record.push_back(QualT->hasTemplateKeyword()); |
| 4261 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 4262 | break; |
| 4263 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4264 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4265 | case TemplateName::DependentTemplate: { |
| 4266 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 4267 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 4268 | Record.push_back(DepT->isIdentifier()); |
| 4269 | if (DepT->isIdentifier()) |
| 4270 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 4271 | else |
| 4272 | Record.push_back(DepT->getOperator()); |
| 4273 | break; |
| 4274 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4275 | |
| 4276 | case TemplateName::SubstTemplateTemplateParm: { |
| 4277 | SubstTemplateTemplateParmStorage *subst |
| 4278 | = Name.getAsSubstTemplateTemplateParm(); |
| 4279 | AddDeclRef(subst->getParameter(), Record); |
| 4280 | AddTemplateName(subst->getReplacement(), Record); |
| 4281 | break; |
| 4282 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4283 | |
| 4284 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4285 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 4286 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 4287 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 4288 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 4289 | break; |
| 4290 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4291 | } |
| 4292 | } |
| 4293 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4294 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4295 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4296 | Record.push_back(Arg.getKind()); |
| 4297 | switch (Arg.getKind()) { |
| 4298 | case TemplateArgument::Null: |
| 4299 | break; |
| 4300 | case TemplateArgument::Type: |
| 4301 | AddTypeRef(Arg.getAsType(), Record); |
| 4302 | break; |
| 4303 | case TemplateArgument::Declaration: |
| 4304 | AddDeclRef(Arg.getAsDecl(), Record); |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4305 | Record.push_back(Arg.isDeclForReferenceParam()); |
| 4306 | break; |
| 4307 | case TemplateArgument::NullPtr: |
| 4308 | AddTypeRef(Arg.getNullPtrType(), Record); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4309 | break; |
| 4310 | case TemplateArgument::Integral: |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 4311 | AddAPSInt(Arg.getAsIntegral(), Record); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4312 | AddTypeRef(Arg.getIntegralType(), Record); |
| 4313 | break; |
| 4314 | case TemplateArgument::Template: |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4315 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 4316 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4317 | case TemplateArgument::TemplateExpansion: |
| 4318 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4319 | if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
| 4320 | Record.push_back(*NumExpansions + 1); |
| 4321 | else |
| 4322 | Record.push_back(0); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4323 | break; |
| 4324 | case TemplateArgument::Expression: |
| 4325 | AddStmt(Arg.getAsExpr()); |
| 4326 | break; |
| 4327 | case TemplateArgument::Pack: |
| 4328 | Record.push_back(Arg.pack_size()); |
| 4329 | for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); |
| 4330 | I != E; ++I) |
| 4331 | AddTemplateArgument(*I, Record); |
| 4332 | break; |
| 4333 | } |
| 4334 | } |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4335 | |
| 4336 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4337 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4338 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4339 | assert(TemplateParams && "No TemplateParams!"); |
| 4340 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 4341 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 4342 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 4343 | Record.push_back(TemplateParams->size()); |
| 4344 | for (TemplateParameterList::const_iterator |
| 4345 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 4346 | P != PEnd; ++P) |
| 4347 | AddDeclRef(*P, Record); |
| 4348 | } |
| 4349 | |
| 4350 | /// \brief Emit a template argument list. |
| 4351 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4352 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4353 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4354 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4355 | Record.push_back(TemplateArgs->size()); |
| 4356 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4357 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 4358 | } |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4359 | |
| 4360 | |
| 4361 | void |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4362 | ASTWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4363 | Record.push_back(Set.size()); |
| 4364 | for (UnresolvedSetImpl::const_iterator |
| 4365 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 4366 | AddDeclRef(I.getDecl(), Record); |
| 4367 | Record.push_back(I.getAccess()); |
| 4368 | } |
| 4369 | } |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4370 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4371 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4372 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4373 | Record.push_back(Base.isVirtual()); |
| 4374 | Record.push_back(Base.isBaseOfClass()); |
| 4375 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 4376 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4377 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4378 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 4379 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 4380 | : SourceLocation(), |
| 4381 | Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4382 | } |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4383 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4384 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 4385 | RecordData Record; |
| 4386 | for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { |
| 4387 | Record.clear(); |
| 4388 | |
| 4389 | // Record the offset of this base-specifier set. |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4390 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4391 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 4392 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 4393 | else { |
| 4394 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 4395 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 4396 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 4397 | } |
| 4398 | |
| 4399 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 4400 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 4401 | Record.push_back(BEnd - B); |
| 4402 | for (; B != BEnd; ++B) |
| 4403 | AddCXXBaseSpecifier(*B, Record); |
| 4404 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | acec34b | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 4405 | |
| 4406 | // Flush any expressions that were written as part of the base specifiers. |
| 4407 | FlushStmts(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | CXXBaseSpecifiersToWrite.clear(); |
| 4411 | } |
| 4412 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 4413 | void ASTWriter::AddCXXCtorInitializers( |
| 4414 | const CXXCtorInitializer * const *CtorInitializers, |
| 4415 | unsigned NumCtorInitializers, |
| 4416 | RecordDataImpl &Record) { |
| 4417 | Record.push_back(NumCtorInitializers); |
| 4418 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 4419 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4420 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4421 | if (Init->isBaseInitializer()) { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4422 | Record.push_back(CTOR_INITIALIZER_BASE); |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4423 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4424 | Record.push_back(Init->isBaseVirtual()); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4425 | } else if (Init->isDelegatingInitializer()) { |
| 4426 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 4427 | AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4428 | } else if (Init->isMemberInitializer()){ |
| 4429 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 4430 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4431 | } else { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 4432 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 4433 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4434 | } |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 4435 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4436 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 4437 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4438 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 4439 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 4440 | Record.push_back(Init->isWritten()); |
| 4441 | if (Init->isWritten()) { |
| 4442 | Record.push_back(Init->getSourceOrder()); |
| 4443 | } else { |
| 4444 | Record.push_back(Init->getNumArrayIndices()); |
| 4445 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 4446 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 4447 | } |
| 4448 | } |
| 4449 | } |
| 4450 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4451 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
| 4452 | assert(D->DefinitionData); |
| 4453 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4454 | Record.push_back(Data.IsLambda); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4455 | Record.push_back(Data.UserDeclaredConstructor); |
| 4456 | Record.push_back(Data.UserDeclaredCopyConstructor); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4457 | Record.push_back(Data.UserDeclaredMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4458 | Record.push_back(Data.UserDeclaredCopyAssignment); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4459 | Record.push_back(Data.UserDeclaredMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4460 | Record.push_back(Data.UserDeclaredDestructor); |
| 4461 | Record.push_back(Data.Aggregate); |
| 4462 | Record.push_back(Data.PlainOldData); |
| 4463 | Record.push_back(Data.Empty); |
| 4464 | Record.push_back(Data.Polymorphic); |
| 4465 | Record.push_back(Data.Abstract); |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 4466 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 4467 | Record.push_back(Data.HasNoNonEmptyBases); |
| 4468 | Record.push_back(Data.HasPrivateFields); |
| 4469 | Record.push_back(Data.HasProtectedFields); |
| 4470 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 4471 | Record.push_back(Data.HasMutableFields); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4472 | Record.push_back(Data.HasOnlyCMembers); |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 4473 | Record.push_back(Data.HasInClassInitializer); |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 4474 | Record.push_back(Data.HasTrivialDefaultConstructor); |
Richard Smith | 6b8bc07 | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 4475 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4476 | Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4477 | Record.push_back(Data.HasConstexprDefaultConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4478 | Record.push_back(Data.HasTrivialCopyConstructor); |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 4479 | Record.push_back(Data.HasTrivialMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4480 | Record.push_back(Data.HasTrivialCopyAssignment); |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 4481 | Record.push_back(Data.HasTrivialMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4482 | Record.push_back(Data.HasTrivialDestructor); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4483 | Record.push_back(Data.HasIrrelevantDestructor); |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 4484 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4485 | Record.push_back(Data.ComputedVisibleConversions); |
Sean Hunt | cdee3fe | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 4486 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4487 | Record.push_back(Data.DeclaredDefaultConstructor); |
| 4488 | Record.push_back(Data.DeclaredCopyConstructor); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4489 | Record.push_back(Data.DeclaredMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4490 | Record.push_back(Data.DeclaredCopyAssignment); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 4491 | Record.push_back(Data.DeclaredMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4492 | Record.push_back(Data.DeclaredDestructor); |
Sebastian Redl | 14c3633 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 4493 | Record.push_back(Data.FailedImplicitMoveConstructor); |
| 4494 | Record.push_back(Data.FailedImplicitMoveAssignment); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 4495 | // IsLambda bit is already saved. |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4496 | |
| 4497 | Record.push_back(Data.NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4498 | if (Data.NumBases > 0) |
| 4499 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 4500 | Record); |
| 4501 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4502 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 4503 | Record.push_back(Data.NumVBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4504 | if (Data.NumVBases > 0) |
| 4505 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 4506 | Record); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4507 | |
| 4508 | AddUnresolvedSet(Data.Conversions, Record); |
| 4509 | AddUnresolvedSet(Data.VisibleConversions, Record); |
| 4510 | // Data.Definition is the owning decl, no need to write it. |
| 4511 | AddDeclRef(Data.FirstFriend, Record); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4512 | |
| 4513 | // Add lambda-specific data. |
| 4514 | if (Data.IsLambda) { |
| 4515 | CXXRecordDecl::LambdaDefinitionData &Lambda = D->getLambdaData(); |
Douglas Gregor | f4b7de1 | 2012-02-21 19:11:17 +0000 | [diff] [blame] | 4516 | Record.push_back(Lambda.Dependent); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4517 | Record.push_back(Lambda.NumCaptures); |
| 4518 | Record.push_back(Lambda.NumExplicitCaptures); |
Douglas Gregor | 9e8c92a | 2012-02-20 19:44:39 +0000 | [diff] [blame] | 4519 | Record.push_back(Lambda.ManglingNumber); |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 4520 | AddDeclRef(Lambda.ContextDecl, Record); |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 4521 | AddTypeSourceInfo(Lambda.MethodTyInfo, Record); |
Douglas Gregor | 9d36f5d | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 4522 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
| 4523 | LambdaExpr::Capture &Capture = Lambda.Captures[I]; |
| 4524 | AddSourceLocation(Capture.getLocation(), Record); |
| 4525 | Record.push_back(Capture.isImplicit()); |
| 4526 | Record.push_back(Capture.getCaptureKind()); // FIXME: stable! |
| 4527 | VarDecl *Var = Capture.capturesVariable()? Capture.getCapturedVar() : 0; |
| 4528 | AddDeclRef(Var, Record); |
| 4529 | AddSourceLocation(Capture.isPackExpansion()? Capture.getEllipsisLoc() |
| 4530 | : SourceLocation(), |
| 4531 | Record); |
| 4532 | } |
| 4533 | } |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 4534 | } |
| 4535 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4536 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4537 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4538 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4539 | assert(FirstDeclID == NextDeclID && |
| 4540 | FirstTypeID == NextTypeID && |
| 4541 | FirstIdentID == NextIdentID && |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4542 | FirstMacroID == NextMacroID && |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4543 | FirstSubmoduleID == NextSubmoduleID && |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4544 | FirstSelectorID == NextSelectorID && |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4545 | "Setting chain after writing has started."); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4546 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4547 | Chain = Reader; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4548 | |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4549 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 4550 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 4551 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4552 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4553 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 4554 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4555 | NextDeclID = FirstDeclID; |
| 4556 | NextTypeID = FirstTypeID; |
| 4557 | NextIdentID = FirstIdentID; |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4558 | NextMacroID = FirstMacroID; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4559 | NextSelectorID = FirstSelectorID; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4560 | NextSubmoduleID = FirstSubmoduleID; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 4561 | } |
| 4562 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4563 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4564 | IdentifierIDs[II] = ID; |
| 4565 | } |
| 4566 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4567 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { |
| 4568 | MacroIDs[MI] = ID; |
| 4569 | } |
| 4570 | |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4571 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4572 | // Always take the highest-numbered type index. This copes with an interesting |
| 4573 | // case for chained AST writing where we schedule writing the type and then, |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4574 | // later, deserialize the type from another AST. In this case, we want to |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4575 | // keep the higher-numbered entry so that we can properly write it out to |
| 4576 | // the AST file. |
| 4577 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 4578 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 4579 | StoredIdx = Idx; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4580 | } |
| 4581 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4582 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4583 | SelectorIDs[S] = ID; |
| 4584 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4585 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4586 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4587 | MacroDefinition *MD) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 4588 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4589 | MacroDefinitions[MD] = ID; |
| 4590 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4591 | |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 4592 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { |
| 4593 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); |
| 4594 | SubmoduleIDs[Mod] = ID; |
| 4595 | } |
| 4596 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4597 | void ASTWriter::UndefinedMacro(MacroInfo *MI) { |
| 4598 | MacroUpdates[MI].UndefLoc = MI->getUndefLoc(); |
| 4599 | } |
| 4600 | |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4601 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4602 | assert(D->isCompleteDefinition()); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4603 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4604 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 4605 | // We are interested when a PCH decl is modified. |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4606 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4607 | // A forward reference was mutated into a definition. Rewrite it. |
| 4608 | // FIXME: This happens during template instantiation, should we |
| 4609 | // have created a new definition decl instead ? |
Argyrios Kyrtzidis | d3d0755 | 2010-10-28 07:38:45 +0000 | [diff] [blame] | 4610 | RewriteDecl(RD); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4611 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4612 | } |
| 4613 | } |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4614 | |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4615 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4616 | assert(!WritingAST && "Already writing the AST!"); |
| 4617 | |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4618 | // TU and namespaces are handled elsewhere. |
| 4619 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 4620 | return; |
| 4621 | |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4622 | if (!(!D->isFromASTFile() && cast<Decl>(DC)->isFromASTFile())) |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4623 | return; // Not a source decl added to a DeclContext from PCH. |
| 4624 | |
| 4625 | AddUpdatedDeclContext(DC); |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4626 | UpdatingVisibleDecls.push_back(D); |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4627 | } |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4628 | |
| 4629 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4630 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4631 | assert(D->isImplicit()); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4632 | if (!(!D->isFromASTFile() && RD->isFromASTFile())) |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4633 | return; // Not a source member added to a class from PCH. |
| 4634 | if (!isa<CXXMethodDecl>(D)) |
| 4635 | return; // We are interested in lazily declared implicit methods. |
| 4636 | |
| 4637 | // A decl coming from PCH was modified. |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4638 | assert(RD->isCompleteDefinition()); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4639 | UpdateRecord &Record = DeclUpdates[RD]; |
| 4640 | Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4641 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4642 | } |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4643 | |
| 4644 | void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, |
| 4645 | const ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 4646 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4647 | assert(!WritingAST && "Already writing the AST!"); |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 4648 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4649 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4650 | return; // Not a source specialization added to a template from PCH. |
| 4651 | |
| 4652 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4653 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4654 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4655 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 4656 | |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4657 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 4658 | const FunctionDecl *D) { |
| 4659 | // The specializations set is kept in the canonical template. |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4660 | assert(!WritingAST && "Already writing the AST!"); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4661 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4662 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4663 | return; // Not a source specialization added to a template from PCH. |
| 4664 | |
| 4665 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4666 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4667 | Record.push_back(reinterpret_cast<uint64_t>(D)); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4668 | } |
| 4669 | |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 4670 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4671 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4672 | if (!D->isFromASTFile()) |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 4673 | return; // Declaration not imported from PCH. |
| 4674 | |
| 4675 | // Implicit decl from a PCH was defined. |
| 4676 | // FIXME: Should implicit definition be a separate FunctionDecl? |
| 4677 | RewriteDecl(D); |
| 4678 | } |
| 4679 | |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4680 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4681 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4682 | if (!D->isFromASTFile()) |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4683 | return; |
| 4684 | |
| 4685 | // Since the actual instantiation is delayed, this really means that we need |
| 4686 | // to update the instantiation location. |
| 4687 | UpdateRecord &Record = DeclUpdates[D]; |
| 4688 | Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER); |
| 4689 | AddSourceLocation( |
| 4690 | D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record); |
| 4691 | } |
| 4692 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4693 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 4694 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 61c5e34 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4695 | assert(!WritingAST && "Already writing the AST!"); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4696 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4697 | return; // Declaration not imported from PCH. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4698 | |
| 4699 | assert(IFD->getDefinition() && "Category on a class without a definition?"); |
| 4700 | ObjCClassesWithCategories.insert( |
| 4701 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4702 | } |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 4703 | |
Argyrios Kyrtzidis | 1a43415 | 2011-11-12 21:07:52 +0000 | [diff] [blame] | 4704 | |
Argyrios Kyrtzidis | c80553e | 2011-11-14 04:52:29 +0000 | [diff] [blame] | 4705 | void ASTWriter::AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop, |
| 4706 | const ObjCPropertyDecl *OrigProp, |
| 4707 | const ObjCCategoryDecl *ClassExt) { |
| 4708 | const ObjCInterfaceDecl *D = ClassExt->getClassInterface(); |
| 4709 | if (!D) |
| 4710 | return; |
| 4711 | |
| 4712 | assert(!WritingAST && "Already writing the AST!"); |
| 4713 | if (!D->isFromASTFile()) |
| 4714 | return; // Declaration not imported from PCH. |
| 4715 | |
| 4716 | RewriteDecl(D); |
| 4717 | } |