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