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