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> |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 56 | static llvm::StringRef data(const std::vector<T, Allocator> &v) { |
| 57 | if (v.empty()) return llvm::StringRef(); |
| 58 | return llvm::StringRef(reinterpret_cast<const char*>(&v[0]), |
| 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> |
| 63 | static llvm::StringRef data(const llvm::SmallVectorImpl<T> &v) { |
| 64 | return llvm::StringRef(reinterpret_cast<const char*>(v.data()), |
| 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); |
Sebastian Redl | a93e3b5 | 2010-07-08 22:01:51 +0000 | [diff] [blame] | 768 | RECORD(CHAINED_METADATA); |
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); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 783 | RECORD(FP_PRAGMA_OPTIONS); |
| 784 | RECORD(OPENCL_EXTENSIONS); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 785 | RECORD(DELEGATING_CTORS); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 786 | RECORD(FILE_SOURCE_LOCATION_OFFSETS); |
| 787 | RECORD(KNOWN_NAMESPACES); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 788 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 789 | // SourceManager Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 790 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 791 | RECORD(SM_SLOC_FILE_ENTRY); |
| 792 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 793 | RECORD(SM_SLOC_BUFFER_BLOB); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 794 | RECORD(SM_SLOC_EXPANSION_ENTRY); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 795 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 796 | // Preprocessor Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 797 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 798 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 799 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 800 | RECORD(PP_TOKEN); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 801 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 802 | // Decls and Types block. |
| 803 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 804 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 805 | RECORD(TYPE_COMPLEX); |
| 806 | RECORD(TYPE_POINTER); |
| 807 | RECORD(TYPE_BLOCK_POINTER); |
| 808 | RECORD(TYPE_LVALUE_REFERENCE); |
| 809 | RECORD(TYPE_RVALUE_REFERENCE); |
| 810 | RECORD(TYPE_MEMBER_POINTER); |
| 811 | RECORD(TYPE_CONSTANT_ARRAY); |
| 812 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 813 | RECORD(TYPE_VARIABLE_ARRAY); |
| 814 | RECORD(TYPE_VECTOR); |
| 815 | RECORD(TYPE_EXT_VECTOR); |
| 816 | RECORD(TYPE_FUNCTION_PROTO); |
| 817 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 818 | RECORD(TYPE_TYPEDEF); |
| 819 | RECORD(TYPE_TYPEOF_EXPR); |
| 820 | RECORD(TYPE_TYPEOF); |
| 821 | RECORD(TYPE_RECORD); |
| 822 | RECORD(TYPE_ENUM); |
| 823 | RECORD(TYPE_OBJC_INTERFACE); |
John McCall | a53d2cb | 2010-05-16 02:12:35 +0000 | [diff] [blame] | 824 | RECORD(TYPE_OBJC_OBJECT); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 825 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 826 | RECORD(TYPE_DECLTYPE); |
| 827 | RECORD(TYPE_ELABORATED); |
| 828 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); |
| 829 | RECORD(TYPE_UNRESOLVED_USING); |
| 830 | RECORD(TYPE_INJECTED_CLASS_NAME); |
| 831 | RECORD(TYPE_OBJC_OBJECT); |
| 832 | RECORD(TYPE_TEMPLATE_TYPE_PARM); |
| 833 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); |
| 834 | RECORD(TYPE_DEPENDENT_NAME); |
| 835 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); |
| 836 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); |
| 837 | RECORD(TYPE_PAREN); |
| 838 | RECORD(TYPE_PACK_EXPANSION); |
| 839 | RECORD(TYPE_ATTRIBUTED); |
| 840 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 841 | RECORD(DECL_TRANSLATION_UNIT); |
| 842 | RECORD(DECL_TYPEDEF); |
| 843 | RECORD(DECL_ENUM); |
| 844 | RECORD(DECL_RECORD); |
| 845 | RECORD(DECL_ENUM_CONSTANT); |
| 846 | RECORD(DECL_FUNCTION); |
| 847 | RECORD(DECL_OBJC_METHOD); |
| 848 | RECORD(DECL_OBJC_INTERFACE); |
| 849 | RECORD(DECL_OBJC_PROTOCOL); |
| 850 | RECORD(DECL_OBJC_IVAR); |
| 851 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
| 852 | RECORD(DECL_OBJC_CLASS); |
| 853 | RECORD(DECL_OBJC_FORWARD_PROTOCOL); |
| 854 | RECORD(DECL_OBJC_CATEGORY); |
| 855 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 856 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 857 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 858 | RECORD(DECL_OBJC_PROPERTY); |
| 859 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 860 | RECORD(DECL_FIELD); |
| 861 | RECORD(DECL_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 862 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 863 | RECORD(DECL_PARM_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 864 | RECORD(DECL_FILE_SCOPE_ASM); |
| 865 | RECORD(DECL_BLOCK); |
| 866 | RECORD(DECL_CONTEXT_LEXICAL); |
| 867 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | b6c2b3f | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 868 | RECORD(DECL_NAMESPACE); |
| 869 | RECORD(DECL_NAMESPACE_ALIAS); |
| 870 | RECORD(DECL_USING); |
| 871 | RECORD(DECL_USING_SHADOW); |
| 872 | RECORD(DECL_USING_DIRECTIVE); |
| 873 | RECORD(DECL_UNRESOLVED_USING_VALUE); |
| 874 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); |
| 875 | RECORD(DECL_LINKAGE_SPEC); |
| 876 | RECORD(DECL_CXX_RECORD); |
| 877 | RECORD(DECL_CXX_METHOD); |
| 878 | RECORD(DECL_CXX_CONSTRUCTOR); |
| 879 | RECORD(DECL_CXX_DESTRUCTOR); |
| 880 | RECORD(DECL_CXX_CONVERSION); |
| 881 | RECORD(DECL_ACCESS_SPEC); |
| 882 | RECORD(DECL_FRIEND); |
| 883 | RECORD(DECL_FRIEND_TEMPLATE); |
| 884 | RECORD(DECL_CLASS_TEMPLATE); |
| 885 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); |
| 886 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); |
| 887 | RECORD(DECL_FUNCTION_TEMPLATE); |
| 888 | RECORD(DECL_TEMPLATE_TYPE_PARM); |
| 889 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); |
| 890 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); |
| 891 | RECORD(DECL_STATIC_ASSERT); |
| 892 | RECORD(DECL_CXX_BASE_SPECIFIERS); |
| 893 | RECORD(DECL_INDIRECTFIELD); |
| 894 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); |
| 895 | |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 896 | // Statements and Exprs can occur in the Decls and Types block. |
| 897 | AddStmtsExprs(Stream, Record); |
| 898 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 899 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 900 | RECORD(PPD_MACRO_EXPANSION); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 901 | RECORD(PPD_MACRO_DEFINITION); |
| 902 | RECORD(PPD_INCLUSION_DIRECTIVE); |
| 903 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 904 | #undef RECORD |
| 905 | #undef BLOCK |
| 906 | Stream.ExitBlock(); |
| 907 | } |
| 908 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 909 | /// \brief Adjusts the given filename to only write out the portion of the |
| 910 | /// filename that is not part of the system root directory. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 911 | /// |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 912 | /// \param Filename the file name to adjust. |
| 913 | /// |
| 914 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 915 | /// the returned filename will be adjusted by this system root. |
| 916 | /// |
| 917 | /// \returns either the original filename (if it needs no adjustment) or the |
| 918 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | static const char * |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 920 | adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 921 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 922 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 923 | if (isysroot.empty()) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 924 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 925 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 926 | // Verify that the filename and the system root have the same prefix. |
| 927 | unsigned Pos = 0; |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 928 | for (; Filename[Pos] && Pos < isysroot.size(); ++Pos) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 929 | if (Filename[Pos] != isysroot[Pos]) |
| 930 | return Filename; // Prefixes don't match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 931 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 932 | // We hit the end of the filename before we hit the end of the system root. |
| 933 | if (!Filename[Pos]) |
| 934 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 935 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 936 | // If the file name has a '/' at the current position, skip over the '/'. |
| 937 | // We distinguish sysroot-based includes from absolute includes by the |
| 938 | // absence of '/' at the beginning of sysroot-based includes. |
| 939 | if (Filename[Pos] == '/') |
| 940 | ++Pos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 941 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 942 | return Filename + Pos; |
| 943 | } |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 944 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 945 | /// \brief Write the AST metadata (e.g., i686-apple-darwin9). |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 946 | void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 947 | const std::string &OutputFile) { |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 948 | using namespace llvm; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 949 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 950 | // Metadata |
| 951 | const TargetInfo &Target = Context.Target; |
| 952 | BitCodeAbbrev *MetaAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 77f4603 | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 953 | MetaAbbrev->Add(BitCodeAbbrevOp( |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 954 | Chain ? CHAINED_METADATA : METADATA)); |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 955 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST major |
| 956 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST minor |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 957 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major |
| 958 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor |
| 959 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
Sebastian Redl | 77f4603 | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 960 | // Target triple or chained PCH name |
| 961 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
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; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 965 | Record.push_back(Chain ? CHAINED_METADATA : METADATA); |
| 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()); |
Sebastian Redl | 77f4603 | 2010-07-09 21:00:24 +0000 | [diff] [blame] | 971 | // FIXME: This writes the absolute path for chained headers. |
| 972 | const std::string &BlobStr = Chain ? Chain->getFileName() : Target.getTriple().getTriple(); |
| 973 | Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, BlobStr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 974 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 975 | // Original file name and file ID |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 976 | SourceManager &SM = Context.getSourceManager(); |
| 977 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 978 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 979 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE_NAME)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 980 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 981 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 982 | |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 983 | llvm::SmallString<128> MainFilePath(MainFile->getName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 984 | |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 985 | llvm::sys::fs::make_absolute(MainFilePath); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 986 | |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 987 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 989 | isysroot); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 990 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 991 | Record.push_back(ORIGINAL_FILE_NAME); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 992 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 993 | |
| 994 | Record.clear(); |
| 995 | Record.push_back(SM.getMainFileID().getOpaqueValue()); |
| 996 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 997 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 998 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 999 | // Original PCH directory |
| 1000 | if (!OutputFile.empty() && OutputFile != "-") { |
| 1001 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1002 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); |
| 1003 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 1004 | unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); |
| 1005 | |
| 1006 | llvm::SmallString<128> OutputPath(OutputFile); |
| 1007 | |
| 1008 | llvm::sys::fs::make_absolute(OutputPath); |
| 1009 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); |
| 1010 | |
| 1011 | RecordData Record; |
| 1012 | Record.push_back(ORIGINAL_PCH_DIR); |
| 1013 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); |
| 1014 | } |
| 1015 | |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1016 | // Repository branch/version information. |
| 1017 | BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1018 | RepoAbbrev->Add(BitCodeAbbrevOp(VERSION_CONTROL_BRANCH_REVISION)); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1019 | RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 1020 | unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 1021 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1022 | Record.push_back(VERSION_CONTROL_BRANCH_REVISION); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 1023 | Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, |
| 1024 | getClangFullRepositoryVersion()); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /// \brief Write the LangOptions structure. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1028 | void ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1029 | RecordData Record; |
| 1030 | Record.push_back(LangOpts.Trigraphs); |
| 1031 | Record.push_back(LangOpts.BCPLComment); // BCPL-style '//' comments. |
| 1032 | Record.push_back(LangOpts.DollarIdents); // '$' allowed in identifiers. |
| 1033 | Record.push_back(LangOpts.AsmPreprocessor); // Preprocessor in asm mode. |
| 1034 | Record.push_back(LangOpts.GNUMode); // True in gnu99 mode false in c99 mode (etc) |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1035 | Record.push_back(LangOpts.GNUKeywords); // Allow GNU-extension keywords |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1036 | Record.push_back(LangOpts.ImplicitInt); // C89 implicit 'int'. |
| 1037 | Record.push_back(LangOpts.Digraphs); // C94, C99 and C++ |
| 1038 | Record.push_back(LangOpts.HexFloats); // C99 Hexadecimal float constants. |
| 1039 | Record.push_back(LangOpts.C99); // C99 Support |
Peter Collingbourne | 7e7fbd0 | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 1040 | Record.push_back(LangOpts.C1X); // C1X Support |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1041 | Record.push_back(LangOpts.Microsoft); // Microsoft extensions. |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1042 | // LangOpts.MSCVersion is ignored because all it does it set a macro, which is |
| 1043 | // already saved elsewhere. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1044 | Record.push_back(LangOpts.CPlusPlus); // C++ Support |
| 1045 | Record.push_back(LangOpts.CPlusPlus0x); // C++0x Support |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1046 | Record.push_back(LangOpts.CXXOperatorNames); // Treat C++ operator names as keywords. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1047 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1048 | Record.push_back(LangOpts.ObjC1); // Objective-C 1 support enabled. |
| 1049 | Record.push_back(LangOpts.ObjC2); // Objective-C 2 support enabled. |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1050 | Record.push_back(LangOpts.ObjCNonFragileABI); // Objective-C |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 1051 | // modern abi enabled. |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1052 | Record.push_back(LangOpts.ObjCNonFragileABI2); // Objective-C enhanced |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 1053 | // modern abi enabled. |
Fariborz Jahanian | f84109e | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 1054 | Record.push_back(LangOpts.AppleKext); // Apple's kernel extensions ABI |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 1055 | Record.push_back(LangOpts.ObjCDefaultSynthProperties); // Objective-C auto-synthesized |
| 1056 | // properties enabled. |
Douglas Gregor | 74da19f | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 1057 | Record.push_back(LangOpts.ObjCInferRelatedResultType); |
Fariborz Jahanian | 4c9d8d0 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 1058 | Record.push_back(LangOpts.NoConstantCFStrings); // non cfstring generation enabled.. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1059 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1060 | Record.push_back(LangOpts.PascalStrings); // Allow Pascal strings |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1061 | Record.push_back(LangOpts.WritableStrings); // Allow writable strings |
| 1062 | Record.push_back(LangOpts.LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 1063 | Record.push_back(LangOpts.AltiVec); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1064 | Record.push_back(LangOpts.Exceptions); // Support exception handling. |
Anders Carlsson | da4b7cf | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 1065 | Record.push_back(LangOpts.ObjCExceptions); |
Anders Carlsson | 7da99b0 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 1066 | Record.push_back(LangOpts.CXXExceptions); |
| 1067 | Record.push_back(LangOpts.SjLjExceptions); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1068 | |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 1069 | Record.push_back(LangOpts.MSBitfields); // MS-compatible structure layout |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1070 | Record.push_back(LangOpts.NeXTRuntime); // Use NeXT runtime. |
| 1071 | Record.push_back(LangOpts.Freestanding); // Freestanding implementation |
| 1072 | Record.push_back(LangOpts.NoBuiltin); // Do not use builtin functions (-fno-builtin) |
| 1073 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 1074 | // Whether static initializers are protected by locks. |
| 1075 | Record.push_back(LangOpts.ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 1076 | Record.push_back(LangOpts.POSIXThreads); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1077 | Record.push_back(LangOpts.Blocks); // block extension to C |
| 1078 | Record.push_back(LangOpts.EmitAllDecls); // Emit all declarations, even if |
| 1079 | // they are unused. |
| 1080 | Record.push_back(LangOpts.MathErrno); // Math functions must respect errno |
| 1081 | // (modulo the platform support). |
| 1082 | |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 1083 | Record.push_back(LangOpts.getSignedOverflowBehavior()); |
| 1084 | Record.push_back(LangOpts.HeinousExtensions); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1085 | |
| 1086 | Record.push_back(LangOpts.Optimize); // Whether __OPTIMIZE__ should be defined. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1087 | Record.push_back(LangOpts.OptimizeSize); // Whether __OPTIMIZE_SIZE__ should be |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1088 | // defined. |
| 1089 | Record.push_back(LangOpts.Static); // Should __STATIC__ be defined (as |
| 1090 | // opposed to __DYNAMIC__). |
| 1091 | Record.push_back(LangOpts.PICLevel); // The value for __PIC__, if non-zero. |
| 1092 | |
| 1093 | Record.push_back(LangOpts.GNUInline); // Should GNU inline semantics be |
| 1094 | // used (instead of C99 semantics). |
| 1095 | Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined. |
Chandler Carruth | 0d2d1bc | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 1096 | Record.push_back(LangOpts.Deprecated); // Should __DEPRECATED be defined. |
Anders Carlsson | a33d9b4 | 2009-05-13 19:49:53 +0000 | [diff] [blame] | 1097 | Record.push_back(LangOpts.AccessControl); // Whether C++ access control should |
| 1098 | // be enabled. |
Eli Friedman | 15b9176 | 2009-06-05 07:05:05 +0000 | [diff] [blame] | 1099 | Record.push_back(LangOpts.CharIsSigned); // Whether char is a signed or |
| 1100 | // unsigned type |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 1101 | Record.push_back(LangOpts.ShortWChar); // force wchar_t to be unsigned short |
Argyrios Kyrtzidis | b1bdced | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 1102 | Record.push_back(LangOpts.ShortEnums); // Should the enum type be equivalent |
| 1103 | // to the smallest integer type with |
| 1104 | // enough room. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1105 | Record.push_back(LangOpts.getGCMode()); |
| 1106 | Record.push_back(LangOpts.getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 1107 | Record.push_back(LangOpts.getStackProtectorMode()); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1108 | Record.push_back(LangOpts.InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 1109 | Record.push_back(LangOpts.OpenCL); |
Peter Collingbourne | 08a5326 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 1110 | Record.push_back(LangOpts.CUDA); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 1111 | Record.push_back(LangOpts.CatchUndefined); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 1112 | Record.push_back(LangOpts.DefaultFPContract); |
Anders Carlsson | 92f5822 | 2009-08-22 22:30:33 +0000 | [diff] [blame] | 1113 | Record.push_back(LangOpts.ElideConstructors); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 1114 | Record.push_back(LangOpts.SpellChecking); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 1115 | Record.push_back(LangOpts.MRTD); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1116 | Record.push_back(LangOpts.ObjCAutoRefCount); |
| 1117 | Record.push_back(LangOpts.ObjCInferRelatedReturnType); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1118 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1121 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1122 | // stat cache Serialization |
| 1123 | //===----------------------------------------------------------------------===// |
| 1124 | |
| 1125 | namespace { |
| 1126 | // Trait used for the on-disk hash table of stat cache results. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1127 | class ASTStatCacheTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1128 | public: |
| 1129 | typedef const char * key_type; |
| 1130 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1132 | typedef struct stat data_type; |
| 1133 | typedef const data_type &data_type_ref; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1134 | |
| 1135 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1136 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1137 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | |
| 1139 | std::pair<unsigned,unsigned> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1140 | EmitKeyDataLength(llvm::raw_ostream& Out, const char *path, |
| 1141 | data_type_ref Data) { |
| 1142 | unsigned StrLen = strlen(path); |
| 1143 | clang::io::Emit16(Out, StrLen); |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1144 | unsigned DataLen = 4 + 4 + 2 + 8 + 8; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1145 | clang::io::Emit8(Out, DataLen); |
| 1146 | return std::make_pair(StrLen + 1, DataLen); |
| 1147 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1149 | void EmitKey(llvm::raw_ostream& Out, const char *path, unsigned KeyLen) { |
| 1150 | Out.write(path, KeyLen); |
| 1151 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1152 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1153 | void EmitData(llvm::raw_ostream &Out, key_type_ref, |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1154 | data_type_ref Data, unsigned DataLen) { |
| 1155 | using namespace clang::io; |
| 1156 | uint64_t Start = Out.tell(); (void)Start; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1158 | Emit32(Out, (uint32_t) Data.st_ino); |
| 1159 | Emit32(Out, (uint32_t) Data.st_dev); |
| 1160 | Emit16(Out, (uint16_t) Data.st_mode); |
| 1161 | Emit64(Out, (uint64_t) Data.st_mtime); |
| 1162 | Emit64(Out, (uint64_t) Data.st_size); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1163 | |
| 1164 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1165 | } |
| 1166 | }; |
| 1167 | } // end anonymous namespace |
| 1168 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1169 | /// \brief Write the stat() system call cache to the AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1170 | void ASTWriter::WriteStatCache(MemorizeStatCalls &StatCalls) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1171 | // Build the on-disk hash table containing information about every |
| 1172 | // stat() call. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1173 | OnDiskChainedHashTableGenerator<ASTStatCacheTrait> Generator; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1174 | unsigned NumStatEntries = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1175 | for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1176 | StatEnd = StatCalls.end(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1177 | Stat != StatEnd; ++Stat, ++NumStatEntries) { |
Chris Lattner | 1e5f83b | 2011-07-14 18:24:21 +0000 | [diff] [blame] | 1178 | llvm::StringRef Filename = Stat->first(); |
| 1179 | Generator.insert(Filename.data(), Stat->second); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1181 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1182 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1183 | llvm::SmallString<4096> StatCacheData; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1184 | uint32_t BucketOffset; |
| 1185 | { |
| 1186 | llvm::raw_svector_ostream Out(StatCacheData); |
| 1187 | // Make sure that no bucket is at offset 0 |
| 1188 | clang::io::Emit32(Out, 0); |
| 1189 | BucketOffset = Generator.Emit(Out); |
| 1190 | } |
| 1191 | |
| 1192 | // Create a blob abbreviation |
| 1193 | using namespace llvm; |
| 1194 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1195 | Abbrev->Add(BitCodeAbbrevOp(STAT_CACHE)); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1196 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1197 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1198 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1199 | unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1200 | |
| 1201 | // Write the stat cache |
| 1202 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1203 | Record.push_back(STAT_CACHE); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1204 | Record.push_back(BucketOffset); |
| 1205 | Record.push_back(NumStatEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1206 | Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1210 | // Source Manager Serialization |
| 1211 | //===----------------------------------------------------------------------===// |
| 1212 | |
| 1213 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1214 | /// file. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1215 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1216 | using namespace llvm; |
| 1217 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1218 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1219 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1220 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1221 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1222 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1223 | // FileEntry fields. |
| 1224 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 1225 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1226 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1227 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1231 | /// buffer. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1232 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1233 | using namespace llvm; |
| 1234 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1235 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1236 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1237 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 1238 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 1239 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 1240 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1241 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 1245 | /// buffer's blob. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1246 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1247 | using namespace llvm; |
| 1248 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1249 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1250 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1251 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1254 | /// \brief Create an abbreviation for the SLocEntry that refers to a macro |
| 1255 | /// expansion. |
| 1256 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1257 | using namespace llvm; |
| 1258 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1259 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1260 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 1261 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 1262 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 1263 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | f60e991 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1264 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1265 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1268 | namespace { |
| 1269 | // Trait used for the on-disk hash table of header search information. |
| 1270 | class HeaderFileInfoTrait { |
| 1271 | ASTWriter &Writer; |
| 1272 | HeaderSearch &HS; |
| 1273 | |
| 1274 | public: |
| 1275 | HeaderFileInfoTrait(ASTWriter &Writer, HeaderSearch &HS) |
| 1276 | : Writer(Writer), HS(HS) { } |
| 1277 | |
| 1278 | typedef const char *key_type; |
| 1279 | typedef key_type key_type_ref; |
| 1280 | |
| 1281 | typedef HeaderFileInfo data_type; |
| 1282 | typedef const data_type &data_type_ref; |
| 1283 | |
| 1284 | static unsigned ComputeHash(const char *path) { |
| 1285 | // The hash is based only on the filename portion of the key, so that the |
| 1286 | // reader can match based on filenames when symlinking or excess path |
| 1287 | // elements ("foo/../", "../") change the form of the name. However, |
| 1288 | // complete path is still the key. |
| 1289 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1290 | } |
| 1291 | |
| 1292 | std::pair<unsigned,unsigned> |
| 1293 | EmitKeyDataLength(llvm::raw_ostream& Out, const char *path, |
| 1294 | data_type_ref Data) { |
| 1295 | unsigned StrLen = strlen(path); |
| 1296 | clang::io::Emit16(Out, StrLen); |
| 1297 | unsigned DataLen = 1 + 2 + 4; |
| 1298 | clang::io::Emit8(Out, DataLen); |
| 1299 | return std::make_pair(StrLen + 1, DataLen); |
| 1300 | } |
| 1301 | |
| 1302 | void EmitKey(llvm::raw_ostream& Out, const char *path, unsigned KeyLen) { |
| 1303 | Out.write(path, KeyLen); |
| 1304 | } |
| 1305 | |
| 1306 | void EmitData(llvm::raw_ostream &Out, key_type_ref, |
| 1307 | data_type_ref Data, unsigned DataLen) { |
| 1308 | using namespace clang::io; |
| 1309 | uint64_t Start = Out.tell(); (void)Start; |
| 1310 | |
Douglas Gregor | dd3e554 | 2011-05-04 00:14:37 +0000 | [diff] [blame] | 1311 | unsigned char Flags = (Data.isImport << 4) |
| 1312 | | (Data.isPragmaOnce << 3) |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1313 | | (Data.DirInfo << 1) |
| 1314 | | Data.Resolved; |
| 1315 | Emit8(Out, (uint8_t)Flags); |
| 1316 | Emit16(Out, (uint16_t) Data.NumIncludes); |
| 1317 | |
| 1318 | if (!Data.ControllingMacro) |
| 1319 | Emit32(Out, (uint32_t)Data.ControllingMacroID); |
| 1320 | else |
| 1321 | Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); |
| 1322 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 1323 | } |
| 1324 | }; |
| 1325 | } // end anonymous namespace |
| 1326 | |
| 1327 | /// \brief Write the header search block for the list of files that |
| 1328 | /// |
| 1329 | /// \param HS The header search structure to save. |
| 1330 | /// |
| 1331 | /// \param Chain Whether we're creating a chained AST file. |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1332 | void ASTWriter::WriteHeaderSearch(HeaderSearch &HS, StringRef isysroot) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1333 | llvm::SmallVector<const FileEntry *, 16> FilesByUID; |
| 1334 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); |
| 1335 | |
| 1336 | if (FilesByUID.size() > HS.header_file_size()) |
| 1337 | FilesByUID.resize(HS.header_file_size()); |
| 1338 | |
| 1339 | HeaderFileInfoTrait GeneratorTrait(*this, HS); |
| 1340 | OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; |
| 1341 | llvm::SmallVector<const char *, 4> SavedStrings; |
| 1342 | unsigned NumHeaderSearchEntries = 0; |
| 1343 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { |
| 1344 | const FileEntry *File = FilesByUID[UID]; |
| 1345 | if (!File) |
| 1346 | continue; |
| 1347 | |
| 1348 | const HeaderFileInfo &HFI = HS.header_file_begin()[UID]; |
| 1349 | if (HFI.External && Chain) |
| 1350 | continue; |
| 1351 | |
| 1352 | // Turn the file name into an absolute path, if it isn't already. |
| 1353 | const char *Filename = File->getName(); |
| 1354 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1355 | |
| 1356 | // If we performed any translation on the file name at all, we need to |
| 1357 | // save this string, since the generator will refer to it later. |
| 1358 | if (Filename != File->getName()) { |
| 1359 | Filename = strdup(Filename); |
| 1360 | SavedStrings.push_back(Filename); |
| 1361 | } |
| 1362 | |
| 1363 | Generator.insert(Filename, HFI, GeneratorTrait); |
| 1364 | ++NumHeaderSearchEntries; |
| 1365 | } |
| 1366 | |
| 1367 | // Create the on-disk hash table in a buffer. |
| 1368 | llvm::SmallString<4096> TableData; |
| 1369 | uint32_t BucketOffset; |
| 1370 | { |
| 1371 | llvm::raw_svector_ostream Out(TableData); |
| 1372 | // Make sure that no bucket is at offset 0 |
| 1373 | clang::io::Emit32(Out, 0); |
| 1374 | BucketOffset = Generator.Emit(Out, GeneratorTrait); |
| 1375 | } |
| 1376 | |
| 1377 | // Create a blob abbreviation |
| 1378 | using namespace llvm; |
| 1379 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1380 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); |
| 1381 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1382 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 1383 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1384 | unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1385 | |
| 1386 | // Write the stat cache |
| 1387 | RecordData Record; |
| 1388 | Record.push_back(HEADER_SEARCH_TABLE); |
| 1389 | Record.push_back(BucketOffset); |
| 1390 | Record.push_back(NumHeaderSearchEntries); |
| 1391 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); |
| 1392 | |
| 1393 | // Free all of the strings we had to duplicate. |
| 1394 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) |
| 1395 | free((void*)SavedStrings[I]); |
| 1396 | } |
| 1397 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1398 | /// \brief Writes the block containing the serialized form of the |
| 1399 | /// source manager. |
| 1400 | /// |
| 1401 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 1402 | /// blob), indexed based on the file name, so that we only create |
| 1403 | /// entries for files that we actually need. In the common case (no |
| 1404 | /// errors), we probably won't have to create file entries for any of |
| 1405 | /// the files in the AST. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1406 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1407 | const Preprocessor &PP, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1408 | StringRef isysroot) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1409 | RecordData Record; |
| 1410 | |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1411 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1412 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1413 | |
| 1414 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | 828e18c | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1415 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 1416 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 1417 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1418 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1419 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1420 | // Write out the source location entry table. We skip the first |
| 1421 | // entry, which is always the same dummy entry. |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1422 | std::vector<uint32_t> SLocEntryOffsets; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1423 | // Write out the offsets of only source location file entries. |
| 1424 | // We will go through them in ASTReader::validateFileEntries(). |
| 1425 | std::vector<uint32_t> SLocFileEntryOffsets; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1426 | RecordData PreloadSLocs; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1427 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); |
| 1428 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1429 | I != N; ++I) { |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1430 | // Get this source location entry. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1431 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1432 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1433 | // Record the offset of this source-location entry. |
| 1434 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1435 | |
| 1436 | // Figure out which record code to use. |
| 1437 | unsigned Code; |
| 1438 | if (SLoc->isFile()) { |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1439 | if (SLoc->getFile().getContentCache()->OrigEntry) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1440 | Code = SM_SLOC_FILE_ENTRY; |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1441 | SLocFileEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1442 | } else |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1443 | Code = SM_SLOC_BUFFER_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1444 | } else |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1445 | Code = SM_SLOC_EXPANSION_ENTRY; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1446 | Record.clear(); |
| 1447 | Record.push_back(Code); |
| 1448 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1449 | // Starting offset of this entry within this module, so skip the dummy. |
| 1450 | Record.push_back(SLoc->getOffset() - 2); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1451 | if (SLoc->isFile()) { |
| 1452 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1453 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1454 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1455 | Record.push_back(File.hasLineDirectives()); |
| 1456 | |
| 1457 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1458 | if (Content->OrigEntry) { |
| 1459 | assert(Content->OrigEntry == Content->ContentsEntry && |
| 1460 | "Writing to AST an overriden file is not supported"); |
| 1461 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1462 | // The source location entry is a file. The blob associated |
| 1463 | // with this entry is the file name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1464 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1465 | // Emit size/modification time for this file. |
Argyrios Kyrtzidis | b1c8649 | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1466 | Record.push_back(Content->OrigEntry->getSize()); |
| 1467 | Record.push_back(Content->OrigEntry->getModificationTime()); |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1468 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1469 | // 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] | 1470 | const char *Filename = Content->OrigEntry->getName(); |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1471 | llvm::SmallString<128> FilePath(Filename); |
Anders Carlsson | 2c10c80 | 2011-03-08 16:04:35 +0000 | [diff] [blame] | 1472 | |
| 1473 | // Ask the file manager to fixup the relative path for us. This will |
| 1474 | // honor the working directory. |
| 1475 | SourceMgr.getFileManager().FixupRelativePath(FilePath); |
| 1476 | |
| 1477 | // FIXME: This call to make_absolute shouldn't be necessary, the |
| 1478 | // call to FixupRelativePath should always return an absolute path. |
Michael J. Spencer | fbfd180 | 2010-12-21 16:45:57 +0000 | [diff] [blame] | 1479 | llvm::sys::fs::make_absolute(FilePath); |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1480 | Filename = FilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1481 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1482 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1483 | Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1484 | } else { |
| 1485 | // The source location entry is a buffer. The blob associated |
| 1486 | // with this entry contains the contents of the buffer. |
| 1487 | |
| 1488 | // We add one to the size so that we capture the trailing NULL |
| 1489 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1490 | // the reader side). |
Douglas Gregor | 36c35ba | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1491 | const llvm::MemoryBuffer *Buffer |
Chris Lattner | e127a0d | 2010-04-20 20:35:58 +0000 | [diff] [blame] | 1492 | = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1493 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1494 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
| 1495 | llvm::StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1496 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1497 | Record.push_back(SM_SLOC_BUFFER_BLOB); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1498 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1499 | llvm::StringRef(Buffer->getBufferStart(), |
| 1500 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1501 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1502 | if (strcmp(Name, "<built-in>") == 0) { |
| 1503 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1504 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1505 | } |
| 1506 | } else { |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1507 | // The source location entry is a macro expansion. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1508 | const SrcMgr::InstantiationInfo &Inst = SLoc->getInstantiation(); |
| 1509 | Record.push_back(Inst.getSpellingLoc().getRawEncoding()); |
| 1510 | Record.push_back(Inst.getInstantiationLocStart().getRawEncoding()); |
| 1511 | Record.push_back(Inst.getInstantiationLocEnd().getRawEncoding()); |
| 1512 | |
| 1513 | // Compute the token length for this macro expansion. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1514 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1515 | if (I + 1 != N) |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1516 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1517 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1518 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1522 | Stream.ExitBlock(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1523 | |
| 1524 | if (SLocEntryOffsets.empty()) |
| 1525 | return; |
| 1526 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1527 | // Write the source-location offsets table into the AST block. This |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1528 | // table is used for lazily loading source-location information. |
| 1529 | using namespace llvm; |
| 1530 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1531 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1532 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1533 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1534 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1535 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1536 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1537 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1538 | Record.push_back(SOURCE_LOCATION_OFFSETS); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1539 | Record.push_back(SLocEntryOffsets.size()); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1540 | Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1541 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1542 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1543 | // If we have module dependencies, write the mapping from source locations to |
| 1544 | // their containing modules, so that the reader can build the remapping. |
| 1545 | if (Chain) { |
| 1546 | // The map consists solely of a blob with the following format: |
| 1547 | // *(offset:i32 len:i16 name:len*i8) |
| 1548 | // Sorted by offset. |
| 1549 | typedef std::pair<uint32_t, llvm::StringRef> ModuleOffset; |
| 1550 | llvm::SmallVector<ModuleOffset, 16> Modules; |
| 1551 | Modules.reserve(Chain->Modules.size()); |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1552 | for (llvm::StringMap<Module*>::const_iterator |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1553 | I = Chain->Modules.begin(), E = Chain->Modules.end(); |
| 1554 | I != E; ++I) { |
| 1555 | Modules.push_back(ModuleOffset(I->getValue()->SLocEntryBaseOffset, |
| 1556 | I->getKey())); |
| 1557 | } |
| 1558 | std::sort(Modules.begin(), Modules.end()); |
| 1559 | |
| 1560 | Abbrev = new BitCodeAbbrev(); |
| 1561 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_MAP)); |
| 1562 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1563 | unsigned SLocMapAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1564 | llvm::SmallString<2048> Buffer; |
| 1565 | { |
| 1566 | llvm::raw_svector_ostream Out(Buffer); |
| 1567 | for (llvm::SmallVector<ModuleOffset, 16>::iterator I = Modules.begin(), |
| 1568 | E = Modules.end(); |
| 1569 | I != E; ++I) { |
| 1570 | io::Emit32(Out, I->first); |
| 1571 | io::Emit16(Out, I->second.size()); |
| 1572 | Out.write(I->second.data(), I->second.size()); |
| 1573 | } |
| 1574 | } |
| 1575 | Record.clear(); |
| 1576 | Record.push_back(SOURCE_LOCATION_MAP); |
| 1577 | Stream.EmitRecordWithBlob(SLocMapAbbrev, Record, |
| 1578 | Buffer.data(), Buffer.size()); |
| 1579 | } |
| 1580 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1581 | Abbrev = new BitCodeAbbrev(); |
| 1582 | Abbrev->Add(BitCodeAbbrevOp(FILE_SOURCE_LOCATION_OFFSETS)); |
| 1583 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
| 1584 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1585 | unsigned SLocFileOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1586 | |
| 1587 | Record.clear(); |
| 1588 | Record.push_back(FILE_SOURCE_LOCATION_OFFSETS); |
| 1589 | Record.push_back(SLocFileEntryOffsets.size()); |
| 1590 | Stream.EmitRecordWithBlob(SLocFileOffsetsAbbrev, Record, |
| 1591 | data(SLocFileEntryOffsets)); |
| 1592 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1593 | // Write the source location entry preloads array, telling the AST |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1594 | // reader which source locations entries it should load eagerly. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1595 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1596 | |
| 1597 | // Write the line table. It depends on remapping working, so it must come |
| 1598 | // after the source location offsets. |
| 1599 | if (SourceMgr.hasLineTable()) { |
| 1600 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1601 | |
| 1602 | Record.clear(); |
| 1603 | // Emit the file names |
| 1604 | Record.push_back(LineTable.getNumFilenames()); |
| 1605 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1606 | // Emit the file name |
| 1607 | const char *Filename = LineTable.getFilename(I); |
| 1608 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 1609 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1610 | Record.push_back(FilenameLen); |
| 1611 | if (FilenameLen) |
| 1612 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1613 | } |
| 1614 | |
| 1615 | // Emit the line entries |
| 1616 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1617 | L != LEnd; ++L) { |
| 1618 | // Only emit entries for local files. |
| 1619 | if (L->first < 0) |
| 1620 | continue; |
| 1621 | |
| 1622 | // Emit the file ID |
| 1623 | Record.push_back(L->first); |
| 1624 | |
| 1625 | // Emit the line entries |
| 1626 | Record.push_back(L->second.size()); |
| 1627 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
| 1628 | LEEnd = L->second.end(); |
| 1629 | LE != LEEnd; ++LE) { |
| 1630 | Record.push_back(LE->FileOffset); |
| 1631 | Record.push_back(LE->LineNo); |
| 1632 | Record.push_back(LE->FilenameID); |
| 1633 | Record.push_back((unsigned)LE->FileKind); |
| 1634 | Record.push_back(LE->IncludeOffset); |
| 1635 | } |
| 1636 | } |
| 1637 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); |
| 1638 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1641 | //===----------------------------------------------------------------------===// |
| 1642 | // Preprocessor Serialization |
| 1643 | //===----------------------------------------------------------------------===// |
| 1644 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1645 | static int compareMacroDefinitions(const void *XPtr, const void *YPtr) { |
| 1646 | const std::pair<const IdentifierInfo *, MacroInfo *> &X = |
| 1647 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; |
| 1648 | const std::pair<const IdentifierInfo *, MacroInfo *> &Y = |
| 1649 | *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; |
| 1650 | return X.first->getName().compare(Y.first->getName()); |
| 1651 | } |
| 1652 | |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1653 | /// \brief Writes the block containing the serialized form of the |
| 1654 | /// preprocessor. |
| 1655 | /// |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1656 | void ASTWriter::WritePreprocessor(const Preprocessor &PP) { |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1657 | RecordData Record; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1658 | |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1659 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1660 | if (PP.getCounterValue() != 0) { |
| 1661 | Record.push_back(PP.getCounterValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1662 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1663 | Record.clear(); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | // Enter the preprocessor block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1667 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1668 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1669 | // 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] | 1670 | // FIXME: use diagnostics subsystem for localization etc. |
| 1671 | if (PP.SawDateOrTime()) |
| 1672 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1673 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1674 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1675 | // Loop over all the macro definitions that are live at the end of the file, |
| 1676 | // emitting each to the PP section. |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1677 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1678 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1679 | // Construct the list of macro definitions that need to be serialized. |
| 1680 | llvm::SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> |
| 1681 | MacrosToEmit; |
| 1682 | llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1683 | for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), |
| 1684 | E = PP.macro_end(Chain == 0); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1685 | I != E; ++I) { |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1686 | MacroDefinitionsSeen.insert(I->first); |
| 1687 | MacrosToEmit.push_back(std::make_pair(I->first, I->second)); |
| 1688 | } |
| 1689 | |
| 1690 | // Sort the set of macro definitions that need to be serialized by the |
| 1691 | // name of the macro, to provide a stable ordering. |
| 1692 | llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), |
| 1693 | &compareMacroDefinitions); |
| 1694 | |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1695 | // Resolve any identifiers that defined macros at the time they were |
| 1696 | // deserialized, adding them to the list of macros to emit (if appropriate). |
| 1697 | for (unsigned I = 0, N = DeserializedMacroNames.size(); I != N; ++I) { |
| 1698 | IdentifierInfo *Name |
| 1699 | = const_cast<IdentifierInfo *>(DeserializedMacroNames[I]); |
| 1700 | if (Name->hasMacroDefinition() && MacroDefinitionsSeen.insert(Name)) |
| 1701 | MacrosToEmit.push_back(std::make_pair(Name, PP.getMacroInfo(Name))); |
| 1702 | } |
| 1703 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1704 | for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { |
| 1705 | const IdentifierInfo *Name = MacrosToEmit[I].first; |
| 1706 | MacroInfo *MI = MacrosToEmit[I].second; |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 1707 | if (!MI) |
| 1708 | continue; |
| 1709 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1710 | // 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] | 1711 | // been redefined by the header (in which case they are not isBuiltinMacro). |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1712 | // Also skip macros from a AST file if we're chaining. |
Douglas Gregor | ee9b0ba | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 1713 | |
| 1714 | // FIXME: There is a (probably minor) optimization we could do here, if |
| 1715 | // the macro comes from the original PCH but the identifier comes from a |
| 1716 | // chained PCH, by storing the offset into the original PCH rather than |
| 1717 | // writing the macro definition a second time. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1718 | if (MI->isBuiltinMacro() || |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1719 | (Chain && Name->isFromAST() && MI->isFromAST())) |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1720 | continue; |
| 1721 | |
Douglas Gregor | 9c73610 | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 1722 | AddIdentifierRef(Name, Record); |
| 1723 | MacroOffsets[Name] = Stream.GetCurrentBitNo(); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1724 | Record.push_back(MI->getDefinitionLoc().getRawEncoding()); |
| 1725 | Record.push_back(MI->isUsed()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1726 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1727 | unsigned Code; |
| 1728 | if (MI->isObjectLike()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1729 | Code = PP_MACRO_OBJECT_LIKE; |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1730 | } else { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1731 | Code = PP_MACRO_FUNCTION_LIKE; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1732 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1733 | Record.push_back(MI->isC99Varargs()); |
| 1734 | Record.push_back(MI->isGNUVarargs()); |
| 1735 | Record.push_back(MI->getNumArgs()); |
| 1736 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1737 | I != E; ++I) |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1738 | AddIdentifierRef(*I, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1739 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1740 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1741 | // If we have a detailed preprocessing record, record the macro definition |
| 1742 | // ID that corresponds to this macro. |
| 1743 | if (PPRec) |
| 1744 | Record.push_back(getMacroDefinitionID(PPRec->findMacroDefinition(MI))); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1745 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1746 | Stream.EmitRecord(Code, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1747 | Record.clear(); |
| 1748 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1749 | // Emit the tokens array. |
| 1750 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1751 | // Note that we know that the preprocessor does not have any annotation |
| 1752 | // tokens in it because they are created by the parser, and thus can't be |
| 1753 | // in a macro definition. |
| 1754 | const Token &Tok = MI->getReplacementToken(TokNo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1756 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1757 | Record.push_back(Tok.getLength()); |
| 1758 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1759 | // FIXME: When reading literal tokens, reconstruct the literal pointer if |
| 1760 | // it is needed. |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1761 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1762 | // FIXME: Should translate token kind to a stable encoding. |
| 1763 | Record.push_back(Tok.getKind()); |
| 1764 | // FIXME: Should translate token flags to a stable encoding. |
| 1765 | Record.push_back(Tok.getFlags()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1767 | Stream.EmitRecord(PP_TOKEN, Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1768 | Record.clear(); |
| 1769 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1770 | ++NumMacros; |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1771 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1772 | Stream.ExitBlock(); |
| 1773 | |
| 1774 | if (PPRec) |
| 1775 | WritePreprocessorDetail(*PPRec); |
| 1776 | } |
| 1777 | |
| 1778 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { |
| 1779 | if (PPRec.begin(Chain) == PPRec.end(Chain)) |
| 1780 | return; |
| 1781 | |
| 1782 | // Enter the preprocessor block. |
| 1783 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1784 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1785 | // If the preprocessor has a preprocessing record, emit it. |
| 1786 | unsigned NumPreprocessingRecords = 0; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1787 | using namespace llvm; |
| 1788 | |
| 1789 | // Set up the abbreviation for |
| 1790 | unsigned InclusionAbbrev = 0; |
| 1791 | { |
| 1792 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1793 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); |
| 1794 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index |
| 1795 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // start location |
| 1796 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // end location |
| 1797 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length |
| 1798 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes |
| 1799 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind |
| 1800 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1801 | InclusionAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1802 | } |
| 1803 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 1804 | unsigned IndexBase = Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1805 | RecordData Record; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1806 | uint64_t BitsInChain = Chain? Chain->TotalModulesSizeInBits : 0; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1807 | for (PreprocessingRecord::iterator E = PPRec.begin(Chain), |
| 1808 | EEnd = PPRec.end(Chain); |
| 1809 | E != EEnd; ++E) { |
| 1810 | Record.clear(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1811 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1812 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
| 1813 | // Record this macro definition's location. |
| 1814 | MacroID ID = getMacroDefinitionID(MD); |
| 1815 | |
| 1816 | // Don't write the macro definition if it is from another AST file. |
| 1817 | if (ID < FirstMacroID) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1818 | continue; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1819 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1820 | // Notify the serialization listener that we're serializing this entity. |
| 1821 | if (SerializationListener) |
| 1822 | SerializationListener->SerializedPreprocessedEntity(*E, |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1823 | BitsInChain + Stream.GetCurrentBitNo()); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1824 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1825 | unsigned Position = ID - FirstMacroID; |
| 1826 | if (Position != MacroDefinitionOffsets.size()) { |
| 1827 | if (Position > MacroDefinitionOffsets.size()) |
| 1828 | MacroDefinitionOffsets.resize(Position + 1); |
| 1829 | |
| 1830 | MacroDefinitionOffsets[Position] = Stream.GetCurrentBitNo(); |
| 1831 | } else |
| 1832 | MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo()); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1833 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1834 | Record.push_back(IndexBase + NumPreprocessingRecords++); |
| 1835 | Record.push_back(ID); |
| 1836 | AddSourceLocation(MD->getSourceRange().getBegin(), Record); |
| 1837 | AddSourceLocation(MD->getSourceRange().getEnd(), Record); |
| 1838 | AddIdentifierRef(MD->getName(), Record); |
| 1839 | AddSourceLocation(MD->getLocation(), Record); |
| 1840 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); |
| 1841 | continue; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1842 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1843 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1844 | // Notify the serialization listener that we're serializing this entity. |
| 1845 | if (SerializationListener) |
| 1846 | SerializationListener->SerializedPreprocessedEntity(*E, |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1847 | BitsInChain + Stream.GetCurrentBitNo()); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1848 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1849 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1850 | Record.push_back(IndexBase + NumPreprocessingRecords++); |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1851 | AddSourceLocation(ME->getSourceRange().getBegin(), Record); |
| 1852 | AddSourceLocation(ME->getSourceRange().getEnd(), Record); |
| 1853 | AddIdentifierRef(ME->getName(), Record); |
| 1854 | Record.push_back(getMacroDefinitionID(ME->getDefinition())); |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1855 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1856 | continue; |
| 1857 | } |
| 1858 | |
| 1859 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { |
| 1860 | Record.push_back(PPD_INCLUSION_DIRECTIVE); |
| 1861 | Record.push_back(IndexBase + NumPreprocessingRecords++); |
| 1862 | AddSourceLocation(ID->getSourceRange().getBegin(), Record); |
| 1863 | AddSourceLocation(ID->getSourceRange().getEnd(), Record); |
| 1864 | Record.push_back(ID->getFileName().size()); |
| 1865 | Record.push_back(ID->wasInQuotes()); |
| 1866 | Record.push_back(static_cast<unsigned>(ID->getKind())); |
| 1867 | llvm::SmallString<64> Buffer; |
| 1868 | Buffer += ID->getFileName(); |
| 1869 | Buffer += ID->getFile()->getName(); |
| 1870 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); |
| 1871 | continue; |
| 1872 | } |
| 1873 | |
| 1874 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); |
| 1875 | } |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1876 | Stream.ExitBlock(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1878 | // Write the offsets table for the preprocessing record. |
| 1879 | if (NumPreprocessingRecords > 0) { |
| 1880 | // Write the offsets table for identifier IDs. |
| 1881 | using namespace llvm; |
| 1882 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1883 | Abbrev->Add(BitCodeAbbrevOp(MACRO_DEFINITION_OFFSETS)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1884 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of records |
| 1885 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macro defs |
| 1886 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1887 | unsigned MacroDefOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1888 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1889 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1890 | Record.push_back(MACRO_DEFINITION_OFFSETS); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1891 | Record.push_back(NumPreprocessingRecords); |
| 1892 | Record.push_back(MacroDefinitionOffsets.size()); |
| 1893 | Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1894 | data(MacroDefinitionOffsets)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1895 | } |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1898 | void ASTWriter::WritePragmaDiagnosticMappings(const Diagnostic &Diag) { |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1899 | RecordData Record; |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1900 | for (Diagnostic::DiagStatePointsTy::const_iterator |
| 1901 | I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); |
| 1902 | I != E; ++I) { |
| 1903 | const Diagnostic::DiagStatePoint &point = *I; |
| 1904 | if (point.Loc.isInvalid()) |
| 1905 | continue; |
| 1906 | |
| 1907 | Record.push_back(point.Loc.getRawEncoding()); |
| 1908 | for (Diagnostic::DiagState::iterator |
| 1909 | I = point.State->begin(), E = point.State->end(); I != E; ++I) { |
| 1910 | unsigned diag = I->first, map = I->second; |
| 1911 | if (map & 0x10) { // mapping from a diagnostic pragma. |
| 1912 | Record.push_back(diag); |
| 1913 | Record.push_back(map & 0x7); |
| 1914 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1915 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1916 | Record.push_back(-1); // mark the end of the diag/map pairs for this |
| 1917 | // location. |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
Argyrios Kyrtzidis | 60f7684 | 2010-11-05 22:20:49 +0000 | [diff] [blame] | 1920 | if (!Record.empty()) |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 1921 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 1924 | void ASTWriter::WriteCXXBaseSpecifiersOffsets() { |
| 1925 | if (CXXBaseSpecifiersOffsets.empty()) |
| 1926 | return; |
| 1927 | |
| 1928 | RecordData Record; |
| 1929 | |
| 1930 | // Create a blob abbreviation for the C++ base specifiers offsets. |
| 1931 | using namespace llvm; |
| 1932 | |
| 1933 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1934 | Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); |
| 1935 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
| 1936 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1937 | unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1938 | |
| 1939 | // Write the selector offsets table. |
| 1940 | Record.clear(); |
| 1941 | Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); |
| 1942 | Record.push_back(CXXBaseSpecifiersOffsets.size()); |
| 1943 | Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 1944 | data(CXXBaseSpecifiersOffsets)); |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 1945 | } |
| 1946 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1947 | //===----------------------------------------------------------------------===// |
| 1948 | // Type Serialization |
| 1949 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1950 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1951 | /// \brief Write the representation of a type to the AST stream. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1952 | void ASTWriter::WriteType(QualType T) { |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 1953 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 1954 | if (Idx.getIndex() == 0) // we haven't seen this type before. |
| 1955 | Idx = TypeIdx(NextTypeID++); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1956 | |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 1957 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); |
Douglas Gregor | 55f48de | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1959 | // Record the offset for this type. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 1960 | unsigned Index = Idx.getIndex() - FirstTypeID; |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1961 | if (TypeOffsets.size() == Index) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1962 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1963 | else if (TypeOffsets.size() < Index) { |
| 1964 | TypeOffsets.resize(Index + 1); |
| 1965 | TypeOffsets[Index] = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | RecordData Record; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1969 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1970 | // Emit the type's representation. |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1971 | ASTTypeWriter W(*this, Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1972 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 1973 | if (T.hasLocalNonFastQualifiers()) { |
| 1974 | Qualifiers Qs = T.getLocalQualifiers(); |
| 1975 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1976 | Record.push_back(Qs.getAsOpaqueValue()); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1977 | W.Code = TYPE_EXT_QUAL; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1978 | } else { |
| 1979 | switch (T->getTypeClass()) { |
| 1980 | // For all of the concrete, non-dependent types, call the |
| 1981 | // appropriate visitor function. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1982 | #define TYPE(Class, Base) \ |
Mike Stump | b716633 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 1983 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1984 | #define ABSTRACT_TYPE(Class, Base) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1985 | #include "clang/AST/TypeNodes.def" |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1986 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | // Emit the serialized record. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1990 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1991 | |
| 1992 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1993 | FlushStmts(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1994 | } |
| 1995 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1996 | //===----------------------------------------------------------------------===// |
| 1997 | // Declaration Serialization |
| 1998 | //===----------------------------------------------------------------------===// |
| 1999 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2000 | /// \brief Write the block containing all of the declaration IDs |
| 2001 | /// lexically declared within the given DeclContext. |
| 2002 | /// |
| 2003 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 2004 | /// bistream, or 0 if no block was written. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2005 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2006 | DeclContext *DC) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2007 | if (DC->decls_empty()) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2008 | return 0; |
| 2009 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2010 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2011 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2012 | Record.push_back(DECL_CONTEXT_LEXICAL); |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2013 | llvm::SmallVector<KindDeclIDPair, 64> Decls; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2014 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 2015 | D != DEnd; ++D) |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 2016 | Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2017 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2018 | ++NumLexicalDeclContexts; |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2019 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, data(Decls)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2020 | return Offset; |
| 2021 | } |
| 2022 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2023 | void ASTWriter::WriteTypeDeclOffsets() { |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2024 | using namespace llvm; |
| 2025 | RecordData Record; |
| 2026 | |
| 2027 | // Write the type offsets array |
| 2028 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2029 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2030 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
| 2031 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2032 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2033 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2034 | Record.push_back(TYPE_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2035 | Record.push_back(TypeOffsets.size()); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2036 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, data(TypeOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2037 | |
| 2038 | // Write the declaration offsets array |
| 2039 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2040 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2041 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
| 2042 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2043 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2044 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2045 | Record.push_back(DECL_OFFSET); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2046 | Record.push_back(DeclOffsets.size()); |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2047 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, data(DeclOffsets)); |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2050 | //===----------------------------------------------------------------------===// |
| 2051 | // Global Method Pool and Selector Serialization |
| 2052 | //===----------------------------------------------------------------------===// |
| 2053 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2054 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2055 | // 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] | 2056 | class ASTMethodPoolTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2057 | ASTWriter &Writer; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2058 | |
| 2059 | public: |
| 2060 | typedef Selector key_type; |
| 2061 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2062 | |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2063 | struct data_type { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2064 | SelectorID ID; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2065 | ObjCMethodList Instance, Factory; |
| 2066 | }; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2067 | typedef const data_type& data_type_ref; |
| 2068 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2069 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2070 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2071 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2072 | return serialization::ComputeHash(Sel); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2073 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2074 | |
| 2075 | std::pair<unsigned,unsigned> |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2076 | EmitKeyDataLength(llvm::raw_ostream& Out, Selector Sel, |
| 2077 | data_type_ref Methods) { |
| 2078 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 2079 | clang::io::Emit16(Out, KeyLen); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2080 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts |
| 2081 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2082 | Method = Method->Next) |
| 2083 | if (Method->Method) |
| 2084 | DataLen += 4; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2085 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2086 | Method = Method->Next) |
| 2087 | if (Method->Method) |
| 2088 | DataLen += 4; |
| 2089 | clang::io::Emit16(Out, DataLen); |
| 2090 | return std::make_pair(KeyLen, DataLen); |
| 2091 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2092 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2093 | void EmitKey(llvm::raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | uint64_t Start = Out.tell(); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2095 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 2096 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2097 | unsigned N = Sel.getNumArgs(); |
| 2098 | clang::io::Emit16(Out, N); |
| 2099 | if (N == 0) |
| 2100 | N = 1; |
| 2101 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2102 | clang::io::Emit32(Out, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2103 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 2104 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2105 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2106 | void EmitData(llvm::raw_ostream& Out, key_type_ref, |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2107 | data_type_ref Methods, unsigned DataLen) { |
| 2108 | uint64_t Start = Out.tell(); (void)Start; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2109 | clang::io::Emit32(Out, Methods.ID); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2110 | unsigned NumInstanceMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2111 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2112 | Method = Method->Next) |
| 2113 | if (Method->Method) |
| 2114 | ++NumInstanceMethods; |
| 2115 | |
| 2116 | unsigned NumFactoryMethods = 0; |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2117 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2118 | Method = Method->Next) |
| 2119 | if (Method->Method) |
| 2120 | ++NumFactoryMethods; |
| 2121 | |
| 2122 | clang::io::Emit16(Out, NumInstanceMethods); |
| 2123 | clang::io::Emit16(Out, NumFactoryMethods); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2124 | for (const ObjCMethodList *Method = &Methods.Instance; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2125 | Method = Method->Next) |
| 2126 | if (Method->Method) |
| 2127 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2128 | for (const ObjCMethodList *Method = &Methods.Factory; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2129 | Method = Method->Next) |
| 2130 | if (Method->Method) |
| 2131 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2132 | |
| 2133 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2134 | } |
| 2135 | }; |
| 2136 | } // end anonymous namespace |
| 2137 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2138 | /// \brief Write ObjC data: selectors and the method pool. |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2139 | /// |
| 2140 | /// The method pool contains both instance and factory methods, stored |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2141 | /// in an on-disk hash table indexed by the selector. The hash table also |
| 2142 | /// contains an empty entry for every other selector known to Sema. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2143 | void ASTWriter::WriteSelectors(Sema &SemaRef) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2144 | using namespace llvm; |
| 2145 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2146 | // Do we have to do anything at all? |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2147 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2148 | return; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2149 | unsigned NumTableEntries = 0; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2150 | // 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] | 2151 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2152 | OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2153 | ASTMethodPoolTrait Trait(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2154 | |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2155 | // Create the on-disk hash table representation. We walk through every |
| 2156 | // selector we've seen and look it up in the method pool. |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2157 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2158 | for (llvm::DenseMap<Selector, SelectorID>::iterator |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2159 | I = SelectorIDs.begin(), E = SelectorIDs.end(); |
| 2160 | I != E; ++I) { |
| 2161 | Selector S = I->first; |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2162 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2163 | ASTMethodPoolTrait::data_type Data = { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2164 | I->second, |
| 2165 | ObjCMethodList(), |
| 2166 | ObjCMethodList() |
| 2167 | }; |
| 2168 | if (F != SemaRef.MethodPool.end()) { |
| 2169 | Data.Instance = F->second.first; |
| 2170 | Data.Factory = F->second.second; |
| 2171 | } |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2172 | // 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] | 2173 | // changed. |
| 2174 | if (Chain && I->second < FirstSelectorID) { |
| 2175 | // Selector already exists. Did it change? |
| 2176 | bool changed = false; |
| 2177 | for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; |
| 2178 | M = M->Next) { |
| 2179 | if (M->Method->getPCHLevel() == 0) |
| 2180 | changed = true; |
| 2181 | } |
| 2182 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; |
| 2183 | M = M->Next) { |
| 2184 | if (M->Method->getPCHLevel() == 0) |
| 2185 | changed = true; |
| 2186 | } |
| 2187 | if (!changed) |
| 2188 | continue; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2189 | } else if (Data.Instance.Method || Data.Factory.Method) { |
| 2190 | // A new method pool entry. |
| 2191 | ++NumTableEntries; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2192 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2193 | Generator.insert(S, Data, Trait); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2194 | } |
| 2195 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2196 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2197 | llvm::SmallString<4096> MethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2198 | uint32_t BucketOffset; |
| 2199 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2200 | ASTMethodPoolTrait Trait(*this); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2201 | llvm::raw_svector_ostream Out(MethodPool); |
| 2202 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2203 | clang::io::Emit32(Out, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2204 | BucketOffset = Generator.Emit(Out, Trait); |
| 2205 | } |
| 2206 | |
| 2207 | // Create a blob abbreviation |
| 2208 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2209 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2210 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2211 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2212 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2213 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2214 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2215 | // Write the method pool |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2216 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2217 | Record.push_back(METHOD_POOL); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2218 | Record.push_back(BucketOffset); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2219 | Record.push_back(NumTableEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2220 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2221 | |
| 2222 | // Create a blob abbreviation for the selector table offsets. |
| 2223 | Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2224 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2225 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2226 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2227 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2228 | |
| 2229 | // Write the selector offsets table. |
| 2230 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2231 | Record.push_back(SELECTOR_OFFSETS); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2232 | Record.push_back(SelectorOffsets.size()); |
| 2233 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2234 | data(SelectorOffsets)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2238 | /// \brief Write the selectors referenced in @selector expression into AST file. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2239 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2240 | using namespace llvm; |
| 2241 | if (SemaRef.ReferencedSelectors.empty()) |
| 2242 | return; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2243 | |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2244 | RecordData Record; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2245 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2246 | // 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] | 2247 | // very tricky to fix, and given that @selector shouldn't really appear in |
| 2248 | // headers, probably not worth it. It's not a correctness issue. |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2249 | for (DenseMap<Selector, SourceLocation>::iterator S = |
| 2250 | SemaRef.ReferencedSelectors.begin(), |
| 2251 | E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { |
| 2252 | Selector Sel = (*S).first; |
| 2253 | SourceLocation Loc = (*S).second; |
| 2254 | AddSelectorRef(Sel, Record); |
| 2255 | AddSourceLocation(Loc, Record); |
| 2256 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2257 | Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2260 | //===----------------------------------------------------------------------===// |
| 2261 | // Identifier Table Serialization |
| 2262 | //===----------------------------------------------------------------------===// |
| 2263 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2264 | namespace { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2265 | class ASTIdentifierTableTrait { |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2266 | ASTWriter &Writer; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2267 | Preprocessor &PP; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2268 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2269 | /// \brief Determines whether this is an "interesting" identifier |
| 2270 | /// that needs a full IdentifierInfo structure written into the hash |
| 2271 | /// table. |
| 2272 | static bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 2273 | return II->isPoisoned() || |
| 2274 | II->isExtensionToken() || |
| 2275 | II->hasMacroDefinition() || |
| 2276 | II->getObjCOrBuiltinID() || |
| 2277 | II->getFETokenInfo<void>(); |
| 2278 | } |
| 2279 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2280 | public: |
| 2281 | typedef const IdentifierInfo* key_type; |
| 2282 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2283 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2284 | typedef IdentID data_type; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2285 | typedef data_type data_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2286 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2287 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2288 | : Writer(Writer), PP(PP) { } |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2289 | |
| 2290 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 2291 | return llvm::HashString(II->getName()); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2292 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2293 | |
| 2294 | std::pair<unsigned,unsigned> |
| 2295 | EmitKeyDataLength(llvm::raw_ostream& Out, const IdentifierInfo* II, |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2296 | IdentID ID) { |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2297 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2298 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
| 2299 | if (isInterestingIdentifier(II)) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2300 | DataLen += 2; // 2 bytes for builtin ID, flags |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2301 | if (II->hasMacroDefinition() && |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2302 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro()) |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2303 | DataLen += 4; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2304 | for (IdentifierResolver::iterator D = IdentifierResolver::begin(II), |
| 2305 | DEnd = IdentifierResolver::end(); |
| 2306 | D != DEnd; ++D) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2307 | DataLen += sizeof(DeclID); |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2308 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2309 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 2310 | // We emit the key length after the data length so that every |
| 2311 | // string is preceded by a 16-bit length. This matches the PTH |
| 2312 | // format for storing identifiers. |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 2313 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2314 | return std::make_pair(KeyLen, DataLen); |
| 2315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2316 | |
| 2317 | void EmitKey(llvm::raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2318 | unsigned KeyLen) { |
| 2319 | // Record the location of the key data. This is used when generating |
| 2320 | // the mapping from persistent IDs to strings. |
| 2321 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 2322 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2324 | |
| 2325 | void EmitData(llvm::raw_ostream& Out, const IdentifierInfo* II, |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2326 | IdentID ID, unsigned) { |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2327 | if (!isInterestingIdentifier(II)) { |
| 2328 | clang::io::Emit32(Out, ID << 1); |
| 2329 | return; |
| 2330 | } |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2331 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 2332 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2333 | uint32_t Bits = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2334 | bool hasMacroDefinition = |
| 2335 | II->hasMacroDefinition() && |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2336 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro(); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2337 | Bits = (uint32_t)II->getObjCOrBuiltinID(); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2338 | Bits = (Bits << 1) | unsigned(hasMacroDefinition); |
| 2339 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 2340 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 2341 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2342 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2343 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2344 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2345 | if (hasMacroDefinition) |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 2346 | clang::io::Emit32(Out, Writer.getMacroOffset(II)); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2347 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2348 | // Emit the declaration IDs in reverse order, because the |
| 2349 | // IdentifierResolver provides the declarations as they would be |
| 2350 | // visible (e.g., the function "stat" would come before the struct |
| 2351 | // "stat"), but IdentifierResolver::AddDeclToIdentifierChain() |
| 2352 | // adds declarations to the end of the list (so we need to see the |
| 2353 | // struct "status" before the function "status"). |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2354 | // Only emit declarations that aren't from a chained PCH, though. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2355 | llvm::SmallVector<Decl *, 16> Decls(IdentifierResolver::begin(II), |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2356 | IdentifierResolver::end()); |
| 2357 | for (llvm::SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
| 2358 | DEnd = Decls.rend(); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2359 | D != DEnd; ++D) |
Sebastian Redl | d8c5abb | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 2360 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2361 | } |
| 2362 | }; |
| 2363 | } // end anonymous namespace |
| 2364 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2365 | /// \brief Write the identifier table into the AST file. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2366 | /// |
| 2367 | /// The identifier table consists of a blob containing string data |
| 2368 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 2369 | /// that maps identifier IDs to locations within the blob. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2370 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2371 | using namespace llvm; |
| 2372 | |
| 2373 | // Create and write out the blob that contains the identifier |
| 2374 | // strings. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2375 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2376 | OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2377 | ASTIdentifierTableTrait Trait(*this, PP); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2378 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2379 | // Look for any identifiers that were named while processing the |
| 2380 | // headers, but are otherwise not needed. We add these to the hash |
| 2381 | // table to enable checking of the predefines buffer in the case |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2382 | // where the user adds new macro definitions when building the AST |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 2383 | // file. |
| 2384 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 2385 | IDEnd = PP.getIdentifierTable().end(); |
| 2386 | ID != IDEnd; ++ID) |
| 2387 | getIdentifierRef(ID->second); |
| 2388 | |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2389 | // Create the on-disk hash table representation. We only store offsets |
| 2390 | // for identifiers that appear here for the first time. |
| 2391 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2392 | for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2393 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 2394 | ID != IDEnd; ++ID) { |
| 2395 | assert(ID->first && "NULL identifier in identifier table"); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2396 | if (!Chain || !ID->first->isFromAST()) |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2397 | Generator.insert(ID->first, ID->second, Trait); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2398 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2399 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2400 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2401 | llvm::SmallString<4096> IdentifierTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2402 | uint32_t BucketOffset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2403 | { |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2404 | ASTIdentifierTableTrait Trait(*this, PP); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2405 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2406 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 2407 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2408 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | // Create a blob abbreviation |
| 2412 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2413 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2414 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2415 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2416 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2417 | |
| 2418 | // Write the identifier table |
| 2419 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2420 | Record.push_back(IDENTIFIER_TABLE); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2421 | Record.push_back(BucketOffset); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 2422 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2426 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2427 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2428 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
| 2429 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 2430 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2431 | |
| 2432 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2433 | Record.push_back(IDENTIFIER_OFFSET); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2434 | Record.push_back(IdentifierOffsets.size()); |
| 2435 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 2436 | data(IdentifierOffsets)); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2439 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2440 | // DeclContext's Name Lookup Table Serialization |
| 2441 | //===----------------------------------------------------------------------===// |
| 2442 | |
| 2443 | namespace { |
| 2444 | // Trait used for the on-disk hash table used in the method pool. |
| 2445 | class ASTDeclContextNameLookupTrait { |
| 2446 | ASTWriter &Writer; |
| 2447 | |
| 2448 | public: |
| 2449 | typedef DeclarationName key_type; |
| 2450 | typedef key_type key_type_ref; |
| 2451 | |
| 2452 | typedef DeclContext::lookup_result data_type; |
| 2453 | typedef const data_type& data_type_ref; |
| 2454 | |
| 2455 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } |
| 2456 | |
| 2457 | unsigned ComputeHash(DeclarationName Name) { |
| 2458 | llvm::FoldingSetNodeID ID; |
| 2459 | ID.AddInteger(Name.getNameKind()); |
| 2460 | |
| 2461 | switch (Name.getNameKind()) { |
| 2462 | case DeclarationName::Identifier: |
| 2463 | ID.AddString(Name.getAsIdentifierInfo()->getName()); |
| 2464 | break; |
| 2465 | case DeclarationName::ObjCZeroArgSelector: |
| 2466 | case DeclarationName::ObjCOneArgSelector: |
| 2467 | case DeclarationName::ObjCMultiArgSelector: |
| 2468 | ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); |
| 2469 | break; |
| 2470 | case DeclarationName::CXXConstructorName: |
| 2471 | case DeclarationName::CXXDestructorName: |
| 2472 | case DeclarationName::CXXConversionFunctionName: |
| 2473 | ID.AddInteger(Writer.GetOrCreateTypeID(Name.getCXXNameType())); |
| 2474 | break; |
| 2475 | case DeclarationName::CXXOperatorName: |
| 2476 | ID.AddInteger(Name.getCXXOverloadedOperator()); |
| 2477 | break; |
| 2478 | case DeclarationName::CXXLiteralOperatorName: |
| 2479 | ID.AddString(Name.getCXXLiteralIdentifier()->getName()); |
| 2480 | case DeclarationName::CXXUsingDirective: |
| 2481 | break; |
| 2482 | } |
| 2483 | |
| 2484 | return ID.ComputeHash(); |
| 2485 | } |
| 2486 | |
| 2487 | std::pair<unsigned,unsigned> |
| 2488 | EmitKeyDataLength(llvm::raw_ostream& Out, DeclarationName Name, |
| 2489 | data_type_ref Lookup) { |
| 2490 | unsigned KeyLen = 1; |
| 2491 | switch (Name.getNameKind()) { |
| 2492 | case DeclarationName::Identifier: |
| 2493 | case DeclarationName::ObjCZeroArgSelector: |
| 2494 | case DeclarationName::ObjCOneArgSelector: |
| 2495 | case DeclarationName::ObjCMultiArgSelector: |
| 2496 | case DeclarationName::CXXConstructorName: |
| 2497 | case DeclarationName::CXXDestructorName: |
| 2498 | case DeclarationName::CXXConversionFunctionName: |
| 2499 | case DeclarationName::CXXLiteralOperatorName: |
| 2500 | KeyLen += 4; |
| 2501 | break; |
| 2502 | case DeclarationName::CXXOperatorName: |
| 2503 | KeyLen += 1; |
| 2504 | break; |
| 2505 | case DeclarationName::CXXUsingDirective: |
| 2506 | break; |
| 2507 | } |
| 2508 | clang::io::Emit16(Out, KeyLen); |
| 2509 | |
| 2510 | // 2 bytes for num of decls and 4 for each DeclID. |
| 2511 | unsigned DataLen = 2 + 4 * (Lookup.second - Lookup.first); |
| 2512 | clang::io::Emit16(Out, DataLen); |
| 2513 | |
| 2514 | return std::make_pair(KeyLen, DataLen); |
| 2515 | } |
| 2516 | |
| 2517 | void EmitKey(llvm::raw_ostream& Out, DeclarationName Name, unsigned) { |
| 2518 | using namespace clang::io; |
| 2519 | |
| 2520 | assert(Name.getNameKind() < 0x100 && "Invalid name kind ?"); |
| 2521 | Emit8(Out, Name.getNameKind()); |
| 2522 | switch (Name.getNameKind()) { |
| 2523 | case DeclarationName::Identifier: |
| 2524 | Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); |
| 2525 | break; |
| 2526 | case DeclarationName::ObjCZeroArgSelector: |
| 2527 | case DeclarationName::ObjCOneArgSelector: |
| 2528 | case DeclarationName::ObjCMultiArgSelector: |
| 2529 | Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); |
| 2530 | break; |
| 2531 | case DeclarationName::CXXConstructorName: |
| 2532 | case DeclarationName::CXXDestructorName: |
| 2533 | case DeclarationName::CXXConversionFunctionName: |
| 2534 | Emit32(Out, Writer.getTypeID(Name.getCXXNameType())); |
| 2535 | break; |
| 2536 | case DeclarationName::CXXOperatorName: |
| 2537 | assert(Name.getCXXOverloadedOperator() < 0x100 && "Invalid operator ?"); |
| 2538 | Emit8(Out, Name.getCXXOverloadedOperator()); |
| 2539 | break; |
| 2540 | case DeclarationName::CXXLiteralOperatorName: |
| 2541 | Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); |
| 2542 | break; |
| 2543 | case DeclarationName::CXXUsingDirective: |
| 2544 | break; |
| 2545 | } |
| 2546 | } |
| 2547 | |
| 2548 | void EmitData(llvm::raw_ostream& Out, key_type_ref, |
| 2549 | data_type Lookup, unsigned DataLen) { |
| 2550 | uint64_t Start = Out.tell(); (void)Start; |
| 2551 | clang::io::Emit16(Out, Lookup.second - Lookup.first); |
| 2552 | for (; Lookup.first != Lookup.second; ++Lookup.first) |
| 2553 | clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first)); |
| 2554 | |
| 2555 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
| 2556 | } |
| 2557 | }; |
| 2558 | } // end anonymous namespace |
| 2559 | |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2560 | /// \brief Write the block containing all of the declaration IDs |
| 2561 | /// visible from the given DeclContext. |
| 2562 | /// |
| 2563 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2564 | /// bitstream, or 0 if no block was written. |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2565 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 2566 | DeclContext *DC) { |
| 2567 | if (DC->getPrimaryContext() != DC) |
| 2568 | return 0; |
| 2569 | |
| 2570 | // Since there is no name lookup into functions or methods, don't bother to |
| 2571 | // build a visible-declarations table for these entities. |
| 2572 | if (DC->isFunctionOrMethod()) |
| 2573 | return 0; |
| 2574 | |
| 2575 | // If not in C++, we perform name lookup for the translation unit via the |
| 2576 | // IdentifierInfo chains, don't bother to build a visible-declarations table. |
| 2577 | // FIXME: In C++ we need the visible declarations in order to "see" the |
| 2578 | // friend declarations, is there a way to do this without writing the table ? |
| 2579 | if (DC->isTranslationUnit() && !Context.getLangOptions().CPlusPlus) |
| 2580 | return 0; |
| 2581 | |
| 2582 | // Force the DeclContext to build a its name-lookup table. |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 2583 | if (DC->hasExternalVisibleStorage()) |
| 2584 | DC->MaterializeVisibleDeclsFromExternalStorage(); |
| 2585 | else |
| 2586 | DC->lookup(DeclarationName()); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 2587 | |
| 2588 | // Serialize the contents of the mapping used for lookup. Note that, |
| 2589 | // although we have two very different code paths, the serialized |
| 2590 | // representation is the same for both cases: a declaration name, |
| 2591 | // followed by a size, followed by references to the visible |
| 2592 | // declarations that have that name. |
| 2593 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 2594 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 2595 | if (!Map || Map->empty()) |
| 2596 | return 0; |
| 2597 | |
| 2598 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2599 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2600 | |
| 2601 | // Create the on-disk hash table representation. |
| 2602 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2603 | D != DEnd; ++D) { |
| 2604 | DeclarationName Name = D->first; |
| 2605 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
| 2606 | Generator.insert(Name, Result, Trait); |
| 2607 | } |
| 2608 | |
| 2609 | // Create the on-disk hash table in a buffer. |
| 2610 | llvm::SmallString<4096> LookupTable; |
| 2611 | uint32_t BucketOffset; |
| 2612 | { |
| 2613 | llvm::raw_svector_ostream Out(LookupTable); |
| 2614 | // Make sure that no bucket is at offset 0 |
| 2615 | clang::io::Emit32(Out, 0); |
| 2616 | BucketOffset = Generator.Emit(Out, Trait); |
| 2617 | } |
| 2618 | |
| 2619 | // Write the lookup table |
| 2620 | RecordData Record; |
| 2621 | Record.push_back(DECL_CONTEXT_VISIBLE); |
| 2622 | Record.push_back(BucketOffset); |
| 2623 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, |
| 2624 | LookupTable.str()); |
| 2625 | |
| 2626 | Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); |
| 2627 | ++NumVisibleDeclContexts; |
| 2628 | return Offset; |
| 2629 | } |
| 2630 | |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2631 | /// \brief Write an UPDATE_VISIBLE block for the given context. |
| 2632 | /// |
| 2633 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing |
| 2634 | /// DeclContext in a dependent AST file. As such, they only exist for the TU |
| 2635 | /// (in C++) and for namespaces. |
| 2636 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2637 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
| 2638 | if (!Map || Map->empty()) |
| 2639 | return; |
| 2640 | |
| 2641 | OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; |
| 2642 | ASTDeclContextNameLookupTrait Trait(*this); |
| 2643 | |
| 2644 | // Create the hash table. |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2645 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 2646 | D != DEnd; ++D) { |
| 2647 | DeclarationName Name = D->first; |
| 2648 | DeclContext::lookup_result Result = D->second.getLookupResult(); |
Sebastian Redl | 5967d62 | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 2649 | // For any name that appears in this table, the results are complete, i.e. |
| 2650 | // they overwrite results from previous PCHs. Merging is always a mess. |
| 2651 | Generator.insert(Name, Result, Trait); |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | // Create the on-disk hash table in a buffer. |
| 2655 | llvm::SmallString<4096> LookupTable; |
| 2656 | uint32_t BucketOffset; |
| 2657 | { |
| 2658 | llvm::raw_svector_ostream Out(LookupTable); |
| 2659 | // Make sure that no bucket is at offset 0 |
| 2660 | clang::io::Emit32(Out, 0); |
| 2661 | BucketOffset = Generator.Emit(Out, Trait); |
| 2662 | } |
| 2663 | |
| 2664 | // Write the lookup table |
| 2665 | RecordData Record; |
| 2666 | Record.push_back(UPDATE_VISIBLE); |
| 2667 | Record.push_back(getDeclID(cast<Decl>(DC))); |
| 2668 | Record.push_back(BucketOffset); |
| 2669 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); |
| 2670 | } |
| 2671 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2672 | /// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. |
| 2673 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { |
| 2674 | RecordData Record; |
| 2675 | Record.push_back(Opts.fp_contract); |
| 2676 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); |
| 2677 | } |
| 2678 | |
| 2679 | /// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. |
| 2680 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { |
| 2681 | if (!SemaRef.Context.getLangOptions().OpenCL) |
| 2682 | return; |
| 2683 | |
| 2684 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); |
| 2685 | RecordData Record; |
| 2686 | #define OPENCLEXT(nm) Record.push_back(Opts.nm); |
| 2687 | #include "clang/Basic/OpenCLExtensions.def" |
| 2688 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); |
| 2689 | } |
| 2690 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 2691 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2692 | // General Serialization Routines |
| 2693 | //===----------------------------------------------------------------------===// |
| 2694 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2695 | /// \brief Write a record containing the given attributes. |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 2696 | void ASTWriter::WriteAttributes(const AttrVec &Attrs, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4eb9fc0 | 2010-10-18 19:20:11 +0000 | [diff] [blame] | 2697 | Record.push_back(Attrs.size()); |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2698 | for (AttrVec::const_iterator i = Attrs.begin(), e = Attrs.end(); i != e; ++i){ |
| 2699 | const Attr * A = *i; |
| 2700 | Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs |
| 2701 | AddSourceLocation(A->getLocation(), Record); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2702 | |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2703 | #include "clang/Serialization/AttrPCHWrite.inc" |
Daniel Dunbar | 4e9255f | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 2704 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2705 | } |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2706 | } |
| 2707 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 2708 | void ASTWriter::AddString(llvm::StringRef Str, RecordDataImpl &Record) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 2709 | Record.push_back(Str.size()); |
| 2710 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 2711 | } |
| 2712 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 2713 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, |
| 2714 | RecordDataImpl &Record) { |
| 2715 | Record.push_back(Version.getMajor()); |
| 2716 | if (llvm::Optional<unsigned> Minor = Version.getMinor()) |
| 2717 | Record.push_back(*Minor + 1); |
| 2718 | else |
| 2719 | Record.push_back(0); |
| 2720 | if (llvm::Optional<unsigned> Subminor = Version.getSubminor()) |
| 2721 | Record.push_back(*Subminor + 1); |
| 2722 | else |
| 2723 | Record.push_back(0); |
| 2724 | } |
| 2725 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2726 | /// \brief Note that the identifier II occurs at the given offset |
| 2727 | /// within the identifier table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2728 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2729 | IdentID ID = IdentifierIDs[II]; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2730 | // 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] | 2731 | // up earlier in the chain and thus don't need an offset. |
| 2732 | if (ID >= FirstIdentID) |
| 2733 | IdentifierOffsets[ID - FirstIdentID] = Offset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2736 | /// \brief Note that the selector Sel occurs at the given offset |
| 2737 | /// within the method pool/selector table. |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2738 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2739 | unsigned ID = SelectorIDs[Sel]; |
| 2740 | assert(ID && "Unknown selector"); |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2741 | // Don't record offsets for selectors that are also available in a different |
| 2742 | // file. |
| 2743 | if (ID < FirstSelectorID) |
| 2744 | return; |
| 2745 | SelectorOffsets[ID - FirstSelectorID] = Offset; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2746 | } |
| 2747 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2748 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2749 | : Stream(Stream), Chain(0), SerializationListener(0), |
| 2750 | FirstDeclID(1), NextDeclID(FirstDeclID), |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2751 | FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2752 | FirstIdentID(1), NextIdentID(FirstIdentID), FirstSelectorID(1), |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 2753 | NextSelectorID(FirstSelectorID), FirstMacroID(1), NextMacroID(FirstMacroID), |
| 2754 | CollectedStmts(&StmtsToEmit), |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 2755 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 2756 | NumVisibleDeclContexts(0), |
| 2757 | FirstCXXBaseSpecifiersID(1), NextCXXBaseSpecifiersID(1), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 2758 | DeclParmVarAbbrev(0), DeclContextLexicalAbbrev(0), |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 2759 | DeclContextVisibleLookupAbbrev(0), UpdateVisibleAbbrev(0), |
| 2760 | DeclRefExprAbbrev(0), CharacterLiteralAbbrev(0), |
| 2761 | DeclRecordAbbrev(0), IntegerLiteralAbbrev(0), |
Jonathan D. Turner | 953c564 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 2762 | DeclTypedefAbbrev(0), |
| 2763 | DeclVarAbbrev(0), DeclFieldAbbrev(0), |
| 2764 | DeclEnumAbbrev(0), DeclObjCIvarAbbrev(0) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2765 | { |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 2766 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2767 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2768 | void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2769 | const std::string &OutputFile, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2770 | StringRef isysroot) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2771 | // Emit the file header. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2772 | Stream.Emit((unsigned)'C', 8); |
| 2773 | Stream.Emit((unsigned)'P', 8); |
| 2774 | Stream.Emit((unsigned)'C', 8); |
| 2775 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2776 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 2777 | WriteBlockInfoBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2778 | |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2779 | if (Chain) |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2780 | WriteASTChain(SemaRef, StatCalls, isysroot); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2781 | else |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2782 | WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2785 | void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2786 | StringRef isysroot, |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2787 | const std::string &OutputFile) { |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2788 | using namespace llvm; |
| 2789 | |
| 2790 | ASTContext &Context = SemaRef.Context; |
| 2791 | Preprocessor &PP = SemaRef.PP; |
| 2792 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2793 | // The translation unit is the first declaration we'll emit. |
| 2794 | DeclIDs[Context.getTranslationUnitDecl()] = 1; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 2795 | ++NextDeclID; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2796 | DeclTypesToEmit.push(Context.getTranslationUnitDecl()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2797 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2798 | // Make sure that we emit IdentifierInfos (and any attached |
| 2799 | // declarations) for builtins. |
| 2800 | { |
| 2801 | IdentifierTable &Table = PP.getIdentifierTable(); |
| 2802 | llvm::SmallVector<const char *, 32> BuiltinNames; |
| 2803 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
| 2804 | Context.getLangOptions().NoBuiltin); |
| 2805 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 2806 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 2807 | } |
| 2808 | |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2809 | // 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] | 2810 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2811 | // headers. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2812 | RecordData TentativeDefinitions; |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 2813 | for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) { |
| 2814 | AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions); |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2815 | } |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2816 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2817 | // Build a record containing all of the file scoped decls in this file. |
| 2818 | RecordData UnusedFileScopedDecls; |
| 2819 | for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i) |
| 2820 | AddDeclRef(SemaRef.UnusedFileScopedDecls[i], UnusedFileScopedDecls); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2821 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2822 | RecordData DelegatingCtorDecls; |
| 2823 | for (unsigned i=0, e = SemaRef.DelegatingCtorDecls.size(); i != e; ++i) |
| 2824 | AddDeclRef(SemaRef.DelegatingCtorDecls[i], DelegatingCtorDecls); |
| 2825 | |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2826 | RecordData WeakUndeclaredIdentifiers; |
| 2827 | if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { |
| 2828 | WeakUndeclaredIdentifiers.push_back( |
| 2829 | SemaRef.WeakUndeclaredIdentifiers.size()); |
| 2830 | for (llvm::DenseMap<IdentifierInfo*,Sema::WeakInfo>::iterator |
| 2831 | I = SemaRef.WeakUndeclaredIdentifiers.begin(), |
| 2832 | E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { |
| 2833 | AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); |
| 2834 | AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); |
| 2835 | AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); |
| 2836 | WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); |
| 2837 | } |
| 2838 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2839 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2840 | // Build a record containing all of the locally-scoped external |
| 2841 | // declarations in this header file. Generally, this record will be |
| 2842 | // empty. |
| 2843 | RecordData LocallyScopedExternalDecls; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2844 | // 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] | 2845 | // nondeterminstic! |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2846 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2847 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 2848 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
| 2849 | TD != TDEnd; ++TD) |
| 2850 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 2851 | |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2852 | // Build a record containing all of the ext_vector declarations. |
| 2853 | RecordData ExtVectorDecls; |
| 2854 | for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I) |
| 2855 | AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls); |
| 2856 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2857 | // Build a record containing all of the VTable uses information. |
| 2858 | RecordData VTableUses; |
Argyrios Kyrtzidis | be4ebcd | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 2859 | if (!SemaRef.VTableUses.empty()) { |
| 2860 | VTableUses.push_back(SemaRef.VTableUses.size()); |
| 2861 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 2862 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 2863 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 2864 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 2865 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | // Build a record containing all of dynamic classes declarations. |
| 2869 | RecordData DynamicClasses; |
| 2870 | for (unsigned I = 0, N = SemaRef.DynamicClasses.size(); I != N; ++I) |
| 2871 | AddDeclRef(SemaRef.DynamicClasses[I], DynamicClasses); |
| 2872 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2873 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 2874 | RecordData PendingInstantiations; |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2875 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 2876 | I = SemaRef.PendingInstantiations.begin(), |
| 2877 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
| 2878 | AddDeclRef(I->first, PendingInstantiations); |
| 2879 | AddSourceLocation(I->second, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2880 | } |
| 2881 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 2882 | "There are local ones at end of translation unit!"); |
| 2883 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2884 | // Build a record containing some declaration references. |
| 2885 | RecordData SemaDeclRefs; |
| 2886 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 2887 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 2888 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 2889 | } |
| 2890 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2891 | RecordData CUDASpecialDeclRefs; |
| 2892 | if (Context.getcudaConfigureCallDecl()) { |
| 2893 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); |
| 2894 | } |
| 2895 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2896 | // Build a record containing all of the known namespaces. |
| 2897 | RecordData KnownNamespaces; |
| 2898 | for (llvm::DenseMap<NamespaceDecl*, bool>::iterator |
| 2899 | I = SemaRef.KnownNamespaces.begin(), |
| 2900 | IEnd = SemaRef.KnownNamespaces.end(); |
| 2901 | I != IEnd; ++I) { |
| 2902 | if (!I->second) |
| 2903 | AddDeclRef(I->first, KnownNamespaces); |
| 2904 | } |
| 2905 | |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2906 | // Write the remaining AST contents. |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2907 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2908 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2909 | WriteMetadata(Context, isysroot, OutputFile); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 2910 | WriteLanguageOptions(Context.getLangOptions()); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 2911 | if (StatCalls && isysroot.empty()) |
Douglas Gregor | dd41ed5 | 2010-07-12 23:48:14 +0000 | [diff] [blame] | 2912 | WriteStatCache(*StatCalls); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2913 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 2914 | // Write the record of special types. |
| 2915 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2916 | |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 2917 | AddTypeRef(Context.getBuiltinVaListType(), Record); |
| 2918 | AddTypeRef(Context.getObjCIdType(), Record); |
| 2919 | AddTypeRef(Context.getObjCSelType(), Record); |
| 2920 | AddTypeRef(Context.getObjCProtoType(), Record); |
| 2921 | AddTypeRef(Context.getObjCClassType(), Record); |
| 2922 | AddTypeRef(Context.getRawCFConstantStringType(), Record); |
| 2923 | AddTypeRef(Context.getRawObjCFastEnumerationStateType(), Record); |
| 2924 | AddTypeRef(Context.getFILEType(), Record); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2925 | AddTypeRef(Context.getjmp_bufType(), Record); |
| 2926 | AddTypeRef(Context.getsigjmp_bufType(), Record); |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2927 | AddTypeRef(Context.ObjCIdRedefinitionType, Record); |
| 2928 | AddTypeRef(Context.ObjCClassRedefinitionType, Record); |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2929 | AddTypeRef(Context.getRawBlockdescriptorType(), Record); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2930 | AddTypeRef(Context.getRawBlockdescriptorExtendedType(), Record); |
Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2931 | AddTypeRef(Context.ObjCSelRedefinitionType, Record); |
| 2932 | AddTypeRef(Context.getRawNSConstantStringType(), Record); |
Argyrios Kyrtzidis | 0061138 | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2933 | Record.push_back(Context.isInt128Installed()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2934 | AddTypeRef(Context.AutoDeductTy, Record); |
| 2935 | AddTypeRef(Context.AutoRRefDeductTy, Record); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2936 | Stream.EmitRecord(SPECIAL_TYPES, Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2937 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2938 | // Keep writing types and declarations until all types and |
| 2939 | // declarations have been written. |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 2940 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2941 | WriteDeclsBlockAbbrevs(); |
| 2942 | while (!DeclTypesToEmit.empty()) { |
| 2943 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 2944 | DeclTypesToEmit.pop(); |
| 2945 | if (DOT.isType()) |
| 2946 | WriteType(DOT.getType()); |
| 2947 | else |
| 2948 | WriteDecl(Context, DOT.getDecl()); |
| 2949 | } |
| 2950 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2951 | |
Douglas Gregor | 813a97b | 2009-10-17 17:25:45 +0000 | [diff] [blame] | 2952 | WritePreprocessor(PP); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2953 | WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2954 | WriteSelectors(SemaRef); |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2955 | WriteReferencedSelectorsPool(SemaRef); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2956 | WriteIdentifierTable(PP); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2957 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 2958 | WriteOpenCLExtensions(SemaRef); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2959 | |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2960 | WriteTypeDeclOffsets(); |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2961 | WritePragmaDiagnosticMappings(Context.getDiagnostics()); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2962 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 2963 | WriteCXXBaseSpecifiersOffsets(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2964 | |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2965 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2966 | if (!ExternalDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2967 | Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2968 | |
| 2969 | // Write the record containing tentative definitions. |
| 2970 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2971 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2972 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 2973 | // Write the record containing unused file scoped decls. |
| 2974 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2975 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2976 | |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2977 | // Write the record containing weak undeclared identifiers. |
| 2978 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2979 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2980 | WeakUndeclaredIdentifiers); |
| 2981 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2982 | // Write the record containing locally-scoped external definitions. |
| 2983 | if (!LocallyScopedExternalDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2984 | Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2985 | LocallyScopedExternalDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2986 | |
| 2987 | // Write the record containing ext_vector type names. |
| 2988 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2989 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2990 | |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2991 | // Write the record containing VTable uses information. |
| 2992 | if (!VTableUses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2993 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2994 | |
| 2995 | // Write the record containing dynamic classes declarations. |
| 2996 | if (!DynamicClasses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2997 | Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2998 | |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2999 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3000 | if (!PendingInstantiations.empty()) |
| 3001 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 3002 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3003 | // Write the record containing declaration references of Sema. |
| 3004 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3005 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3006 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3007 | // Write the record containing CUDA-specific declaration references. |
| 3008 | if (!CUDASpecialDeclRefs.empty()) |
| 3009 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3010 | |
| 3011 | // Write the delegating constructors. |
| 3012 | if (!DelegatingCtorDecls.empty()) |
| 3013 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3014 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 3015 | // Write the known namespaces. |
| 3016 | if (!KnownNamespaces.empty()) |
| 3017 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); |
| 3018 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3019 | // Some simple statistics |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 3020 | Record.clear(); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 3021 | Record.push_back(NumStatements); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 3022 | Record.push_back(NumMacros); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3023 | Record.push_back(NumLexicalDeclContexts); |
| 3024 | Record.push_back(NumVisibleDeclContexts); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3025 | Stream.EmitRecord(STATISTICS, Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 3026 | Stream.ExitBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3029 | void ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3030 | StringRef isysroot) { |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3031 | using namespace llvm; |
| 3032 | |
| 3033 | ASTContext &Context = SemaRef.Context; |
| 3034 | Preprocessor &PP = SemaRef.PP; |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3035 | |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3036 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3037 | Stream.EnterSubblock(AST_BLOCK_ID, 5); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 3038 | WriteMetadata(Context, isysroot, ""); |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 3039 | if (StatCalls && isysroot.empty()) |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3040 | WriteStatCache(*StatCalls); |
| 3041 | // FIXME: Source manager block should only write new stuff, which could be |
| 3042 | // done by tracking the largest ID in the chain |
| 3043 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3044 | |
| 3045 | // The special types are in the chained PCH. |
| 3046 | |
| 3047 | // We don't start with the translation unit, but with its decls that |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3048 | // don't come from the chained PCH. |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3049 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3050 | llvm::SmallVector<KindDeclIDPair, 64> NewGlobalDecls; |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3051 | for (DeclContext::decl_iterator I = TU->noload_decls_begin(), |
| 3052 | E = TU->noload_decls_end(); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3053 | I != E; ++I) { |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 3054 | if ((*I)->getPCHLevel() == 0) |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3055 | NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3056 | else if ((*I)->isChangedSinceDeserialization()) |
| 3057 | (void)GetDeclRef(*I); // Make sure it's written, but don't record it. |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3058 | } |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3059 | // We also need to write a lexical updates block for the TU. |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 3060 | llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3061 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 3062 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3063 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); |
| 3064 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3065 | Record.push_back(TU_UPDATE_LEXICAL); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 3066 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, |
Benjamin Kramer | 6e089c6 | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 3067 | data(NewGlobalDecls)); |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 3068 | // And a visible updates block for the DeclContexts. |
| 3069 | Abv = new llvm::BitCodeAbbrev(); |
| 3070 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); |
| 3071 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); |
| 3072 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); |
| 3073 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); |
| 3074 | UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); |
| 3075 | WriteDeclContextVisibleUpdate(TU); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3076 | |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3077 | // Build a record containing all of the new tentative definitions in this |
| 3078 | // file, in TentativeDefinitions order. |
| 3079 | RecordData TentativeDefinitions; |
| 3080 | for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) { |
| 3081 | if (SemaRef.TentativeDefinitions[i]->getPCHLevel() == 0) |
| 3082 | AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions); |
| 3083 | } |
| 3084 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3085 | // Build a record containing all of the file scoped decls in this file. |
| 3086 | RecordData UnusedFileScopedDecls; |
| 3087 | for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i) { |
| 3088 | if (SemaRef.UnusedFileScopedDecls[i]->getPCHLevel() == 0) |
| 3089 | AddDeclRef(SemaRef.UnusedFileScopedDecls[i], UnusedFileScopedDecls); |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3090 | } |
| 3091 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3092 | // Build a record containing all of the delegating constructor decls in this |
| 3093 | // file. |
| 3094 | RecordData DelegatingCtorDecls; |
| 3095 | for (unsigned i=0, e = SemaRef.DelegatingCtorDecls.size(); i != e; ++i) { |
| 3096 | if (SemaRef.DelegatingCtorDecls[i]->getPCHLevel() == 0) |
| 3097 | AddDeclRef(SemaRef.DelegatingCtorDecls[i], DelegatingCtorDecls); |
| 3098 | } |
| 3099 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3100 | // We write the entire table, overwriting the tables from the chain. |
| 3101 | RecordData WeakUndeclaredIdentifiers; |
| 3102 | if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { |
| 3103 | WeakUndeclaredIdentifiers.push_back( |
| 3104 | SemaRef.WeakUndeclaredIdentifiers.size()); |
| 3105 | for (llvm::DenseMap<IdentifierInfo*,Sema::WeakInfo>::iterator |
| 3106 | I = SemaRef.WeakUndeclaredIdentifiers.begin(), |
| 3107 | E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { |
| 3108 | AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); |
| 3109 | AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); |
| 3110 | AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); |
| 3111 | WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); |
| 3112 | } |
| 3113 | } |
| 3114 | |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3115 | // Build a record containing all of the locally-scoped external |
| 3116 | // declarations in this header file. Generally, this record will be |
| 3117 | // empty. |
| 3118 | RecordData LocallyScopedExternalDecls; |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3119 | // FIXME: This is filling in the AST file in densemap order which is |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3120 | // nondeterminstic! |
| 3121 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
| 3122 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 3123 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
| 3124 | TD != TDEnd; ++TD) { |
| 3125 | if (TD->second->getPCHLevel() == 0) |
| 3126 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 3127 | } |
| 3128 | |
| 3129 | // Build a record containing all of the ext_vector declarations. |
| 3130 | RecordData ExtVectorDecls; |
| 3131 | for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I) { |
| 3132 | if (SemaRef.ExtVectorDecls[I]->getPCHLevel() == 0) |
| 3133 | AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls); |
| 3134 | } |
| 3135 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3136 | // Build a record containing all of the VTable uses information. |
| 3137 | // We write everything here, because it's too hard to determine whether |
| 3138 | // a use is new to this part. |
| 3139 | RecordData VTableUses; |
| 3140 | if (!SemaRef.VTableUses.empty()) { |
| 3141 | VTableUses.push_back(SemaRef.VTableUses.size()); |
| 3142 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { |
| 3143 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); |
| 3144 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); |
| 3145 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); |
| 3146 | } |
| 3147 | } |
| 3148 | |
| 3149 | // Build a record containing all of dynamic classes declarations. |
| 3150 | RecordData DynamicClasses; |
| 3151 | for (unsigned I = 0, N = SemaRef.DynamicClasses.size(); I != N; ++I) |
| 3152 | if (SemaRef.DynamicClasses[I]->getPCHLevel() == 0) |
| 3153 | AddDeclRef(SemaRef.DynamicClasses[I], DynamicClasses); |
| 3154 | |
| 3155 | // Build a record containing all of pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3156 | RecordData PendingInstantiations; |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3157 | for (std::deque<Sema::PendingImplicitInstantiation>::iterator |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3158 | I = SemaRef.PendingInstantiations.begin(), |
| 3159 | N = SemaRef.PendingInstantiations.end(); I != N; ++I) { |
Sebastian Redl | c1d3ffb | 2011-04-24 16:27:30 +0000 | [diff] [blame] | 3160 | AddDeclRef(I->first, PendingInstantiations); |
| 3161 | AddSourceLocation(I->second, PendingInstantiations); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3162 | } |
| 3163 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && |
| 3164 | "There are local ones at end of translation unit!"); |
| 3165 | |
| 3166 | // Build a record containing some declaration references. |
| 3167 | // It's not worth the effort to avoid duplication here. |
| 3168 | RecordData SemaDeclRefs; |
| 3169 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { |
| 3170 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); |
| 3171 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); |
| 3172 | } |
| 3173 | |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3174 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3175 | WriteDeclsBlockAbbrevs(); |
Argyrios Kyrtzidis | d3d0755 | 2010-10-28 07:38:45 +0000 | [diff] [blame] | 3176 | for (DeclsToRewriteTy::iterator |
| 3177 | I = DeclsToRewrite.begin(), E = DeclsToRewrite.end(); I != E; ++I) |
| 3178 | DeclTypesToEmit.push(const_cast<Decl*>(*I)); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3179 | while (!DeclTypesToEmit.empty()) { |
| 3180 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 3181 | DeclTypesToEmit.pop(); |
| 3182 | if (DOT.isType()) |
| 3183 | WriteType(DOT.getType()); |
| 3184 | else |
| 3185 | WriteDecl(Context, DOT.getDecl()); |
| 3186 | } |
| 3187 | Stream.ExitBlock(); |
| 3188 | |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3189 | WritePreprocessor(PP); |
Sebastian Redl | a68340f | 2010-08-04 22:21:29 +0000 | [diff] [blame] | 3190 | WriteSelectors(SemaRef); |
| 3191 | WriteReferencedSelectorsPool(SemaRef); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3192 | WriteIdentifierTable(PP); |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3193 | WriteFPPragmaOptions(SemaRef.getFPOptions()); |
| 3194 | WriteOpenCLExtensions(SemaRef); |
| 3195 | |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3196 | WriteTypeDeclOffsets(); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3197 | // FIXME: For chained PCH only write the new mappings (we currently |
| 3198 | // write all of them again). |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3199 | WritePragmaDiagnosticMappings(Context.getDiagnostics()); |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3200 | |
Anders Carlsson | c850578 | 2011-03-06 18:41:18 +0000 | [diff] [blame] | 3201 | WriteCXXBaseSpecifiersOffsets(); |
| 3202 | |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3203 | /// Build a record containing first declarations from a chained PCH and the |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3204 | /// most recent declarations in this AST that they point to. |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3205 | RecordData FirstLatestDeclIDs; |
| 3206 | for (FirstLatestDeclMap::iterator |
| 3207 | I = FirstLatestDecls.begin(), E = FirstLatestDecls.end(); I != E; ++I) { |
| 3208 | assert(I->first->getPCHLevel() > I->second->getPCHLevel() && |
| 3209 | "Expected first & second to be in different PCHs"); |
| 3210 | AddDeclRef(I->first, FirstLatestDeclIDs); |
| 3211 | AddDeclRef(I->second, FirstLatestDeclIDs); |
| 3212 | } |
| 3213 | if (!FirstLatestDeclIDs.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3214 | Stream.EmitRecord(REDECLS_UPDATE_LATEST, FirstLatestDeclIDs); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3215 | |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3216 | // Write the record containing external, unnamed definitions. |
| 3217 | if (!ExternalDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3218 | Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3219 | |
| 3220 | // Write the record containing tentative definitions. |
| 3221 | if (!TentativeDefinitions.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3222 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3223 | |
Argyrios Kyrtzidis | 49b96d1 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3224 | // Write the record containing unused file scoped decls. |
| 3225 | if (!UnusedFileScopedDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3226 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3227 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3228 | // Write the record containing weak undeclared identifiers. |
| 3229 | if (!WeakUndeclaredIdentifiers.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3230 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3231 | WeakUndeclaredIdentifiers); |
| 3232 | |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3233 | // Write the record containing locally-scoped external definitions. |
| 3234 | if (!LocallyScopedExternalDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3235 | Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3236 | LocallyScopedExternalDecls); |
| 3237 | |
| 3238 | // Write the record containing ext_vector type names. |
| 3239 | if (!ExtVectorDecls.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3240 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3241 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3242 | // Write the record containing VTable uses information. |
| 3243 | if (!VTableUses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3244 | Stream.EmitRecord(VTABLE_USES, VTableUses); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3245 | |
| 3246 | // Write the record containing dynamic classes declarations. |
| 3247 | if (!DynamicClasses.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3248 | Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3249 | |
| 3250 | // Write the record containing pending implicit instantiations. |
Chandler Carruth | 62c78d5 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 3251 | if (!PendingInstantiations.empty()) |
| 3252 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 3253 | |
| 3254 | // Write the record containing declaration references of Sema. |
| 3255 | if (!SemaDeclRefs.empty()) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3256 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 3257 | |
| 3258 | // Write the delegating constructors. |
| 3259 | if (!DelegatingCtorDecls.empty()) |
| 3260 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3261 | |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 3262 | // Write the updates to DeclContexts. |
| 3263 | for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator |
| 3264 | I = UpdatedDeclContexts.begin(), |
| 3265 | E = UpdatedDeclContexts.end(); |
Sebastian Redl | 1d1e42b | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3266 | I != E; ++I) |
| 3267 | WriteDeclContextVisibleUpdate(*I); |
| 3268 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3269 | WriteDeclUpdatesBlocks(); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3270 | |
Sebastian Redl | 083abdf | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 3271 | Record.clear(); |
| 3272 | Record.push_back(NumStatements); |
| 3273 | Record.push_back(NumMacros); |
| 3274 | Record.push_back(NumLexicalDeclContexts); |
| 3275 | Record.push_back(NumVisibleDeclContexts); |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3276 | WriteDeclReplacementsBlock(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3277 | Stream.EmitRecord(STATISTICS, Record); |
Sebastian Redl | 1dc13a1 | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 3278 | Stream.ExitBlock(); |
| 3279 | } |
| 3280 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3281 | void ASTWriter::WriteDeclUpdatesBlocks() { |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3282 | if (DeclUpdates.empty()) |
| 3283 | return; |
| 3284 | |
| 3285 | RecordData OffsetsRecord; |
Douglas Gregor | a72d8c4 | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 3286 | Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3287 | for (DeclUpdateMap::iterator |
| 3288 | I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { |
| 3289 | const Decl *D = I->first; |
| 3290 | UpdateRecord &URec = I->second; |
| 3291 | |
Argyrios Kyrtzidis | ba901b5 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 3292 | if (DeclsToRewrite.count(D)) |
| 3293 | continue; // The decl will be written completely,no need to store updates. |
| 3294 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3295 | uint64_t Offset = Stream.GetCurrentBitNo(); |
| 3296 | Stream.EmitRecord(DECL_UPDATES, URec); |
| 3297 | |
| 3298 | OffsetsRecord.push_back(GetDeclRef(D)); |
| 3299 | OffsetsRecord.push_back(Offset); |
| 3300 | } |
| 3301 | Stream.ExitBlock(); |
| 3302 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); |
| 3303 | } |
| 3304 | |
Argyrios Kyrtzidis | aacdd02 | 2010-10-24 17:26:43 +0000 | [diff] [blame] | 3305 | void ASTWriter::WriteDeclReplacementsBlock() { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3306 | if (ReplacedDecls.empty()) |
| 3307 | return; |
| 3308 | |
| 3309 | RecordData Record; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3310 | for (llvm::SmallVector<std::pair<DeclID, uint64_t>, 16>::iterator |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3311 | I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { |
| 3312 | Record.push_back(I->first); |
| 3313 | Record.push_back(I->second); |
| 3314 | } |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3315 | Stream.EmitRecord(DECL_REPLACEMENTS, Record); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3316 | } |
| 3317 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3318 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3319 | Record.push_back(Loc.getRawEncoding()); |
| 3320 | } |
| 3321 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3322 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3323 | AddSourceLocation(Range.getBegin(), Record); |
| 3324 | AddSourceLocation(Range.getEnd(), Record); |
| 3325 | } |
| 3326 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3327 | void ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3328 | Record.push_back(Value.getBitWidth()); |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3329 | const uint64_t *Words = Value.getRawData(); |
| 3330 | Record.append(Words, Words + Value.getNumWords()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3331 | } |
| 3332 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3333 | void ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3334 | Record.push_back(Value.isUnsigned()); |
| 3335 | AddAPInt(Value, Record); |
| 3336 | } |
| 3337 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3338 | void ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 3339 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 3340 | } |
| 3341 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3342 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3343 | Record.push_back(getIdentifierRef(II)); |
| 3344 | } |
| 3345 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3346 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3347 | if (II == 0) |
| 3348 | return 0; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3349 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3350 | IdentID &ID = IdentifierIDs[II]; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3351 | if (ID == 0) |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3352 | ID = NextIdentID++; |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 3353 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3354 | } |
| 3355 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 3356 | MacroID ASTWriter::getMacroDefinitionID(MacroDefinition *MD) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3357 | if (MD == 0) |
| 3358 | return 0; |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 3359 | |
| 3360 | MacroID &ID = MacroDefinitions[MD]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3361 | if (ID == 0) |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3362 | ID = NextMacroID++; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3363 | return ID; |
| 3364 | } |
| 3365 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3366 | void ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3367 | Record.push_back(getSelectorRef(SelRef)); |
| 3368 | } |
| 3369 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3370 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3371 | if (Sel.getAsOpaquePtr() == 0) { |
| 3372 | return 0; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3373 | } |
| 3374 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3375 | SelectorID &SID = SelectorIDs[Sel]; |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3376 | if (SID == 0 && Chain) { |
| 3377 | // This might trigger a ReadSelector callback, which will set the ID for |
| 3378 | // this selector. |
| 3379 | Chain->LoadSelector(Sel); |
| 3380 | } |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3381 | if (SID == 0) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3382 | SID = NextSelectorID++; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3383 | } |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3384 | return SID; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3385 | } |
| 3386 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3387 | void ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 3388 | AddDeclRef(Temp->getDestructor(), Record); |
| 3389 | } |
| 3390 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3391 | void ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, |
| 3392 | CXXBaseSpecifier const *BasesEnd, |
| 3393 | RecordDataImpl &Record) { |
| 3394 | assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); |
| 3395 | CXXBaseSpecifiersToWrite.push_back( |
| 3396 | QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, |
| 3397 | Bases, BasesEnd)); |
| 3398 | Record.push_back(NextCXXBaseSpecifiersID++); |
| 3399 | } |
| 3400 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3401 | void ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3402 | const TemplateArgumentLocInfo &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3403 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3404 | switch (Kind) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3405 | case TemplateArgument::Expression: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3406 | AddStmt(Arg.getAsExpr()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3407 | break; |
| 3408 | case TemplateArgument::Type: |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3409 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3410 | break; |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3411 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3412 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3413 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3414 | break; |
| 3415 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3416 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3417 | AddSourceLocation(Arg.getTemplateNameLoc(), Record); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3418 | AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3419 | break; |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3420 | case TemplateArgument::Null: |
| 3421 | case TemplateArgument::Integral: |
| 3422 | case TemplateArgument::Declaration: |
| 3423 | case TemplateArgument::Pack: |
| 3424 | break; |
| 3425 | } |
| 3426 | } |
| 3427 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3428 | void ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3429 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3430 | AddTemplateArgument(Arg.getArgument(), Record); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3431 | |
| 3432 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { |
| 3433 | bool InfoHasSameExpr |
| 3434 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); |
| 3435 | Record.push_back(InfoHasSameExpr); |
| 3436 | if (InfoHasSameExpr) |
| 3437 | return; // Avoid storing the same expr twice. |
| 3438 | } |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3439 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), |
| 3440 | Record); |
| 3441 | } |
| 3442 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3443 | void ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, |
| 3444 | RecordDataImpl &Record) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3445 | if (TInfo == 0) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3446 | AddTypeRef(QualType(), Record); |
| 3447 | return; |
| 3448 | } |
| 3449 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3450 | AddTypeLoc(TInfo->getTypeLoc(), Record); |
| 3451 | } |
| 3452 | |
| 3453 | void ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { |
| 3454 | AddTypeRef(TL.getType(), Record); |
| 3455 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3456 | TypeLocWriter TLW(*this, Record); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3457 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 3458 | TLW.Visit(TL); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3459 | } |
| 3460 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3461 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 7fb3518 | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 3462 | Record.push_back(GetOrCreateTypeID(T)); |
| 3463 | } |
| 3464 | |
| 3465 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3466 | return MakeTypeID(T, |
| 3467 | std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); |
| 3468 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3469 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3470 | TypeID ASTWriter::getTypeID(QualType T) const { |
Argyrios Kyrtzidis | eb3f04e | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 3471 | return MakeTypeID(T, |
| 3472 | std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | TypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { |
| 3476 | if (T.isNull()) |
| 3477 | return TypeIdx(); |
| 3478 | assert(!T.getLocalFastQualifiers()); |
| 3479 | |
Argyrios Kyrtzidis | 01b81c4 | 2010-08-20 16:04:04 +0000 | [diff] [blame] | 3480 | TypeIdx &Idx = TypeIdxs[T]; |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3481 | if (Idx.getIndex() == 0) { |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3482 | // 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] | 3483 | // into the queue of types to emit. |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3484 | Idx = TypeIdx(NextTypeID++); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3485 | DeclTypesToEmit.push(T); |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 3486 | } |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3487 | return Idx; |
| 3488 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3489 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3490 | TypeIdx ASTWriter::getTypeIdx(QualType T) const { |
Argyrios Kyrtzidis | 26fca90 | 2010-08-20 16:04:09 +0000 | [diff] [blame] | 3491 | if (T.isNull()) |
| 3492 | return TypeIdx(); |
| 3493 | assert(!T.getLocalFastQualifiers()); |
| 3494 | |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3495 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3496 | assert(I != TypeIdxs.end() && "Type not emitted!"); |
| 3497 | return I->second; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3498 | } |
| 3499 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3500 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3501 | Record.push_back(GetDeclRef(D)); |
| 3502 | } |
| 3503 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3504 | DeclID ASTWriter::GetDeclRef(const Decl *D) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3505 | if (D == 0) { |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3506 | return 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3507 | } |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3508 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3509 | DeclID &ID = DeclIDs[D]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3510 | if (ID == 0) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3511 | // We haven't seen this declaration before. Give it a new ID and |
| 3512 | // enqueue it in the list of declarations to emit. |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3513 | ID = NextDeclID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3514 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 3515 | } else if (ID < FirstDeclID && D->isChangedSinceDeserialization()) { |
| 3516 | // We don't add it to the replacement collection here, because we don't |
| 3517 | // have the offset yet. |
| 3518 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
| 3519 | // Reset the flag, so that we don't add this decl multiple times. |
| 3520 | const_cast<Decl *>(D)->setChangedSinceDeserialization(false); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3521 | } |
| 3522 | |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3523 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3526 | DeclID ASTWriter::getDeclID(const Decl *D) { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3527 | if (D == 0) |
| 3528 | return 0; |
| 3529 | |
| 3530 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 3531 | return DeclIDs[D]; |
| 3532 | } |
| 3533 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3534 | void ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 3535 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3536 | Record.push_back(Name.getNameKind()); |
| 3537 | switch (Name.getNameKind()) { |
| 3538 | case DeclarationName::Identifier: |
| 3539 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 3540 | break; |
| 3541 | |
| 3542 | case DeclarationName::ObjCZeroArgSelector: |
| 3543 | case DeclarationName::ObjCOneArgSelector: |
| 3544 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3545 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3546 | break; |
| 3547 | |
| 3548 | case DeclarationName::CXXConstructorName: |
| 3549 | case DeclarationName::CXXDestructorName: |
| 3550 | case DeclarationName::CXXConversionFunctionName: |
| 3551 | AddTypeRef(Name.getCXXNameType(), Record); |
| 3552 | break; |
| 3553 | |
| 3554 | case DeclarationName::CXXOperatorName: |
| 3555 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 3556 | break; |
| 3557 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3558 | case DeclarationName::CXXLiteralOperatorName: |
| 3559 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 3560 | break; |
| 3561 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3562 | case DeclarationName::CXXUsingDirective: |
| 3563 | // No extra data to emit |
| 3564 | break; |
| 3565 | } |
| 3566 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3567 | |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3568 | void ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3569 | DeclarationName Name, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3570 | switch (Name.getNameKind()) { |
| 3571 | case DeclarationName::CXXConstructorName: |
| 3572 | case DeclarationName::CXXDestructorName: |
| 3573 | case DeclarationName::CXXConversionFunctionName: |
| 3574 | AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); |
| 3575 | break; |
| 3576 | |
| 3577 | case DeclarationName::CXXOperatorName: |
| 3578 | AddSourceLocation( |
| 3579 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), |
| 3580 | Record); |
| 3581 | AddSourceLocation( |
| 3582 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), |
| 3583 | Record); |
| 3584 | break; |
| 3585 | |
| 3586 | case DeclarationName::CXXLiteralOperatorName: |
| 3587 | AddSourceLocation( |
| 3588 | SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), |
| 3589 | Record); |
| 3590 | break; |
| 3591 | |
| 3592 | case DeclarationName::Identifier: |
| 3593 | case DeclarationName::ObjCZeroArgSelector: |
| 3594 | case DeclarationName::ObjCOneArgSelector: |
| 3595 | case DeclarationName::ObjCMultiArgSelector: |
| 3596 | case DeclarationName::CXXUsingDirective: |
| 3597 | break; |
| 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | void ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3602 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3603 | AddDeclarationName(NameInfo.getName(), Record); |
| 3604 | AddSourceLocation(NameInfo.getLoc(), Record); |
| 3605 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); |
| 3606 | } |
| 3607 | |
| 3608 | void ASTWriter::AddQualifierInfo(const QualifierInfo &Info, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3609 | RecordDataImpl &Record) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3610 | AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3611 | Record.push_back(Info.NumTemplParamLists); |
| 3612 | for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) |
| 3613 | AddTemplateParameterList(Info.TemplParamLists[i], Record); |
| 3614 | } |
| 3615 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3616 | void ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3617 | RecordDataImpl &Record) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3618 | // 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] | 3619 | // typically accommodate the vast majority. |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3620 | llvm::SmallVector<NestedNameSpecifier *, 8> NestedNames; |
| 3621 | |
| 3622 | // Push each of the NNS's onto a stack for serialization in reverse order. |
| 3623 | while (NNS) { |
| 3624 | NestedNames.push_back(NNS); |
| 3625 | NNS = NNS->getPrefix(); |
| 3626 | } |
| 3627 | |
| 3628 | Record.push_back(NestedNames.size()); |
| 3629 | while(!NestedNames.empty()) { |
| 3630 | NNS = NestedNames.pop_back_val(); |
| 3631 | NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); |
| 3632 | Record.push_back(Kind); |
| 3633 | switch (Kind) { |
| 3634 | case NestedNameSpecifier::Identifier: |
| 3635 | AddIdentifierRef(NNS->getAsIdentifier(), Record); |
| 3636 | break; |
| 3637 | |
| 3638 | case NestedNameSpecifier::Namespace: |
| 3639 | AddDeclRef(NNS->getAsNamespace(), Record); |
| 3640 | break; |
| 3641 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 3642 | case NestedNameSpecifier::NamespaceAlias: |
| 3643 | AddDeclRef(NNS->getAsNamespaceAlias(), Record); |
| 3644 | break; |
| 3645 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3646 | case NestedNameSpecifier::TypeSpec: |
| 3647 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3648 | AddTypeRef(QualType(NNS->getAsType(), 0), Record); |
| 3649 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 3650 | break; |
| 3651 | |
| 3652 | case NestedNameSpecifier::Global: |
| 3653 | // Don't need to write an associated value. |
| 3654 | break; |
| 3655 | } |
| 3656 | } |
| 3657 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3658 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3659 | void ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 3660 | RecordDataImpl &Record) { |
| 3661 | // 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] | 3662 | // typically accommodate the vast majority. |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 3663 | llvm::SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 3664 | |
| 3665 | // Push each of the nested-name-specifiers's onto a stack for |
| 3666 | // serialization in reverse order. |
| 3667 | while (NNS) { |
| 3668 | NestedNames.push_back(NNS); |
| 3669 | NNS = NNS.getPrefix(); |
| 3670 | } |
| 3671 | |
| 3672 | Record.push_back(NestedNames.size()); |
| 3673 | while(!NestedNames.empty()) { |
| 3674 | NNS = NestedNames.pop_back_val(); |
| 3675 | NestedNameSpecifier::SpecifierKind Kind |
| 3676 | = NNS.getNestedNameSpecifier()->getKind(); |
| 3677 | Record.push_back(Kind); |
| 3678 | switch (Kind) { |
| 3679 | case NestedNameSpecifier::Identifier: |
| 3680 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); |
| 3681 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 3682 | break; |
| 3683 | |
| 3684 | case NestedNameSpecifier::Namespace: |
| 3685 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); |
| 3686 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 3687 | break; |
| 3688 | |
| 3689 | case NestedNameSpecifier::NamespaceAlias: |
| 3690 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); |
| 3691 | AddSourceRange(NNS.getLocalSourceRange(), Record); |
| 3692 | break; |
| 3693 | |
| 3694 | case NestedNameSpecifier::TypeSpec: |
| 3695 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3696 | Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); |
| 3697 | AddTypeLoc(NNS.getTypeLoc(), Record); |
| 3698 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 3699 | break; |
| 3700 | |
| 3701 | case NestedNameSpecifier::Global: |
| 3702 | AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); |
| 3703 | break; |
| 3704 | } |
| 3705 | } |
| 3706 | } |
| 3707 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3708 | void ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3709 | TemplateName::NameKind Kind = Name.getKind(); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3710 | Record.push_back(Kind); |
| 3711 | switch (Kind) { |
| 3712 | case TemplateName::Template: |
| 3713 | AddDeclRef(Name.getAsTemplateDecl(), Record); |
| 3714 | break; |
| 3715 | |
| 3716 | case TemplateName::OverloadedTemplate: { |
| 3717 | OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); |
| 3718 | Record.push_back(OvT->size()); |
| 3719 | for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); |
| 3720 | I != E; ++I) |
| 3721 | AddDeclRef(*I, Record); |
| 3722 | break; |
| 3723 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3724 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3725 | case TemplateName::QualifiedTemplate: { |
| 3726 | QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); |
| 3727 | AddNestedNameSpecifier(QualT->getQualifier(), Record); |
| 3728 | Record.push_back(QualT->hasTemplateKeyword()); |
| 3729 | AddDeclRef(QualT->getTemplateDecl(), Record); |
| 3730 | break; |
| 3731 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3732 | |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3733 | case TemplateName::DependentTemplate: { |
| 3734 | DependentTemplateName *DepT = Name.getAsDependentTemplateName(); |
| 3735 | AddNestedNameSpecifier(DepT->getQualifier(), Record); |
| 3736 | Record.push_back(DepT->isIdentifier()); |
| 3737 | if (DepT->isIdentifier()) |
| 3738 | AddIdentifierRef(DepT->getIdentifier(), Record); |
| 3739 | else |
| 3740 | Record.push_back(DepT->getOperator()); |
| 3741 | break; |
| 3742 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 3743 | |
| 3744 | case TemplateName::SubstTemplateTemplateParm: { |
| 3745 | SubstTemplateTemplateParmStorage *subst |
| 3746 | = Name.getAsSubstTemplateTemplateParm(); |
| 3747 | AddDeclRef(subst->getParameter(), Record); |
| 3748 | AddTemplateName(subst->getReplacement(), Record); |
| 3749 | break; |
| 3750 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3751 | |
| 3752 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 3753 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 3754 | = Name.getAsSubstTemplateTemplateParmPack(); |
| 3755 | AddDeclRef(SubstPack->getParameterPack(), Record); |
| 3756 | AddTemplateArgument(SubstPack->getArgumentPack(), Record); |
| 3757 | break; |
| 3758 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3759 | } |
| 3760 | } |
| 3761 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3762 | void ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3763 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3764 | Record.push_back(Arg.getKind()); |
| 3765 | switch (Arg.getKind()) { |
| 3766 | case TemplateArgument::Null: |
| 3767 | break; |
| 3768 | case TemplateArgument::Type: |
| 3769 | AddTypeRef(Arg.getAsType(), Record); |
| 3770 | break; |
| 3771 | case TemplateArgument::Declaration: |
| 3772 | AddDeclRef(Arg.getAsDecl(), Record); |
| 3773 | break; |
| 3774 | case TemplateArgument::Integral: |
| 3775 | AddAPSInt(*Arg.getAsIntegral(), Record); |
| 3776 | AddTypeRef(Arg.getIntegralType(), Record); |
| 3777 | break; |
| 3778 | case TemplateArgument::Template: |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3779 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
| 3780 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3781 | case TemplateArgument::TemplateExpansion: |
| 3782 | AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3783 | if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) |
| 3784 | Record.push_back(*NumExpansions + 1); |
| 3785 | else |
| 3786 | Record.push_back(0); |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3787 | break; |
| 3788 | case TemplateArgument::Expression: |
| 3789 | AddStmt(Arg.getAsExpr()); |
| 3790 | break; |
| 3791 | case TemplateArgument::Pack: |
| 3792 | Record.push_back(Arg.pack_size()); |
| 3793 | for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); |
| 3794 | I != E; ++I) |
| 3795 | AddTemplateArgument(*I, Record); |
| 3796 | break; |
| 3797 | } |
| 3798 | } |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3799 | |
| 3800 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3801 | ASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3802 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3803 | assert(TemplateParams && "No TemplateParams!"); |
| 3804 | AddSourceLocation(TemplateParams->getTemplateLoc(), Record); |
| 3805 | AddSourceLocation(TemplateParams->getLAngleLoc(), Record); |
| 3806 | AddSourceLocation(TemplateParams->getRAngleLoc(), Record); |
| 3807 | Record.push_back(TemplateParams->size()); |
| 3808 | for (TemplateParameterList::const_iterator |
| 3809 | P = TemplateParams->begin(), PEnd = TemplateParams->end(); |
| 3810 | P != PEnd; ++P) |
| 3811 | AddDeclRef(*P, Record); |
| 3812 | } |
| 3813 | |
| 3814 | /// \brief Emit a template argument list. |
| 3815 | void |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3816 | ASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3817 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3818 | assert(TemplateArgs && "No TemplateArgs!"); |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 3819 | Record.push_back(TemplateArgs->size()); |
| 3820 | for (int i=0, e = TemplateArgs->size(); i != e; ++i) |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 3821 | AddTemplateArgument(TemplateArgs->get(i), Record); |
| 3822 | } |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 3823 | |
| 3824 | |
| 3825 | void |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3826 | ASTWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 3827 | Record.push_back(Set.size()); |
| 3828 | for (UnresolvedSetImpl::const_iterator |
| 3829 | I = Set.begin(), E = Set.end(); I != E; ++I) { |
| 3830 | AddDeclRef(I.getDecl(), Record); |
| 3831 | Record.push_back(I.getAccess()); |
| 3832 | } |
| 3833 | } |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3834 | |
Sebastian Redl | a4232eb | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3835 | void ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3836 | RecordDataImpl &Record) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3837 | Record.push_back(Base.isVirtual()); |
| 3838 | Record.push_back(Base.isBaseOfClass()); |
| 3839 | Record.push_back(Base.getAccessSpecifierAsWritten()); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 3840 | Record.push_back(Base.getInheritConstructors()); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 3841 | AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3842 | AddSourceRange(Base.getSourceRange(), Record); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 3843 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() |
| 3844 | : SourceLocation(), |
| 3845 | Record); |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 3846 | } |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3847 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3848 | void ASTWriter::FlushCXXBaseSpecifiers() { |
| 3849 | RecordData Record; |
| 3850 | for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { |
| 3851 | Record.clear(); |
| 3852 | |
| 3853 | // Record the offset of this base-specifier set. |
| 3854 | unsigned Index = CXXBaseSpecifiersToWrite[I].ID - FirstCXXBaseSpecifiersID; |
| 3855 | if (Index == CXXBaseSpecifiersOffsets.size()) |
| 3856 | CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); |
| 3857 | else { |
| 3858 | if (Index > CXXBaseSpecifiersOffsets.size()) |
| 3859 | CXXBaseSpecifiersOffsets.resize(Index + 1); |
| 3860 | CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); |
| 3861 | } |
| 3862 | |
| 3863 | const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, |
| 3864 | *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; |
| 3865 | Record.push_back(BEnd - B); |
| 3866 | for (; B != BEnd; ++B) |
| 3867 | AddCXXBaseSpecifier(*B, Record); |
| 3868 | Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); |
Douglas Gregor | acec34b | 2010-10-30 04:28:16 +0000 | [diff] [blame] | 3869 | |
| 3870 | // Flush any expressions that were written as part of the base specifiers. |
| 3871 | FlushStmts(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | CXXBaseSpecifiersToWrite.clear(); |
| 3875 | } |
| 3876 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 3877 | void ASTWriter::AddCXXCtorInitializers( |
| 3878 | const CXXCtorInitializer * const *CtorInitializers, |
| 3879 | unsigned NumCtorInitializers, |
| 3880 | RecordDataImpl &Record) { |
| 3881 | Record.push_back(NumCtorInitializers); |
| 3882 | for (unsigned i=0; i != NumCtorInitializers; ++i) { |
| 3883 | const CXXCtorInitializer *Init = CtorInitializers[i]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3884 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3885 | if (Init->isBaseInitializer()) { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 3886 | Record.push_back(CTOR_INITIALIZER_BASE); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3887 | AddTypeSourceInfo(Init->getBaseClassInfo(), Record); |
| 3888 | Record.push_back(Init->isBaseVirtual()); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 3889 | } else if (Init->isDelegatingInitializer()) { |
| 3890 | Record.push_back(CTOR_INITIALIZER_DELEGATING); |
| 3891 | AddDeclRef(Init->getTargetConstructor(), Record); |
| 3892 | } else if (Init->isMemberInitializer()){ |
| 3893 | Record.push_back(CTOR_INITIALIZER_MEMBER); |
| 3894 | AddDeclRef(Init->getMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3895 | } else { |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 3896 | Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); |
| 3897 | AddDeclRef(Init->getIndirectMember(), Record); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3898 | } |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 3899 | |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3900 | AddSourceLocation(Init->getMemberLocation(), Record); |
| 3901 | AddStmt(Init->getInit()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 3902 | AddSourceLocation(Init->getLParenLoc(), Record); |
| 3903 | AddSourceLocation(Init->getRParenLoc(), Record); |
| 3904 | Record.push_back(Init->isWritten()); |
| 3905 | if (Init->isWritten()) { |
| 3906 | Record.push_back(Init->getSourceOrder()); |
| 3907 | } else { |
| 3908 | Record.push_back(Init->getNumArrayIndices()); |
| 3909 | for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) |
| 3910 | AddDeclRef(Init->getArrayIndex(i), Record); |
| 3911 | } |
| 3912 | } |
| 3913 | } |
| 3914 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3915 | void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { |
| 3916 | assert(D->DefinitionData); |
| 3917 | struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; |
| 3918 | Record.push_back(Data.UserDeclaredConstructor); |
| 3919 | Record.push_back(Data.UserDeclaredCopyConstructor); |
| 3920 | Record.push_back(Data.UserDeclaredCopyAssignment); |
| 3921 | Record.push_back(Data.UserDeclaredDestructor); |
| 3922 | Record.push_back(Data.Aggregate); |
| 3923 | Record.push_back(Data.PlainOldData); |
| 3924 | Record.push_back(Data.Empty); |
| 3925 | Record.push_back(Data.Polymorphic); |
| 3926 | Record.push_back(Data.Abstract); |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 3927 | Record.push_back(Data.IsStandardLayout); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 3928 | Record.push_back(Data.HasNoNonEmptyBases); |
| 3929 | Record.push_back(Data.HasPrivateFields); |
| 3930 | Record.push_back(Data.HasProtectedFields); |
| 3931 | Record.push_back(Data.HasPublicFields); |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 3932 | Record.push_back(Data.HasMutableFields); |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 3933 | Record.push_back(Data.HasTrivialDefaultConstructor); |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 3934 | Record.push_back(Data.HasConstExprNonCopyMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3935 | Record.push_back(Data.HasTrivialCopyConstructor); |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 3936 | Record.push_back(Data.HasTrivialMoveConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3937 | Record.push_back(Data.HasTrivialCopyAssignment); |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 3938 | Record.push_back(Data.HasTrivialMoveAssignment); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3939 | Record.push_back(Data.HasTrivialDestructor); |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 3940 | Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3941 | Record.push_back(Data.ComputedVisibleConversions); |
Sean Hunt | cdee3fe | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 3942 | Record.push_back(Data.UserProvidedDefaultConstructor); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3943 | Record.push_back(Data.DeclaredDefaultConstructor); |
| 3944 | Record.push_back(Data.DeclaredCopyConstructor); |
| 3945 | Record.push_back(Data.DeclaredCopyAssignment); |
| 3946 | Record.push_back(Data.DeclaredDestructor); |
| 3947 | |
| 3948 | Record.push_back(Data.NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3949 | if (Data.NumBases > 0) |
| 3950 | AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, |
| 3951 | Record); |
| 3952 | |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3953 | // FIXME: Make VBases lazily computed when needed to avoid storing them. |
| 3954 | Record.push_back(Data.NumVBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3955 | if (Data.NumVBases > 0) |
| 3956 | AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, |
| 3957 | Record); |
Argyrios Kyrtzidis | 89eaf3a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 3958 | |
| 3959 | AddUnresolvedSet(Data.Conversions, Record); |
| 3960 | AddUnresolvedSet(Data.VisibleConversions, Record); |
| 3961 | // Data.Definition is the owning decl, no need to write it. |
| 3962 | AddDeclRef(Data.FirstFriend, Record); |
| 3963 | } |
| 3964 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3965 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3966 | assert(Reader && "Cannot remove chain"); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3967 | assert(!Chain && "Cannot replace chain"); |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3968 | assert(FirstDeclID == NextDeclID && |
| 3969 | FirstTypeID == NextTypeID && |
| 3970 | FirstIdentID == NextIdentID && |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3971 | FirstSelectorID == NextSelectorID && |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 3972 | FirstMacroID == NextMacroID && |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3973 | FirstCXXBaseSpecifiersID == NextCXXBaseSpecifiersID && |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3974 | "Setting chain after writing has started."); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3975 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3976 | Chain = Reader; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3977 | |
| 3978 | FirstDeclID += Chain->getTotalNumDecls(); |
| 3979 | FirstTypeID += Chain->getTotalNumTypes(); |
| 3980 | FirstIdentID += Chain->getTotalNumIdentifiers(); |
| 3981 | FirstSelectorID += Chain->getTotalNumSelectors(); |
| 3982 | FirstMacroID += Chain->getTotalNumMacroDefinitions(); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3983 | FirstCXXBaseSpecifiersID += Chain->getTotalNumCXXBaseSpecifiers(); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3984 | NextDeclID = FirstDeclID; |
| 3985 | NextTypeID = FirstTypeID; |
| 3986 | NextIdentID = FirstIdentID; |
| 3987 | NextSelectorID = FirstSelectorID; |
| 3988 | NextMacroID = FirstMacroID; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3989 | NextCXXBaseSpecifiersID = FirstCXXBaseSpecifiersID; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 3990 | } |
| 3991 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3992 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3993 | IdentifierIDs[II] = ID; |
Douglas Gregor | 040a804 | 2011-02-11 00:26:14 +0000 | [diff] [blame] | 3994 | if (II->hasMacroDefinition()) |
| 3995 | DeserializedMacroNames.push_back(II); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3996 | } |
| 3997 | |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3998 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3999 | // Always take the highest-numbered type index. This copes with an interesting |
| 4000 | // 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] | 4001 | // 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] | 4002 | // keep the higher-numbered entry so that we can properly write it out to |
| 4003 | // the AST file. |
| 4004 | TypeIdx &StoredIdx = TypeIdxs[T]; |
| 4005 | if (Idx.getIndex() >= StoredIdx.getIndex()) |
| 4006 | StoredIdx = Idx; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4007 | } |
| 4008 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4009 | void ASTWriter::DeclRead(DeclID ID, const Decl *D) { |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4010 | DeclIDs[D] = ID; |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4011 | } |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4012 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4013 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { |
Sebastian Redl | 5d05007 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 4014 | SelectorIDs[S] = ID; |
| 4015 | } |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4016 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4017 | void ASTWriter::MacroDefinitionRead(serialization::MacroID ID, |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 4018 | MacroDefinition *MD) { |
| 4019 | MacroDefinitions[MD] = ID; |
| 4020 | } |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4021 | |
| 4022 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |
| 4023 | assert(D->isDefinition()); |
| 4024 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 4025 | // We are interested when a PCH decl is modified. |
| 4026 | if (RD->getPCHLevel() > 0) { |
| 4027 | // A forward reference was mutated into a definition. Rewrite it. |
| 4028 | // FIXME: This happens during template instantiation, should we |
| 4029 | // have created a new definition decl instead ? |
Argyrios Kyrtzidis | d3d0755 | 2010-10-28 07:38:45 +0000 | [diff] [blame] | 4030 | RewriteDecl(RD); |
Argyrios Kyrtzidis | 565bf30 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | for (CXXRecordDecl::redecl_iterator |
| 4034 | I = RD->redecls_begin(), E = RD->redecls_end(); I != E; ++I) { |
| 4035 | CXXRecordDecl *Redecl = cast<CXXRecordDecl>(*I); |
| 4036 | if (Redecl == RD) |
| 4037 | continue; |
| 4038 | |
| 4039 | // We are interested when a PCH decl is modified. |
| 4040 | if (Redecl->getPCHLevel() > 0) { |
| 4041 | UpdateRecord &Record = DeclUpdates[Redecl]; |
| 4042 | Record.push_back(UPD_CXX_SET_DEFINITIONDATA); |
| 4043 | assert(Redecl->DefinitionData); |
| 4044 | assert(Redecl->DefinitionData->Definition == D); |
| 4045 | AddDeclRef(D, Record); // the DefinitionDecl |
| 4046 | } |
| 4047 | } |
| 4048 | } |
| 4049 | } |
Argyrios Kyrtzidis | 100050b | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 4050 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { |
| 4051 | // TU and namespaces are handled elsewhere. |
| 4052 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) |
| 4053 | return; |
| 4054 | |
| 4055 | if (!(D->getPCHLevel() == 0 && cast<Decl>(DC)->getPCHLevel() > 0)) |
| 4056 | return; // Not a source decl added to a DeclContext from PCH. |
| 4057 | |
| 4058 | AddUpdatedDeclContext(DC); |
| 4059 | } |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4060 | |
| 4061 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { |
| 4062 | assert(D->isImplicit()); |
| 4063 | if (!(D->getPCHLevel() == 0 && RD->getPCHLevel() > 0)) |
| 4064 | return; // Not a source member added to a class from PCH. |
| 4065 | if (!isa<CXXMethodDecl>(D)) |
| 4066 | return; // We are interested in lazily declared implicit methods. |
| 4067 | |
| 4068 | // A decl coming from PCH was modified. |
| 4069 | assert(RD->isDefinition()); |
| 4070 | UpdateRecord &Record = DeclUpdates[RD]; |
| 4071 | Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); |
| 4072 | AddDeclRef(D, Record); |
| 4073 | } |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4074 | |
| 4075 | void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, |
| 4076 | const ClassTemplateSpecializationDecl *D) { |
Argyrios Kyrtzidis | 0f04f69 | 2010-10-28 07:38:47 +0000 | [diff] [blame] | 4077 | // The specializations set is kept in the canonical template. |
| 4078 | TD = TD->getCanonicalDecl(); |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4079 | if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0)) |
| 4080 | return; // Not a source specialization added to a template from PCH. |
| 4081 | |
| 4082 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4083 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
| 4084 | AddDeclRef(D, Record); |
| 4085 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 4086 | |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 4087 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, |
| 4088 | const FunctionDecl *D) { |
| 4089 | // The specializations set is kept in the canonical template. |
| 4090 | TD = TD->getCanonicalDecl(); |
| 4091 | if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0)) |
| 4092 | return; // Not a source specialization added to a template from PCH. |
| 4093 | |
| 4094 | UpdateRecord &Record = DeclUpdates[TD]; |
| 4095 | Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); |
| 4096 | AddDeclRef(D, Record); |
| 4097 | } |
| 4098 | |
Sebastian Redl | 58a2cd8 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 4099 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { |
| 4100 | if (D->getPCHLevel() == 0) |
| 4101 | return; // Declaration not imported from PCH. |
| 4102 | |
| 4103 | // Implicit decl from a PCH was defined. |
| 4104 | // FIXME: Should implicit definition be a separate FunctionDecl? |
| 4105 | RewriteDecl(D); |
| 4106 | } |
| 4107 | |
Sebastian Redl | f79a719 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4108 | void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { |
| 4109 | if (D->getPCHLevel() == 0) |
| 4110 | return; |
| 4111 | |
| 4112 | // Since the actual instantiation is delayed, this really means that we need |
| 4113 | // to update the instantiation location. |
| 4114 | UpdateRecord &Record = DeclUpdates[D]; |
| 4115 | Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER); |
| 4116 | AddSourceLocation( |
| 4117 | D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record); |
| 4118 | } |
| 4119 | |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 4120 | ASTSerializationListener::~ASTSerializationListener() { } |