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