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" |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 15 | #include "clang/Serialization/ASTSerializationListener.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 17 | #include "clang/Sema/Sema.h" |
| 18 | #include "clang/Sema/IdentifierResolver.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTContext.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclContextInternals.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclTemplate.h" |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclFriend.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 26 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 27 | #include "clang/AST/TypeLocVisitor.h" |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 28 | #include "clang/Serialization/ASTReader.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 29 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 30 | #include "clang/Lex/PreprocessingRecord.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 31 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 32 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 34 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 35 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 36 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 37 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 38 | #include "clang/Basic/TargetInfo.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) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 95 | assert(false && "Built-in types are never serialized"); |
| 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()); |
| 189 | Record.push_back(T->getTypeQuals()); |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 190 | Record.push_back(static_cast<unsigned>(T->getRefQualifier())); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 191 | Record.push_back(T->getExceptionSpecType()); |
| 192 | if (T->getExceptionSpecType() == EST_Dynamic) { |
| 193 | Record.push_back(T->getNumExceptions()); |
| 194 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 195 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
| 196 | } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 197 | Writer.AddStmt(T->getNoexceptExpr()); |
| 198 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 199 | Code = TYPE_FUNCTION_PROTO; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 202 | void ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 203 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 204 | Code = TYPE_UNRESOLVED_USING; |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 205 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 206 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 207 | void ASTTypeWriter::VisitTypedefType(const TypedefType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 208 | Writer.AddDeclRef(T->getDecl(), Record); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 209 | assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); |
| 210 | Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 211 | Code = TYPE_TYPEDEF; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 214 | void ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 215 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 216 | Code = TYPE_TYPEOF_EXPR; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 219 | void ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 220 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 221 | Code = TYPE_TYPEOF; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 224 | void ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 225 | Writer.AddStmt(T->getUnderlyingExpr()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 226 | Code = TYPE_DECLTYPE; |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 229 | void ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 230 | Writer.AddTypeRef(T->getBaseType(), Record); |
| 231 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 232 | Record.push_back(T->getUTTKind()); |
| 233 | Code = TYPE_UNARY_TRANSFORM; |
| 234 | } |
| 235 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 236 | void ASTTypeWriter::VisitAutoType(const AutoType *T) { |
| 237 | Writer.AddTypeRef(T->getDeducedType(), Record); |
| 238 | Code = TYPE_AUTO; |
| 239 | } |
| 240 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 241 | void ASTTypeWriter::VisitTagType(const TagType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 242 | Record.push_back(T->isDependentType()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 243 | Writer.AddDeclRef(T->getDecl(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | assert(!T->isBeingDefined() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 245 | "Cannot serialize in the middle of a type definition"); |
| 246 | } |
| 247 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 248 | void ASTTypeWriter::VisitRecordType(const RecordType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 249 | VisitTagType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 250 | Code = TYPE_RECORD; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 253 | void ASTTypeWriter::VisitEnumType(const EnumType *T) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 254 | VisitTagType(T); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 255 | Code = TYPE_ENUM; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 256 | } |
| 257 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 258 | void ASTTypeWriter::VisitAttributedType(const AttributedType *T) { |
| 259 | Writer.AddTypeRef(T->getModifiedType(), Record); |
| 260 | Writer.AddTypeRef(T->getEquivalentType(), Record); |
| 261 | Record.push_back(T->getAttrKind()); |
| 262 | Code = TYPE_ATTRIBUTED; |
| 263 | } |
| 264 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 266 | ASTTypeWriter::VisitSubstTemplateTypeParmType( |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 267 | const SubstTemplateTypeParmType *T) { |
| 268 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 269 | Writer.AddTypeRef(T->getReplacementType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 270 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | void |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 274 | ASTTypeWriter::VisitSubstTemplateTypeParmPackType( |
| 275 | const SubstTemplateTypeParmPackType *T) { |
| 276 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 277 | Writer.AddTemplateArgument(T->getArgumentPack(), Record); |
| 278 | Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; |
| 279 | } |
| 280 | |
| 281 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 282 | ASTTypeWriter::VisitTemplateSpecializationType( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 283 | const TemplateSpecializationType *T) { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 284 | Record.push_back(T->isDependentType()); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 285 | Writer.AddTemplateName(T->getTemplateName(), Record); |
| 286 | Record.push_back(T->getNumArgs()); |
| 287 | for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); |
| 288 | ArgI != ArgE; ++ArgI) |
| 289 | Writer.AddTemplateArgument(*ArgI, Record); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 290 | Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : |
| 291 | T->isCanonicalUnqualified() ? QualType() |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 292 | : T->getCanonicalTypeInternal(), |
| 293 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 294 | Code = TYPE_TEMPLATE_SPECIALIZATION; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 298 | ASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 299 | VisitArrayType(T); |
| 300 | Writer.AddStmt(T->getSizeExpr()); |
| 301 | Writer.AddSourceRange(T->getBracketsRange(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 302 | Code = TYPE_DEPENDENT_SIZED_ARRAY; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 306 | ASTTypeWriter::VisitDependentSizedExtVectorType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 307 | const DependentSizedExtVectorType *T) { |
| 308 | // FIXME: Serialize this type (C++ only) |
| 309 | assert(false && "Cannot serialize dependent sized extended vector types"); |
| 310 | } |
| 311 | |
| 312 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 313 | ASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 314 | Record.push_back(T->getDepth()); |
| 315 | Record.push_back(T->getIndex()); |
| 316 | Record.push_back(T->isParameterPack()); |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 317 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 318 | Code = TYPE_TEMPLATE_TYPE_PARM; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 322 | ASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 323 | Record.push_back(T->getKeyword()); |
| 324 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 325 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
Argyrios Kyrtzidis | f48d45e | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 326 | Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() |
| 327 | : T->getCanonicalTypeInternal(), |
| 328 | Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 329 | Code = TYPE_DEPENDENT_NAME; |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 333 | ASTTypeWriter::VisitDependentTemplateSpecializationType( |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 334 | const DependentTemplateSpecializationType *T) { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 335 | Record.push_back(T->getKeyword()); |
| 336 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 337 | Writer.AddIdentifierRef(T->getIdentifier(), Record); |
| 338 | Record.push_back(T->getNumArgs()); |
| 339 | for (DependentTemplateSpecializationType::iterator |
| 340 | I = T->begin(), E = T->end(); I != E; ++I) |
| 341 | Writer.AddTemplateArgument(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 342 | Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 345 | void ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { |
| 346 | Writer.AddTypeRef(T->getPattern(), Record); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 347 | if (llvm::Optional<unsigned> NumExpansions = T->getNumExpansions()) |
| 348 | Record.push_back(*NumExpansions + 1); |
| 349 | else |
| 350 | Record.push_back(0); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 351 | Code = TYPE_PACK_EXPANSION; |
| 352 | } |
| 353 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 354 | void ASTTypeWriter::VisitParenType(const ParenType *T) { |
| 355 | Writer.AddTypeRef(T->getInnerType(), Record); |
| 356 | Code = TYPE_PAREN; |
| 357 | } |
| 358 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 359 | void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 360 | Record.push_back(T->getKeyword()); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 361 | Writer.AddNestedNameSpecifier(T->getQualifier(), Record); |
| 362 | Writer.AddTypeRef(T->getNamedType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 363 | Code = TYPE_ELABORATED; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 366 | void ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 367 | Writer.AddDeclRef(T->getDecl(), Record); |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 368 | Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 369 | Code = TYPE_INJECTED_CLASS_NAME; |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 372 | void ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 373 | Writer.AddDeclRef(T->getDecl(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 374 | Code = TYPE_OBJC_INTERFACE; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 377 | void ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 378 | Writer.AddTypeRef(T->getBaseType(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 379 | Record.push_back(T->getNumProtocols()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 380 | for (ObjCObjectType::qual_iterator I = T->qual_begin(), |
Steve Naroff | 446ee4e | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 381 | E = T->qual_end(); I != E; ++I) |
| 382 | Writer.AddDeclRef(*I, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 383 | Code = TYPE_OBJC_OBJECT; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 386 | void |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 387 | ASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 389 | Code = TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 390 | } |
| 391 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 392 | namespace { |
| 393 | |
| 394 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 395 | ASTWriter &Writer; |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 396 | ASTWriter::RecordDataImpl &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 397 | |
| 398 | public: |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 399 | TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 400 | : Writer(Writer), Record(Record) { } |
| 401 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 402 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 403 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 404 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 405 | #include "clang/AST/TypeLocNodes.def" |
| 406 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 407 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 408 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | } |
| 412 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 413 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 414 | // nothing to do |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 415 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 416 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 417 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 418 | if (TL.needsExtraLocalData()) { |
| 419 | Record.push_back(TL.getWrittenTypeSpec()); |
| 420 | Record.push_back(TL.getWrittenSignSpec()); |
| 421 | Record.push_back(TL.getWrittenWidthSpec()); |
| 422 | Record.push_back(TL.hasModeAttr()); |
| 423 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 424 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 425 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 426 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 427 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 428 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 429 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 430 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 431 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 432 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 433 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 434 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 435 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 436 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 437 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 438 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 439 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 440 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 441 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 442 | Writer.AddTypeSourceInfo(TL.getClassTInfo(), 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::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 445 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 446 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 447 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 448 | if (TL.getSizeExpr()) |
| 449 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 450 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 451 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 452 | VisitArrayTypeLoc(TL); |
| 453 | } |
| 454 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 455 | VisitArrayTypeLoc(TL); |
| 456 | } |
| 457 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 458 | VisitArrayTypeLoc(TL); |
| 459 | } |
| 460 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 461 | DependentSizedArrayTypeLoc TL) { |
| 462 | VisitArrayTypeLoc(TL); |
| 463 | } |
| 464 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 465 | DependentSizedExtVectorTypeLoc TL) { |
| 466 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 467 | } |
| 468 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 469 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 470 | } |
| 471 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 472 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 473 | } |
| 474 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 475 | Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); |
| 476 | Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 477 | Record.push_back(TL.getTrailingReturn()); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 478 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 479 | Writer.AddDeclRef(TL.getArg(i), Record); |
| 480 | } |
| 481 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 482 | VisitFunctionTypeLoc(TL); |
| 483 | } |
| 484 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 485 | VisitFunctionTypeLoc(TL); |
| 486 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 487 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 488 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 489 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 490 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 491 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 492 | } |
| 493 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 494 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 495 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 496 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 497 | } |
| 498 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 499 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 500 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 501 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 502 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 503 | } |
| 504 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 505 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 506 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 507 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 508 | Writer.AddSourceLocation(TL.getKWLoc(), Record); |
| 509 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 510 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 511 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
| 512 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 513 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 514 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 515 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 516 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 517 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 518 | } |
| 519 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 520 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 521 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 522 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 523 | Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); |
| 524 | if (TL.hasAttrOperand()) { |
| 525 | SourceRange range = TL.getAttrOperandParensRange(); |
| 526 | Writer.AddSourceLocation(range.getBegin(), Record); |
| 527 | Writer.AddSourceLocation(range.getEnd(), Record); |
| 528 | } |
| 529 | if (TL.hasAttrExprOperand()) { |
| 530 | Expr *operand = TL.getAttrExprOperand(); |
| 531 | Record.push_back(operand ? 1 : 0); |
| 532 | if (operand) Writer.AddStmt(operand); |
| 533 | } else if (TL.hasAttrEnumOperand()) { |
| 534 | Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); |
| 535 | } |
| 536 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 537 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 538 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 539 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 540 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 541 | SubstTemplateTypeParmTypeLoc TL) { |
| 542 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 543 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 544 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( |
| 545 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 546 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 547 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 548 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 549 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 550 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 551 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 552 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 553 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 554 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), |
| 555 | TL.getArgLoc(i).getLocInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 556 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 557 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 558 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 559 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 560 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 561 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 562 | Writer.AddSourceLocation(TL.getKeywordLoc(), Record); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 563 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 564 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 565 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 566 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 567 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 568 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 569 | Writer.AddSourceLocation(TL.getKeywordLoc(), Record); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 570 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 571 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 572 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 573 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( |
| 574 | DependentTemplateSpecializationTypeLoc TL) { |
| 575 | Writer.AddSourceLocation(TL.getKeywordLoc(), Record); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 576 | Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 577 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 578 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 579 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 580 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 581 | Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), |
| 582 | TL.getArgLoc(I).getLocInfo(), Record); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 583 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 584 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 585 | Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); |
| 586 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 587 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 588 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 589 | } |
| 590 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 591 | Record.push_back(TL.hasBaseTypeAsWritten()); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 592 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 593 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 594 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 595 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 596 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 597 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 598 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 599 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 600 | |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 601 | //===----------------------------------------------------------------------===// |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 602 | // ASTWriter Implementation |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 603 | //===----------------------------------------------------------------------===// |
| 604 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 605 | static void EmitBlockID(unsigned ID, const char *Name, |
| 606 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 607 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 608 | Record.clear(); |
| 609 | Record.push_back(ID); |
| 610 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 611 | |
| 612 | // Emit the block name if present. |
| 613 | if (Name == 0 || Name[0] == 0) return; |
| 614 | Record.clear(); |
| 615 | while (*Name) |
| 616 | Record.push_back(*Name++); |
| 617 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 618 | } |
| 619 | |
| 620 | static void EmitRecordID(unsigned ID, const char *Name, |
| 621 | llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 622 | ASTWriter::RecordDataImpl &Record) { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 623 | Record.clear(); |
| 624 | Record.push_back(ID); |
| 625 | while (*Name) |
| 626 | Record.push_back(*Name++); |
| 627 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 631 | ASTWriter::RecordDataImpl &Record) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 632 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 633 | RECORD(STMT_STOP); |
| 634 | RECORD(STMT_NULL_PTR); |
| 635 | RECORD(STMT_NULL); |
| 636 | RECORD(STMT_COMPOUND); |
| 637 | RECORD(STMT_CASE); |
| 638 | RECORD(STMT_DEFAULT); |
| 639 | RECORD(STMT_LABEL); |
| 640 | RECORD(STMT_IF); |
| 641 | RECORD(STMT_SWITCH); |
| 642 | RECORD(STMT_WHILE); |
| 643 | RECORD(STMT_DO); |
| 644 | RECORD(STMT_FOR); |
| 645 | RECORD(STMT_GOTO); |
| 646 | RECORD(STMT_INDIRECT_GOTO); |
| 647 | RECORD(STMT_CONTINUE); |
| 648 | RECORD(STMT_BREAK); |
| 649 | RECORD(STMT_RETURN); |
| 650 | RECORD(STMT_DECL); |
| 651 | RECORD(STMT_ASM); |
| 652 | RECORD(EXPR_PREDEFINED); |
| 653 | RECORD(EXPR_DECL_REF); |
| 654 | RECORD(EXPR_INTEGER_LITERAL); |
| 655 | RECORD(EXPR_FLOATING_LITERAL); |
| 656 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 657 | RECORD(EXPR_STRING_LITERAL); |
| 658 | RECORD(EXPR_CHARACTER_LITERAL); |
| 659 | RECORD(EXPR_PAREN); |
| 660 | RECORD(EXPR_UNARY_OPERATOR); |
| 661 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 662 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 663 | RECORD(EXPR_CALL); |
| 664 | RECORD(EXPR_MEMBER); |
| 665 | RECORD(EXPR_BINARY_OPERATOR); |
| 666 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 667 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 668 | RECORD(EXPR_IMPLICIT_CAST); |
| 669 | RECORD(EXPR_CSTYLE_CAST); |
| 670 | RECORD(EXPR_COMPOUND_LITERAL); |
| 671 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 672 | RECORD(EXPR_INIT_LIST); |
| 673 | RECORD(EXPR_DESIGNATED_INIT); |
| 674 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 675 | RECORD(EXPR_VA_ARG); |
| 676 | RECORD(EXPR_ADDR_LABEL); |
| 677 | RECORD(EXPR_STMT); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 678 | RECORD(EXPR_CHOOSE); |
| 679 | RECORD(EXPR_GNU_NULL); |
| 680 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 681 | RECORD(EXPR_BLOCK); |
| 682 | RECORD(EXPR_BLOCK_DECL_REF); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 683 | RECORD(EXPR_GENERIC_SELECTION); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 684 | RECORD(EXPR_OBJC_STRING_LITERAL); |
| 685 | RECORD(EXPR_OBJC_ENCODE); |
| 686 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 687 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 688 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 689 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 690 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 691 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 692 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 693 | RECORD(STMT_OBJC_CATCH); |
| 694 | RECORD(STMT_OBJC_FINALLY); |
| 695 | RECORD(STMT_OBJC_AT_TRY); |
| 696 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 697 | RECORD(STMT_OBJC_AT_THROW); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 698 | RECORD(EXPR_CXX_OPERATOR_CALL); |
| 699 | RECORD(EXPR_CXX_CONSTRUCT); |
| 700 | RECORD(EXPR_CXX_STATIC_CAST); |
| 701 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 702 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 703 | RECORD(EXPR_CXX_CONST_CAST); |
| 704 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
| 705 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 706 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 707 | RECORD(EXPR_CXX_TYPEID_EXPR); |
| 708 | RECORD(EXPR_CXX_TYPEID_TYPE); |
| 709 | RECORD(EXPR_CXX_UUIDOF_EXPR); |
| 710 | RECORD(EXPR_CXX_UUIDOF_TYPE); |
| 711 | RECORD(EXPR_CXX_THIS); |
| 712 | RECORD(EXPR_CXX_THROW); |
| 713 | RECORD(EXPR_CXX_DEFAULT_ARG); |
| 714 | RECORD(EXPR_CXX_BIND_TEMPORARY); |
| 715 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); |
| 716 | RECORD(EXPR_CXX_NEW); |
| 717 | RECORD(EXPR_CXX_DELETE); |
| 718 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); |
| 719 | RECORD(EXPR_EXPR_WITH_CLEANUPS); |
| 720 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); |
| 721 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); |
| 722 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); |
| 723 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); |
| 724 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); |
| 725 | RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); |
| 726 | RECORD(EXPR_CXX_NOEXCEPT); |
| 727 | RECORD(EXPR_OPAQUE_VALUE); |
| 728 | RECORD(EXPR_BINARY_TYPE_TRAIT); |
| 729 | RECORD(EXPR_PACK_EXPANSION); |
| 730 | RECORD(EXPR_SIZEOF_PACK); |
| 731 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 732 | RECORD(EXPR_CUDA_KERNEL_CALL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 733 | #undef RECORD |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 736 | void ASTWriter::WriteBlockInfoBlock() { |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 737 | RecordData Record; |
| 738 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 740 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) |
| 741 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 743 | // AST Top-Level Block. |
Sebastian Redl | f29f0a2 | 2010-08-18 23:57:22 +0000 | [diff] [blame] | 744 | BLOCK(AST_BLOCK); |
Zhongxing Xu | 51e774d | 2009-06-03 09:23:28 +0000 | [diff] [blame] | 745 | RECORD(ORIGINAL_FILE_NAME); |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 746 | RECORD(ORIGINAL_FILE_ID); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 747 | RECORD(TYPE_OFFSET); |
| 748 | RECORD(DECL_OFFSET); |
| 749 | RECORD(LANGUAGE_OPTIONS); |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 750 | RECORD(METADATA); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 751 | RECORD(IDENTIFIER_OFFSET); |
| 752 | RECORD(IDENTIFIER_TABLE); |
| 753 | RECORD(EXTERNAL_DEFINITIONS); |
| 754 | RECORD(SPECIAL_TYPES); |
| 755 | RECORD(STATISTICS); |
| 756 | RECORD(TENTATIVE_DEFINITIONS); |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 757 | RECORD(UNUSED_FILESCOPED_DECLS); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 758 | RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); |
| 759 | RECORD(SELECTOR_OFFSETS); |
| 760 | RECORD(METHOD_POOL); |
| 761 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 762 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 763 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 764 | RECORD(STAT_CACHE); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 765 | RECORD(EXT_VECTOR_DECLS); |
Ted Kremenek | 5b4ec63 | 2010-01-22 20:59:36 +0000 | [diff] [blame] | 766 | RECORD(VERSION_CONTROL_BRANCH_REVISION); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 767 | RECORD(MACRO_DEFINITION_OFFSETS); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 768 | RECORD(IMPORTS); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 769 | RECORD(REFERENCED_SELECTOR_POOL); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 770 | RECORD(TU_UPDATE_LEXICAL); |
| 771 | RECORD(REDECLS_UPDATE_LATEST); |
| 772 | RECORD(SEMA_DECL_REFS); |
| 773 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); |
| 774 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); |
| 775 | RECORD(DECL_REPLACEMENTS); |
| 776 | RECORD(UPDATE_VISIBLE); |
| 777 | RECORD(DECL_UPDATE_OFFSETS); |
| 778 | RECORD(DECL_UPDATES); |
| 779 | RECORD(CXX_BASE_SPECIFIER_OFFSETS); |
| 780 | RECORD(DIAG_PRAGMA_MAPPINGS); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 781 | RECORD(CUDA_SPECIAL_DECL_REFS); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 782 | RECORD(HEADER_SEARCH_TABLE); |
Douglas Gregor | 837593f | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 783 | RECORD(ORIGINAL_PCH_DIR); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 784 | RECORD(FP_PRAGMA_OPTIONS); |
| 785 | RECORD(OPENCL_EXTENSIONS); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 786 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 787 | RECORD(FILE_SOURCE_LOCATION_OFFSETS); |
| 788 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | 837593f | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 789 | RECORD(MODULE_OFFSET_MAP); |
| 790 | RECORD(SOURCE_MANAGER_LINE_TABLE); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 791 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 792 | // SourceManager Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 793 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 794 | RECORD(SM_SLOC_FILE_ENTRY); |
| 795 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 796 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 797 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 799 | // Preprocessor Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 800 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 801 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 802 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 803 | RECORD(PP_TOKEN); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 804 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 805 | // Decls and Types block. |
| 806 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 807 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 808 | RECORD(TYPE_COMPLEX); |
| 809 | RECORD(TYPE_POINTER); |
| 810 | RECORD(TYPE_BLOCK_POINTER); |
| 811 | RECORD(TYPE_LVALUE_REFERENCE); |
| 812 | RECORD(TYPE_RVALUE_REFERENCE); |
| 813 | RECORD(TYPE_MEMBER_POINTER); |
| 814 | RECORD(TYPE_CONSTANT_ARRAY); |
| 815 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 816 | RECORD(TYPE_VARIABLE_ARRAY); |
| 817 | RECORD(TYPE_VECTOR); |
| 818 | RECORD(TYPE_EXT_VECTOR); |
| 819 | RECORD(TYPE_FUNCTION_PROTO); |
| 820 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 821 | RECORD(TYPE_TYPEDEF); |
| 822 | RECORD(TYPE_TYPEOF_EXPR); |
| 823 | RECORD(TYPE_TYPEOF); |
| 824 | RECORD(TYPE_RECORD); |
| 825 | RECORD(TYPE_ENUM); |
| 826 | RECORD(TYPE_OBJC_INTERFACE); |
John McCall | a53d2cb | 2010-05-16 02:12:35 +0000 | [diff] [blame] | 827 | RECORD(TYPE_OBJC_OBJECT); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 828 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 829 | RECORD(TYPE_DECLTYPE); |
| 830 | RECORD(TYPE_ELABORATED); |
| 831 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 832 | RECORD(TYPE_UNRESOLVED_USING); |
| 833 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 834 | RECORD(TYPE_OBJC_OBJECT); |
| 835 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 836 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 837 | RECORD(TYPE_DEPENDENT_NAME); |
| 838 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 839 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 840 | RECORD(TYPE_PAREN); |
| 841 | RECORD(TYPE_PACK_EXPANSION); |
| 842 | RECORD(TYPE_ATTRIBUTED); |
| 843 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 844 | RECORD(DECL_TYPEDEF); |
| 845 | RECORD(DECL_ENUM); |
| 846 | RECORD(DECL_RECORD); |
| 847 | RECORD(DECL_ENUM_CONSTANT); |
| 848 | RECORD(DECL_FUNCTION); |
| 849 | RECORD(DECL_OBJC_METHOD); |
| 850 | RECORD(DECL_OBJC_INTERFACE); |
| 851 | RECORD(DECL_OBJC_PROTOCOL); |
| 852 | RECORD(DECL_OBJC_IVAR); |
| 853 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
| 854 | RECORD(DECL_OBJC_CLASS); |
| 855 | RECORD(DECL_OBJC_FORWARD_PROTOCOL); |
| 856 | RECORD(DECL_OBJC_CATEGORY); |
| 857 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 858 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 859 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 860 | RECORD(DECL_OBJC_PROPERTY); |
| 861 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 862 | RECORD(DECL_FIELD); |
| 863 | RECORD(DECL_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 864 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 865 | RECORD(DECL_PARM_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 866 | RECORD(DECL_FILE_SCOPE_ASM); |
| 867 | RECORD(DECL_BLOCK); |
| 868 | RECORD(DECL_CONTEXT_LEXICAL); |
| 869 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 870 | RECORD(DECL_NAMESPACE); |
| 871 | RECORD(DECL_NAMESPACE_ALIAS); |
| 872 | RECORD(DECL_USING); |
| 873 | RECORD(DECL_USING_SHADOW); |
| 874 | RECORD(DECL_USING_DIRECTIVE); |
| 875 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 876 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 877 | RECORD(DECL_LINKAGE_SPEC); |
| 878 | RECORD(DECL_CXX_RECORD); |
| 879 | RECORD(DECL_CXX_METHOD); |
| 880 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 881 | RECORD(DECL_CXX_DESTRUCTOR); |
| 882 | RECORD(DECL_CXX_CONVERSION); |
| 883 | RECORD(DECL_ACCESS_SPEC); |
| 884 | RECORD(DECL_FRIEND); |
| 885 | RECORD(DECL_FRIEND_TEMPLATE); |
| 886 | RECORD(DECL_CLASS_TEMPLATE); |
| 887 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 888 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
| 889 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 890 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 891 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 892 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 893 | RECORD(DECL_STATIC_ASSERT); |
| 894 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 895 | RECORD(DECL_INDIRECTFIELD); |
| 896 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 897 | |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 898 | // Statements and Exprs can occur in the Decls and Types block. |
| 899 | AddStmtsExprs(Stream, Record); |
| 900 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 901 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 902 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 903 | RECORD(PPD_MACRO_DEFINITION); |
| 904 | RECORD(PPD_INCLUSION_DIRECTIVE); |
| 905 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 906 | #undef RECORD |
| 907 | #undef BLOCK |
| 908 | Stream.ExitBlock(); |
| 909 | } |
| 910 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 911 | /// \brief Adjusts the given filename to only write out the portion of the |
| 912 | /// filename that is not part of the system root directory. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | /// |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 914 | /// \param Filename the file name to adjust. |
| 915 | /// |
| 916 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 917 | /// the returned filename will be adjusted by this system root. |
| 918 | /// |
| 919 | /// \returns either the original filename (if it needs no adjustment) or the |
| 920 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 921 | static const char * |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 922 | adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 923 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 924 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 925 | if (isysroot.empty()) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 926 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 928 | // Verify that the filename and the system root have the same prefix. |
| 929 | unsigned Pos = 0; |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 930 | for (; Filename[Pos] && Pos < isysroot.size(); ++Pos) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 931 | if (Filename[Pos] != isysroot[Pos]) |
| 932 | return Filename; // Prefixes don't match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 933 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 934 | // We hit the end of the filename before we hit the end of the system root. |
| 935 | if (!Filename[Pos]) |
| 936 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 937 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 938 | // If the file name has a '/' at the current position, skip over the '/'. |
| 939 | // We distinguish sysroot-based includes from absolute includes by the |
| 940 | // absence of '/' at the beginning of sysroot-based includes. |
| 941 | if (Filename[Pos] == '/') |
| 942 | ++Pos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 943 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 944 | return Filename + Pos; |
| 945 | } |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 946 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 947 | /// \brief Write the AST metadata (e.g., i686-apple-darwin9). |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 948 | void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 949 | const std::string &OutputFile) { |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 950 | using namespace llvm; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 951 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 952 | // Metadata |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 953 | const TargetInfo &Target = Context.getTargetInfo(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 954 | BitCodeAbbrev *MetaAbbrev = new BitCodeAbbrev(); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 955 | MetaAbbrev->Add(BitCodeAbbrevOp(METADATA)); |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 956 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST major |
| 957 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST minor |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 958 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major |
| 959 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor |
| 960 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 961 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Target triple |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 962 | unsigned MetaAbbrevCode = Stream.EmitAbbrev(MetaAbbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 963 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 964 | RecordData Record; |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 965 | Record.push_back(METADATA); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 966 | Record.push_back(VERSION_MAJOR); |
| 967 | Record.push_back(VERSION_MINOR); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 968 | Record.push_back(CLANG_VERSION_MAJOR); |
| 969 | Record.push_back(CLANG_VERSION_MINOR); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 970 | Record.push_back(!isysroot.empty()); |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 971 | const std::string &Triple = Target.getTriple().getTriple(); |
| 972 | Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, Triple); |
| 973 | |
| 974 | if (Chain) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 975 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); |
| 976 | llvm::SmallVector<char, 128> ModulePaths; |
| 977 | Record.clear(); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 978 | |
| 979 | for (ModuleManager::ModuleIterator M = Mgr.begin(), MEnd = Mgr.end(); |
| 980 | M != MEnd; ++M) { |
| 981 | // Skip modules that weren't directly imported. |
| 982 | if (!(*M)->isDirectlyImported()) |
| 983 | continue; |
| 984 | |
| 985 | Record.push_back((unsigned)(*M)->Kind); // FIXME: Stable encoding |
| 986 | // FIXME: Write import location, once it matters. |
| 987 | // FIXME: This writes the absolute path for AST files we depend on. |
| 988 | const std::string &FileName = (*M)->FileName; |
| 989 | Record.push_back(FileName.size()); |
| 990 | Record.append(FileName.begin(), FileName.end()); |
| 991 | } |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 992 | Stream.EmitRecord(IMPORTS, Record); |
| 993 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 995 | // Original file name and file ID |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 996 | SourceManager &SM = Context.getSourceManager(); |
| 997 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 998 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 999 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE_NAME)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1000 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1001 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 1002 | |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1003 | llvm::SmallString<128> MainFilePath(MainFile->getName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1005 | llvm::sys::fs::make_absolute(MainFilePath); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1006 | |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1007 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1008 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1009 | isysroot); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1010 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1011 | Record.push_back(ORIGINAL_FILE_NAME); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1012 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1013 | |
| 1014 | Record.clear(); |
| 1015 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 1016 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1017 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1018 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1019 | // Original PCH directory |
| 1020 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1021 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1022 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1023 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1024 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1025 | |
| 1026 | llvm::SmallString<128> OutputPath(OutputFile); |
| 1027 | |
| 1028 | llvm::sys::fs::make_absolute(OutputPath); |
| 1029 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1030 | |
| 1031 | RecordData Record; |
| 1032 | Record.push_back(ORIGINAL_PCH_DIR); |
| 1033 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1034 | } |
| 1035 | |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1036 | // Repository branch/version information. |
| 1037 | BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1038 | RepoAbbrev->Add(BitCodeAbbrevOp(VERSION_CONTROL_BRANCH_REVISION)); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1039 | RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1040 | unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 1041 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1042 | Record.push_back(VERSION_CONTROL_BRANCH_REVISION); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1043 | Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, |
| 1044 | getClangFullRepositoryVersion()); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | /// \brief Write the LangOptions structure. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1048 | void ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1049 | RecordData Record; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame^] | 1050 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 1051 | Record.push_back(LangOpts.Name); |
| 1052 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 1053 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); |
| 1054 | #include "clang/Basic/LangOptions.def" |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1055 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1058 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1059 | // stat cache Serialization |
| 1060 | //===----------------------------------------------------------------------===// |
| 1061 | |
| 1062 | namespace { |
| 1063 | // Trait used for the on-disk hash table of stat cache results. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1064 | class ASTStatCacheTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1065 | public: |
| 1066 | typedef const char * key_type; |
| 1067 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1068 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1069 | typedef struct stat data_type; |
| 1070 | typedef const data_type &data_type_ref; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1071 | |
| 1072 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1073 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1074 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1075 | |
| 1076 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1077 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1078 | data_type_ref Data) { |
| 1079 | unsigned StrLen = strlen(path); |
| 1080 | clang::io::Emit16(Out, StrLen); |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1081 | unsigned DataLen = 4 + 4 + 2 + 8 + 8; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1082 | clang::io::Emit8(Out, DataLen); |
| 1083 | return std::make_pair(StrLen + 1, DataLen); |
| 1084 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1086 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1087 | Out.write(path, KeyLen); |
| 1088 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1089 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1090 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1091 | data_type_ref Data, unsigned DataLen) { |
| 1092 | using namespace clang::io; |
| 1093 | uint64_t Start = Out.tell(); (void)Start; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1095 | Emit32(Out, (uint32_t) Data.st_ino); |
| 1096 | Emit32(Out, (uint32_t) Data.st_dev); |
| 1097 | Emit16(Out, (uint16_t) Data.st_mode); |
| 1098 | Emit64(Out, (uint64_t) Data.st_mtime); |
| 1099 | Emit64(Out, (uint64_t) Data.st_size); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1100 | |
| 1101 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1102 | } |
| 1103 | }; |
| 1104 | } // end anonymous namespace |
| 1105 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1106 | /// \brief Write the stat() system call cache to the AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1107 | void ASTWriter::WriteStatCache(MemorizeStatCalls &StatCalls) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1108 | // Build the on-disk hash table containing information about every |
| 1109 | // stat() call. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1110 | OnDiskChainedHashTableGenerator<ASTStatCacheTrait> Generator; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1111 | unsigned NumStatEntries = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1113 | StatEnd = StatCalls.end(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1114 | Stat != StatEnd; ++Stat, ++NumStatEntries) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1115 | StringRef Filename = Stat->first(); |
Chris Lattner | 1e5f83b | 2011-07-14 18:24:21 +0000 | [diff] [blame] | 1116 | Generator.insert(Filename.data(), Stat->second); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1117 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1119 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1120 | llvm::SmallString<4096> StatCacheData; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1121 | uint32_t BucketOffset; |
| 1122 | { |
| 1123 | llvm::raw_svector_ostream Out(StatCacheData); |
| 1124 | // Make sure that no bucket is at offset 0 |
| 1125 | clang::io::Emit32(Out, 0); |
| 1126 | BucketOffset = Generator.Emit(Out); |
| 1127 | } |
| 1128 | |
| 1129 | // Create a blob abbreviation |
| 1130 | using namespace llvm; |
| 1131 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1132 | Abbrev->Add(BitCodeAbbrevOp(STAT_CACHE)); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1133 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1134 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1135 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1136 | unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1137 | |
| 1138 | // Write the stat cache |
| 1139 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1140 | Record.push_back(STAT_CACHE); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1141 | Record.push_back(BucketOffset); |
| 1142 | Record.push_back(NumStatEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1143 | Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1147 | // Source Manager Serialization |
| 1148 | //===----------------------------------------------------------------------===// |
| 1149 | |
| 1150 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1151 | /// file. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1152 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1153 | using namespace llvm; |
| 1154 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1155 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1156 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1157 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1158 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1159 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1160 | // FileEntry fields. |
| 1161 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1162 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1163 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1164 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1165 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1169 | /// buffer. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1170 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1171 | using namespace llvm; |
| 1172 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1173 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1174 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1175 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1176 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1177 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1178 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1179 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1183 | /// buffer's blob. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1184 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1185 | using namespace llvm; |
| 1186 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1187 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1188 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1189 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1192 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1193 | /// expansion. |
| 1194 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1195 | using namespace llvm; |
| 1196 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1197 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1198 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1199 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1200 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1201 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | f60e991 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1202 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1203 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1206 | namespace { |
| 1207 | // Trait used for the on-disk hash table of header search information. |
| 1208 | class HeaderFileInfoTrait { |
| 1209 | ASTWriter &Writer; |
| 1210 | HeaderSearch &HS; |
| 1211 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1212 | // Keep track of the framework names we've used during serialization. |
| 1213 | SmallVector<char, 128> FrameworkStringData; |
| 1214 | llvm::StringMap<unsigned> FrameworkNameOffset; |
| 1215 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1216 | public: |
| 1217 | HeaderFileInfoTrait(ASTWriter &Writer, HeaderSearch &HS) |
| 1218 | : Writer(Writer), HS(HS) { } |
| 1219 | |
| 1220 | typedef const char *key_type; |
| 1221 | typedef key_type key_type_ref; |
| 1222 | |
| 1223 | typedef HeaderFileInfo data_type; |
| 1224 | typedef const data_type &data_type_ref; |
| 1225 | |
| 1226 | static unsigned ComputeHash(const char *path) { |
| 1227 | // The hash is based only on the filename portion of the key, so that the |
| 1228 | // reader can match based on filenames when symlinking or excess path |
| 1229 | // elements ("foo/../", "../") change the form of the name. However, |
| 1230 | // complete path is still the key. |
| 1231 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1232 | } |
| 1233 | |
| 1234 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1235 | EmitKeyDataLength(raw_ostream& Out, const char *path, |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1236 | data_type_ref Data) { |
| 1237 | unsigned StrLen = strlen(path); |
| 1238 | clang::io::Emit16(Out, StrLen); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1239 | unsigned DataLen = 1 + 2 + 4 + 4; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1240 | clang::io::Emit8(Out, DataLen); |
| 1241 | return std::make_pair(StrLen + 1, DataLen); |
| 1242 | } |
| 1243 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1244 | void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1245 | Out.write(path, KeyLen); |
| 1246 | } |
| 1247 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1248 | void EmitData(raw_ostream &Out, key_type_ref, |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1249 | data_type_ref Data, unsigned DataLen) { |
| 1250 | using namespace clang::io; |
| 1251 | uint64_t Start = Out.tell(); (void)Start; |
| 1252 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1253 | unsigned char Flags = (Data.isImport << 5) |
| 1254 | | (Data.isPragmaOnce << 4) |
| 1255 | | (Data.DirInfo << 2) |
| 1256 | | (Data.Resolved << 1) |
| 1257 | | Data.IndexHeaderMapHeader; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1258 | Emit8(Out, (uint8_t)Flags); |
| 1259 | Emit16(Out, (uint16_t) Data.NumIncludes); |
| 1260 | |
| 1261 | if (!Data.ControllingMacro) |
| 1262 | Emit32(Out, (uint32_t)Data.ControllingMacroID); |
| 1263 | else |
| 1264 | Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1265 | |
| 1266 | unsigned Offset = 0; |
| 1267 | if (!Data.Framework.empty()) { |
| 1268 | // If this header refers into a framework, save the framework name. |
| 1269 | llvm::StringMap<unsigned>::iterator Pos |
| 1270 | = FrameworkNameOffset.find(Data.Framework); |
| 1271 | if (Pos == FrameworkNameOffset.end()) { |
| 1272 | Offset = FrameworkStringData.size() + 1; |
| 1273 | FrameworkStringData.append(Data.Framework.begin(), |
| 1274 | Data.Framework.end()); |
| 1275 | FrameworkStringData.push_back(0); |
| 1276 | |
| 1277 | FrameworkNameOffset[Data.Framework] = Offset; |
| 1278 | } else |
| 1279 | Offset = Pos->second; |
| 1280 | } |
| 1281 | Emit32(Out, Offset); |
| 1282 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1283 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1284 | } |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1285 | |
| 1286 | const char *strings_begin() const { return FrameworkStringData.begin(); } |
| 1287 | const char *strings_end() const { return FrameworkStringData.end(); } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1288 | }; |
| 1289 | } // end anonymous namespace |
| 1290 | |
| 1291 | /// \brief Write the header search block for the list of files that |
| 1292 | /// |
| 1293 | /// \param HS The header search structure to save. |
| 1294 | /// |
| 1295 | /// \param Chain Whether we're creating a chained AST file. |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1296 | void ASTWriter::WriteHeaderSearch(HeaderSearch &HS, StringRef isysroot) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1297 | SmallVector<const FileEntry *, 16> FilesByUID; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1298 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1299 | |
| 1300 | if (FilesByUID.size() > HS.header_file_size()) |
| 1301 | FilesByUID.resize(HS.header_file_size()); |
| 1302 | |
| 1303 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
| 1304 | OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1305 | SmallVector<const char *, 4> SavedStrings; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1306 | unsigned NumHeaderSearchEntries = 0; |
| 1307 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1308 | const FileEntry *File = FilesByUID[UID]; |
| 1309 | if (!File) |
| 1310 | continue; |
| 1311 | |
| 1312 | const HeaderFileInfo &HFI = HS.header_file_begin()[UID]; |
| 1313 | if (HFI.External && Chain) |
| 1314 | continue; |
| 1315 | |
| 1316 | // Turn the file name into an absolute path, if it isn't already. |
| 1317 | const char *Filename = File->getName(); |
| 1318 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1319 | |
| 1320 | // If we performed any translation on the file name at all, we need to |
| 1321 | // save this string, since the generator will refer to it later. |
| 1322 | if (Filename != File->getName()) { |
| 1323 | Filename = strdup(Filename); |
| 1324 | SavedStrings.push_back(Filename); |
| 1325 | } |
| 1326 | |
| 1327 | Generator.insert(Filename, HFI, GeneratorTrait); |
| 1328 | ++NumHeaderSearchEntries; |
| 1329 | } |
| 1330 | |
| 1331 | // Create the on-disk hash table in a buffer. |
| 1332 | llvm::SmallString<4096> TableData; |
| 1333 | uint32_t BucketOffset; |
| 1334 | { |
| 1335 | llvm::raw_svector_ostream Out(TableData); |
| 1336 | // Make sure that no bucket is at offset 0 |
| 1337 | clang::io::Emit32(Out, 0); |
| 1338 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1339 | } |
| 1340 | |
| 1341 | // Create a blob abbreviation |
| 1342 | using namespace llvm; |
| 1343 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1344 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1345 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1346 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1347 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1348 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1349 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1350 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1351 | // Write the header search table |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1352 | RecordData Record; |
| 1353 | Record.push_back(HEADER_SEARCH_TABLE); |
| 1354 | Record.push_back(BucketOffset); |
| 1355 | Record.push_back(NumHeaderSearchEntries); |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1356 | Record.push_back(TableData.size()); |
| 1357 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1358 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); |
| 1359 | |
| 1360 | // Free all of the strings we had to duplicate. |
| 1361 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
| 1362 | free((void*)SavedStrings[I]); |
| 1363 | } |
| 1364 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1365 | /// \brief Writes the block containing the serialized form of the |
| 1366 | /// source manager. |
| 1367 | /// |
| 1368 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1369 | /// blob), indexed based on the file name, so that we only create |
| 1370 | /// entries for files that we actually need. In the common case (no |
| 1371 | /// errors), we probably won't have to create file entries for any of |
| 1372 | /// the files in the AST. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1373 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1374 | const Preprocessor &PP, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1375 | StringRef isysroot) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1376 | RecordData Record; |
| 1377 | |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1378 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1379 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1380 | |
| 1381 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | 828e18c | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1382 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1383 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1384 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1385 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1386 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1387 | // Write out the source location entry table. We skip the first |
| 1388 | // entry, which is always the same dummy entry. |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1389 | std::vector<uint32_t> SLocEntryOffsets; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1390 | // Write out the offsets of only source location file entries. |
| 1391 | // We will go through them in ASTReader::validateFileEntries(). |
| 1392 | std::vector<uint32_t> SLocFileEntryOffsets; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1393 | RecordData PreloadSLocs; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1394 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1395 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1396 | I != N; ++I) { |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1397 | // Get this source location entry. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1398 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1399 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1400 | // Record the offset of this source-location entry. |
| 1401 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1402 | |
| 1403 | // Figure out which record code to use. |
| 1404 | unsigned Code; |
| 1405 | if (SLoc->isFile()) { |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1406 | if (SLoc->getFile().getContentCache()->OrigEntry) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1407 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1408 | SLocFileEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1409 | } else |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1410 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1411 | } else |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1412 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1413 | Record.clear(); |
| 1414 | Record.push_back(Code); |
| 1415 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1416 | // Starting offset of this entry within this module, so skip the dummy. |
| 1417 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1418 | if (SLoc->isFile()) { |
| 1419 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1420 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1421 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1422 | Record.push_back(File.hasLineDirectives()); |
| 1423 | |
| 1424 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1425 | if (Content->OrigEntry) { |
| 1426 | assert(Content->OrigEntry == Content->ContentsEntry && |
| 1427 | "Writing to AST an overriden file is not supported"); |
| 1428 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1429 | // The source location entry is a file. The blob associated |
| 1430 | // with this entry is the file name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1431 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1432 | // Emit size/modification time for this file. |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1433 | Record.push_back(Content->OrigEntry->getSize()); |
| 1434 | Record.push_back(Content->OrigEntry->getModificationTime()); |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1435 | |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1436 | Record.push_back(File.NumCreatedFIDs); |
| 1437 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1438 | // 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] | 1439 | const char *Filename = Content->OrigEntry->getName(); |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1440 | llvm::SmallString<128> FilePath(Filename); |
Anders Carlsson | 2c10c80 | 2011-03-08 16:04:35 +0000 | [diff] [blame] | 1441 | |
| 1442 | // Ask the file manager to fixup the relative path for us. This will |
| 1443 | // honor the working directory. |
| 1444 | SourceMgr.getFileManager().FixupRelativePath(FilePath); |
| 1445 | |
| 1446 | // FIXME: This call to make_absolute shouldn't be necessary, the |
| 1447 | // call to FixupRelativePath should always return an absolute path. |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1448 | llvm::sys::fs::make_absolute(FilePath); |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1449 | Filename = FilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1451 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1452 | Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1453 | } else { |
| 1454 | // The source location entry is a buffer. The blob associated |
| 1455 | // with this entry contains the contents of the buffer. |
| 1456 | |
| 1457 | // We add one to the size so that we capture the trailing NULL |
| 1458 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1459 | // the reader side). |
Douglas Gregor | 36c35ba | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1460 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1461 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1462 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1463 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1464 | StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1465 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1466 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1467 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1468 | StringRef(Buffer->getBufferStart(), |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1469 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1470 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1471 | if (strcmp(Name, "<built-in>") == 0) { |
| 1472 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1473 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1474 | } |
| 1475 | } else { |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1476 | // The source location entry is a macro expansion. |
Chandler Carruth | 1728762 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 1477 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); |
Chandler Carruth | 78df836 | 2011-07-26 04:41:47 +0000 | [diff] [blame] | 1478 | Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); |
| 1479 | Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); |
Argyrios Kyrtzidis | d21683c | 2011-08-17 00:31:14 +0000 | [diff] [blame] | 1480 | Record.push_back(Expansion.isMacroArgExpansion() ? 0 |
| 1481 | : Expansion.getExpansionLocEnd().getRawEncoding()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1482 | |
| 1483 | // Compute the token length for this macro expansion. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1484 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1485 | if (I + 1 != N) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1486 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1487 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1488 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1489 | } |
| 1490 | } |
| 1491 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1492 | Stream.ExitBlock(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1493 | |
| 1494 | if (SLocEntryOffsets.empty()) |
| 1495 | return; |
| 1496 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1497 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1498 | // table is used for lazily loading source-location information. |
| 1499 | using namespace llvm; |
| 1500 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1501 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1502 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1503 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1504 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1505 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1506 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1507 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1508 | Record.push_back(SOURCE_LOCATION_OFFSETS); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1509 | Record.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1510 | Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1511 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1512 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1513 | Abbrev = new BitCodeAbbrev(); |
| 1514 | Abbrev->Add(BitCodeAbbrevOp(FILE_SOURCE_LOCATION_OFFSETS)); |
| 1515 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
| 1516 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1517 | unsigned SLocFileOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1518 | |
| 1519 | Record.clear(); |
| 1520 | Record.push_back(FILE_SOURCE_LOCATION_OFFSETS); |
| 1521 | Record.push_back(SLocFileEntryOffsets.size()); |
| 1522 | Stream.EmitRecordWithBlob(SLocFileOffsetsAbbrev, Record, |
| 1523 | data(SLocFileEntryOffsets)); |
| 1524 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1525 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1526 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1527 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1528 | |
| 1529 | // Write the line table. It depends on remapping working, so it must come |
| 1530 | // after the source location offsets. |
| 1531 | if (SourceMgr.hasLineTable()) { |
| 1532 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1533 | |
| 1534 | Record.clear(); |
| 1535 | // Emit the file names |
| 1536 | Record.push_back(LineTable.getNumFilenames()); |
| 1537 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1538 | // Emit the file name |
| 1539 | const char *Filename = LineTable.getFilename(I); |
| 1540 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1541 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1542 | Record.push_back(FilenameLen); |
| 1543 | if (FilenameLen) |
| 1544 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1545 | } |
| 1546 | |
| 1547 | // Emit the line entries |
| 1548 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1549 | L != LEnd; ++L) { |
| 1550 | // Only emit entries for local files. |
| 1551 | if (L->first < 0) |
| 1552 | continue; |
| 1553 | |
| 1554 | // Emit the file ID |
| 1555 | Record.push_back(L->first); |
| 1556 | |
| 1557 | // Emit the line entries |
| 1558 | Record.push_back(L->second.size()); |
| 1559 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1560 | LEEnd = L->second.end(); |
| 1561 | LE != LEEnd; ++LE) { |
| 1562 | Record.push_back(LE->FileOffset); |
| 1563 | Record.push_back(LE->LineNo); |
| 1564 | Record.push_back(LE->FilenameID); |
| 1565 | Record.push_back((unsigned)LE->FileKind); |
| 1566 | Record.push_back(LE->IncludeOffset); |
| 1567 | } |
| 1568 | } |
| 1569 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 1570 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1573 | //===----------------------------------------------------------------------===// |
| 1574 | // Preprocessor Serialization |
| 1575 | //===----------------------------------------------------------------------===// |
| 1576 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1577 | static int compareMacroDefinitions(const void *XPtr, const void *YPtr) { |
| 1578 | const std::pair<const IdentifierInfo *, MacroInfo *> &X = |
| 1579 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; |
| 1580 | const std::pair<const IdentifierInfo *, MacroInfo *> &Y = |
| 1581 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; |
| 1582 | return X.first->getName().compare(Y.first->getName()); |
| 1583 | } |
| 1584 | |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1585 | /// \brief Writes the block containing the serialized form of the |
| 1586 | /// preprocessor. |
| 1587 | /// |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1588 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1589 | RecordData Record; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1590 | |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1591 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1592 | if (PP.getCounterValue() != 0) { |
| 1593 | Record.push_back(PP.getCounterValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1594 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1595 | Record.clear(); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | // Enter the preprocessor block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1599 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1600 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1601 | // 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] | 1602 | // FIXME: use diagnostics subsystem for localization etc. |
| 1603 | if (PP.SawDateOrTime()) |
| 1604 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1605 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1606 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1607 | // Loop over all the macro definitions that are live at the end of the file, |
| 1608 | // emitting each to the PP section. |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1609 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1610 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1611 | // Construct the list of macro definitions that need to be serialized. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1612 | SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1613 | MacrosToEmit; |
| 1614 | llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1615 | for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), |
| 1616 | E = PP.macro_end(Chain == 0); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1617 | I != E; ++I) { |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1618 | if (!IsModule || I->second->isExported()) { |
| 1619 | MacroDefinitionsSeen.insert(I->first); |
| 1620 | MacrosToEmit.push_back(std::make_pair(I->first, I->second)); |
| 1621 | } |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | // Sort the set of macro definitions that need to be serialized by the |
| 1625 | // name of the macro, to provide a stable ordering. |
| 1626 | llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), |
| 1627 | &compareMacroDefinitions); |
| 1628 | |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1629 | // Resolve any identifiers that defined macros at the time they were |
| 1630 | // deserialized, adding them to the list of macros to emit (if appropriate). |
| 1631 | for (unsigned I = 0, N = DeserializedMacroNames.size(); I != N; ++I) { |
| 1632 | IdentifierInfo *Name |
| 1633 | = const_cast<IdentifierInfo *>(DeserializedMacroNames[I]); |
| 1634 | if (Name->hasMacroDefinition() && MacroDefinitionsSeen.insert(Name)) |
| 1635 | MacrosToEmit.push_back(std::make_pair(Name, PP.getMacroInfo(Name))); |
| 1636 | } |
| 1637 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1638 | for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { |
| 1639 | const IdentifierInfo *Name = MacrosToEmit[I].first; |
| 1640 | MacroInfo *MI = MacrosToEmit[I].second; |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1641 | if (!MI) |
| 1642 | continue; |
| 1643 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1644 | // Don't emit builtin macros like __LINE__ to the AST file unless they have |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1645 | // been redefined by the header (in which case they are not isBuiltinMacro). |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1646 | // Also skip macros from a AST file if we're chaining. |
Douglas Gregor | ee9b0ba | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 1647 | |
| 1648 | // FIXME: There is a (probably minor) optimization we could do here, if |
| 1649 | // the macro comes from the original PCH but the identifier comes from a |
| 1650 | // chained PCH, by storing the offset into the original PCH rather than |
| 1651 | // writing the macro definition a second time. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1652 | if (MI->isBuiltinMacro() || |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1653 | (Chain && Name->isFromAST() && MI->isFromAST() && |
| 1654 | !MI->hasChangedAfterLoad())) |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1655 | continue; |
| 1656 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1657 | AddIdentifierRef(Name, Record); |
| 1658 | MacroOffsets[Name] = Stream.GetCurrentBitNo(); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1659 | Record.push_back(MI->getDefinitionLoc().getRawEncoding()); |
| 1660 | Record.push_back(MI->isUsed()); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1661 | AddSourceLocation(MI->getExportLocation(), Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1662 | unsigned Code; |
| 1663 | if (MI->isObjectLike()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1664 | Code = PP_MACRO_OBJECT_LIKE; |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1665 | } else { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1666 | Code = PP_MACRO_FUNCTION_LIKE; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1667 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1668 | Record.push_back(MI->isC99Varargs()); |
| 1669 | Record.push_back(MI->isGNUVarargs()); |
| 1670 | Record.push_back(MI->getNumArgs()); |
| 1671 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1672 | I != E; ++I) |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1673 | AddIdentifierRef(*I, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1674 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1676 | // If we have a detailed preprocessing record, record the macro definition |
| 1677 | // ID that corresponds to this macro. |
| 1678 | if (PPRec) |
| 1679 | Record.push_back(getMacroDefinitionID(PPRec->findMacroDefinition(MI))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1680 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1681 | Stream.EmitRecord(Code, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1682 | Record.clear(); |
| 1683 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1684 | // Emit the tokens array. |
| 1685 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1686 | // Note that we know that the preprocessor does not have any annotation |
| 1687 | // tokens in it because they are created by the parser, and thus can't be |
| 1688 | // in a macro definition. |
| 1689 | const Token &Tok = MI->getReplacementToken(TokNo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1690 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1691 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1692 | Record.push_back(Tok.getLength()); |
| 1693 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1694 | // FIXME: When reading literal tokens, reconstruct the literal pointer if |
| 1695 | // it is needed. |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1696 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1697 | // FIXME: Should translate token kind to a stable encoding. |
| 1698 | Record.push_back(Tok.getKind()); |
| 1699 | // FIXME: Should translate token flags to a stable encoding. |
| 1700 | Record.push_back(Tok.getFlags()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1701 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1702 | Stream.EmitRecord(PP_TOKEN, Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1703 | Record.clear(); |
| 1704 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1705 | ++NumMacros; |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1706 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1707 | Stream.ExitBlock(); |
| 1708 | |
| 1709 | if (PPRec) |
| 1710 | WritePreprocessorDetail(*PPRec); |
| 1711 | } |
| 1712 | |
| 1713 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
| 1714 | if (PPRec.begin(Chain) == PPRec.end(Chain)) |
| 1715 | return; |
| 1716 | |
| 1717 | // Enter the preprocessor block. |
| 1718 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1719 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1720 | // If the preprocessor has a preprocessing record, emit it. |
| 1721 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1722 | using namespace llvm; |
| 1723 | |
| 1724 | // Set up the abbreviation for |
| 1725 | unsigned InclusionAbbrev = 0; |
| 1726 | { |
| 1727 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1728 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
| 1729 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index |
| 1730 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // start location |
| 1731 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // end location |
| 1732 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 1733 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 1734 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
| 1735 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1736 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1737 | } |
| 1738 | |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1739 | unsigned FirstPreprocessorEntityID |
| 1740 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) |
| 1741 | + NUM_PREDEF_PP_ENTITY_IDS; |
| 1742 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1743 | RecordData Record; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1744 | uint64_t BitsInChain = Chain? Chain->TotalModulesSizeInBits : 0; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1745 | for (PreprocessingRecord::iterator E = PPRec.begin(Chain), |
| 1746 | EEnd = PPRec.end(Chain); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1747 | E != EEnd; |
| 1748 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1749 | Record.clear(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1750 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1751 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
| 1752 | // Record this macro definition's location. |
| 1753 | MacroID ID = getMacroDefinitionID(MD); |
| 1754 | |
| 1755 | // Don't write the macro definition if it is from another AST file. |
| 1756 | if (ID < FirstMacroID) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1757 | continue; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1758 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1759 | // Notify the serialization listener that we're serializing this entity. |
| 1760 | if (SerializationListener) |
| 1761 | SerializationListener->SerializedPreprocessedEntity(*E, |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1762 | BitsInChain + Stream.GetCurrentBitNo()); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1763 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1764 | unsigned Position = ID - FirstMacroID; |
| 1765 | if (Position != MacroDefinitionOffsets.size()) { |
| 1766 | if (Position > MacroDefinitionOffsets.size()) |
| 1767 | MacroDefinitionOffsets.resize(Position + 1); |
| 1768 | |
| 1769 | MacroDefinitionOffsets[Position] = Stream.GetCurrentBitNo(); |
| 1770 | } else |
| 1771 | MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo()); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1772 | |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1773 | Record.push_back(NextPreprocessorEntityID); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1774 | Record.push_back(ID); |
| 1775 | AddSourceLocation(MD->getSourceRange().getBegin(), Record); |
| 1776 | AddSourceLocation(MD->getSourceRange().getEnd(), Record); |
| 1777 | AddIdentifierRef(MD->getName(), Record); |
| 1778 | AddSourceLocation(MD->getLocation(), Record); |
| 1779 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 1780 | continue; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1781 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1782 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1783 | // Notify the serialization listener that we're serializing this entity. |
| 1784 | if (SerializationListener) |
| 1785 | SerializationListener->SerializedPreprocessedEntity(*E, |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1786 | BitsInChain + Stream.GetCurrentBitNo()); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1787 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1788 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1789 | Record.push_back(NextPreprocessorEntityID); |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1790 | AddSourceLocation(ME->getSourceRange().getBegin(), Record); |
| 1791 | AddSourceLocation(ME->getSourceRange().getEnd(), Record); |
Argyrios Kyrtzidis | 8f7c540 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 1792 | Record.push_back(ME->isBuiltinMacro()); |
| 1793 | if (ME->isBuiltinMacro()) |
| 1794 | AddIdentifierRef(ME->getName(), Record); |
| 1795 | else |
| 1796 | Record.push_back(getMacroDefinitionID(ME->getDefinition())); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1797 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1798 | continue; |
| 1799 | } |
| 1800 | |
| 1801 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 1802 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1803 | Record.push_back(NextPreprocessorEntityID); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1804 | AddSourceLocation(ID->getSourceRange().getBegin(), Record); |
| 1805 | AddSourceLocation(ID->getSourceRange().getEnd(), Record); |
| 1806 | Record.push_back(ID->getFileName().size()); |
| 1807 | Record.push_back(ID->wasInQuotes()); |
| 1808 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
| 1809 | llvm::SmallString<64> Buffer; |
| 1810 | Buffer += ID->getFileName(); |
| 1811 | Buffer += ID->getFile()->getName(); |
| 1812 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
| 1813 | continue; |
| 1814 | } |
| 1815 | |
| 1816 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 1817 | } |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1818 | Stream.ExitBlock(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1819 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1820 | // Write the offsets table for the preprocessing record. |
| 1821 | if (NumPreprocessingRecords > 0) { |
| 1822 | // Write the offsets table for identifier IDs. |
| 1823 | using namespace llvm; |
| 1824 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1825 | Abbrev->Add(BitCodeAbbrevOp(MACRO_DEFINITION_OFFSETS)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1826 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of records |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1827 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1828 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macro defs |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 1829 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first macro def |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1830 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1831 | unsigned MacroDefOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1832 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1833 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1834 | Record.push_back(MACRO_DEFINITION_OFFSETS); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1835 | Record.push_back(NumPreprocessingRecords); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1836 | Record.push_back(FirstPreprocessorEntityID - NUM_PREDEF_PP_ENTITY_IDS); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1837 | Record.push_back(MacroDefinitionOffsets.size()); |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 1838 | Record.push_back(FirstMacroID - NUM_PREDEF_MACRO_IDS); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1839 | Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1840 | data(MacroDefinitionOffsets)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1841 | } |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1844 | void ASTWriter::WritePragmaDiagnosticMappings(const Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1845 | RecordData Record; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1846 | for (Diagnostic::DiagStatePointsTy::const_iterator |
| 1847 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 1848 | I != E; ++I) { |
| 1849 | const Diagnostic::DiagStatePoint &point = *I; |
| 1850 | if (point.Loc.isInvalid()) |
| 1851 | continue; |
| 1852 | |
| 1853 | Record.push_back(point.Loc.getRawEncoding()); |
| 1854 | for (Diagnostic::DiagState::iterator |
| 1855 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
| 1856 | unsigned diag = I->first, map = I->second; |
| 1857 | if (map & 0x10) { // mapping from a diagnostic pragma. |
| 1858 | Record.push_back(diag); |
| 1859 | Record.push_back(map & 0x7); |
| 1860 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1861 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1862 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 1863 | // location. |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
Argyrios Kyrtzidis | 60f7684 | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 1866 | if (!Record.empty()) |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1867 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 1870 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 1871 | if (CXXBaseSpecifiersOffsets.empty()) |
| 1872 | return; |
| 1873 | |
| 1874 | RecordData Record; |
| 1875 | |
| 1876 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 1877 | using namespace llvm; |
| 1878 | |
| 1879 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1880 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 1881 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 1882 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1883 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1884 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 1885 | // Write the base specifier offsets table. |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 1886 | Record.clear(); |
| 1887 | Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); |
| 1888 | Record.push_back(CXXBaseSpecifiersOffsets.size()); |
| 1889 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1890 | data(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1893 | //===----------------------------------------------------------------------===// |
| 1894 | // Type Serialization |
| 1895 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1896 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1897 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1898 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 1899 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 1900 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 1901 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1902 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 1903 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | 55f48de | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 1904 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1905 | // Record the offset for this type. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 1906 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1907 | if (TypeOffsets.size() == Index) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1908 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1909 | else if (TypeOffsets.size() < Index) { |
| 1910 | TypeOffsets.resize(Index + 1); |
| 1911 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | RecordData Record; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1915 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1916 | // Emit the type's representation. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1917 | ASTTypeWriter W(*this, Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1918 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 1919 | if (T.hasLocalNonFastQualifiers()) { |
| 1920 | Qualifiers Qs = T.getLocalQualifiers(); |
| 1921 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1922 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1923 | W.Code = TYPE_EXT_QUAL; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1924 | } else { |
| 1925 | switch (T->getTypeClass()) { |
| 1926 | // For all of the concrete, non-dependent types, call the |
| 1927 | // appropriate visitor function. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1928 | #define TYPE(Class, Base) \ |
Mike Stump | b716633 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 1929 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1930 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1931 | #include "clang/AST/TypeNodes.def" |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1932 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | // Emit the serialized record. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1936 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1937 | |
| 1938 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1939 | FlushStmts(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1942 | //===----------------------------------------------------------------------===// |
| 1943 | // Declaration Serialization |
| 1944 | //===----------------------------------------------------------------------===// |
| 1945 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1946 | /// \brief Write the block containing all of the declaration IDs |
| 1947 | /// lexically declared within the given DeclContext. |
| 1948 | /// |
| 1949 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 1950 | /// bistream, or 0 if no block was written. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1951 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1952 | DeclContext *DC) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1953 | if (DC->decls_empty()) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1954 | return 0; |
| 1955 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1956 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1957 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1958 | Record.push_back(DECL_CONTEXT_LEXICAL); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1959 | SmallVector<KindDeclIDPair, 64> Decls; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1960 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 1961 | D != DEnd; ++D) |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 1962 | Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1963 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 1964 | ++NumLexicalDeclContexts; |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1965 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, data(Decls)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1966 | return Offset; |
| 1967 | } |
| 1968 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1969 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 1970 | using namespace llvm; |
| 1971 | RecordData Record; |
| 1972 | |
| 1973 | // Write the type offsets array |
| 1974 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1975 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 1976 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1977 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 1978 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 1979 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1980 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1981 | Record.push_back(TYPE_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 1982 | Record.push_back(TypeOffsets.size()); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1983 | Record.push_back(FirstTypeID - NUM_PREDEF_TYPE_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1984 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, data(TypeOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 1985 | |
| 1986 | // Write the declaration offsets array |
| 1987 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1988 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 1989 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1990 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 1991 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 1992 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1993 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1994 | Record.push_back(DECL_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 1995 | Record.push_back(DeclOffsets.size()); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 1996 | Record.push_back(FirstDeclID - NUM_PREDEF_DECL_IDS); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1997 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, data(DeclOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2000 | //===----------------------------------------------------------------------===// |
| 2001 | // Global Method Pool and Selector Serialization |
| 2002 | //===----------------------------------------------------------------------===// |
| 2003 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2004 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2005 | // 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] | 2006 | class ASTMethodPoolTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2007 | ASTWriter &Writer; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2008 | |
| 2009 | public: |
| 2010 | typedef Selector key_type; |
| 2011 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2012 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2013 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2014 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2015 | ObjCMethodList Instance, Factory; |
| 2016 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2017 | typedef const data_type& data_type_ref; |
| 2018 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2019 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2020 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2021 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2022 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2023 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2024 | |
| 2025 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2026 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2027 | data_type_ref Methods) { |
| 2028 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 2029 | clang::io::Emit16(Out, KeyLen); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2030 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2031 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2032 | Method = Method->Next) |
| 2033 | if (Method->Method) |
| 2034 | DataLen += 4; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2035 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2036 | Method = Method->Next) |
| 2037 | if (Method->Method) |
| 2038 | DataLen += 4; |
| 2039 | clang::io::Emit16(Out, DataLen); |
| 2040 | return std::make_pair(KeyLen, DataLen); |
| 2041 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2042 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2043 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | uint64_t Start = Out.tell(); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2045 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2046 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2047 | unsigned N = Sel.getNumArgs(); |
| 2048 | clang::io::Emit16(Out, N); |
| 2049 | if (N == 0) |
| 2050 | N = 1; |
| 2051 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2052 | clang::io::Emit32(Out, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2053 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 2054 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2055 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2056 | void EmitData(raw_ostream& Out, key_type_ref, |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2057 | data_type_ref Methods, unsigned DataLen) { |
| 2058 | uint64_t Start = Out.tell(); (void)Start; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2059 | clang::io::Emit32(Out, Methods.ID); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2060 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2061 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2062 | Method = Method->Next) |
| 2063 | if (Method->Method) |
| 2064 | ++NumInstanceMethods; |
| 2065 | |
| 2066 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2067 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2068 | Method = Method->Next) |
| 2069 | if (Method->Method) |
| 2070 | ++NumFactoryMethods; |
| 2071 | |
| 2072 | clang::io::Emit16(Out, NumInstanceMethods); |
| 2073 | clang::io::Emit16(Out, NumFactoryMethods); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2074 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2075 | Method = Method->Next) |
| 2076 | if (Method->Method) |
| 2077 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2078 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2079 | Method = Method->Next) |
| 2080 | if (Method->Method) |
| 2081 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2082 | |
| 2083 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2084 | } |
| 2085 | }; |
| 2086 | } // end anonymous namespace |
| 2087 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2088 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2089 | /// |
| 2090 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2091 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2092 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2093 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2094 | using namespace llvm; |
| 2095 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2096 | // Do we have to do anything at all? |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2097 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2098 | return; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2099 | unsigned NumTableEntries = 0; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2100 | // 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] | 2101 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2102 | OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2103 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2104 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2105 | // Create the on-disk hash table representation. We walk through every |
| 2106 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2107 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2108 | for (llvm::DenseMap<Selector, SelectorID>::iterator |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2109 | I = SelectorIDs.begin(), E = SelectorIDs.end(); |
| 2110 | I != E; ++I) { |
| 2111 | Selector S = I->first; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2112 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2113 | ASTMethodPoolTrait::data_type Data = { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2114 | I->second, |
| 2115 | ObjCMethodList(), |
| 2116 | ObjCMethodList() |
| 2117 | }; |
| 2118 | if (F != SemaRef.MethodPool.end()) { |
| 2119 | Data.Instance = F->second.first; |
| 2120 | Data.Factory = F->second.second; |
| 2121 | } |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2122 | // 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] | 2123 | // changed. |
| 2124 | if (Chain && I->second < FirstSelectorID) { |
| 2125 | // Selector already exists. Did it change? |
| 2126 | bool changed = false; |
| 2127 | for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; |
| 2128 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2129 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2130 | changed = true; |
| 2131 | } |
| 2132 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; |
| 2133 | M = M->Next) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2134 | if (!M->Method->isFromASTFile()) |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2135 | changed = true; |
| 2136 | } |
| 2137 | if (!changed) |
| 2138 | continue; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2139 | } else if (Data.Instance.Method || Data.Factory.Method) { |
| 2140 | // A new method pool entry. |
| 2141 | ++NumTableEntries; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2142 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2143 | Generator.insert(S, Data, Trait); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2146 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | llvm::SmallString<4096> MethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2148 | uint32_t BucketOffset; |
| 2149 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2150 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2151 | llvm::raw_svector_ostream Out(MethodPool); |
| 2152 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2153 | clang::io::Emit32(Out, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2154 | BucketOffset = Generator.Emit(Out, Trait); |
| 2155 | } |
| 2156 | |
| 2157 | // Create a blob abbreviation |
| 2158 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2159 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2160 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2161 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2162 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2163 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2164 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2165 | // Write the method pool |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2166 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2167 | Record.push_back(METHOD_POOL); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2168 | Record.push_back(BucketOffset); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2169 | Record.push_back(NumTableEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2170 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2171 | |
| 2172 | // Create a blob abbreviation for the selector table offsets. |
| 2173 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2174 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2175 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2176 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2177 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2178 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2179 | |
| 2180 | // Write the selector offsets table. |
| 2181 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2182 | Record.push_back(SELECTOR_OFFSETS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2183 | Record.push_back(SelectorOffsets.size()); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2184 | Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2185 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2186 | data(SelectorOffsets)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2187 | } |
| 2188 | } |
| 2189 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2190 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2191 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2192 | using namespace llvm; |
| 2193 | if (SemaRef.ReferencedSelectors.empty()) |
| 2194 | return; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2195 | |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2196 | RecordData Record; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2197 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2198 | // 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] | 2199 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 2200 | // headers, probably not worth it. It's not a correctness issue. |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2201 | for (DenseMap<Selector, SourceLocation>::iterator S = |
| 2202 | SemaRef.ReferencedSelectors.begin(), |
| 2203 | E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { |
| 2204 | Selector Sel = (*S).first; |
| 2205 | SourceLocation Loc = (*S).second; |
| 2206 | AddSelectorRef(Sel, Record); |
| 2207 | AddSourceLocation(Loc, Record); |
| 2208 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2209 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2212 | //===----------------------------------------------------------------------===// |
| 2213 | // Identifier Table Serialization |
| 2214 | //===----------------------------------------------------------------------===// |
| 2215 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2216 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2217 | class ASTIdentifierTableTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2218 | ASTWriter &Writer; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2219 | Preprocessor &PP; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2220 | bool IsModule; |
| 2221 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2222 | /// \brief Determines whether this is an "interesting" identifier |
| 2223 | /// that needs a full IdentifierInfo structure written into the hash |
| 2224 | /// table. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2225 | bool isInterestingIdentifier(IdentifierInfo *II, MacroInfo *&Macro) { |
| 2226 | Macro = 0; |
| 2227 | |
| 2228 | if (II->isPoisoned() || |
| 2229 | II->isExtensionToken() || |
| 2230 | II->getObjCOrBuiltinID() || |
| 2231 | II->getFETokenInfo<void>()) |
| 2232 | return true; |
| 2233 | |
| 2234 | if (!II->hasMacroDefinition()) |
| 2235 | return false; |
| 2236 | |
| 2237 | if (!IsModule) |
| 2238 | return true; |
| 2239 | |
| 2240 | if ((Macro = PP.getMacroInfo(II))) |
| 2241 | return Macro->isExported(); |
| 2242 | |
| 2243 | return false; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2246 | public: |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2247 | typedef IdentifierInfo* key_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2248 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2249 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2250 | typedef IdentID data_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2251 | typedef data_type data_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2252 | |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2253 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, bool IsModule) |
| 2254 | : Writer(Writer), PP(PP), IsModule(IsModule) { } |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2255 | |
| 2256 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 2257 | return llvm::HashString(II->getName()); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2258 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2259 | |
| 2260 | std::pair<unsigned,unsigned> |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2261 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2262 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2263 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2264 | MacroInfo *Macro; |
| 2265 | if (isInterestingIdentifier(II, Macro)) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2266 | DataLen += 2; // 2 bytes for builtin ID, flags |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2267 | if (II->hasMacroDefinition() && |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2268 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro()) |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2269 | DataLen += 4; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2270 | for (IdentifierResolver::iterator D = IdentifierResolver::begin(II), |
| 2271 | DEnd = IdentifierResolver::end(); |
| 2272 | D != DEnd; ++D) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2273 | DataLen += sizeof(DeclID); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2274 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2275 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 2276 | // We emit the key length after the data length so that every |
| 2277 | // string is preceded by a 16-bit length. This matches the PTH |
| 2278 | // format for storing identifiers. |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2279 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2280 | return std::make_pair(KeyLen, DataLen); |
| 2281 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2282 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2283 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2284 | unsigned KeyLen) { |
| 2285 | // Record the location of the key data. This is used when generating |
| 2286 | // the mapping from persistent IDs to strings. |
| 2287 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2288 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2290 | |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2291 | void EmitData(raw_ostream& Out, IdentifierInfo* II, |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2292 | IdentID ID, unsigned) { |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2293 | MacroInfo *Macro; |
| 2294 | if (!isInterestingIdentifier(II, Macro)) { |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2295 | clang::io::Emit32(Out, ID << 1); |
| 2296 | return; |
| 2297 | } |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2298 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2299 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2300 | uint32_t Bits = 0; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2301 | bool hasMacroDefinition |
| 2302 | = II->hasMacroDefinition() && |
| 2303 | (Macro || (Macro = PP.getMacroInfo(II))) && !Macro->isBuiltinMacro(); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2304 | Bits = (uint32_t)II->getObjCOrBuiltinID(); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2305 | Bits = (Bits << 1) | unsigned(hasMacroDefinition); |
| 2306 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 2307 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 2308 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2309 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2310 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2311 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2312 | if (hasMacroDefinition) |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2313 | clang::io::Emit32(Out, Writer.getMacroOffset(II)); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2314 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2315 | // Emit the declaration IDs in reverse order, because the |
| 2316 | // IdentifierResolver provides the declarations as they would be |
| 2317 | // visible (e.g., the function "stat" would come before the struct |
| 2318 | // "stat"), but IdentifierResolver::AddDeclToIdentifierChain() |
| 2319 | // adds declarations to the end of the list (so we need to see the |
| 2320 | // struct "status" before the function "status"). |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2321 | // Only emit declarations that aren't from a chained PCH, though. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2322 | SmallVector<Decl *, 16> Decls(IdentifierResolver::begin(II), |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2323 | IdentifierResolver::end()); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2324 | for (SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2325 | DEnd = Decls.rend(); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2326 | D != DEnd; ++D) |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 2327 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2328 | } |
| 2329 | }; |
| 2330 | } // end anonymous namespace |
| 2331 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2332 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2333 | /// |
| 2334 | /// The identifier table consists of a blob containing string data |
| 2335 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 2336 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2337 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, bool IsModule) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2338 | using namespace llvm; |
| 2339 | |
| 2340 | // Create and write out the blob that contains the identifier |
| 2341 | // strings. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2342 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2343 | OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2344 | ASTIdentifierTableTrait Trait(*this, PP, IsModule); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2345 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2346 | // Look for any identifiers that were named while processing the |
| 2347 | // headers, but are otherwise not needed. We add these to the hash |
| 2348 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2349 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2350 | // file. |
| 2351 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 2352 | IDEnd = PP.getIdentifierTable().end(); |
| 2353 | ID != IDEnd; ++ID) |
| 2354 | getIdentifierRef(ID->second); |
| 2355 | |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2356 | // Create the on-disk hash table representation. We only store offsets |
| 2357 | // for identifiers that appear here for the first time. |
| 2358 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2359 | for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2360 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 2361 | ID != IDEnd; ++ID) { |
| 2362 | assert(ID->first && "NULL identifier in identifier table"); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2363 | if (!Chain || !ID->first->isFromAST()) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2364 | Generator.insert(const_cast<IdentifierInfo *>(ID->first), ID->second, |
| 2365 | Trait); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2366 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2367 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2368 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2369 | llvm::SmallString<4096> IdentifierTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2370 | uint32_t BucketOffset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2371 | { |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2372 | ASTIdentifierTableTrait Trait(*this, PP, IsModule); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2373 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2374 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2375 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2376 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | // Create a blob abbreviation |
| 2380 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2381 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2382 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2383 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2384 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2385 | |
| 2386 | // Write the identifier table |
| 2387 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2388 | Record.push_back(IDENTIFIER_TABLE); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2389 | Record.push_back(BucketOffset); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2390 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2394 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2395 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2396 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2397 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2398 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2399 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2400 | |
| 2401 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2402 | Record.push_back(IDENTIFIER_OFFSET); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2403 | Record.push_back(IdentifierOffsets.size()); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2404 | Record.push_back(FirstIdentID - NUM_PREDEF_IDENT_IDS); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2405 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2406 | data(IdentifierOffsets)); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2409 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2410 | // DeclContext's Name Lookup Table Serialization |
| 2411 | //===----------------------------------------------------------------------===// |
| 2412 | |
| 2413 | namespace { |
| 2414 | // Trait used for the on-disk hash table used in the method pool. |
| 2415 | class ASTDeclContextNameLookupTrait { |
| 2416 | ASTWriter &Writer; |
| 2417 | |
| 2418 | public: |
| 2419 | typedef DeclarationName key_type; |
| 2420 | typedef key_type key_type_ref; |
| 2421 | |
| 2422 | typedef DeclContext::lookup_result data_type; |
| 2423 | typedef const data_type& data_type_ref; |
| 2424 | |
| 2425 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 2426 | |
| 2427 | unsigned ComputeHash(DeclarationName Name) { |
| 2428 | llvm::FoldingSetNodeID ID; |
| 2429 | ID.AddInteger(Name.getNameKind()); |
| 2430 | |
| 2431 | switch (Name.getNameKind()) { |
| 2432 | case DeclarationName::Identifier: |
| 2433 | ID.AddString(Name.getAsIdentifierInfo()->getName()); |
| 2434 | break; |
| 2435 | case DeclarationName::ObjCZeroArgSelector: |
| 2436 | case DeclarationName::ObjCOneArgSelector: |
| 2437 | case DeclarationName::ObjCMultiArgSelector: |
| 2438 | ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); |
| 2439 | break; |
| 2440 | case DeclarationName::CXXConstructorName: |
| 2441 | case DeclarationName::CXXDestructorName: |
| 2442 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2443 | break; |
| 2444 | case DeclarationName::CXXOperatorName: |
| 2445 | ID.AddInteger(Name.getCXXOverloadedOperator()); |
| 2446 | break; |
| 2447 | case DeclarationName::CXXLiteralOperatorName: |
| 2448 | ID.AddString(Name.getCXXLiteralIdentifier()->getName()); |
| 2449 | case DeclarationName::CXXUsingDirective: |
| 2450 | break; |
| 2451 | } |
| 2452 | |
| 2453 | return ID.ComputeHash(); |
| 2454 | } |
| 2455 | |
| 2456 | std::pair<unsigned,unsigned> |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2457 | EmitKeyDataLength(raw_ostream& Out, DeclarationName Name, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2458 | data_type_ref Lookup) { |
| 2459 | unsigned KeyLen = 1; |
| 2460 | switch (Name.getNameKind()) { |
| 2461 | case DeclarationName::Identifier: |
| 2462 | case DeclarationName::ObjCZeroArgSelector: |
| 2463 | case DeclarationName::ObjCOneArgSelector: |
| 2464 | case DeclarationName::ObjCMultiArgSelector: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2465 | case DeclarationName::CXXLiteralOperatorName: |
| 2466 | KeyLen += 4; |
| 2467 | break; |
| 2468 | case DeclarationName::CXXOperatorName: |
| 2469 | KeyLen += 1; |
| 2470 | break; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2471 | case DeclarationName::CXXConstructorName: |
| 2472 | case DeclarationName::CXXDestructorName: |
| 2473 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2474 | case DeclarationName::CXXUsingDirective: |
| 2475 | break; |
| 2476 | } |
| 2477 | clang::io::Emit16(Out, KeyLen); |
| 2478 | |
| 2479 | // 2 bytes for num of decls and 4 for each DeclID. |
| 2480 | unsigned DataLen = 2 + 4 * (Lookup.second - Lookup.first); |
| 2481 | clang::io::Emit16(Out, DataLen); |
| 2482 | |
| 2483 | return std::make_pair(KeyLen, DataLen); |
| 2484 | } |
| 2485 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2486 | void EmitKey(raw_ostream& Out, DeclarationName Name, unsigned) { |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2487 | using namespace clang::io; |
| 2488 | |
| 2489 | assert(Name.getNameKind() < 0x100 && "Invalid name kind ?"); |
| 2490 | Emit8(Out, Name.getNameKind()); |
| 2491 | switch (Name.getNameKind()) { |
| 2492 | case DeclarationName::Identifier: |
| 2493 | Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); |
| 2494 | break; |
| 2495 | case DeclarationName::ObjCZeroArgSelector: |
| 2496 | case DeclarationName::ObjCOneArgSelector: |
| 2497 | case DeclarationName::ObjCMultiArgSelector: |
| 2498 | Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); |
| 2499 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2500 | case DeclarationName::CXXOperatorName: |
| 2501 | assert(Name.getCXXOverloadedOperator() < 0x100 && "Invalid operator ?"); |
| 2502 | Emit8(Out, Name.getCXXOverloadedOperator()); |
| 2503 | break; |
| 2504 | case DeclarationName::CXXLiteralOperatorName: |
| 2505 | Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); |
| 2506 | break; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2507 | case DeclarationName::CXXConstructorName: |
| 2508 | case DeclarationName::CXXDestructorName: |
| 2509 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2510 | case DeclarationName::CXXUsingDirective: |
| 2511 | break; |
| 2512 | } |
| 2513 | } |
| 2514 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2515 | void EmitData(raw_ostream& Out, key_type_ref, |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2516 | data_type Lookup, unsigned DataLen) { |
| 2517 | uint64_t Start = Out.tell(); (void)Start; |
| 2518 | clang::io::Emit16(Out, Lookup.second - Lookup.first); |
| 2519 | for (; Lookup.first != Lookup.second; ++Lookup.first) |
| 2520 | clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first)); |
| 2521 | |
| 2522 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 2523 | } |
| 2524 | }; |
| 2525 | } // end anonymous namespace |
| 2526 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2527 | /// \brief Write the block containing all of the declaration IDs |
| 2528 | /// visible from the given DeclContext. |
| 2529 | /// |
| 2530 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2531 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2532 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 2533 | DeclContext *DC) { |
| 2534 | if (DC->getPrimaryContext() != DC) |
| 2535 | return 0; |
| 2536 | |
| 2537 | // Since there is no name lookup into functions or methods, don't bother to |
| 2538 | // build a visible-declarations table for these entities. |
| 2539 | if (DC->isFunctionOrMethod()) |
| 2540 | return 0; |
| 2541 | |
| 2542 | // If not in C++, we perform name lookup for the translation unit via the |
| 2543 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
| 2544 | // FIXME: In C++ we need the visible declarations in order to "see" the |
| 2545 | // friend declarations, is there a way to do this without writing the table ? |
| 2546 | if (DC->isTranslationUnit() && !Context.getLangOptions().CPlusPlus) |
| 2547 | return 0; |
| 2548 | |
| 2549 | // Force the DeclContext to build a its name-lookup table. |
Douglas Gregor | c266de9 | 2011-08-24 21:56:08 +0000 | [diff] [blame] | 2550 | if (!DC->hasExternalVisibleStorage()) |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 2551 | DC->lookup(DeclarationName()); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2552 | |
| 2553 | // Serialize the contents of the mapping used for lookup. Note that, |
| 2554 | // although we have two very different code paths, the serialized |
| 2555 | // representation is the same for both cases: a declaration name, |
| 2556 | // followed by a size, followed by references to the visible |
| 2557 | // declarations that have that name. |
| 2558 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 2559 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 2560 | if (!Map || Map->empty()) |
| 2561 | return 0; |
| 2562 | |
| 2563 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2564 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2565 | |
| 2566 | // Create the on-disk hash table representation. |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2567 | DeclarationName ConversionName; |
| 2568 | llvm::SmallVector<NamedDecl *, 4> ConversionDecls; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2569 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2570 | D != DEnd; ++D) { |
| 2571 | DeclarationName Name = D->first; |
| 2572 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2573 | if (Result.first != Result.second) { |
| 2574 | if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { |
| 2575 | // Hash all conversion function names to the same name. The actual |
| 2576 | // type information in conversion function name is not used in the |
| 2577 | // key (since such type information is not stable across different |
| 2578 | // modules), so the intended effect is to coalesce all of the conversion |
| 2579 | // functions under a single key. |
| 2580 | if (!ConversionName) |
| 2581 | ConversionName = Name; |
| 2582 | ConversionDecls.append(Result.first, Result.second); |
| 2583 | continue; |
| 2584 | } |
| 2585 | |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 2586 | Generator.insert(Name, Result, Trait); |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2587 | } |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
Douglas Gregor | e5a54b6 | 2011-08-30 20:49:19 +0000 | [diff] [blame] | 2590 | // Add the conversion functions |
| 2591 | if (!ConversionDecls.empty()) { |
| 2592 | Generator.insert(ConversionName, |
| 2593 | DeclContext::lookup_result(ConversionDecls.begin(), |
| 2594 | ConversionDecls.end()), |
| 2595 | Trait); |
| 2596 | } |
| 2597 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2598 | // Create the on-disk hash table in a buffer. |
| 2599 | llvm::SmallString<4096> LookupTable; |
| 2600 | uint32_t BucketOffset; |
| 2601 | { |
| 2602 | llvm::raw_svector_ostream Out(LookupTable); |
| 2603 | // Make sure that no bucket is at offset 0 |
| 2604 | clang::io::Emit32(Out, 0); |
| 2605 | BucketOffset = Generator.Emit(Out, Trait); |
| 2606 | } |
| 2607 | |
| 2608 | // Write the lookup table |
| 2609 | RecordData Record; |
| 2610 | Record.push_back(DECL_CONTEXT_VISIBLE); |
| 2611 | Record.push_back(BucketOffset); |
| 2612 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
| 2613 | LookupTable.str()); |
| 2614 | |
| 2615 | Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); |
| 2616 | ++NumVisibleDeclContexts; |
| 2617 | return Offset; |
| 2618 | } |
| 2619 | |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2620 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 2621 | /// |
| 2622 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 2623 | /// DeclContext in a dependent AST file. As such, they only exist for the TU |
| 2624 | /// (in C++) and for namespaces. |
| 2625 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2626 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 2627 | if (!Map || Map->empty()) |
| 2628 | return; |
| 2629 | |
| 2630 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2631 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2632 | |
| 2633 | // Create the hash table. |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2634 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2635 | D != DEnd; ++D) { |
| 2636 | DeclarationName Name = D->first; |
| 2637 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 2638 | // For any name that appears in this table, the results are complete, i.e. |
| 2639 | // they overwrite results from previous PCHs. Merging is always a mess. |
Argyrios Kyrtzidis | 45118d8 | 2011-08-30 19:43:23 +0000 | [diff] [blame] | 2640 | if (Result.first != Result.second) |
| 2641 | Generator.insert(Name, Result, Trait); |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | // Create the on-disk hash table in a buffer. |
| 2645 | llvm::SmallString<4096> LookupTable; |
| 2646 | uint32_t BucketOffset; |
| 2647 | { |
| 2648 | llvm::raw_svector_ostream Out(LookupTable); |
| 2649 | // Make sure that no bucket is at offset 0 |
| 2650 | clang::io::Emit32(Out, 0); |
| 2651 | BucketOffset = Generator.Emit(Out, Trait); |
| 2652 | } |
| 2653 | |
| 2654 | // Write the lookup table |
| 2655 | RecordData Record; |
| 2656 | Record.push_back(UPDATE_VISIBLE); |
| 2657 | Record.push_back(getDeclID(cast<Decl>(DC))); |
| 2658 | Record.push_back(BucketOffset); |
| 2659 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); |
| 2660 | } |
| 2661 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2662 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 2663 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
| 2664 | RecordData Record; |
| 2665 | Record.push_back(Opts.fp_contract); |
| 2666 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 2667 | } |
| 2668 | |
| 2669 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 2670 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
| 2671 | if (!SemaRef.Context.getLangOptions().OpenCL) |
| 2672 | return; |
| 2673 | |
| 2674 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 2675 | RecordData Record; |
| 2676 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 2677 | #include "clang/Basic/OpenCLExtensions.def" |
| 2678 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 2679 | } |
| 2680 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2681 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2682 | // General Serialization Routines |
| 2683 | //===----------------------------------------------------------------------===// |
| 2684 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2685 | /// \brief Write a record containing the given attributes. |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 2686 | void ASTWriter::WriteAttributes(const AttrVec &Attrs, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4eb9fc0 | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 2687 | Record.push_back(Attrs.size()); |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2688 | for (AttrVec::const_iterator i = Attrs.begin(), e = Attrs.end(); i != e; ++i){ |
| 2689 | const Attr * A = *i; |
| 2690 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
Argyrios Kyrtzidis | 768d6ca | 2011-09-13 16:05:58 +0000 | [diff] [blame] | 2691 | AddSourceRange(A->getRange(), Record); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2692 | |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2693 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | 4e9255f | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 2694 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2695 | } |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2696 | } |
| 2697 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2698 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2699 | Record.push_back(Str.size()); |
| 2700 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 2701 | } |
| 2702 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 2703 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 2704 | RecordDataImpl &Record) { |
| 2705 | Record.push_back(Version.getMajor()); |
| 2706 | if (llvm::Optional<unsigned> Minor = Version.getMinor()) |
| 2707 | Record.push_back(*Minor + 1); |
| 2708 | else |
| 2709 | Record.push_back(0); |
| 2710 | if (llvm::Optional<unsigned> Subminor = Version.getSubminor()) |
| 2711 | Record.push_back(*Subminor + 1); |
| 2712 | else |
| 2713 | Record.push_back(0); |
| 2714 | } |
| 2715 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2716 | /// \brief Note that the identifier II occurs at the given offset |
| 2717 | /// within the identifier table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2718 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2719 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2720 | // 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] | 2721 | // up earlier in the chain and thus don't need an offset. |
| 2722 | if (ID >= FirstIdentID) |
| 2723 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2724 | } |
| 2725 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2726 | /// \brief Note that the selector Sel occurs at the given offset |
| 2727 | /// within the method pool/selector table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2728 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2729 | unsigned ID = SelectorIDs[Sel]; |
| 2730 | assert(ID && "Unknown selector"); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2731 | // Don't record offsets for selectors that are also available in a different |
| 2732 | // file. |
| 2733 | if (ID < FirstSelectorID) |
| 2734 | return; |
| 2735 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2736 | } |
| 2737 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2738 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 2739 | : Stream(Stream), Context(0), Chain(0), SerializationListener(0), |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 2740 | FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2741 | FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2742 | FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2743 | FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2744 | FirstMacroID(NUM_PREDEF_MACRO_IDS), NextMacroID(FirstMacroID), |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 2745 | CollectedStmts(&StmtsToEmit), |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2746 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 2747 | NumVisibleDeclContexts(0), |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2748 | NextCXXBaseSpecifiersID(1), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 2749 | DeclParmVarAbbrev(0), DeclContextLexicalAbbrev(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 2750 | DeclContextVisibleLookupAbbrev(0), UpdateVisibleAbbrev(0), |
| 2751 | DeclRefExprAbbrev(0), CharacterLiteralAbbrev(0), |
| 2752 | DeclRecordAbbrev(0), IntegerLiteralAbbrev(0), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 2753 | DeclTypedefAbbrev(0), |
| 2754 | DeclVarAbbrev(0), DeclFieldAbbrev(0), |
| 2755 | DeclEnumAbbrev(0), DeclObjCIvarAbbrev(0) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2756 | { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 2757 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2758 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2759 | void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2760 | const std::string &OutputFile, |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2761 | bool IsModule, StringRef isysroot) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2762 | // Emit the file header. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2763 | Stream.Emit((unsigned)'C', 8); |
| 2764 | Stream.Emit((unsigned)'P', 8); |
| 2765 | Stream.Emit((unsigned)'C', 8); |
| 2766 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2767 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 2768 | WriteBlockInfoBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2769 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 2770 | Context = &SemaRef.Context; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2771 | WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile, IsModule); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 2772 | Context = 0; |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 2775 | template<typename Vector> |
| 2776 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, |
| 2777 | ASTWriter::RecordData &Record) { |
| 2778 | for (typename Vector::iterator I = Vec.begin(0, true), E = Vec.end(); |
| 2779 | I != E; ++I) { |
| 2780 | Writer.AddDeclRef(*I, Record); |
| 2781 | } |
| 2782 | } |
| 2783 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2784 | void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2785 | StringRef isysroot, |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2786 | const std::string &OutputFile, bool IsModule) { |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2787 | using namespace llvm; |
| 2788 | |
| 2789 | ASTContext &Context = SemaRef.Context; |
| 2790 | Preprocessor &PP = SemaRef.PP; |
| 2791 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2792 | // Set up predefined declaration IDs. |
| 2793 | DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 2794 | if (Context.ObjCIdDecl) |
| 2795 | DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID; |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 2796 | if (Context.ObjCSelDecl) |
| 2797 | DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID; |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 2798 | if (Context.ObjCClassDecl) |
| 2799 | DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID; |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 2800 | if (Context.Int128Decl) |
| 2801 | DeclIDs[Context.Int128Decl] = PREDEF_DECL_INT_128_ID; |
| 2802 | if (Context.UInt128Decl) |
| 2803 | DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID; |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 2804 | if (Context.ObjCInstanceTypeDecl) |
| 2805 | DeclIDs[Context.ObjCInstanceTypeDecl] = PREDEF_DECL_OBJC_INSTANCETYPE_ID; |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 2806 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 2807 | if (!Chain) { |
| 2808 | // Make sure that we emit IdentifierInfos (and any attached |
| 2809 | // declarations) for builtins. We don't need to do this when we're |
| 2810 | // emitting chained PCH files, because all of the builtins will be |
| 2811 | // in the original PCH file. |
| 2812 | // FIXME: Modules won't like this at all. |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2813 | IdentifierTable &Table = PP.getIdentifierTable(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2814 | SmallVector<const char *, 32> BuiltinNames; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2815 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
| 2816 | Context.getLangOptions().NoBuiltin); |
| 2817 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 2818 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 2819 | } |
| 2820 | |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2821 | // 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] | 2822 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2823 | // headers. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2824 | RecordData TentativeDefinitions; |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 2825 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 2826 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2827 | // Build a record containing all of the file scoped decls in this file. |
| 2828 | RecordData UnusedFileScopedDecls; |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 2829 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, |
| 2830 | UnusedFileScopedDecls); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2831 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 2832 | // Build a record containing all of the delegating constructors we still need |
| 2833 | // to resolve. |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2834 | RecordData DelegatingCtorDecls; |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 2835 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2836 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 2837 | // Write the set of weak, undeclared identifiers. We always write the |
| 2838 | // entire table, since later PCH files in a PCH chain are only interested in |
| 2839 | // the results at the end of the chain. |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2840 | RecordData WeakUndeclaredIdentifiers; |
| 2841 | if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2842 | for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2843 | I = SemaRef.WeakUndeclaredIdentifiers.begin(), |
| 2844 | E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { |
| 2845 | AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); |
| 2846 | AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); |
| 2847 | AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); |
| 2848 | WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); |
| 2849 | } |
| 2850 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2851 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2852 | // Build a record containing all of the locally-scoped external |
| 2853 | // declarations in this header file. Generally, this record will be |
| 2854 | // empty. |
| 2855 | RecordData LocallyScopedExternalDecls; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2856 | // 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] | 2857 | // nondeterminstic! |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2858 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2859 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 2860 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 2861 | TD != TDEnd; ++TD) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2862 | if (!TD->second->isFromASTFile()) |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 2863 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 2864 | } |
| 2865 | |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2866 | // Build a record containing all of the ext_vector declarations. |
| 2867 | RecordData ExtVectorDecls; |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 2868 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2869 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2870 | // Build a record containing all of the VTable uses information. |
| 2871 | RecordData VTableUses; |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 2872 | if (!SemaRef.VTableUses.empty()) { |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 2873 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 2874 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 2875 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 2876 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 2877 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | // Build a record containing all of dynamic classes declarations. |
| 2881 | RecordData DynamicClasses; |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 2882 | AddLazyVectorDecls(*this, SemaRef.DynamicClasses, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2883 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2884 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 2885 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2886 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 2887 | I = SemaRef.PendingInstantiations.begin(), |
| 2888 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 2889 | AddDeclRef(I->first, PendingInstantiations); |
| 2890 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2891 | } |
| 2892 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 2893 | "There are local ones at end of translation unit!"); |
| 2894 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2895 | // Build a record containing some declaration references. |
| 2896 | RecordData SemaDeclRefs; |
| 2897 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 2898 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 2899 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 2900 | } |
| 2901 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2902 | RecordData CUDASpecialDeclRefs; |
| 2903 | if (Context.getcudaConfigureCallDecl()) { |
| 2904 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 2905 | } |
| 2906 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2907 | // Build a record containing all of the known namespaces. |
| 2908 | RecordData KnownNamespaces; |
| 2909 | for (llvm::DenseMap<NamespaceDecl*, bool>::iterator |
| 2910 | I = SemaRef.KnownNamespaces.begin(), |
| 2911 | IEnd = SemaRef.KnownNamespaces.end(); |
| 2912 | I != IEnd; ++I) { |
| 2913 | if (!I->second) |
| 2914 | AddDeclRef(I->first, KnownNamespaces); |
| 2915 | } |
| 2916 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2917 | // Write the remaining AST contents. |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2918 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2919 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2920 | WriteMetadata(Context, isysroot, OutputFile); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2921 | WriteLanguageOptions(Context.getLangOptions()); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2922 | if (StatCalls && isysroot.empty()) |
Douglas Gregor | dd41ed5 | 2010-07-12 23:48:14 +0000 | [diff] [blame] | 2923 | WriteStatCache(*StatCalls); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2924 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Douglas Gregor | 69a9e01 | 2011-08-01 16:54:33 +0000 | [diff] [blame] | 2925 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 2926 | if (Chain) { |
| 2927 | // Write the mapping information describing our module dependencies and how |
| 2928 | // each of those modules were mapped into our own offset/ID space, so that |
| 2929 | // the reader can build the appropriate mapping to its own offset/ID space. |
| 2930 | // The map consists solely of a blob with the following format: |
| 2931 | // *(module-name-len:i16 module-name:len*i8 |
| 2932 | // source-location-offset:i32 |
| 2933 | // identifier-id:i32 |
| 2934 | // preprocessed-entity-id:i32 |
| 2935 | // macro-definition-id:i32 |
| 2936 | // selector-id:i32 |
| 2937 | // declaration-id:i32 |
| 2938 | // c++-base-specifiers-id:i32 |
| 2939 | // type-id:i32) |
| 2940 | // |
| 2941 | llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2942 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); |
| 2943 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2944 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2945 | llvm::SmallString<2048> Buffer; |
| 2946 | { |
| 2947 | llvm::raw_svector_ostream Out(Buffer); |
| 2948 | for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), |
| 2949 | MEnd = Chain->ModuleMgr.end(); |
| 2950 | M != MEnd; ++M) { |
| 2951 | StringRef FileName = (*M)->FileName; |
| 2952 | io::Emit16(Out, FileName.size()); |
| 2953 | Out.write(FileName.data(), FileName.size()); |
| 2954 | io::Emit32(Out, (*M)->SLocEntryBaseOffset); |
| 2955 | io::Emit32(Out, (*M)->BaseIdentifierID); |
| 2956 | io::Emit32(Out, (*M)->BasePreprocessedEntityID); |
| 2957 | io::Emit32(Out, (*M)->BaseMacroDefinitionID); |
| 2958 | io::Emit32(Out, (*M)->BaseSelectorID); |
| 2959 | io::Emit32(Out, (*M)->BaseDeclID); |
| 2960 | io::Emit32(Out, (*M)->BaseTypeIndex); |
| 2961 | } |
| 2962 | } |
| 2963 | Record.clear(); |
| 2964 | Record.push_back(MODULE_OFFSET_MAP); |
| 2965 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, |
| 2966 | Buffer.data(), Buffer.size()); |
| 2967 | } |
| 2968 | |
| 2969 | // Create a lexical update block containing all of the declarations in the |
| 2970 | // translation unit that do not come from other AST files. |
| 2971 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
| 2972 | SmallVector<KindDeclIDPair, 64> NewGlobalDecls; |
| 2973 | for (DeclContext::decl_iterator I = TU->noload_decls_begin(), |
| 2974 | E = TU->noload_decls_end(); |
| 2975 | I != E; ++I) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 2976 | if (!(*I)->isFromASTFile()) |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 2977 | NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); |
| 2978 | else if ((*I)->isChangedSinceDeserialization()) |
| 2979 | (void)GetDeclRef(*I); // Make sure it's written, but don't record it. |
| 2980 | } |
| 2981 | |
| 2982 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
| 2983 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
| 2984 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 2985 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
| 2986 | Record.clear(); |
| 2987 | Record.push_back(TU_UPDATE_LEXICAL); |
| 2988 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
| 2989 | data(NewGlobalDecls)); |
| 2990 | |
| 2991 | // And a visible updates block for the translation unit. |
| 2992 | Abv = new llvm::BitCodeAbbrev(); |
| 2993 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 2994 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 2995 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); |
| 2996 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 2997 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 2998 | WriteDeclContextVisibleUpdate(TU); |
| 2999 | |
| 3000 | // If the translation unit has an anonymous namespace, and we don't already |
| 3001 | // have an update block for it, write it as an update block. |
| 3002 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { |
| 3003 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; |
| 3004 | if (Record.empty()) { |
| 3005 | Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE); |
| 3006 | AddDeclRef(NS, Record); |
| 3007 | } |
| 3008 | } |
| 3009 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3010 | // Form the record of special types. |
| 3011 | RecordData SpecialTypes; |
| 3012 | AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes); |
Douglas Gregor | 30403a6 | 2011-08-11 22:04:35 +0000 | [diff] [blame] | 3013 | AddTypeRef(Context.ObjCProtoType, SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3014 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3015 | AddTypeRef(Context.getFILEType(), SpecialTypes); |
| 3016 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); |
| 3017 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); |
| 3018 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); |
| 3019 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3020 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3021 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3022 | // Keep writing types and declarations until all types and |
| 3023 | // declarations have been written. |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3024 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3025 | WriteDeclsBlockAbbrevs(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3026 | for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), |
| 3027 | E = DeclsToRewrite.end(); |
| 3028 | I != E; ++I) |
| 3029 | DeclTypesToEmit.push(const_cast<Decl*>(*I)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3030 | while (!DeclTypesToEmit.empty()) { |
| 3031 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 3032 | DeclTypesToEmit.pop(); |
| 3033 | if (DOT.isType()) |
| 3034 | WriteType(DOT.getType()); |
| 3035 | else |
| 3036 | WriteDecl(Context, DOT.getDecl()); |
| 3037 | } |
| 3038 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3039 | |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3040 | WritePreprocessor(PP, IsModule); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3041 | WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3042 | WriteSelectors(SemaRef); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3043 | WriteReferencedSelectorsPool(SemaRef); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3044 | WriteIdentifierTable(PP, IsModule); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3045 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 3046 | WriteOpenCLExtensions(SemaRef); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3047 | |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3048 | WriteTypeDeclOffsets(); |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3049 | WritePragmaDiagnosticMappings(Context.getDiagnostics()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3050 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 3051 | WriteCXXBaseSpecifiersOffsets(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3052 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3053 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); |
| 3054 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3055 | /// Build a record containing first declarations from a chained PCH and the |
| 3056 | /// most recent declarations in this AST that they point to. |
| 3057 | RecordData FirstLatestDeclIDs; |
| 3058 | for (FirstLatestDeclMap::iterator I = FirstLatestDecls.begin(), |
| 3059 | E = FirstLatestDecls.end(); |
| 3060 | I != E; ++I) { |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3061 | AddDeclRef(I->first, FirstLatestDeclIDs); |
| 3062 | AddDeclRef(I->second, FirstLatestDeclIDs); |
| 3063 | } |
| 3064 | |
| 3065 | if (!FirstLatestDeclIDs.empty()) |
| 3066 | Stream.EmitRecord(REDECLS_UPDATE_LATEST, FirstLatestDeclIDs); |
| 3067 | |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3068 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3069 | if (!ExternalDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3070 | Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3071 | |
| 3072 | // Write the record containing tentative definitions. |
| 3073 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3074 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3075 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3076 | // Write the record containing unused file scoped decls. |
| 3077 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3078 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3079 | |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3080 | // Write the record containing weak undeclared identifiers. |
| 3081 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3082 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 3083 | WeakUndeclaredIdentifiers); |
| 3084 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3085 | // Write the record containing locally-scoped external definitions. |
| 3086 | if (!LocallyScopedExternalDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3087 | Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3088 | LocallyScopedExternalDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3089 | |
| 3090 | // Write the record containing ext_vector type names. |
| 3091 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3092 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3094 | // Write the record containing VTable uses information. |
| 3095 | if (!VTableUses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3096 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3097 | |
| 3098 | // Write the record containing dynamic classes declarations. |
| 3099 | if (!DynamicClasses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3100 | Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3101 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3102 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3103 | if (!PendingInstantiations.empty()) |
| 3104 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3105 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3106 | // Write the record containing declaration references of Sema. |
| 3107 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3108 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3109 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3110 | // Write the record containing CUDA-specific declaration references. |
| 3111 | if (!CUDASpecialDeclRefs.empty()) |
| 3112 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3113 | |
| 3114 | // Write the delegating constructors. |
| 3115 | if (!DelegatingCtorDecls.empty()) |
| 3116 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3117 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3118 | // Write the known namespaces. |
| 3119 | if (!KnownNamespaces.empty()) |
| 3120 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
| 3121 | |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3122 | // Write the visible updates to DeclContexts. |
| 3123 | for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator |
| 3124 | I = UpdatedDeclContexts.begin(), |
| 3125 | E = UpdatedDeclContexts.end(); |
| 3126 | I != E; ++I) |
| 3127 | WriteDeclContextVisibleUpdate(*I); |
| 3128 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3129 | WriteDeclUpdatesBlocks(); |
Douglas Gregor | b7c324f | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 3130 | WriteDeclReplacementsBlock(); |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3131 | WriteChainedObjCCategories(); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3132 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3133 | // Some simple statistics |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3134 | Record.clear(); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3135 | Record.push_back(NumStatements); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 3136 | Record.push_back(NumMacros); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3137 | Record.push_back(NumLexicalDeclContexts); |
| 3138 | Record.push_back(NumVisibleDeclContexts); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3139 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3140 | Stream.ExitBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3141 | } |
| 3142 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3143 | void ASTWriter::WriteDeclUpdatesBlocks() { |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3144 | if (DeclUpdates.empty()) |
| 3145 | return; |
| 3146 | |
| 3147 | RecordData OffsetsRecord; |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3148 | Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3149 | for (DeclUpdateMap::iterator |
| 3150 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3151 | const Decl *D = I->first; |
| 3152 | UpdateRecord &URec = I->second; |
| 3153 | |
Argyrios Kyrtzidis | ba901b5 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 3154 | if (DeclsToRewrite.count(D)) |
| 3155 | continue; // The decl will be written completely,no need to store updates. |
| 3156 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3157 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 3158 | Stream.EmitRecord(DECL_UPDATES, URec); |
| 3159 | |
| 3160 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 3161 | OffsetsRecord.push_back(Offset); |
| 3162 | } |
| 3163 | Stream.ExitBlock(); |
| 3164 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); |
| 3165 | } |
| 3166 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3167 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3168 | if (ReplacedDecls.empty()) |
| 3169 | return; |
| 3170 | |
| 3171 | RecordData Record; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3172 | for (SmallVector<std::pair<DeclID, uint64_t>, 16>::iterator |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3173 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
| 3174 | Record.push_back(I->first); |
| 3175 | Record.push_back(I->second); |
| 3176 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3177 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3178 | } |
| 3179 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3180 | void ASTWriter::WriteChainedObjCCategories() { |
| 3181 | if (LocalChainedObjCCategories.empty()) |
| 3182 | return; |
| 3183 | |
| 3184 | RecordData Record; |
| 3185 | for (SmallVector<ChainedObjCCategoriesData, 16>::iterator |
| 3186 | I = LocalChainedObjCCategories.begin(), |
| 3187 | E = LocalChainedObjCCategories.end(); I != E; ++I) { |
| 3188 | ChainedObjCCategoriesData &Data = *I; |
| 3189 | serialization::DeclID |
| 3190 | HeadCatID = getDeclID(Data.Interface->getCategoryList()); |
| 3191 | assert(HeadCatID != 0 && "Category not written ?"); |
| 3192 | |
| 3193 | Record.push_back(Data.InterfaceID); |
| 3194 | Record.push_back(HeadCatID); |
| 3195 | Record.push_back(Data.TailCatID); |
| 3196 | } |
| 3197 | Stream.EmitRecord(OBJC_CHAINED_CATEGORIES, Record); |
| 3198 | } |
| 3199 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3200 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3201 | Record.push_back(Loc.getRawEncoding()); |
| 3202 | } |
| 3203 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3204 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3205 | AddSourceLocation(Range.getBegin(), Record); |
| 3206 | AddSourceLocation(Range.getEnd(), Record); |
| 3207 | } |
| 3208 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3209 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3210 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3211 | const uint64_t *Words = Value.getRawData(); |
| 3212 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3213 | } |
| 3214 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3215 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3216 | Record.push_back(Value.isUnsigned()); |
| 3217 | AddAPInt(Value, Record); |
| 3218 | } |
| 3219 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3220 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 3221 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 3222 | } |
| 3223 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3224 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3225 | Record.push_back(getIdentifierRef(II)); |
| 3226 | } |
| 3227 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3228 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3229 | if (II == 0) |
| 3230 | return 0; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3231 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3232 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3233 | if (ID == 0) |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3234 | ID = NextIdentID++; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3235 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3236 | } |
| 3237 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 3238 | MacroID ASTWriter::getMacroDefinitionID(MacroDefinition *MD) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3239 | if (MD == 0) |
| 3240 | return 0; |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 3241 | |
| 3242 | MacroID &ID = MacroDefinitions[MD]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3243 | if (ID == 0) |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3244 | ID = NextMacroID++; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3245 | return ID; |
| 3246 | } |
| 3247 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3248 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3249 | Record.push_back(getSelectorRef(SelRef)); |
| 3250 | } |
| 3251 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3252 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3253 | if (Sel.getAsOpaquePtr() == 0) { |
| 3254 | return 0; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3255 | } |
| 3256 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3257 | SelectorID &SID = SelectorIDs[Sel]; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3258 | if (SID == 0 && Chain) { |
| 3259 | // This might trigger a ReadSelector callback, which will set the ID for |
| 3260 | // this selector. |
| 3261 | Chain->LoadSelector(Sel); |
| 3262 | } |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3263 | if (SID == 0) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3264 | SID = NextSelectorID++; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3265 | } |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3266 | return SID; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3267 | } |
| 3268 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3269 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 3270 | AddDeclRef(Temp->getDestructor(), Record); |
| 3271 | } |
| 3272 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3273 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
| 3274 | CXXBaseSpecifier const *BasesEnd, |
| 3275 | RecordDataImpl &Record) { |
| 3276 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 3277 | CXXBaseSpecifiersToWrite.push_back( |
| 3278 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 3279 | Bases, BasesEnd)); |
| 3280 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 3281 | } |
| 3282 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3283 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3284 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3285 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3286 | switch (Kind) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3287 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3288 | AddStmt(Arg.getAsExpr()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3289 | break; |
| 3290 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3291 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3292 | break; |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3293 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3294 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3295 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3296 | break; |
| 3297 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3298 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3299 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3300 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3301 | break; |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3302 | case TemplateArgument::Null: |
| 3303 | case TemplateArgument::Integral: |
| 3304 | case TemplateArgument::Declaration: |
| 3305 | case TemplateArgument::Pack: |
| 3306 | break; |
| 3307 | } |
| 3308 | } |
| 3309 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3310 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3311 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3312 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3313 | |
| 3314 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 3315 | bool InfoHasSameExpr |
| 3316 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 3317 | Record.push_back(InfoHasSameExpr); |
| 3318 | if (InfoHasSameExpr) |
| 3319 | return; // Avoid storing the same expr twice. |
| 3320 | } |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3321 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 3322 | Record); |
| 3323 | } |
| 3324 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3325 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 3326 | RecordDataImpl &Record) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3327 | if (TInfo == 0) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3328 | AddTypeRef(QualType(), Record); |
| 3329 | return; |
| 3330 | } |
| 3331 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3332 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 3333 | } |
| 3334 | |
| 3335 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 3336 | AddTypeRef(TL.getType(), Record); |
| 3337 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3338 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3339 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3340 | TLW.Visit(TL); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3341 | } |
| 3342 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3343 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 7fb3518 | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 3344 | Record.push_back(GetOrCreateTypeID(T)); |
| 3345 | } |
| 3346 | |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3347 | TypeID ASTWriter::GetOrCreateTypeID( QualType T) { |
| 3348 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3349 | std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); |
| 3350 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3351 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3352 | TypeID ASTWriter::getTypeID(QualType T) const { |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3353 | return MakeTypeID(*Context, T, |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3354 | std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | TypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { |
| 3358 | if (T.isNull()) |
| 3359 | return TypeIdx(); |
| 3360 | assert(!T.getLocalFastQualifiers()); |
| 3361 | |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 3362 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3363 | if (Idx.getIndex() == 0) { |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3364 | // 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] | 3365 | // into the queue of types to emit. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3366 | Idx = TypeIdx(NextTypeID++); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3367 | DeclTypesToEmit.push(T); |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3368 | } |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3369 | return Idx; |
| 3370 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3371 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3372 | TypeIdx ASTWriter::getTypeIdx(QualType T) const { |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3373 | if (T.isNull()) |
| 3374 | return TypeIdx(); |
| 3375 | assert(!T.getLocalFastQualifiers()); |
| 3376 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3377 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3378 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 3379 | return I->second; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3382 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3383 | Record.push_back(GetDeclRef(D)); |
| 3384 | } |
| 3385 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3386 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3387 | if (D == 0) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3388 | return 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3389 | } |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3390 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3391 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3392 | if (ID == 0) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3393 | // We haven't seen this declaration before. Give it a new ID and |
| 3394 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3395 | ID = NextDeclID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3396 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3397 | } else if (ID < FirstDeclID && D->isChangedSinceDeserialization()) { |
| 3398 | // We don't add it to the replacement collection here, because we don't |
| 3399 | // have the offset yet. |
| 3400 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
| 3401 | // Reset the flag, so that we don't add this decl multiple times. |
| 3402 | const_cast<Decl *>(D)->setChangedSinceDeserialization(false); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3403 | } |
| 3404 | |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3405 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3406 | } |
| 3407 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3408 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3409 | if (D == 0) |
| 3410 | return 0; |
| 3411 | |
| 3412 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 3413 | return DeclIDs[D]; |
| 3414 | } |
| 3415 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3416 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 3417 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3418 | Record.push_back(Name.getNameKind()); |
| 3419 | switch (Name.getNameKind()) { |
| 3420 | case DeclarationName::Identifier: |
| 3421 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 3422 | break; |
| 3423 | |
| 3424 | case DeclarationName::ObjCZeroArgSelector: |
| 3425 | case DeclarationName::ObjCOneArgSelector: |
| 3426 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3427 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3428 | break; |
| 3429 | |
| 3430 | case DeclarationName::CXXConstructorName: |
| 3431 | case DeclarationName::CXXDestructorName: |
| 3432 | case DeclarationName::CXXConversionFunctionName: |
| 3433 | AddTypeRef(Name.getCXXNameType(), Record); |
| 3434 | break; |
| 3435 | |
| 3436 | case DeclarationName::CXXOperatorName: |
| 3437 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 3438 | break; |
| 3439 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3440 | case DeclarationName::CXXLiteralOperatorName: |
| 3441 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 3442 | break; |
| 3443 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3444 | case DeclarationName::CXXUsingDirective: |
| 3445 | // No extra data to emit |
| 3446 | break; |
| 3447 | } |
| 3448 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3449 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3450 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3451 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3452 | switch (Name.getNameKind()) { |
| 3453 | case DeclarationName::CXXConstructorName: |
| 3454 | case DeclarationName::CXXDestructorName: |
| 3455 | case DeclarationName::CXXConversionFunctionName: |
| 3456 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 3457 | break; |
| 3458 | |
| 3459 | case DeclarationName::CXXOperatorName: |
| 3460 | AddSourceLocation( |
| 3461 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 3462 | Record); |
| 3463 | AddSourceLocation( |
| 3464 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 3465 | Record); |
| 3466 | break; |
| 3467 | |
| 3468 | case DeclarationName::CXXLiteralOperatorName: |
| 3469 | AddSourceLocation( |
| 3470 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 3471 | Record); |
| 3472 | break; |
| 3473 | |
| 3474 | case DeclarationName::Identifier: |
| 3475 | case DeclarationName::ObjCZeroArgSelector: |
| 3476 | case DeclarationName::ObjCOneArgSelector: |
| 3477 | case DeclarationName::ObjCMultiArgSelector: |
| 3478 | case DeclarationName::CXXUsingDirective: |
| 3479 | break; |
| 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3484 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3485 | AddDeclarationName(NameInfo.getName(), Record); |
| 3486 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 3487 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 3488 | } |
| 3489 | |
| 3490 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3491 | RecordDataImpl &Record) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3492 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3493 | Record.push_back(Info.NumTemplParamLists); |
| 3494 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 3495 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 3496 | } |
| 3497 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3498 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3499 | RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3500 | // 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] | 3501 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3502 | SmallVector<NestedNameSpecifier *, 8> NestedNames; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3503 | |
| 3504 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 3505 | while (NNS) { |
| 3506 | NestedNames.push_back(NNS); |
| 3507 | NNS = NNS->getPrefix(); |
| 3508 | } |
| 3509 | |
| 3510 | Record.push_back(NestedNames.size()); |
| 3511 | while(!NestedNames.empty()) { |
| 3512 | NNS = NestedNames.pop_back_val(); |
| 3513 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 3514 | Record.push_back(Kind); |
| 3515 | switch (Kind) { |
| 3516 | case NestedNameSpecifier::Identifier: |
| 3517 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 3518 | break; |
| 3519 | |
| 3520 | case NestedNameSpecifier::Namespace: |
| 3521 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 3522 | break; |
| 3523 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 3524 | case NestedNameSpecifier::NamespaceAlias: |
| 3525 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 3526 | break; |
| 3527 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3528 | case NestedNameSpecifier::TypeSpec: |
| 3529 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3530 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 3531 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 3532 | break; |
| 3533 | |
| 3534 | case NestedNameSpecifier::Global: |
| 3535 | // Don't need to write an associated value. |
| 3536 | break; |
| 3537 | } |
| 3538 | } |
| 3539 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3540 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3541 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 3542 | RecordDataImpl &Record) { |
| 3543 | // 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] | 3544 | // typically accommodate the vast majority. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3545 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3546 | |
| 3547 | // Push each of the nested-name-specifiers's onto a stack for |
| 3548 | // serialization in reverse order. |
| 3549 | while (NNS) { |
| 3550 | NestedNames.push_back(NNS); |
| 3551 | NNS = NNS.getPrefix(); |
| 3552 | } |
| 3553 | |
| 3554 | Record.push_back(NestedNames.size()); |
| 3555 | while(!NestedNames.empty()) { |
| 3556 | NNS = NestedNames.pop_back_val(); |
| 3557 | NestedNameSpecifier::SpecifierKind Kind |
| 3558 | = NNS.getNestedNameSpecifier()->getKind(); |
| 3559 | Record.push_back(Kind); |
| 3560 | switch (Kind) { |
| 3561 | case NestedNameSpecifier::Identifier: |
| 3562 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 3563 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 3564 | break; |
| 3565 | |
| 3566 | case NestedNameSpecifier::Namespace: |
| 3567 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 3568 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 3569 | break; |
| 3570 | |
| 3571 | case NestedNameSpecifier::NamespaceAlias: |
| 3572 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 3573 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 3574 | break; |
| 3575 | |
| 3576 | case NestedNameSpecifier::TypeSpec: |
| 3577 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3578 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 3579 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 3580 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 3581 | break; |
| 3582 | |
| 3583 | case NestedNameSpecifier::Global: |
| 3584 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 3585 | break; |
| 3586 | } |
| 3587 | } |
| 3588 | } |
| 3589 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3590 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3591 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3592 | Record.push_back(Kind); |
| 3593 | switch (Kind) { |
| 3594 | case TemplateName::Template: |
| 3595 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 3596 | break; |
| 3597 | |
| 3598 | case TemplateName::OverloadedTemplate: { |
| 3599 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 3600 | Record.push_back(OvT->size()); |
| 3601 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 3602 | I != E; ++I) |
| 3603 | AddDeclRef(*I, Record); |
| 3604 | break; |
| 3605 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3606 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3607 | case TemplateName::QualifiedTemplate: { |
| 3608 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 3609 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 3610 | Record.push_back(QualT->hasTemplateKeyword()); |
| 3611 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 3612 | break; |
| 3613 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3614 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3615 | case TemplateName::DependentTemplate: { |
| 3616 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 3617 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 3618 | Record.push_back(DepT->isIdentifier()); |
| 3619 | if (DepT->isIdentifier()) |
| 3620 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 3621 | else |
| 3622 | Record.push_back(DepT->getOperator()); |
| 3623 | break; |
| 3624 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 3625 | |
| 3626 | case TemplateName::SubstTemplateTemplateParm: { |
| 3627 | SubstTemplateTemplateParmStorage *subst |
| 3628 | = Name.getAsSubstTemplateTemplateParm(); |
| 3629 | AddDeclRef(subst->getParameter(), Record); |
| 3630 | AddTemplateName(subst->getReplacement(), Record); |
| 3631 | break; |
| 3632 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3633 | |
| 3634 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 3635 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 3636 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 3637 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 3638 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 3639 | break; |
| 3640 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3641 | } |
| 3642 | } |
| 3643 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3644 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3645 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3646 | Record.push_back(Arg.getKind()); |
| 3647 | switch (Arg.getKind()) { |
| 3648 | case TemplateArgument::Null: |
| 3649 | break; |
| 3650 | case TemplateArgument::Type: |
| 3651 | AddTypeRef(Arg.getAsType(), Record); |
| 3652 | break; |
| 3653 | case TemplateArgument::Declaration: |
| 3654 | AddDeclRef(Arg.getAsDecl(), Record); |
| 3655 | break; |
| 3656 | case TemplateArgument::Integral: |
| 3657 | AddAPSInt(*Arg.getAsIntegral(), Record); |
| 3658 | AddTypeRef(Arg.getIntegralType(), Record); |
| 3659 | break; |
| 3660 | case TemplateArgument::Template: |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3661 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 3662 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3663 | case TemplateArgument::TemplateExpansion: |
| 3664 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3665 | if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
| 3666 | Record.push_back(*NumExpansions + 1); |
| 3667 | else |
| 3668 | Record.push_back(0); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3669 | break; |
| 3670 | case TemplateArgument::Expression: |
| 3671 | AddStmt(Arg.getAsExpr()); |
| 3672 | break; |
| 3673 | case TemplateArgument::Pack: |
| 3674 | Record.push_back(Arg.pack_size()); |
| 3675 | for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); |
| 3676 | I != E; ++I) |
| 3677 | AddTemplateArgument(*I, Record); |
| 3678 | break; |
| 3679 | } |
| 3680 | } |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3681 | |
| 3682 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3683 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3684 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3685 | assert(TemplateParams && "No TemplateParams!"); |
| 3686 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 3687 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 3688 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 3689 | Record.push_back(TemplateParams->size()); |
| 3690 | for (TemplateParameterList::const_iterator |
| 3691 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 3692 | P != PEnd; ++P) |
| 3693 | AddDeclRef(*P, Record); |
| 3694 | } |
| 3695 | |
| 3696 | /// \brief Emit a template argument list. |
| 3697 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3698 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3699 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3700 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 3701 | Record.push_back(TemplateArgs->size()); |
| 3702 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3703 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 3704 | } |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 3705 | |
| 3706 | |
| 3707 | void |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3708 | ASTWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 3709 | Record.push_back(Set.size()); |
| 3710 | for (UnresolvedSetImpl::const_iterator |
| 3711 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 3712 | AddDeclRef(I.getDecl(), Record); |
| 3713 | Record.push_back(I.getAccess()); |
| 3714 | } |
| 3715 | } |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3716 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3717 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3718 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3719 | Record.push_back(Base.isVirtual()); |
| 3720 | Record.push_back(Base.isBaseOfClass()); |
| 3721 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 3722 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 3723 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3724 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 3725 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 3726 | : SourceLocation(), |
| 3727 | Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3728 | } |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3729 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3730 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 3731 | RecordData Record; |
| 3732 | for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { |
| 3733 | Record.clear(); |
| 3734 | |
| 3735 | // Record the offset of this base-specifier set. |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3736 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3737 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 3738 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 3739 | else { |
| 3740 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 3741 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 3742 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 3743 | } |
| 3744 | |
| 3745 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 3746 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 3747 | Record.push_back(BEnd - B); |
| 3748 | for (; B != BEnd; ++B) |
| 3749 | AddCXXBaseSpecifier(*B, Record); |
| 3750 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | acec34b | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 3751 | |
| 3752 | // Flush any expressions that were written as part of the base specifiers. |
| 3753 | FlushStmts(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | CXXBaseSpecifiersToWrite.clear(); |
| 3757 | } |
| 3758 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 3759 | void ASTWriter::AddCXXCtorInitializers( |
| 3760 | const CXXCtorInitializer * const *CtorInitializers, |
| 3761 | unsigned NumCtorInitializers, |
| 3762 | RecordDataImpl &Record) { |
| 3763 | Record.push_back(NumCtorInitializers); |
| 3764 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 3765 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3766 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3767 | if (Init->isBaseInitializer()) { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 3768 | Record.push_back(CTOR_INITIALIZER_BASE); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3769 | AddTypeSourceInfo(Init->getBaseClassInfo(), Record); |
| 3770 | Record.push_back(Init->isBaseVirtual()); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 3771 | } else if (Init->isDelegatingInitializer()) { |
| 3772 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
| 3773 | AddDeclRef(Init->getTargetConstructor(), Record); |
| 3774 | } else if (Init->isMemberInitializer()){ |
| 3775 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 3776 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3777 | } else { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 3778 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 3779 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3780 | } |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 3781 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3782 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 3783 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3784 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 3785 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 3786 | Record.push_back(Init->isWritten()); |
| 3787 | if (Init->isWritten()) { |
| 3788 | Record.push_back(Init->getSourceOrder()); |
| 3789 | } else { |
| 3790 | Record.push_back(Init->getNumArrayIndices()); |
| 3791 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 3792 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 3793 | } |
| 3794 | } |
| 3795 | } |
| 3796 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3797 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
| 3798 | assert(D->DefinitionData); |
| 3799 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
| 3800 | Record.push_back(Data.UserDeclaredConstructor); |
| 3801 | Record.push_back(Data.UserDeclaredCopyConstructor); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 3802 | Record.push_back(Data.UserDeclaredMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3803 | Record.push_back(Data.UserDeclaredCopyAssignment); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 3804 | Record.push_back(Data.UserDeclaredMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3805 | Record.push_back(Data.UserDeclaredDestructor); |
| 3806 | Record.push_back(Data.Aggregate); |
| 3807 | Record.push_back(Data.PlainOldData); |
| 3808 | Record.push_back(Data.Empty); |
| 3809 | Record.push_back(Data.Polymorphic); |
| 3810 | Record.push_back(Data.Abstract); |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 3811 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 3812 | Record.push_back(Data.HasNoNonEmptyBases); |
| 3813 | Record.push_back(Data.HasPrivateFields); |
| 3814 | Record.push_back(Data.HasProtectedFields); |
| 3815 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 3816 | Record.push_back(Data.HasMutableFields); |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 3817 | Record.push_back(Data.HasTrivialDefaultConstructor); |
Richard Smith | 6b8bc07 | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 3818 | Record.push_back(Data.HasConstexprNonCopyMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3819 | Record.push_back(Data.HasTrivialCopyConstructor); |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 3820 | Record.push_back(Data.HasTrivialMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3821 | Record.push_back(Data.HasTrivialCopyAssignment); |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 3822 | Record.push_back(Data.HasTrivialMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3823 | Record.push_back(Data.HasTrivialDestructor); |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 3824 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3825 | Record.push_back(Data.ComputedVisibleConversions); |
Sean Hunt | cdee3fe | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 3826 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3827 | Record.push_back(Data.DeclaredDefaultConstructor); |
| 3828 | Record.push_back(Data.DeclaredCopyConstructor); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 3829 | Record.push_back(Data.DeclaredMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3830 | Record.push_back(Data.DeclaredCopyAssignment); |
Douglas Gregor | 58e9797 | 2011-09-06 16:38:46 +0000 | [diff] [blame] | 3831 | Record.push_back(Data.DeclaredMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3832 | Record.push_back(Data.DeclaredDestructor); |
Sebastian Redl | 14c3633 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 3833 | Record.push_back(Data.FailedImplicitMoveConstructor); |
| 3834 | Record.push_back(Data.FailedImplicitMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3835 | |
| 3836 | Record.push_back(Data.NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3837 | if (Data.NumBases > 0) |
| 3838 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 3839 | Record); |
| 3840 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3841 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 3842 | Record.push_back(Data.NumVBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3843 | if (Data.NumVBases > 0) |
| 3844 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 3845 | Record); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3846 | |
| 3847 | AddUnresolvedSet(Data.Conversions, Record); |
| 3848 | AddUnresolvedSet(Data.VisibleConversions, Record); |
| 3849 | // Data.Definition is the owning decl, no need to write it. |
| 3850 | AddDeclRef(Data.FirstFriend, Record); |
| 3851 | } |
| 3852 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3853 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3854 | assert(Reader && "Cannot remove chain"); |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 3855 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3856 | assert(FirstDeclID == NextDeclID && |
| 3857 | FirstTypeID == NextTypeID && |
| 3858 | FirstIdentID == NextIdentID && |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3859 | FirstSelectorID == NextSelectorID && |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3860 | FirstMacroID == NextMacroID && |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3861 | "Setting chain after writing has started."); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3862 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3863 | Chain = Reader; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3864 | |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 3865 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); |
| 3866 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); |
| 3867 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); |
| 3868 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); |
| 3869 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacroDefinitions(); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3870 | NextDeclID = FirstDeclID; |
| 3871 | NextTypeID = FirstTypeID; |
| 3872 | NextIdentID = FirstIdentID; |
| 3873 | NextSelectorID = FirstSelectorID; |
| 3874 | NextMacroID = FirstMacroID; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3875 | } |
| 3876 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3877 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3878 | IdentifierIDs[II] = ID; |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 3879 | if (II->hasMacroDefinition()) |
| 3880 | DeserializedMacroNames.push_back(II); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3881 | } |
| 3882 | |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3883 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3884 | // Always take the highest-numbered type index. This copes with an interesting |
| 3885 | // 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] | 3886 | // 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] | 3887 | // keep the higher-numbered entry so that we can properly write it out to |
| 3888 | // the AST file. |
| 3889 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 3890 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 3891 | StoredIdx = Idx; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3892 | } |
| 3893 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3894 | void ASTWriter::DeclRead(DeclID ID, const Decl *D) { |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3895 | DeclIDs[D] = ID; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3896 | } |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3897 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3898 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3899 | SelectorIDs[S] = ID; |
| 3900 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3901 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3902 | void ASTWriter::MacroDefinitionRead(serialization::MacroID ID, |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3903 | MacroDefinition *MD) { |
| 3904 | MacroDefinitions[MD] = ID; |
| 3905 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 3906 | |
| 3907 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
| 3908 | assert(D->isDefinition()); |
| 3909 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 3910 | // We are interested when a PCH decl is modified. |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3911 | if (RD->isFromASTFile()) { |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 3912 | // A forward reference was mutated into a definition. Rewrite it. |
| 3913 | // FIXME: This happens during template instantiation, should we |
| 3914 | // have created a new definition decl instead ? |
Argyrios Kyrtzidis | d3d0755 | 2010-10-28 07:38:45 +0000 | [diff] [blame] | 3915 | RewriteDecl(RD); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | for (CXXRecordDecl::redecl_iterator |
| 3919 | I = RD->redecls_begin(), E = RD->redecls_end(); I != E; ++I) { |
| 3920 | CXXRecordDecl *Redecl = cast<CXXRecordDecl>(*I); |
| 3921 | if (Redecl == RD) |
| 3922 | continue; |
| 3923 | |
| 3924 | // We are interested when a PCH decl is modified. |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3925 | if (Redecl->isFromASTFile()) { |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 3926 | UpdateRecord &Record = DeclUpdates[Redecl]; |
| 3927 | Record.push_back(UPD_CXX_SET_DEFINITIONDATA); |
| 3928 | assert(Redecl->DefinitionData); |
| 3929 | assert(Redecl->DefinitionData->Definition == D); |
| 3930 | AddDeclRef(D, Record); // the DefinitionDecl |
| 3931 | } |
| 3932 | } |
| 3933 | } |
| 3934 | } |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 3935 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
| 3936 | // TU and namespaces are handled elsewhere. |
| 3937 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 3938 | return; |
| 3939 | |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3940 | if (!(!D->isFromASTFile() && cast<Decl>(DC)->isFromASTFile())) |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 3941 | return; // Not a source decl added to a DeclContext from PCH. |
| 3942 | |
| 3943 | AddUpdatedDeclContext(DC); |
| 3944 | } |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 3945 | |
| 3946 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
| 3947 | assert(D->isImplicit()); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3948 | if (!(!D->isFromASTFile() && RD->isFromASTFile())) |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 3949 | return; // Not a source member added to a class from PCH. |
| 3950 | if (!isa<CXXMethodDecl>(D)) |
| 3951 | return; // We are interested in lazily declared implicit methods. |
| 3952 | |
| 3953 | // A decl coming from PCH was modified. |
| 3954 | assert(RD->isDefinition()); |
| 3955 | UpdateRecord &Record = DeclUpdates[RD]; |
| 3956 | Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); |
| 3957 | AddDeclRef(D, Record); |
| 3958 | } |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 3959 | |
| 3960 | void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, |
| 3961 | const ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 3962 | // The specializations set is kept in the canonical template. |
| 3963 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3964 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 3965 | return; // Not a source specialization added to a template from PCH. |
| 3966 | |
| 3967 | UpdateRecord &Record = DeclUpdates[TD]; |
| 3968 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
| 3969 | AddDeclRef(D, Record); |
| 3970 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3971 | |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 3972 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 3973 | const FunctionDecl *D) { |
| 3974 | // The specializations set is kept in the canonical template. |
| 3975 | TD = TD->getCanonicalDecl(); |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3976 | if (!(!D->isFromASTFile() && TD->isFromASTFile())) |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 3977 | return; // Not a source specialization added to a template from PCH. |
| 3978 | |
| 3979 | UpdateRecord &Record = DeclUpdates[TD]; |
| 3980 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
| 3981 | AddDeclRef(D, Record); |
| 3982 | } |
| 3983 | |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 3984 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3985 | if (!D->isFromASTFile()) |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 3986 | return; // Declaration not imported from PCH. |
| 3987 | |
| 3988 | // Implicit decl from a PCH was defined. |
| 3989 | // FIXME: Should implicit definition be a separate FunctionDecl? |
| 3990 | RewriteDecl(D); |
| 3991 | } |
| 3992 | |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 3993 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 3994 | if (!D->isFromASTFile()) |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 3995 | return; |
| 3996 | |
| 3997 | // Since the actual instantiation is delayed, this really means that we need |
| 3998 | // to update the instantiation location. |
| 3999 | UpdateRecord &Record = DeclUpdates[D]; |
| 4000 | Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER); |
| 4001 | AddSourceLocation( |
| 4002 | D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record); |
| 4003 | } |
| 4004 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4005 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, |
| 4006 | const ObjCInterfaceDecl *IFD) { |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4007 | if (!IFD->isFromASTFile()) |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4008 | return; // Declaration not imported from PCH. |
| 4009 | if (CatD->getNextClassCategory() && |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 4010 | !CatD->getNextClassCategory()->isFromASTFile()) |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4011 | return; // We already recorded that the tail of a category chain should be |
| 4012 | // attached to an interface. |
| 4013 | |
| 4014 | ChainedObjCCategoriesData Data = { IFD, GetDeclRef(IFD), GetDeclRef(CatD) }; |
| 4015 | LocalChainedObjCCategories.push_back(Data); |
| 4016 | } |
| 4017 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 4018 | ASTSerializationListener::~ASTSerializationListener() { } |