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