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