ASTWriter.cpp revision 7da99b05aa9482e76b2954223b5652469004aec2
14ee2ad04344446e610172a0e73949212923014dfSebastian Redl//===--- ASTWriter.cpp - AST File Writer ----------------------------------===// 22cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// 32cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// The LLVM Compiler Infrastructure 42cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// 52cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// This file is distributed under the University of Illinois Open Source 62cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// License. See LICENSE.TXT for details. 72cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// 82cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 92cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// 10a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl// This file defines the ASTWriter class, which writes AST files. 112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// 122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 147faa2ec03a7ef120ac165bb45b6c70a8b20c9f1cSebastian Redl#include "clang/Serialization/ASTWriter.h" 1589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor#include "clang/Serialization/ASTSerializationListener.h" 160eca89e9890db4d8336ce762a5b359a1d58ca02bArgyrios Kyrtzidis#include "ASTCommon.h" 17e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Sema.h" 18e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/IdentifierResolver.h" 192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/ASTContext.h" 202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/Decl.h" 212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/DeclContextInternals.h" 222a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall#include "clang/AST/DeclTemplate.h" 2389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis#include "clang/AST/DeclFriend.h" 240b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor#include "clang/AST/Expr.h" 257a1fad38256eb4c5129359be85ba1ea1678eb5c9John McCall#include "clang/AST/ExprCXX.h" 262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/Type.h" 27a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#include "clang/AST/TypeLocVisitor.h" 286ab7cd853e9c15cf986a8a7c3db1f8d20e275409Sebastian Redl#include "clang/Serialization/ASTReader.h" 297c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner#include "clang/Lex/MacroInfo.h" 306a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor#include "clang/Lex/PreprocessingRecord.h" 317c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner#include "clang/Lex/Preprocessor.h" 3283d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff#include "clang/Lex/HeaderSearch.h" 3314f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "clang/Basic/FileManager.h" 3410e286aa8d39fb51a21412850265d9dae74613eeChris Lattner#include "clang/Basic/FileSystemStatCache.h" 353251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor#include "clang/Basic/OnDiskHashTable.h" 3614f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "clang/Basic/SourceManager.h" 37bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor#include "clang/Basic/SourceManagerInternals.h" 382bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor#include "clang/Basic/TargetInfo.h" 39ab41e63821dc60ad144d0684df8d79a9eef86b75Douglas Gregor#include "clang/Basic/Version.h" 4017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APFloat.h" 4117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APInt.h" 422596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar#include "llvm/ADT/StringExtras.h" 432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/Bitcode/BitstreamWriter.h" 44fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer#include "llvm/Support/FileSystem.h" 4514f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "llvm/Support/MemoryBuffer.h" 4603013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/Path.h" 473c304bd9ec2b4611572d4cbae9e1727bbecb5dc9Chris Lattner#include <cstdio> 48cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor#include <string.h> 492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorusing namespace clang; 508538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlusing namespace clang::serialization; 512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 52ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redltemplate <typename T, typename Allocator> 53ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian RedlT *data(std::vector<T, Allocator> &v) { 54ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl return v.empty() ? 0 : &v.front(); 55ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl} 56ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redltemplate <typename T, typename Allocator> 57ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redlconst T *data(const std::vector<T, Allocator> &v) { 58ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl return v.empty() ? 0 : &v.front(); 59ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl} 60ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl 612cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// Type serialization 632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 6412b1c7615d4f9a2edc544be499f895f16ac100edChris Lattner 652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace { 663397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl class ASTTypeWriter { 67a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 6889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record; 692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor public: 712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Type code that corresponds to the record generated. 728538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl TypeCode Code; 732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 7489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) 758538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } 762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor void VisitArrayType(const ArrayType *T); 782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor void VisitFunctionType(const FunctionType *T); 792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor void VisitTagType(const TagType *T); 802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); 822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define ABSTRACT_TYPE(Class, Base) 832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/TypeNodes.def" 842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor }; 852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 873397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { 882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor assert(false && "Built-in types are never serialized"); 892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 913397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitComplexType(const ComplexType *T) { 922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getElementType(), Record); 938538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_COMPLEX; 942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 963397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitPointerType(const PointerType *T) { 972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getPointeeType(), Record); 988538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_POINTER; 992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1002cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1013397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { 1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(T->getPointeeType(), Record); 1038538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_BLOCK_POINTER; 1042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1063397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { 1072cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getPointeeType(), Record); 1088538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_LVALUE_REFERENCE; 1092cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1113397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { 1122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getPointeeType(), Record); 1138538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_RVALUE_REFERENCE; 1142cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1152cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1163397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { 1171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(T->getPointeeType(), Record); 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(QualType(T->getClass(), 0), Record); 1198538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_MEMBER_POINTER; 1202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1223397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitArrayType(const ArrayType *T) { 1232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getElementType(), Record); 1242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getSizeModifier()); // FIXME: stable values 1250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values 1262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1272cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1283397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { 1292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitArrayType(T); 1302cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddAPInt(T->getSize(), Record); 1318538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_CONSTANT_ARRAY; 1322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1343397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { 1352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitArrayType(T); 1368538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_INCOMPLETE_ARRAY; 1372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1393397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { 1402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitArrayType(T); 1417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Writer.AddSourceLocation(T->getLBracketLoc(), Record); 1427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Writer.AddSourceLocation(T->getRBracketLoc(), Record); 143c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Writer.AddStmt(T->getSizeExpr()); 1448538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_VARIABLE_ARRAY; 1452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1473397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitVectorType(const VectorType *T) { 1482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getElementType(), Record); 1492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getNumElements()); 150e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson Record.push_back(T->getVectorKind()); 1518538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_VECTOR; 1522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1543397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { 1552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitVectorType(T); 1568538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_EXT_VECTOR; 1572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1582cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1593397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionType(const FunctionType *T) { 1602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getResultType(), Record); 161264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionType::ExtInfo C = T->getExtInfo(); 162264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Record.push_back(C.getNoReturn()); 163425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola Record.push_back(C.getRegParm()); 164ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor // FIXME: need to stabilize encoding of calling convention... 165264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Record.push_back(C.getCC()); 1662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1672cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1683397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { 1692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitFunctionType(T); 1708538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_FUNCTION_NO_PROTO; 1712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1733397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { 1742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitFunctionType(T); 1752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getNumArgs()); 1762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) 1772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getArgType(I), Record); 1782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->isVariadic()); 1792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getTypeQuals()); 180c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor Record.push_back(static_cast<unsigned>(T->getRefQualifier())); 181465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Record.push_back(T->hasExceptionSpec()); 182465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Record.push_back(T->hasAnyExceptionSpec()); 183465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Record.push_back(T->getNumExceptions()); 184465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) 185465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Writer.AddTypeRef(T->getExceptionType(I), Record); 1868538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_FUNCTION_PROTO; 1872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1893397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { 190ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Writer.AddDeclRef(T->getDecl(), Record); 1918538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_UNRESOLVED_USING; 192ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 193ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 1943397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypedefType(const TypedefType *T) { 1952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddDeclRef(T->getDecl(), Record); 1969763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); 1979763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); 1988538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TYPEDEF; 1992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2002cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2013397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { 202c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Writer.AddStmt(T->getUnderlyingExpr()); 2038538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TYPEOF_EXPR; 2042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2063397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { 2072cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getUnderlyingType(), Record); 2088538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TYPEOF; 2092cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2113397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { 212395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Writer.AddStmt(T->getUnderlyingExpr()); 2138538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DECLTYPE; 214395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 215395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 21634b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid ASTTypeWriter::VisitAutoType(const AutoType *T) { 21734b41d939a1328f484511c6002ba2456db879a29Richard Smith Writer.AddTypeRef(T->getDeducedType(), Record); 21834b41d939a1328f484511c6002ba2456db879a29Richard Smith Code = TYPE_AUTO; 21934b41d939a1328f484511c6002ba2456db879a29Richard Smith} 22034b41d939a1328f484511c6002ba2456db879a29Richard Smith 2213397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTagType(const TagType *T) { 222be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis Record.push_back(T->isDependentType()); 2232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddDeclRef(T->getDecl(), Record); 2241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!T->isBeingDefined() && 2252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor "Cannot serialize in the middle of a type definition"); 2262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2272cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2283397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitRecordType(const RecordType *T) { 2292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitTagType(T); 2308538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_RECORD; 2312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2333397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitEnumType(const EnumType *T) { 2342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitTagType(T); 2358538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_ENUM; 2362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid ASTTypeWriter::VisitAttributedType(const AttributedType *T) { 2399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddTypeRef(T->getModifiedType(), Record); 2409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddTypeRef(T->getEquivalentType(), Record); 2419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Record.push_back(T->getAttrKind()); 2429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Code = TYPE_ATTRIBUTED; 2439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 2449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 2451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 2463397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitSubstTemplateTypeParmType( 24749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const SubstTemplateTypeParmType *T) { 24849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); 24949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Writer.AddTypeRef(T->getReplacementType(), Record); 2508538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; 25149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 25249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 25349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallvoid 254c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorASTTypeWriter::VisitSubstTemplateTypeParmPackType( 255c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const SubstTemplateTypeParmPackType *T) { 256c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); 257c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Writer.AddTemplateArgument(T->getArgumentPack(), Record); 258c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; 259c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 260c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 261c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid 2623397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitTemplateSpecializationType( 2632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor const TemplateSpecializationType *T) { 264be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis Record.push_back(T->isDependentType()); 26590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Writer.AddTemplateName(T->getTemplateName(), Record); 26690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->getNumArgs()); 26790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); 26890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis ArgI != ArgE; ++ArgI) 26990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Writer.AddTemplateArgument(*ArgI, Record); 2709763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() 2719763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis : T->getCanonicalTypeInternal(), 2729763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Record); 2738538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TEMPLATE_SPECIALIZATION; 27490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 27590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 27690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 2773397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { 278ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis VisitArrayType(T); 279ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis Writer.AddStmt(T->getSizeExpr()); 280ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis Writer.AddSourceRange(T->getBracketsRange(), Record); 2818538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DEPENDENT_SIZED_ARRAY; 28290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 28390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 28490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 2853397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentSizedExtVectorType( 28690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis const DependentSizedExtVectorType *T) { 28790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis // FIXME: Serialize this type (C++ only) 28890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis assert(false && "Cannot serialize dependent sized extended vector types"); 28990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 29090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 29190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 2923397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { 29390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->getDepth()); 29490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->getIndex()); 29590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->isParameterPack()); 29690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Writer.AddIdentifierRef(T->getName(), Record); 2978538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TEMPLATE_TYPE_PARM; 29890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 29990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 30090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 3013397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { 3028dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Record.push_back(T->getKeyword()); 3038dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Writer.AddNestedNameSpecifier(T->getQualifier(), Record); 3048dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Writer.AddIdentifierRef(T->getIdentifier(), Record); 305f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() 306f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis : T->getCanonicalTypeInternal(), 307f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis Record); 3088538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DEPENDENT_NAME; 30990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 31090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 31190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 3123397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentTemplateSpecializationType( 31390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis const DependentTemplateSpecializationType *T) { 3143acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Record.push_back(T->getKeyword()); 3153acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddNestedNameSpecifier(T->getQualifier(), Record); 3163acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddIdentifierRef(T->getIdentifier(), Record); 3173acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Record.push_back(T->getNumArgs()); 3183acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis for (DependentTemplateSpecializationType::iterator 3193acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis I = T->begin(), E = T->end(); I != E; ++I) 3203acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddTemplateArgument(*I, Record); 3218538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; 3222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorvoid ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { 3257536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Writer.AddTypeRef(T->getPattern(), Record); 326cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (llvm::Optional<unsigned> NumExpansions = T->getNumExpansions()) 327cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Record.push_back(*NumExpansions + 1); 328cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor else 329cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Record.push_back(0); 3307536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Code = TYPE_PACK_EXPANSION; 3317536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 3327536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 333075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaravoid ASTTypeWriter::VisitParenType(const ParenType *T) { 334075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Writer.AddTypeRef(T->getInnerType(), Record); 335075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Code = TYPE_PAREN; 336075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 337075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 3383397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { 339465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Record.push_back(T->getKeyword()); 3403acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddNestedNameSpecifier(T->getQualifier(), Record); 3413acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddTypeRef(T->getNamedType(), Record); 3428538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_ELABORATED; 3432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3453397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { 3463cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Writer.AddDeclRef(T->getDecl(), Record); 34731f17ecbef57b5679c017c375db330546b7b5145John McCall Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); 3488538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_INJECTED_CLASS_NAME; 3493cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 3503cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 3513397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { 352deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor Writer.AddDeclRef(T->getDecl(), Record); 3538538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_OBJC_INTERFACE; 354c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 355c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3563397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { 357c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Writer.AddTypeRef(T->getBaseType(), Record); 3582cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getNumProtocols()); 359c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (ObjCObjectType::qual_iterator I = T->qual_begin(), 360446ee4eb4fc4c705a59365252df7a5c253daafa1Steve Naroff E = T->qual_end(); I != E; ++I) 361446ee4eb4fc4c705a59365252df7a5c253daafa1Steve Naroff Writer.AddDeclRef(*I, Record); 3628538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_OBJC_OBJECT; 3632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 365d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffvoid 3663397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { 3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(T->getPointeeType(), Record); 3688538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_OBJC_OBJECT_POINTER; 3692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 371a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallnamespace { 372a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 373a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallclass TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { 374a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 37589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record; 376a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 377a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallpublic: 37889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) 379a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall : Writer(Writer), Record(Record) { } 380a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 38151bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 382a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#define TYPELOC(CLASS, PARENT) \ 38351bd803fbdade51d674598ed45da3d54190a656cJohn McCall void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); 384a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#include "clang/AST/TypeLocNodes.def" 385a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 38651bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); 38751bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); 388a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}; 389a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 390a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 391a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 39251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { 39351bd803fbdade51d674598ed45da3d54190a656cJohn McCall // nothing to do 39451bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 39551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { 396ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); 397ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (TL.needsExtraLocalData()) { 398ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.getWrittenTypeSpec()); 399ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.getWrittenSignSpec()); 400ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.getWrittenWidthSpec()); 401ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.hasModeAttr()); 402ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 40351bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 40451bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { 40551bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 40651bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 40751bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { 40851bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getStarLoc(), Record); 40951bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 41051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { 41151bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getCaretLoc(), Record); 41251bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 41351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { 41451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getAmpLoc(), Record); 41551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 41651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { 41751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); 41851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 41951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { 42051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getStarLoc(), Record); 42151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 42251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { 42351bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getLBracketLoc(), Record); 42451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getRBracketLoc(), Record); 42551bd803fbdade51d674598ed45da3d54190a656cJohn McCall Record.push_back(TL.getSizeExpr() ? 1 : 0); 42651bd803fbdade51d674598ed45da3d54190a656cJohn McCall if (TL.getSizeExpr()) 42751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddStmt(TL.getSizeExpr()); 42851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 42951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { 43051bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 43151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 43251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { 43351bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 43451bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 43551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { 43651bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 43751bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 43851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDependentSizedArrayTypeLoc( 43951bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedArrayTypeLoc TL) { 44051bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 44151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( 44351bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedExtVectorTypeLoc TL) { 44451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 44551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { 44751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 44851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { 45051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 45151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 45251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { 45351bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getLParenLoc(), Record); 45451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getRParenLoc(), Record); 455dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor Record.push_back(TL.getTrailingReturn()); 45651bd803fbdade51d674598ed45da3d54190a656cJohn McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) 45751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddDeclRef(TL.getArg(i), Record); 45851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 45951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { 46051bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitFunctionTypeLoc(TL); 46151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 46251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { 46351bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitFunctionTypeLoc(TL); 46451bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 465ed97649e9574b9d854fa4d6109c9333ae0993554John McCallvoid TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { 466ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 467ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 46851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { 46951bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 47051bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 47151bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { 472cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getTypeofLoc(), Record); 473cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getLParenLoc(), Record); 474cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getRParenLoc(), Record); 47551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 47651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { 477cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getTypeofLoc(), Record); 478cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getLParenLoc(), Record); 479cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getRParenLoc(), Record); 480cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); 48151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 48251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { 48351bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 484a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 48534b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { 48634b41d939a1328f484511c6002ba2456db879a29Richard Smith Writer.AddSourceLocation(TL.getNameLoc(), Record); 48734b41d939a1328f484511c6002ba2456db879a29Richard Smith} 48851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { 48951bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 490a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 49151bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { 49251bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 493a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 4949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { 4959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); 4969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) { 4979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceRange range = TL.getAttrOperandParensRange(); 4989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(range.getBegin(), Record); 4999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(range.getEnd(), Record); 5009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 5019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) { 5029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Expr *operand = TL.getAttrExprOperand(); 5039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Record.push_back(operand ? 1 : 0); 5049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (operand) Writer.AddStmt(operand); 5059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } else if (TL.hasAttrEnumOperand()) { 5069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); 5079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 5089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 50951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { 51051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 511a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 51249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallvoid TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( 51349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmTypeLoc TL) { 51449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 51549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 516c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( 517c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 518c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Writer.AddSourceLocation(TL.getNameLoc(), Record); 519c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 52051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTemplateSpecializationTypeLoc( 52151bd803fbdade51d674598ed45da3d54190a656cJohn McCall TemplateSpecializationTypeLoc TL) { 522833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); 523833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Writer.AddSourceLocation(TL.getLAngleLoc(), Record); 524833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Writer.AddSourceLocation(TL.getRAngleLoc(), Record); 525833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) 52644f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), 52744f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis TL.getArgLoc(i).getLocInfo(), Record); 528a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 529075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaravoid TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { 530075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Writer.AddSourceLocation(TL.getLParenLoc(), Record); 531075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Writer.AddSourceLocation(TL.getRParenLoc(), Record); 532075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 533465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaravoid TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { 534e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara Writer.AddSourceLocation(TL.getKeywordLoc(), Record); 535e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara Writer.AddSourceRange(TL.getQualifierRange(), Record); 536a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 5373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallvoid TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { 5383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 5393cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 5404714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregorvoid TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { 541e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara Writer.AddSourceLocation(TL.getKeywordLoc(), Record); 542e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara Writer.AddSourceRange(TL.getQualifierRange(), Record); 54351bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 544a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 54533500955d731c73717af52088b7fc0e7a85681e7John McCallvoid TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( 54633500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypeLoc TL) { 54733500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getKeywordLoc(), Record); 54833500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceRange(TL.getQualifierRange(), Record); 54933500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 55033500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getLAngleLoc(), Record); 55133500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getRAngleLoc(), Record); 55233500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) 55344f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), 55444f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis TL.getArgLoc(I).getLocInfo(), Record); 55533500955d731c73717af52088b7fc0e7a85681e7John McCall} 5567536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorvoid TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { 5577536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); 5587536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 55951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { 56051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 561c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 562c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { 563c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Record.push_back(TL.hasBaseTypeAsWritten()); 56454e14c4db764c0636160d26c5bbf491637c83a76John McCall Writer.AddSourceLocation(TL.getLAngleLoc(), Record); 56554e14c4db764c0636160d26c5bbf491637c83a76John McCall Writer.AddSourceLocation(TL.getRAngleLoc(), Record); 56654e14c4db764c0636160d26c5bbf491637c83a76John McCall for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) 56754e14c4db764c0636160d26c5bbf491637c83a76John McCall Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); 568a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 56951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { 57051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getStarLoc(), Record); 571a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 572a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 5734dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner//===----------------------------------------------------------------------===// 574a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl// ASTWriter Implementation 5752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 5762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 577b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattnerstatic void EmitBlockID(unsigned ID, const char *Name, 578b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner llvm::BitstreamWriter &Stream, 57989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record) { 580b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.clear(); 581b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(ID); 582b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); 583b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 584b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner // Emit the block name if present. 585b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner if (Name == 0 || Name[0] == 0) return; 586b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.clear(); 587b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner while (*Name) 588b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(*Name++); 589b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); 590b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner} 591b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 592b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattnerstatic void EmitRecordID(unsigned ID, const char *Name, 593b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner llvm::BitstreamWriter &Stream, 59489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record) { 595b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.clear(); 596b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(ID); 597b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner while (*Name) 598b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(*Name++); 599b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); 6000558df2da807646e65d4fa290f4e92114af1a746Chris Lattner} 6010558df2da807646e65d4fa290f4e92114af1a746Chris Lattner 6020558df2da807646e65d4fa290f4e92114af1a746Chris Lattnerstatic void AddStmtsExprs(llvm::BitstreamWriter &Stream, 60389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record) { 6048538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define RECORD(X) EmitRecordID(X, #X, Stream, Record) 6050558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_STOP); 6060558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_NULL_PTR); 6070558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_NULL); 6080558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_COMPOUND); 6090558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_CASE); 6100558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_DEFAULT); 6110558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_LABEL); 6120558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_IF); 6130558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_SWITCH); 6140558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_WHILE); 6150558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_DO); 6160558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_FOR); 6170558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_GOTO); 6180558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_INDIRECT_GOTO); 6190558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_CONTINUE); 6200558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_BREAK); 6210558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_RETURN); 6220558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_DECL); 6230558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_ASM); 6240558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_PREDEFINED); 6250558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_DECL_REF); 6260558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_INTEGER_LITERAL); 6270558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_FLOATING_LITERAL); 6280558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_IMAGINARY_LITERAL); 6290558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_STRING_LITERAL); 6300558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CHARACTER_LITERAL); 6310558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_PAREN); 6320558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_UNARY_OPERATOR); 6330558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_SIZEOF_ALIGN_OF); 6340558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_ARRAY_SUBSCRIPT); 6350558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CALL); 6360558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_MEMBER); 6370558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_BINARY_OPERATOR); 6380558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); 6390558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CONDITIONAL_OPERATOR); 6400558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_IMPLICIT_CAST); 6410558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CSTYLE_CAST); 6420558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_COMPOUND_LITERAL); 6430558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_EXT_VECTOR_ELEMENT); 6440558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_INIT_LIST); 6450558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_DESIGNATED_INIT); 6460558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_IMPLICIT_VALUE_INIT); 6470558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_VA_ARG); 6480558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_ADDR_LABEL); 6490558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_STMT); 6500558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CHOOSE); 6510558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_GNU_NULL); 6520558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_SHUFFLE_VECTOR); 6530558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_BLOCK); 6540558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_BLOCK_DECL_REF); 6550558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_STRING_LITERAL); 6560558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_ENCODE); 6570558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_SELECTOR_EXPR); 6580558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_PROTOCOL_EXPR); 6590558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_IVAR_REF_EXPR); 6600558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); 6610558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_KVC_REF_EXPR); 6620558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_MESSAGE_EXPR); 6630558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_FOR_COLLECTION); 6640558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_CATCH); 6650558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_FINALLY); 6660558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_AT_TRY); 6670558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_AT_SYNCHRONIZED); 6680558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_AT_THROW); 669eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_OPERATOR_CALL); 670eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_CONSTRUCT); 671eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_STATIC_CAST); 672eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_DYNAMIC_CAST); 673eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_REINTERPRET_CAST); 674eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_CONST_CAST); 675eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_FUNCTIONAL_CAST); 676eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_BOOL_LITERAL); 677eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_NULL_PTR_LITERAL); 678b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_TYPEID_EXPR); 679b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_TYPEID_TYPE); 680b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UUIDOF_EXPR); 681b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UUIDOF_TYPE); 682b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_THIS); 683b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_THROW); 684b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DEFAULT_ARG); 685b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_BIND_TEMPORARY); 686b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_SCALAR_VALUE_INIT); 687b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_NEW); 688b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DELETE); 689b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); 690b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_EXPR_WITH_CLEANUPS); 691b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); 692b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); 693b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); 694b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNRESOLVED_MEMBER); 695b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); 696b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); 697b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_NOEXCEPT); 698b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_OPAQUE_VALUE); 699b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_BINARY_TYPE_TRAIT); 700b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_PACK_EXPANSION); 701b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_SIZEOF_PACK); 702b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); 703e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne RECORD(EXPR_CUDA_KERNEL_CALL); 7040558df2da807646e65d4fa290f4e92114af1a746Chris Lattner#undef RECORD 705b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner} 7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 707a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteBlockInfoBlock() { 708b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RecordData Record; 709b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7118538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) 7128538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define RECORD(X) EmitRecordID(X, #X, Stream, Record) 7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7143397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // AST Top-Level Block. 715f29f0a28c4d9599b389bbb6d186e14af753dc5a3Sebastian Redl BLOCK(AST_BLOCK); 71651e774d42269e3b22d746184c0b9076fc13b32e6Zhongxing Xu RECORD(ORIGINAL_FILE_NAME); 717b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_OFFSET); 718b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_OFFSET); 719b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(LANGUAGE_OPTIONS); 720ab41e63821dc60ad144d0684df8d79a9eef86b75Douglas Gregor RECORD(METADATA); 721b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(IDENTIFIER_OFFSET); 722b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(IDENTIFIER_TABLE); 723b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(EXTERNAL_DEFINITIONS); 724b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SPECIAL_TYPES); 725b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(STATISTICS); 726b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TENTATIVE_DEFINITIONS); 72749b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis RECORD(UNUSED_FILESCOPED_DECLS); 728b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); 729b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SELECTOR_OFFSETS); 730b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(METHOD_POOL); 731b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_COUNTER_VALUE); 7327f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RECORD(SOURCE_LOCATION_OFFSETS); 7337f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RECORD(SOURCE_LOCATION_PRELOADS); 7344fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor RECORD(STAT_CACHE); 735b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor RECORD(EXT_VECTOR_DECLS); 7365b4ec636637c9d876102240127cc0dca9280e83aTed Kremenek RECORD(VERSION_CONTROL_BRANCH_REVISION); 7376a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor RECORD(MACRO_DEFINITION_OFFSETS); 738a93e3b5bde9f0a7b59215f19f176f7d69881b81cSebastian Redl RECORD(CHAINED_METADATA); 739320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian RECORD(REFERENCED_SELECTOR_POOL); 740b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TU_UPDATE_LEXICAL); 741b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(REDECLS_UPDATE_LATEST); 742b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(SEMA_DECL_REFS); 743b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(WEAK_UNDECLARED_IDENTIFIERS); 744b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(PENDING_IMPLICIT_INSTANTIATIONS); 745b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_REPLACEMENTS); 746b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(UPDATE_VISIBLE); 747b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UPDATE_OFFSETS); 748b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UPDATES); 749b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(CXX_BASE_SPECIFIER_OFFSETS); 750b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DIAG_PRAGMA_MAPPINGS); 75184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RECORD(CUDA_SPECIAL_DECL_REFS); 752cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor RECORD(HEADER_SEARCH_TABLE); 75384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RECORD(FP_PRAGMA_OPTIONS); 75484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RECORD(OPENCL_EXTENSIONS); 755cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 756b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner // SourceManager Block. 7572f4efd10c805cb779618c1a22a35eb07b5043c4eChris Lattner BLOCK(SOURCE_MANAGER_BLOCK); 758b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_FILE_ENTRY); 759b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_BUFFER_ENTRY); 760b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_BUFFER_BLOB); 761b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_INSTANTIATION_ENTRY); 762b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_LINE_TABLE); 7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 764b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner // Preprocessor Block. 7652f4efd10c805cb779618c1a22a35eb07b5043c4eChris Lattner BLOCK(PREPROCESSOR_BLOCK); 766b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_MACRO_OBJECT_LIKE); 767b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_MACRO_FUNCTION_LIKE); 768b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_TOKEN); 769b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor 77061d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor // Decls and Types block. 77161d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor BLOCK(DECLTYPES_BLOCK); 772b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_EXT_QUAL); 773b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_COMPLEX); 774b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_POINTER); 775b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_BLOCK_POINTER); 776b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_LVALUE_REFERENCE); 777b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_RVALUE_REFERENCE); 778b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_MEMBER_POINTER); 779b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_CONSTANT_ARRAY); 780b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_INCOMPLETE_ARRAY); 781b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_VARIABLE_ARRAY); 782b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_VECTOR); 783b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_EXT_VECTOR); 784b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_FUNCTION_PROTO); 785b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_FUNCTION_NO_PROTO); 786b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_TYPEDEF); 787b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_TYPEOF_EXPR); 788b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_TYPEOF); 789b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_RECORD); 790b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_ENUM); 791b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_OBJC_INTERFACE); 792a53d2cbe37e4be0d95b9d3e09f74eafae31fc940John McCall RECORD(TYPE_OBJC_OBJECT); 793d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff RECORD(TYPE_OBJC_OBJECT_POINTER); 794b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DECLTYPE); 795b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_ELABORATED); 796b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); 797b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_UNRESOLVED_USING); 798b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_INJECTED_CLASS_NAME); 799b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_OBJC_OBJECT); 800b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_TEMPLATE_TYPE_PARM); 801b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_TEMPLATE_SPECIALIZATION); 802b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DEPENDENT_NAME); 803b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); 804b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DEPENDENT_SIZED_ARRAY); 805b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_PAREN); 806b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_PACK_EXPANSION); 807b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_ATTRIBUTED); 808b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); 8090ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_TRANSLATION_UNIT); 8100ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_TYPEDEF); 8110ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_ENUM); 8120ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_RECORD); 8130ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_ENUM_CONSTANT); 8140ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_FUNCTION); 8150ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_METHOD); 8160ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_INTERFACE); 8170ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_PROTOCOL); 8180ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_IVAR); 8190ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_AT_DEFS_FIELD); 8200ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_CLASS); 8210ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_FORWARD_PROTOCOL); 8220ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_CATEGORY); 8230ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_CATEGORY_IMPL); 8240ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_IMPLEMENTATION); 8250ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_COMPATIBLE_ALIAS); 8260ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_PROPERTY); 8270ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_PROPERTY_IMPL); 828b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_FIELD); 829b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_VAR); 8300ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_IMPLICIT_PARAM); 831b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_PARM_VAR); 8320ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_FILE_SCOPE_ASM); 8330ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_BLOCK); 8340ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_CONTEXT_LEXICAL); 8350ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_CONTEXT_VISIBLE); 836b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_NAMESPACE); 837b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_NAMESPACE_ALIAS); 838b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_USING); 839b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_USING_SHADOW); 840b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_USING_DIRECTIVE); 841b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UNRESOLVED_USING_VALUE); 842b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UNRESOLVED_USING_TYPENAME); 843b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_LINKAGE_SPEC); 844b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_RECORD); 845b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_METHOD); 846b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_CONSTRUCTOR); 847b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_DESTRUCTOR); 848b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_CONVERSION); 849b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_ACCESS_SPEC); 850b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_FRIEND); 851b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_FRIEND_TEMPLATE); 852b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CLASS_TEMPLATE); 853b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); 854b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); 855b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_FUNCTION_TEMPLATE); 856b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_TEMPLATE_TYPE_PARM); 857b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_NON_TYPE_TEMPLATE_PARM); 858b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_TEMPLATE_TEMPLATE_PARM); 859b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_STATIC_ASSERT); 860b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_BASE_SPECIFIERS); 861b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_INDIRECTFIELD); 862b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); 863b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor 8644800a5c79023271408af49797e09be32aca93232Douglas Gregor BLOCK(PREPROCESSOR_DETAIL_BLOCK); 8654800a5c79023271408af49797e09be32aca93232Douglas Gregor RECORD(PPD_MACRO_INSTANTIATION); 8664800a5c79023271408af49797e09be32aca93232Douglas Gregor RECORD(PPD_MACRO_DEFINITION); 8674800a5c79023271408af49797e09be32aca93232Douglas Gregor RECORD(PPD_INCLUSION_DIRECTIVE); 8684800a5c79023271408af49797e09be32aca93232Douglas Gregor 86961d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor // Statements and Exprs can occur in the Decls and Types block. 8700558df2da807646e65d4fa290f4e92114af1a746Chris Lattner AddStmtsExprs(Stream, Record); 871b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner#undef RECORD 872b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner#undef BLOCK 873b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.ExitBlock(); 874b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner} 875b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 876e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \brief Adjusts the given filename to only write out the portion of the 877e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// filename that is not part of the system root directory. 8781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 879e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \param Filename the file name to adjust. 880e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// 881e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and 882e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// the returned filename will be adjusted by this system root. 883e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// 884e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \returns either the original filename (if it needs no adjustment) or the 885e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// adjusted filename (which points into the @p Filename parameter). 8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpstatic const char * 887e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas GregoradjustFilenameForRelocatablePCH(const char *Filename, const char *isysroot) { 888e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor assert(Filename && "No file name to adjust?"); 8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 890e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (!isysroot) 891e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename; 8921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 893e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // Verify that the filename and the system root have the same prefix. 894e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor unsigned Pos = 0; 895e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor for (; Filename[Pos] && isysroot[Pos]; ++Pos) 896e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (Filename[Pos] != isysroot[Pos]) 897e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename; // Prefixes don't match. 8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 899e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // We hit the end of the filename before we hit the end of the system root. 900e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (!Filename[Pos]) 901e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename; 9021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 903e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // If the file name has a '/' at the current position, skip over the '/'. 904e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // We distinguish sysroot-based includes from absolute includes by the 905e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // absence of '/' at the beginning of sysroot-based includes. 906e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (Filename[Pos] == '/') 907e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor ++Pos; 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 909e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename + Pos; 910e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor} 911b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 9123397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the AST metadata (e.g., i686-apple-darwin9). 9138e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidisvoid ASTWriter::WriteMetadata(ASTContext &Context, const char *isysroot, 9148e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis const std::string &OutputFile) { 9152bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor using namespace llvm; 916b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor 917e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // Metadata 918e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const TargetInfo &Target = Context.Target; 919e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor BitCodeAbbrev *MetaAbbrev = new BitCodeAbbrev(); 92077f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl MetaAbbrev->Add(BitCodeAbbrevOp( 9218538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Chain ? CHAINED_METADATA : METADATA)); 9223397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST major 9233397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST minor 924e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major 925e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor 926e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable 92777f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl // Target triple or chained PCH name 92877f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 929e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor unsigned MetaAbbrevCode = Stream.EmitAbbrev(MetaAbbrev); 9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 931e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor RecordData Record; 9328538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(Chain ? CHAINED_METADATA : METADATA); 9338538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(VERSION_MAJOR); 9348538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(VERSION_MINOR); 935e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Record.push_back(CLANG_VERSION_MAJOR); 936e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Record.push_back(CLANG_VERSION_MINOR); 937e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Record.push_back(isysroot != 0); 93877f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl // FIXME: This writes the absolute path for chained headers. 93977f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl const std::string &BlobStr = Chain ? Chain->getFileName() : Target.getTriple().getTriple(); 94077f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, BlobStr); 9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 942b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor // Original file name 943b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor SourceManager &SM = Context.getSourceManager(); 944b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { 945b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); 9468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE_NAME)); 947b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name 948b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); 949b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor 950fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer llvm::SmallString<128> MainFilePath(MainFile->getName()); 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 952fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer llvm::sys::fs::make_absolute(MainFilePath); 953b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor 954aba54a95e9d5e4dc9056abec6bb70ea777c4a7bcKovarththanan Rajaratnam const char *MainFileNameStr = MainFilePath.c_str(); 9551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, 956e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor isysroot); 957b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor RecordData Record; 9588538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(ORIGINAL_FILE_NAME); 959ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); 960b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor } 96111a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 9628e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis // Original PCH directory 9638e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis if (!OutputFile.empty() && OutputFile != "-") { 9648e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 9658e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); 9668e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name 9678e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); 9688e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 9698e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis llvm::SmallString<128> OutputPath(OutputFile); 9708e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 9718e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis llvm::sys::fs::make_absolute(OutputPath); 9728e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis StringRef origDir = llvm::sys::path::parent_path(OutputPath); 9738e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 9748e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis RecordData Record; 9758e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Record.push_back(ORIGINAL_PCH_DIR); 9768e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); 9778e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis } 9788e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 979f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek // Repository branch/version information. 980f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); 9818538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl RepoAbbrev->Add(BitCodeAbbrevOp(VERSION_CONTROL_BRANCH_REVISION)); 982f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag 983f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); 984445e23e9b909ec8e21303c7dd82c90b72fc09ac4Douglas Gregor Record.clear(); 9858538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(VERSION_CONTROL_BRANCH_REVISION); 986f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, 987f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek getClangFullRepositoryVersion()); 9882bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor} 9892bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor 9902bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor/// \brief Write the LangOptions structure. 991a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) { 9920a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor RecordData Record; 9930a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Trigraphs); 9940a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.BCPLComment); // BCPL-style '//' comments. 9950a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.DollarIdents); // '$' allowed in identifiers. 9960a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.AsmPreprocessor); // Preprocessor in asm mode. 9970a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.GNUMode); // True in gnu99 mode false in c99 mode (etc) 998eb5d7b752651283de5abfcc2f91df7227582a08dChandler Carruth Record.push_back(LangOpts.GNUKeywords); // Allow GNU-extension keywords 9990a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.ImplicitInt); // C89 implicit 'int'. 10000a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Digraphs); // C94, C99 and C++ 10010a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.HexFloats); // C99 Hexadecimal float constants. 10020a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.C99); // C99 Support 10030a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Microsoft); // Microsoft extensions. 1004dae4ac4fe56ec60fc93b3e3c9f51e79e682084b9Michael J. Spencer // LangOpts.MSCVersion is ignored because all it does it set a macro, which is 1005dae4ac4fe56ec60fc93b3e3c9f51e79e682084b9Michael J. Spencer // already saved elsewhere. 10060a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.CPlusPlus); // C++ Support 10070a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.CPlusPlus0x); // C++0x Support 10080a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.CXXOperatorNames); // Treat C++ operator names as keywords. 10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10100a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.ObjC1); // Objective-C 1 support enabled. 10110a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.ObjC2); // Objective-C 2 support enabled. 101211a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam Record.push_back(LangOpts.ObjCNonFragileABI); // Objective-C 1013412e798941ca64e2e6b084323915fa9aa5f6bdf3Fariborz Jahanian // modern abi enabled. 101411a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam Record.push_back(LangOpts.ObjCNonFragileABI2); // Objective-C enhanced 1015412e798941ca64e2e6b084323915fa9aa5f6bdf3Fariborz Jahanian // modern abi enabled. 1016f84109ee6aeffb09366bd70c8593ce1b7818b1adFariborz Jahanian Record.push_back(LangOpts.AppleKext); // Apple's kernel extensions ABI 1017c32647d111e516593b9ba242cad7b8ff4016c155Ted Kremenek Record.push_back(LangOpts.ObjCDefaultSynthProperties); // Objective-C auto-synthesized 1018c32647d111e516593b9ba242cad7b8ff4016c155Ted Kremenek // properties enabled. 10194c9d8d0eca5ca635d9a30222f690db9140e98325Fariborz Jahanian Record.push_back(LangOpts.NoConstantCFStrings); // non cfstring generation enabled.. 10201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10210a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.PascalStrings); // Allow Pascal strings 10220a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.WritableStrings); // Allow writable strings 10230a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.LaxVectorConversions); 1024b9e7e63ae2098bc02e79c032df0a3124d09a4b4eNate Begeman Record.push_back(LangOpts.AltiVec); 10250a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Exceptions); // Support exception handling. 1026da4b7cf09ebfd4e4098b516081fa9dae2f5c99e0Anders Carlsson Record.push_back(LangOpts.ObjCExceptions); 10277da99b05aa9482e76b2954223b5652469004aec2Anders Carlsson Record.push_back(LangOpts.CXXExceptions); 10287da99b05aa9482e76b2954223b5652469004aec2Anders Carlsson Record.push_back(LangOpts.SjLjExceptions); 10290a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 10306f75550e40a9177db9979fc130ce3ece026b137dDouglas Gregor Record.push_back(LangOpts.MSBitfields); // MS-compatible structure layout 10310a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.NeXTRuntime); // Use NeXT runtime. 10320a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Freestanding); // Freestanding implementation 10330a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.NoBuiltin); // Do not use builtin functions (-fno-builtin) 10340a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 1035ea5ce4705df0743093925585d8edc80e0d8fe3ffChris Lattner // Whether static initializers are protected by locks. 1036ea5ce4705df0743093925585d8edc80e0d8fe3ffChris Lattner Record.push_back(LangOpts.ThreadsafeStatics); 1037972d954bd216c86a961bb7f81c53af85de17c2f0Douglas Gregor Record.push_back(LangOpts.POSIXThreads); 10380a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Blocks); // block extension to C 10390a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.EmitAllDecls); // Emit all declarations, even if 10400a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // they are unused. 10410a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.MathErrno); // Math functions must respect errno 10420a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // (modulo the platform support). 10430a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 1044a4d71455f0d418e16cc0c5c5aa55a3bad3494aeeChris Lattner Record.push_back(LangOpts.getSignedOverflowBehavior()); 1045a4d71455f0d418e16cc0c5c5aa55a3bad3494aeeChris Lattner Record.push_back(LangOpts.HeinousExtensions); 10460a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 10470a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Optimize); // Whether __OPTIMIZE__ should be defined. 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Record.push_back(LangOpts.OptimizeSize); // Whether __OPTIMIZE_SIZE__ should be 10490a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // defined. 10500a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Static); // Should __STATIC__ be defined (as 10510a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // opposed to __DYNAMIC__). 10520a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.PICLevel); // The value for __PIC__, if non-zero. 10530a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 10540a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.GNUInline); // Should GNU inline semantics be 10550a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // used (instead of C99 semantics). 10560a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined. 1057a33d9b4ebf732a5da6d56fd7319ff6c020789b1cAnders Carlsson Record.push_back(LangOpts.AccessControl); // Whether C++ access control should 1058a33d9b4ebf732a5da6d56fd7319ff6c020789b1cAnders Carlsson // be enabled. 105915b91764d08e886391c865c4a444d7b51141c284Eli Friedman Record.push_back(LangOpts.CharIsSigned); // Whether char is a signed or 106015b91764d08e886391c865c4a444d7b51141c284Eli Friedman // unsigned type 1061a6fda124bf380479529d6a80b84b62cacd3cb707John Thompson Record.push_back(LangOpts.ShortWChar); // force wchar_t to be unsigned short 1062b1bdced5967c54d029cd12907e8939c78decf14cArgyrios Kyrtzidis Record.push_back(LangOpts.ShortEnums); // Should the enum type be equivalent 1063b1bdced5967c54d029cd12907e8939c78decf14cArgyrios Kyrtzidis // to the smallest integer type with 1064b1bdced5967c54d029cd12907e8939c78decf14cArgyrios Kyrtzidis // enough room. 10650a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.getGCMode()); 10660a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.getVisibilityMode()); 1067ab8e281b32a3d3b9b18257d26844362bf806ecdcDaniel Dunbar Record.push_back(LangOpts.getStackProtectorMode()); 10680a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.InstantiationDepth); 1069b9e7e63ae2098bc02e79c032df0a3124d09a4b4eNate Begeman Record.push_back(LangOpts.OpenCL); 107008a53269b1f8241e2e6797e845abbe640fb18253Peter Collingbourne Record.push_back(LangOpts.CUDA); 10719c276ae0f24d4cee8f7954069d4b8eae45d0447dMike Stump Record.push_back(LangOpts.CatchUndefined); 107284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Record.push_back(LangOpts.DefaultFPContract); 107392f5822df6a0d7571df44b5d279ed4f017fbb0e6Anders Carlsson Record.push_back(LangOpts.ElideConstructors); 1074a0068fc64351db9c47916566e3b85ab733cd8d6dDouglas Gregor Record.push_back(LangOpts.SpellChecking); 10758538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(LANGUAGE_OPTIONS, Record); 10760a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor} 10770a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 107814f79002e58556798e86168c63e48d533287eda5Douglas Gregor//===----------------------------------------------------------------------===// 10794fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// stat cache Serialization 10804fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 10814fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 10824fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregornamespace { 10834fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Trait used for the on-disk hash table of stat cache results. 10843397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlclass ASTStatCacheTrait { 10854fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregorpublic: 10864fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor typedef const char * key_type; 10874fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor typedef key_type key_type_ref; 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 108974e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner typedef struct stat data_type; 109074e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner typedef const data_type &data_type_ref; 10914fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 10924fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor static unsigned ComputeHash(const char *path) { 10932596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar return llvm::HashString(path); 10944fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 10951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<unsigned,unsigned> 10974fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor EmitKeyDataLength(llvm::raw_ostream& Out, const char *path, 10984fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor data_type_ref Data) { 10994fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor unsigned StrLen = strlen(path); 11004fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor clang::io::Emit16(Out, StrLen); 110174e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner unsigned DataLen = 4 + 4 + 2 + 8 + 8; 11024fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor clang::io::Emit8(Out, DataLen); 11034fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor return std::make_pair(StrLen + 1, DataLen); 11044fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 11051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11064fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor void EmitKey(llvm::raw_ostream& Out, const char *path, unsigned KeyLen) { 11074fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Out.write(path, KeyLen); 11084fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111074e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner void EmitData(llvm::raw_ostream &Out, key_type_ref, 11114fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor data_type_ref Data, unsigned DataLen) { 11124fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor using namespace clang::io; 11134fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor uint64_t Start = Out.tell(); (void)Start; 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111574e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit32(Out, (uint32_t) Data.st_ino); 111674e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit32(Out, (uint32_t) Data.st_dev); 111774e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit16(Out, (uint16_t) Data.st_mode); 111874e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit64(Out, (uint64_t) Data.st_mtime); 111974e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit64(Out, (uint64_t) Data.st_size); 11204fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11214fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor assert(Out.tell() - Start == DataLen && "Wrong data length"); 11224fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 11234fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor}; 11244fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor} // end anonymous namespace 11254fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11263397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the stat() system call cache to the AST file. 1127a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteStatCache(MemorizeStatCalls &StatCalls) { 11284fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Build the on-disk hash table containing information about every 11294fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // stat() call. 11303397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl OnDiskChainedHashTableGenerator<ASTStatCacheTrait> Generator; 11314fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor unsigned NumStatEntries = 0; 11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), 11334fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor StatEnd = StatCalls.end(); 1134e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Stat != StatEnd; ++Stat, ++NumStatEntries) { 1135e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const char *Filename = Stat->first(); 1136e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Generator.insert(Filename, Stat->second); 1137e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor } 11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11394fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Create the on-disk hash table in a buffer. 11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::SmallString<4096> StatCacheData; 11414fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor uint32_t BucketOffset; 11424fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor { 11434fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor llvm::raw_svector_ostream Out(StatCacheData); 11444fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Make sure that no bucket is at offset 0 11454fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor clang::io::Emit32(Out, 0); 11464fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor BucketOffset = Generator.Emit(Out); 11474fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 11484fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11494fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Create a blob abbreviation 11504fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor using namespace llvm; 11514fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 11528538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(STAT_CACHE)); 11534fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 11544fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 11554fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 11564fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); 11574fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11584fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Write the stat cache 11594fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor RecordData Record; 11608538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(STAT_CACHE); 11614fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Record.push_back(BucketOffset); 11624fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Record.push_back(NumStatEntries); 1163ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); 11644fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor} 11654fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11664fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 116714f79002e58556798e86168c63e48d533287eda5Douglas Gregor// Source Manager Serialization 116814f79002e58556798e86168c63e48d533287eda5Douglas Gregor//===----------------------------------------------------------------------===// 116914f79002e58556798e86168c63e48d533287eda5Douglas Gregor 117014f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to a 117114f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// file. 1172c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { 117314f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 117414f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 11758538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); 117614f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset 117714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location 117814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic 117914f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives 11802d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor // FileEntry fields. 11812d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size 11822d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time 118314f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name 1184c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 118514f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 118614f79002e58556798e86168c63e48d533287eda5Douglas Gregor 118714f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to a 118814f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// buffer. 1189c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { 119014f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 119114f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 11928538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); 119314f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset 119414f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location 119514f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic 119614f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives 119714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob 1198c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 119914f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 120014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 120114f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to a 120214f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// buffer's blob. 1203c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { 120414f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 120514f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 12068538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); 120714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob 1208c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 120914f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 121014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 121114f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to an 121214f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// buffer. 1213c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocInstantiationAbbrev(llvm::BitstreamWriter &Stream) { 121414f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 121514f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 12168538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_INSTANTIATION_ENTRY)); 121714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset 121814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location 121914f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location 122014f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location 1221f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length 1222c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 122314f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 122414f79002e58556798e86168c63e48d533287eda5Douglas Gregor 1225cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregornamespace { 1226cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Trait used for the on-disk hash table of header search information. 1227cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor class HeaderFileInfoTrait { 1228cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ASTWriter &Writer; 1229cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor HeaderSearch &HS; 1230cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1231cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor public: 1232cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor HeaderFileInfoTrait(ASTWriter &Writer, HeaderSearch &HS) 1233cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor : Writer(Writer), HS(HS) { } 1234cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1235cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef const char *key_type; 1236cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef key_type key_type_ref; 1237cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1238cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef HeaderFileInfo data_type; 1239cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef const data_type &data_type_ref; 1240cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1241cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor static unsigned ComputeHash(const char *path) { 1242cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // The hash is based only on the filename portion of the key, so that the 1243cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // reader can match based on filenames when symlinking or excess path 1244cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // elements ("foo/../", "../") change the form of the name. However, 1245cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // complete path is still the key. 1246cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor return llvm::HashString(llvm::sys::path::filename(path)); 1247cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1248cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1249cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor std::pair<unsigned,unsigned> 1250cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor EmitKeyDataLength(llvm::raw_ostream& Out, const char *path, 1251cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor data_type_ref Data) { 1252cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned StrLen = strlen(path); 1253cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor clang::io::Emit16(Out, StrLen); 1254cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned DataLen = 1 + 2 + 4; 1255cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor clang::io::Emit8(Out, DataLen); 1256cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor return std::make_pair(StrLen + 1, DataLen); 1257cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1258cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1259cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor void EmitKey(llvm::raw_ostream& Out, const char *path, unsigned KeyLen) { 1260cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Out.write(path, KeyLen); 1261cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1262cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1263cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor void EmitData(llvm::raw_ostream &Out, key_type_ref, 1264cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor data_type_ref Data, unsigned DataLen) { 1265cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor using namespace clang::io; 1266cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor uint64_t Start = Out.tell(); (void)Start; 1267cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1268cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned char Flags = (Data.isImport << 3) 1269cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor | (Data.DirInfo << 1) 1270cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor | Data.Resolved; 1271cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit8(Out, (uint8_t)Flags); 1272cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit16(Out, (uint16_t) Data.NumIncludes); 1273cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1274cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (!Data.ControllingMacro) 1275cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit32(Out, (uint32_t)Data.ControllingMacroID); 1276cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor else 1277cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); 1278cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor assert(Out.tell() - Start == DataLen && "Wrong data length"); 1279cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1280cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor }; 1281cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor} // end anonymous namespace 1282cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1283cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \brief Write the header search block for the list of files that 1284cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// 1285cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \param HS The header search structure to save. 1286cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// 1287cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \param Chain Whether we're creating a chained AST file. 1288cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregorvoid ASTWriter::WriteHeaderSearch(HeaderSearch &HS, const char* isysroot) { 1289cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor llvm::SmallVector<const FileEntry *, 16> FilesByUID; 1290cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor HS.getFileMgr().GetUniqueIDMapping(FilesByUID); 1291cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1292cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (FilesByUID.size() > HS.header_file_size()) 1293cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor FilesByUID.resize(HS.header_file_size()); 1294cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1295cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor HeaderFileInfoTrait GeneratorTrait(*this, HS); 1296cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; 1297cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor llvm::SmallVector<const char *, 4> SavedStrings; 1298cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned NumHeaderSearchEntries = 0; 1299cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { 1300cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor const FileEntry *File = FilesByUID[UID]; 1301cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (!File) 1302cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor continue; 1303cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1304cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor const HeaderFileInfo &HFI = HS.header_file_begin()[UID]; 1305cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (HFI.External && Chain) 1306cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor continue; 1307cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1308cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Turn the file name into an absolute path, if it isn't already. 1309cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor const char *Filename = File->getName(); 1310cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); 1311cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1312cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // If we performed any translation on the file name at all, we need to 1313cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // save this string, since the generator will refer to it later. 1314cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (Filename != File->getName()) { 1315cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Filename = strdup(Filename); 1316cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor SavedStrings.push_back(Filename); 1317cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1318cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1319cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Generator.insert(Filename, HFI, GeneratorTrait); 1320cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ++NumHeaderSearchEntries; 1321cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1322cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1323cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Create the on-disk hash table in a buffer. 1324cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor llvm::SmallString<4096> TableData; 1325cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor uint32_t BucketOffset; 1326cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor { 1327cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor llvm::raw_svector_ostream Out(TableData); 1328cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Make sure that no bucket is at offset 0 1329cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor clang::io::Emit32(Out, 0); 1330cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor BucketOffset = Generator.Emit(Out, GeneratorTrait); 1331cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1332cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1333cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Create a blob abbreviation 1334cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor using namespace llvm; 1335cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 1336cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); 1337cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 1338cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 1339cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 1340cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); 1341cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1342cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Write the stat cache 1343cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor RecordData Record; 1344cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Record.push_back(HEADER_SEARCH_TABLE); 1345cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Record.push_back(BucketOffset); 1346cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Record.push_back(NumHeaderSearchEntries); 1347cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); 1348cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1349cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Free all of the strings we had to duplicate. 1350cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) 1351cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor free((void*)SavedStrings[I]); 1352cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor} 1353cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 135414f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Writes the block containing the serialized form of the 135514f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// source manager. 135614f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// 135714f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// TODO: We should probably use an on-disk hash table (stored in a 135814f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// blob), indexed based on the file name, so that we only create 135914f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// entries for files that we actually need. In the common case (no 136014f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// errors), we probably won't have to create file entries for any of 136114f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// the files in the AST. 1362a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, 1363e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const Preprocessor &PP, 1364e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const char *isysroot) { 13657f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RecordData Record; 13667f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 1367f04ad69fed38d26fc0d6f7d6fd0a4631ddfbc7feChris Lattner // Enter the source manager block. 13688538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); 136914f79002e58556798e86168c63e48d533287eda5Douglas Gregor 137014f79002e58556798e86168c63e48d533287eda5Douglas Gregor // Abbreviations for the various kinds of source-location entries. 1371828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); 1372828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); 1373828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); 1374828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocInstantiationAbbrv = CreateSLocInstantiationAbbrev(Stream); 13757f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 13767f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Write the line table. 13777f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor if (SourceMgr.hasLineTable()) { 13787f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor LineTableInfo &LineTable = SourceMgr.getLineTable(); 13797f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 13807f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the file names 13817f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LineTable.getNumFilenames()); 13827f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { 13837f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the file name 13847f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor const char *Filename = LineTable.getFilename(I); 1385e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); 13867f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor unsigned FilenameLen = Filename? strlen(Filename) : 0; 13877f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(FilenameLen); 13887f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor if (FilenameLen) 13897f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.insert(Record.end(), Filename, Filename + FilenameLen); 13907f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor } 13911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13927f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the line entries 13937f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); 13947f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor L != LEnd; ++L) { 13957f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the file ID 13967f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(L->first); 13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13987f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the line entries 13997f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(L->second.size()); 14001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (std::vector<LineEntry>::iterator LE = L->second.begin(), 14017f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor LEEnd = L->second.end(); 14027f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor LE != LEEnd; ++LE) { 14037f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LE->FileOffset); 14047f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LE->LineNo); 14057f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LE->FilenameID); 14067f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back((unsigned)LE->FileKind); 14077f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LE->IncludeOffset); 14087f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor } 14097f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor } 14108538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SM_LINE_TABLE, Record); 14117f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor } 14127f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 141314f79002e58556798e86168c63e48d533287eda5Douglas Gregor // Write out the source location entry table. We skip the first 141414f79002e58556798e86168c63e48d533287eda5Douglas Gregor // entry, which is always the same dummy entry. 1415090d9b53e32bb30d9e74de895bb59b409bd49e00Chris Lattner std::vector<uint32_t> SLocEntryOffsets; 14167f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RecordData PreloadSLocs; 14170fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl unsigned BaseSLocID = Chain ? Chain->getTotalNumSLocs() : 0; 14180fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl SLocEntryOffsets.reserve(SourceMgr.sloc_entry_size() - 1 - BaseSLocID); 14190fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl for (unsigned I = BaseSLocID + 1, N = SourceMgr.sloc_entry_size(); 14200fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl I != N; ++I) { 1421bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor // Get this source location entry. 1422bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor const SrcMgr::SLocEntry *SLoc = &SourceMgr.getSLocEntry(I); 142311a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 14247f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Record the offset of this source-location entry. 14257f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); 14267f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 142714f79002e58556798e86168c63e48d533287eda5Douglas Gregor // Figure out which record code to use. 142814f79002e58556798e86168c63e48d533287eda5Douglas Gregor unsigned Code; 142914f79002e58556798e86168c63e48d533287eda5Douglas Gregor if (SLoc->isFile()) { 143014f79002e58556798e86168c63e48d533287eda5Douglas Gregor if (SLoc->getFile().getContentCache()->Entry) 14318538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = SM_SLOC_FILE_ENTRY; 143214f79002e58556798e86168c63e48d533287eda5Douglas Gregor else 14338538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = SM_SLOC_BUFFER_ENTRY; 143414f79002e58556798e86168c63e48d533287eda5Douglas Gregor } else 14358538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = SM_SLOC_INSTANTIATION_ENTRY; 14367f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.clear(); 143714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(Code); 143814f79002e58556798e86168c63e48d533287eda5Douglas Gregor 143914f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(SLoc->getOffset()); 144014f79002e58556798e86168c63e48d533287eda5Douglas Gregor if (SLoc->isFile()) { 144114f79002e58556798e86168c63e48d533287eda5Douglas Gregor const SrcMgr::FileInfo &File = SLoc->getFile(); 144214f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(File.getIncludeLoc().getRawEncoding()); 144314f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding 1444bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor Record.push_back(File.hasLineDirectives()); 144514f79002e58556798e86168c63e48d533287eda5Douglas Gregor 144614f79002e58556798e86168c63e48d533287eda5Douglas Gregor const SrcMgr::ContentCache *Content = File.getContentCache(); 144714f79002e58556798e86168c63e48d533287eda5Douglas Gregor if (Content->Entry) { 144814f79002e58556798e86168c63e48d533287eda5Douglas Gregor // The source location entry is a file. The blob associated 144914f79002e58556798e86168c63e48d533287eda5Douglas Gregor // with this entry is the file name. 14501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14512d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor // Emit size/modification time for this file. 14522d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor Record.push_back(Content->Entry->getSize()); 14532d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor Record.push_back(Content->Entry->getModificationTime()); 14542d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor 1455e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // Turn the file name into an absolute path, if it isn't already. 1456e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const char *Filename = Content->Entry->getName(); 1457fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer llvm::SmallString<128> FilePath(Filename); 1458fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer llvm::sys::fs::make_absolute(FilePath); 1459aba54a95e9d5e4dc9056abec6bb70ea777c4a7bcKovarththanan Rajaratnam Filename = FilePath.c_str(); 14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1461e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); 1462ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); 146314f79002e58556798e86168c63e48d533287eda5Douglas Gregor } else { 146414f79002e58556798e86168c63e48d533287eda5Douglas Gregor // The source location entry is a buffer. The blob associated 146514f79002e58556798e86168c63e48d533287eda5Douglas Gregor // with this entry contains the contents of the buffer. 146614f79002e58556798e86168c63e48d533287eda5Douglas Gregor 146714f79002e58556798e86168c63e48d533287eda5Douglas Gregor // We add one to the size so that we capture the trailing NULL 146814f79002e58556798e86168c63e48d533287eda5Douglas Gregor // that is required by llvm::MemoryBuffer::getMemBuffer (on 146914f79002e58556798e86168c63e48d533287eda5Douglas Gregor // the reader side). 147036c35ba0aca641e60e5dbee8efbc620c08b9bd61Douglas Gregor const llvm::MemoryBuffer *Buffer 1471e127a0d80155b45dafe77f2b4380e5fa111a3345Chris Lattner = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); 147214f79002e58556798e86168c63e48d533287eda5Douglas Gregor const char *Name = Buffer->getBufferIdentifier(); 1473ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, 1474ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar llvm::StringRef(Name, strlen(Name) + 1)); 147514f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.clear(); 14768538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(SM_SLOC_BUFFER_BLOB); 1477c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, 1478ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar llvm::StringRef(Buffer->getBufferStart(), 1479ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Buffer->getBufferSize() + 1)); 14807f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 14817f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor if (strcmp(Name, "<built-in>") == 0) 14820fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl PreloadSLocs.push_back(BaseSLocID + SLocEntryOffsets.size()); 148314f79002e58556798e86168c63e48d533287eda5Douglas Gregor } 148414f79002e58556798e86168c63e48d533287eda5Douglas Gregor } else { 148514f79002e58556798e86168c63e48d533287eda5Douglas Gregor // The source location entry is an instantiation. 148614f79002e58556798e86168c63e48d533287eda5Douglas Gregor const SrcMgr::InstantiationInfo &Inst = SLoc->getInstantiation(); 148714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(Inst.getSpellingLoc().getRawEncoding()); 148814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(Inst.getInstantiationLocStart().getRawEncoding()); 148914f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(Inst.getInstantiationLocEnd().getRawEncoding()); 149014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 1491f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor // Compute the token length for this macro expansion. 1492f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor unsigned NextOffset = SourceMgr.getNextOffset(); 1493bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor if (I + 1 != N) 1494bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor NextOffset = SourceMgr.getSLocEntry(I + 1).getOffset(); 1495f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor Record.push_back(NextOffset - SLoc->getOffset() - 1); 1496c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecordWithAbbrev(SLocInstantiationAbbrv, Record); 149714f79002e58556798e86168c63e48d533287eda5Douglas Gregor } 149814f79002e58556798e86168c63e48d533287eda5Douglas Gregor } 149914f79002e58556798e86168c63e48d533287eda5Douglas Gregor 15007f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Stream.ExitBlock(); 1501bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor 15027f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor if (SLocEntryOffsets.empty()) 15037f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor return; 15042eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor 15053397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Write the source-location offsets table into the AST block. This 15067f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // table is used for lazily loading source-location information. 15077f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor using namespace llvm; 15087f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 15098538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); 15107f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs 15117f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // next offset 15127f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets 15137f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15157f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.clear(); 15168538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(SOURCE_LOCATION_OFFSETS); 15177f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(SLocEntryOffsets.size()); 15188db9faed418ea743f55c31e1ccecadbb23bd55b7Sebastian Redl unsigned BaseOffset = Chain ? Chain->getNextSLocOffset() : 0; 15198db9faed418ea743f55c31e1ccecadbb23bd55b7Sebastian Redl Record.push_back(SourceMgr.getNextOffset() - BaseOffset); 15207f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, 1521ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(SLocEntryOffsets), 1522090d9b53e32bb30d9e74de895bb59b409bd49e00Chris Lattner SLocEntryOffsets.size()*sizeof(SLocEntryOffsets[0])); 15237f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 15243397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Write the source location entry preloads array, telling the AST 15257f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // reader which source locations entries it should load eagerly. 15268538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); 152714f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 152814f79002e58556798e86168c63e48d533287eda5Douglas Gregor 15294fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 15304fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Preprocessor Serialization 15314fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 15324fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 15339c7361006b8cd95333958150dd0c803261807b68Douglas Gregorstatic int compareMacroDefinitions(const void *XPtr, const void *YPtr) { 15349c7361006b8cd95333958150dd0c803261807b68Douglas Gregor const std::pair<const IdentifierInfo *, MacroInfo *> &X = 15359c7361006b8cd95333958150dd0c803261807b68Douglas Gregor *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; 15369c7361006b8cd95333958150dd0c803261807b68Douglas Gregor const std::pair<const IdentifierInfo *, MacroInfo *> &Y = 15379c7361006b8cd95333958150dd0c803261807b68Douglas Gregor *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; 15389c7361006b8cd95333958150dd0c803261807b68Douglas Gregor return X.first->getName().compare(Y.first->getName()); 15399c7361006b8cd95333958150dd0c803261807b68Douglas Gregor} 15409c7361006b8cd95333958150dd0c803261807b68Douglas Gregor 15410b1fb988012da21d996c43e36867787a7a07b889Chris Lattner/// \brief Writes the block containing the serialized form of the 15420b1fb988012da21d996c43e36867787a7a07b889Chris Lattner/// preprocessor. 15430b1fb988012da21d996c43e36867787a7a07b889Chris Lattner/// 1544a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WritePreprocessor(const Preprocessor &PP) { 15457c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner RecordData Record; 15467c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner 1547c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner // If the preprocessor __COUNTER__ value has been bumped, remember it. 1548c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner if (PP.getCounterValue() != 0) { 1549c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner Record.push_back(PP.getCounterValue()); 15508538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(PP_COUNTER_VALUE, Record); 1551c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner Record.clear(); 15522eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor } 15532eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor 15542eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor // Enter the preprocessor block. 1555ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); 15561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15573397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // If the AST file contains __DATE__ or __TIME__ emit a warning about this. 15582eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor // FIXME: use diagnostics subsystem for localization etc. 15592eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor if (PP.SawDateOrTime()) 15602eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); 15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1562ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor 15637c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner // Loop over all the macro definitions that are live at the end of the file, 15647c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner // emitting each to the PP section. 15656a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); 156620249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 15679c7361006b8cd95333958150dd0c803261807b68Douglas Gregor // Construct the list of macro definitions that need to be serialized. 15689c7361006b8cd95333958150dd0c803261807b68Douglas Gregor llvm::SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> 15699c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacrosToEmit; 15709c7361006b8cd95333958150dd0c803261807b68Douglas Gregor llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; 1571040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), 1572040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor E = PP.macro_end(Chain == 0); 15737c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner I != E; ++I) { 15749c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacroDefinitionsSeen.insert(I->first); 15759c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacrosToEmit.push_back(std::make_pair(I->first, I->second)); 15769c7361006b8cd95333958150dd0c803261807b68Douglas Gregor } 15779c7361006b8cd95333958150dd0c803261807b68Douglas Gregor 15789c7361006b8cd95333958150dd0c803261807b68Douglas Gregor // Sort the set of macro definitions that need to be serialized by the 15799c7361006b8cd95333958150dd0c803261807b68Douglas Gregor // name of the macro, to provide a stable ordering. 15809c7361006b8cd95333958150dd0c803261807b68Douglas Gregor llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), 15819c7361006b8cd95333958150dd0c803261807b68Douglas Gregor &compareMacroDefinitions); 15829c7361006b8cd95333958150dd0c803261807b68Douglas Gregor 1583040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor // Resolve any identifiers that defined macros at the time they were 1584040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor // deserialized, adding them to the list of macros to emit (if appropriate). 1585040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor for (unsigned I = 0, N = DeserializedMacroNames.size(); I != N; ++I) { 1586040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor IdentifierInfo *Name 1587040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor = const_cast<IdentifierInfo *>(DeserializedMacroNames[I]); 1588040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor if (Name->hasMacroDefinition() && MacroDefinitionsSeen.insert(Name)) 1589040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor MacrosToEmit.push_back(std::make_pair(Name, PP.getMacroInfo(Name))); 1590040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor } 1591040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor 15929c7361006b8cd95333958150dd0c803261807b68Douglas Gregor for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { 15939c7361006b8cd95333958150dd0c803261807b68Douglas Gregor const IdentifierInfo *Name = MacrosToEmit[I].first; 15949c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacroInfo *MI = MacrosToEmit[I].second; 1595040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor if (!MI) 1596040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor continue; 1597040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor 15983397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Don't emit builtin macros like __LINE__ to the AST file unless they have 15997c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner // been redefined by the header (in which case they are not isBuiltinMacro). 16003397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Also skip macros from a AST file if we're chaining. 1601ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor 1602ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor // FIXME: There is a (probably minor) optimization we could do here, if 1603ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor // the macro comes from the original PCH but the identifier comes from a 1604ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor // chained PCH, by storing the offset into the original PCH rather than 1605ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor // writing the macro definition a second time. 160620249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer if (MI->isBuiltinMacro() || 16079c7361006b8cd95333958150dd0c803261807b68Douglas Gregor (Chain && Name->isFromAST() && MI->isFromAST())) 16087c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner continue; 16097c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner 16109c7361006b8cd95333958150dd0c803261807b68Douglas Gregor AddIdentifierRef(Name, Record); 16119c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacroOffsets[Name] = Stream.GetCurrentBitNo(); 16127c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->getDefinitionLoc().getRawEncoding()); 16137c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->isUsed()); 16141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16157c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner unsigned Code; 16167c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner if (MI->isObjectLike()) { 16178538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = PP_MACRO_OBJECT_LIKE; 16187c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner } else { 16198538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = PP_MACRO_FUNCTION_LIKE; 16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16217c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->isC99Varargs()); 16227c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->isGNUVarargs()); 16237c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->getNumArgs()); 16247c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); 16257c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner I != E; ++I) 16267356a31327be9b3c3434a0c88746028980da5684Chris Lattner AddIdentifierRef(*I, Record); 16277c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner } 162820249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 16296a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // If we have a detailed preprocessing record, record the macro definition 16306a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // ID that corresponds to this macro. 16316a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor if (PPRec) 16326a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Record.push_back(getMacroDefinitionID(PPRec->findMacroDefinition(MI))); 163320249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 1634c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecord(Code, Record); 16357c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.clear(); 1636f04ad69fed38d26fc0d6f7d6fd0a4631ddfbc7feChris Lattner 1637df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // Emit the tokens array. 1638df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { 1639df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // Note that we know that the preprocessor does not have any annotation 1640df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // tokens in it because they are created by the parser, and thus can't be 1641df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // in a macro definition. 1642df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner const Token &Tok = MI->getReplacementToken(TokNo); 16431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1644df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.push_back(Tok.getLocation().getRawEncoding()); 1645df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.push_back(Tok.getLength()); 1646df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner 1647df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // FIXME: When reading literal tokens, reconstruct the literal pointer if 1648df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // it is needed. 16497356a31327be9b3c3434a0c88746028980da5684Chris Lattner AddIdentifierRef(Tok.getIdentifierInfo(), Record); 1650df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // FIXME: Should translate token kind to a stable encoding. 1651df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.push_back(Tok.getKind()); 1652df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // FIXME: Should translate token flags to a stable encoding. 1653df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.push_back(Tok.getFlags()); 16541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(PP_TOKEN, Record); 1656df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.clear(); 1657df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner } 165837e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor ++NumMacros; 16597c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner } 16604800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.ExitBlock(); 16614800a5c79023271408af49797e09be32aca93232Douglas Gregor 16624800a5c79023271408af49797e09be32aca93232Douglas Gregor if (PPRec) 16634800a5c79023271408af49797e09be32aca93232Douglas Gregor WritePreprocessorDetail(*PPRec); 16644800a5c79023271408af49797e09be32aca93232Douglas Gregor} 16654800a5c79023271408af49797e09be32aca93232Douglas Gregor 16664800a5c79023271408af49797e09be32aca93232Douglas Gregorvoid ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { 16674800a5c79023271408af49797e09be32aca93232Douglas Gregor if (PPRec.begin(Chain) == PPRec.end(Chain)) 16684800a5c79023271408af49797e09be32aca93232Douglas Gregor return; 16694800a5c79023271408af49797e09be32aca93232Douglas Gregor 16704800a5c79023271408af49797e09be32aca93232Douglas Gregor // Enter the preprocessor block. 16714800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); 167220249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 16736a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // If the preprocessor has a preprocessing record, emit it. 16746a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor unsigned NumPreprocessingRecords = 0; 16754800a5c79023271408af49797e09be32aca93232Douglas Gregor using namespace llvm; 16764800a5c79023271408af49797e09be32aca93232Douglas Gregor 16774800a5c79023271408af49797e09be32aca93232Douglas Gregor // Set up the abbreviation for 16784800a5c79023271408af49797e09be32aca93232Douglas Gregor unsigned InclusionAbbrev = 0; 16794800a5c79023271408af49797e09be32aca93232Douglas Gregor { 16804800a5c79023271408af49797e09be32aca93232Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 16814800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); 16824800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index 16834800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // start location 16844800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // end location 16854800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length 16864800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes 16874800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind 16884800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 16894800a5c79023271408af49797e09be32aca93232Douglas Gregor InclusionAbbrev = Stream.EmitAbbrev(Abbrev); 16904800a5c79023271408af49797e09be32aca93232Douglas Gregor } 16914800a5c79023271408af49797e09be32aca93232Douglas Gregor 16924800a5c79023271408af49797e09be32aca93232Douglas Gregor unsigned IndexBase = Chain ? PPRec.getNumPreallocatedEntities() : 0; 16934800a5c79023271408af49797e09be32aca93232Douglas Gregor RecordData Record; 16944800a5c79023271408af49797e09be32aca93232Douglas Gregor for (PreprocessingRecord::iterator E = PPRec.begin(Chain), 16954800a5c79023271408af49797e09be32aca93232Douglas Gregor EEnd = PPRec.end(Chain); 16964800a5c79023271408af49797e09be32aca93232Douglas Gregor E != EEnd; ++E) { 16974800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.clear(); 169820249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 16994800a5c79023271408af49797e09be32aca93232Douglas Gregor if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { 17004800a5c79023271408af49797e09be32aca93232Douglas Gregor // Record this macro definition's location. 17014800a5c79023271408af49797e09be32aca93232Douglas Gregor MacroID ID = getMacroDefinitionID(MD); 17024800a5c79023271408af49797e09be32aca93232Douglas Gregor 17034800a5c79023271408af49797e09be32aca93232Douglas Gregor // Don't write the macro definition if it is from another AST file. 17044800a5c79023271408af49797e09be32aca93232Douglas Gregor if (ID < FirstMacroID) 17056a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor continue; 17064800a5c79023271408af49797e09be32aca93232Douglas Gregor 170789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor // Notify the serialization listener that we're serializing this entity. 170889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor if (SerializationListener) 170989d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor SerializationListener->SerializedPreprocessedEntity(*E, 17104800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.GetCurrentBitNo()); 171189d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 17124800a5c79023271408af49797e09be32aca93232Douglas Gregor unsigned Position = ID - FirstMacroID; 17134800a5c79023271408af49797e09be32aca93232Douglas Gregor if (Position != MacroDefinitionOffsets.size()) { 17144800a5c79023271408af49797e09be32aca93232Douglas Gregor if (Position > MacroDefinitionOffsets.size()) 17154800a5c79023271408af49797e09be32aca93232Douglas Gregor MacroDefinitionOffsets.resize(Position + 1); 17164800a5c79023271408af49797e09be32aca93232Douglas Gregor 17174800a5c79023271408af49797e09be32aca93232Douglas Gregor MacroDefinitionOffsets[Position] = Stream.GetCurrentBitNo(); 17184800a5c79023271408af49797e09be32aca93232Douglas Gregor } else 17194800a5c79023271408af49797e09be32aca93232Douglas Gregor MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo()); 172089d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 17214800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(IndexBase + NumPreprocessingRecords++); 17224800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(ID); 17234800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MD->getSourceRange().getBegin(), Record); 17244800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MD->getSourceRange().getEnd(), Record); 17254800a5c79023271408af49797e09be32aca93232Douglas Gregor AddIdentifierRef(MD->getName(), Record); 17264800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MD->getLocation(), Record); 17274800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); 17284800a5c79023271408af49797e09be32aca93232Douglas Gregor continue; 17294800a5c79023271408af49797e09be32aca93232Douglas Gregor } 17304800a5c79023271408af49797e09be32aca93232Douglas Gregor 17314800a5c79023271408af49797e09be32aca93232Douglas Gregor // Notify the serialization listener that we're serializing this entity. 17324800a5c79023271408af49797e09be32aca93232Douglas Gregor if (SerializationListener) 17334800a5c79023271408af49797e09be32aca93232Douglas Gregor SerializationListener->SerializedPreprocessedEntity(*E, 17344800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.GetCurrentBitNo()); 17354800a5c79023271408af49797e09be32aca93232Douglas Gregor 17364800a5c79023271408af49797e09be32aca93232Douglas Gregor if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) { 17374800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(IndexBase + NumPreprocessingRecords++); 17384800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MI->getSourceRange().getBegin(), Record); 17394800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MI->getSourceRange().getEnd(), Record); 17404800a5c79023271408af49797e09be32aca93232Douglas Gregor AddIdentifierRef(MI->getName(), Record); 17414800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(getMacroDefinitionID(MI->getDefinition())); 17424800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EmitRecord(PPD_MACRO_INSTANTIATION, Record); 17434800a5c79023271408af49797e09be32aca93232Douglas Gregor continue; 17446a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor } 174520249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 17464800a5c79023271408af49797e09be32aca93232Douglas Gregor if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { 17474800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(PPD_INCLUSION_DIRECTIVE); 17484800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(IndexBase + NumPreprocessingRecords++); 17494800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(ID->getSourceRange().getBegin(), Record); 17504800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(ID->getSourceRange().getEnd(), Record); 17514800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(ID->getFileName().size()); 17524800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(ID->wasInQuotes()); 17534800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(static_cast<unsigned>(ID->getKind())); 17544800a5c79023271408af49797e09be32aca93232Douglas Gregor llvm::SmallString<64> Buffer; 17554800a5c79023271408af49797e09be32aca93232Douglas Gregor Buffer += ID->getFileName(); 17564800a5c79023271408af49797e09be32aca93232Douglas Gregor Buffer += ID->getFile()->getName(); 17574800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); 17584800a5c79023271408af49797e09be32aca93232Douglas Gregor continue; 17594800a5c79023271408af49797e09be32aca93232Douglas Gregor } 17604800a5c79023271408af49797e09be32aca93232Douglas Gregor 17614800a5c79023271408af49797e09be32aca93232Douglas Gregor llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); 17624800a5c79023271408af49797e09be32aca93232Douglas Gregor } 1763c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.ExitBlock(); 176420249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 17656a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // Write the offsets table for the preprocessing record. 17666a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor if (NumPreprocessingRecords > 0) { 17676a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // Write the offsets table for identifier IDs. 17686a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor using namespace llvm; 17696a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 17708538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(MACRO_DEFINITION_OFFSETS)); 17716a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of records 17726a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macro defs 17736a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 17746a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor unsigned MacroDefOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 177520249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 17766a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Record.clear(); 17778538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(MACRO_DEFINITION_OFFSETS); 17786a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Record.push_back(NumPreprocessingRecords); 17796a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Record.push_back(MacroDefinitionOffsets.size()); 17806a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record, 1781ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(MacroDefinitionOffsets), 17826a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor MacroDefinitionOffsets.size() * sizeof(uint32_t)); 17836a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor } 17840b1fb988012da21d996c43e36867787a7a07b889Chris Lattner} 17850b1fb988012da21d996c43e36867787a7a07b889Chris Lattner 17863efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidisvoid ASTWriter::WritePragmaDiagnosticMappings(const Diagnostic &Diag) { 1787f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis RecordData Record; 17883efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis for (Diagnostic::DiagStatePointsTy::const_iterator 17893efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); 17903efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis I != E; ++I) { 17913efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis const Diagnostic::DiagStatePoint &point = *I; 17923efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis if (point.Loc.isInvalid()) 17933efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis continue; 17943efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis 17953efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Record.push_back(point.Loc.getRawEncoding()); 17963efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis for (Diagnostic::DiagState::iterator 17973efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis I = point.State->begin(), E = point.State->end(); I != E; ++I) { 17983efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis unsigned diag = I->first, map = I->second; 17993efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis if (map & 0x10) { // mapping from a diagnostic pragma. 18003efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Record.push_back(diag); 18013efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Record.push_back(map & 0x7); 18023efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis } 1803f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis } 18043efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Record.push_back(-1); // mark the end of the diag/map pairs for this 18053efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis // location. 1806f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis } 1807f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis 180860f7684881f9f6bc779e91212aea89d9afc723ddArgyrios Kyrtzidis if (!Record.empty()) 18093efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); 1810f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis} 1811f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis 18124fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 18134fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Type Serialization 18144fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 18150b1fb988012da21d996c43e36867787a7a07b889Chris Lattner 18163397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the representation of a type to the AST stream. 1817a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteType(QualType T) { 181801b81c4d074bba9c18372d521405dfe32fc4f552Argyrios Kyrtzidis TypeIdx &Idx = TypeIdxs[T]; 1819c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis if (Idx.getIndex() == 0) // we haven't seen this type before. 1820c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis Idx = TypeIdx(NextTypeID++); 18211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 182297475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); 182355f48de5f6b10b50f4d88a9f7235f4532f799550Douglas Gregor 18242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Record the offset for this type. 1825c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis unsigned Index = Idx.getIndex() - FirstTypeID; 1826681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl if (TypeOffsets.size() == Index) 1827c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor TypeOffsets.push_back(Stream.GetCurrentBitNo()); 1828681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl else if (TypeOffsets.size() < Index) { 1829681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl TypeOffsets.resize(Index + 1); 1830681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl TypeOffsets[Index] = Stream.GetCurrentBitNo(); 18312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 18322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 18332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor RecordData Record; 18341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Emit the type's representation. 18363397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTTypeWriter W(*this, Record); 18370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1838a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (T.hasLocalNonFastQualifiers()) { 1839a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Qs = T.getLocalQualifiers(); 1840a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor AddTypeRef(T.getLocalUnqualifiedType(), Record); 18410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Record.push_back(Qs.getAsOpaqueValue()); 18428538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl W.Code = TYPE_EXT_QUAL; 18430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } else { 18440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall switch (T->getTypeClass()) { 18450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // For all of the concrete, non-dependent types, call the 18460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // appropriate visitor function. 18472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define TYPE(Class, Base) \ 1848b7166334d897e1e4e6a5b428fe2d0ec752ef187fMike Stump case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; 18492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define ABSTRACT_TYPE(Class, Base) 18502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/TypeNodes.def" 18510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 18522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 18532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 18542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Emit the serialized record. 1855c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecord(W.Code, Record); 18560b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 18570b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor // Flush any expressions that were written as part of this type. 1858c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor FlushStmts(); 18592cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 18602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 18614fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 18624fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Declaration Serialization 18634fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 18644fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 18652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// \brief Write the block containing all of the declaration IDs 18662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// lexically declared within the given DeclContext. 18672cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// 18682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// \returns the offset of the DECL_CONTEXT_LEXICAL block within the 18692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// bistream, or 0 if no block was written. 1870a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redluint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, 18712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor DeclContext *DC) { 187217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis if (DC->decls_empty()) 18732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor return 0; 18742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1875c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor uint64_t Offset = Stream.GetCurrentBitNo(); 18762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor RecordData Record; 18778538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(DECL_CONTEXT_LEXICAL); 1878eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis llvm::SmallVector<KindDeclIDPair, 64> Decls; 187917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); 188017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis D != DEnd; ++D) 1881eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); 18822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 18832512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor ++NumLexicalDeclContexts; 1884681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, 1885eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis reinterpret_cast<char*>(Decls.data()), 1886eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis Decls.size() * sizeof(KindDeclIDPair)); 18872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor return Offset; 18882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 18892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1890a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteTypeDeclOffsets() { 18911476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl using namespace llvm; 18921476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl RecordData Record; 18931476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 18941476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // Write the type offsets array 18951476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 18968538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); 18971476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types 18981476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block 18991476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 19001476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.clear(); 19018538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(TYPE_OFFSET); 19021476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.push_back(TypeOffsets.size()); 19031476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, 1904ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(TypeOffsets), 19051476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl TypeOffsets.size() * sizeof(TypeOffsets[0])); 19061476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 19071476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // Write the declaration offsets array 19081476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev = new BitCodeAbbrev(); 19098538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); 19101476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations 19111476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block 19121476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 19131476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.clear(); 19148538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(DECL_OFFSET); 19151476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.push_back(DeclOffsets.size()); 19161476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, 1917ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(DeclOffsets), 19181476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl DeclOffsets.size() * sizeof(DeclOffsets[0])); 19191476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl} 19201476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 19214fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 19224fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Global Method Pool and Selector Serialization 19234fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 19244fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 19253251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregornamespace { 1926f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor// Trait used for the on-disk hash table used in the method pool. 19273397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlclass ASTMethodPoolTrait { 1928a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 1929f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 1930f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregorpublic: 1931f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor typedef Selector key_type; 1932f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor typedef key_type key_type_ref; 19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19345d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl struct data_type { 19358538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl SelectorID ID; 19365d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl ObjCMethodList Instance, Factory; 19375d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl }; 1938f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor typedef const data_type& data_type_ref; 1939f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 19403397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } 19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1942f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor static unsigned ComputeHash(Selector Sel) { 19430eca89e9890db4d8336ce762a5b359a1d58ca02bArgyrios Kyrtzidis return serialization::ComputeHash(Sel); 1944f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 19451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<unsigned,unsigned> 1947f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor EmitKeyDataLength(llvm::raw_ostream& Out, Selector Sel, 1948f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor data_type_ref Methods) { 1949f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); 1950f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, KeyLen); 19515d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts 19525d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Instance; Method; 1953f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 1954f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 1955f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor DataLen += 4; 19565d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Factory; Method; 1957f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 1958f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 1959f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor DataLen += 4; 1960f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, DataLen); 1961f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor return std::make_pair(KeyLen, DataLen); 1962f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 196483941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor void EmitKey(llvm::raw_ostream& Out, Selector Sel, unsigned) { 19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump uint64_t Start = Out.tell(); 196683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor assert((Start >> 32) == 0 && "Selector key offset too large"); 196783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Writer.SetSelectorOffset(Sel, Start); 1968f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned N = Sel.getNumArgs(); 1969f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, N); 1970f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (N == 0) 1971f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor N = 1; 1972f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor for (unsigned I = 0; I != N; ++I) 19731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump clang::io::Emit32(Out, 1974f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); 1975f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 19761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1977f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor void EmitData(llvm::raw_ostream& Out, key_type_ref, 1978a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor data_type_ref Methods, unsigned DataLen) { 1979a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor uint64_t Start = Out.tell(); (void)Start; 19805d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl clang::io::Emit32(Out, Methods.ID); 1981f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned NumInstanceMethods = 0; 19825d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Instance; Method; 1983f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 1984f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 1985f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ++NumInstanceMethods; 1986f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 1987f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned NumFactoryMethods = 0; 19885d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Factory; Method; 1989f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 1990f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 1991f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ++NumFactoryMethods; 1992f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 1993f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, NumInstanceMethods); 1994f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, NumFactoryMethods); 19955d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Instance; Method; 1996f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 1997f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 1998f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); 19995d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Factory; Method; 2000f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2001f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2002f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); 2003a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor 2004a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor assert(Out.tell() - Start == DataLen && "Data length is wrong"); 2005f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2006f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor}; 2007f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor} // end anonymous namespace 2008f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2009059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl/// \brief Write ObjC data: selectors and the method pool. 2010f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor/// 2011f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor/// The method pool contains both instance and factory methods, stored 2012059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl/// in an on-disk hash table indexed by the selector. The hash table also 2013059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl/// contains an empty entry for every other selector known to Sema. 2014a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteSelectors(Sema &SemaRef) { 2015f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor using namespace llvm; 2016f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2017059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // Do we have to do anything at all? 20185d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) 2019059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl return; 2020e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl unsigned NumTableEntries = 0; 2021059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // Create and write out the blob that contains selectors and the method pool. 2022f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor { 20233397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; 20245d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ASTMethodPoolTrait Trait(*this); 20251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2026059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // Create the on-disk hash table representation. We walk through every 2027059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // selector we've seen and look it up in the method pool. 2028e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl SelectorOffsets.resize(NextSelectorID - FirstSelectorID); 20298538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl for (llvm::DenseMap<Selector, SelectorID>::iterator 20305d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl I = SelectorIDs.begin(), E = SelectorIDs.end(); 20315d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl I != E; ++I) { 20325d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Selector S = I->first; 2033059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); 20343397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTMethodPoolTrait::data_type Data = { 20355d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl I->second, 20365d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl ObjCMethodList(), 20375d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl ObjCMethodList() 20385d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl }; 20395d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl if (F != SemaRef.MethodPool.end()) { 20405d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Data.Instance = F->second.first; 20415d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Data.Factory = F->second.second; 20425d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl } 20433397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Only write this selector if it's not in an existing AST or something 2044e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // changed. 2045e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (Chain && I->second < FirstSelectorID) { 2046e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // Selector already exists. Did it change? 2047e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl bool changed = false; 2048e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; 2049e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl M = M->Next) { 2050e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (M->Method->getPCHLevel() == 0) 2051e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl changed = true; 2052e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 2053e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; 2054e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl M = M->Next) { 2055e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (M->Method->getPCHLevel() == 0) 2056e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl changed = true; 2057e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 2058e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (!changed) 2059e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl continue; 2060fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl } else if (Data.Instance.Method || Data.Factory.Method) { 2061fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl // A new method pool entry. 2062fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl ++NumTableEntries; 2063e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 20645d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Generator.insert(S, Data, Trait); 2065f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2066f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2067f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Create the on-disk hash table in a buffer. 20681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::SmallString<4096> MethodPool; 2069f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor uint32_t BucketOffset; 2070f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor { 20713397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTMethodPoolTrait Trait(*this); 2072f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor llvm::raw_svector_ostream Out(MethodPool); 2073f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Make sure that no bucket is at offset 0 2074a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor clang::io::Emit32(Out, 0); 2075f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor BucketOffset = Generator.Emit(Out, Trait); 2076f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2077f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2078f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Create a blob abbreviation 2079f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 20808538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); 2081f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 208283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 2083f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2084f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); 2085f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 208683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor // Write the method pool 2087f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor RecordData Record; 20888538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(METHOD_POOL); 2089f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Record.push_back(BucketOffset); 2090e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl Record.push_back(NumTableEntries); 2091ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); 209283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor 209383941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor // Create a blob abbreviation for the selector table offsets. 209483941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Abbrev = new BitCodeAbbrev(); 20958538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); 20967c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size 209783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 209883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 209983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor 210083941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor // Write the selector offsets table. 210183941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Record.clear(); 21028538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(SELECTOR_OFFSETS); 210383941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Record.push_back(SelectorOffsets.size()); 210483941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, 2105ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(SelectorOffsets), 210683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor SelectorOffsets.size() * 4); 2107f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2108f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor} 2109f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 21103397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the selectors referenced in @selector expression into AST file. 2111a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { 2112320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian using namespace llvm; 2113320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian if (SemaRef.ReferencedSelectors.empty()) 2114320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian return; 2115725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl 2116320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian RecordData Record; 2117725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl 21183397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Note: this writes out all references even for a dependent AST. But it is 2119a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl // very tricky to fix, and given that @selector shouldn't really appear in 2120a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl // headers, probably not worth it. It's not a correctness issue. 2121320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian for (DenseMap<Selector, SourceLocation>::iterator S = 2122320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian SemaRef.ReferencedSelectors.begin(), 2123320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { 2124320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian Selector Sel = (*S).first; 2125320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian SourceLocation Loc = (*S).second; 2126320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian AddSelectorRef(Sel, Record); 2127320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian AddSourceLocation(Loc, Record); 2128320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian } 21298538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); 2130320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian} 2131320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian 21324fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 21334fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Identifier Table Serialization 21344fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 21354fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 2136f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregornamespace { 21373397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlclass ASTIdentifierTableTrait { 2138a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 213937e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor Preprocessor &PP; 21403251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 2141a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor /// \brief Determines whether this is an "interesting" identifier 2142a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor /// that needs a full IdentifierInfo structure written into the hash 2143a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor /// table. 2144a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor static bool isInterestingIdentifier(const IdentifierInfo *II) { 2145a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor return II->isPoisoned() || 2146a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor II->isExtensionToken() || 2147a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor II->hasMacroDefinition() || 2148a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor II->getObjCOrBuiltinID() || 2149a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor II->getFETokenInfo<void>(); 2150a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor } 2151a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor 21523251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregorpublic: 21533251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor typedef const IdentifierInfo* key_type; 21543251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor typedef key_type key_type_ref; 21551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21568538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl typedef IdentID data_type; 21573251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor typedef data_type data_type_ref; 21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21593397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP) 216037e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor : Writer(Writer), PP(PP) { } 21613251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 21623251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor static unsigned ComputeHash(const IdentifierInfo* II) { 21632596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar return llvm::HashString(II->getName()); 21643251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 21651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<unsigned,unsigned> 21671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EmitKeyDataLength(llvm::raw_ostream& Out, const IdentifierInfo* II, 21688538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID ID) { 2169e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar unsigned KeyLen = II->getLength() + 1; 2170a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 2171a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor if (isInterestingIdentifier(II)) { 21725998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor DataLen += 2; // 2 bytes for builtin ID, flags 21731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (II->hasMacroDefinition() && 2174a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro()) 21755998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor DataLen += 4; 2176a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor for (IdentifierResolver::iterator D = IdentifierResolver::begin(II), 2177a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor DEnd = IdentifierResolver::end(); 2178a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor D != DEnd; ++D) 21798538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl DataLen += sizeof(DeclID); 2180a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor } 2181668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor clang::io::Emit16(Out, DataLen); 218202fc75169afe785c114e795ec4d24edfb4073c42Douglas Gregor // We emit the key length after the data length so that every 218302fc75169afe785c114e795ec4d24edfb4073c42Douglas Gregor // string is preceded by a 16-bit length. This matches the PTH 218402fc75169afe785c114e795ec4d24edfb4073c42Douglas Gregor // format for storing identifiers. 2185d6595a40fe12e3d5ffe5ce48987b379d547439a4Douglas Gregor clang::io::Emit16(Out, KeyLen); 21863251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor return std::make_pair(KeyLen, DataLen); 21873251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 21881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void EmitKey(llvm::raw_ostream& Out, const IdentifierInfo* II, 21903251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor unsigned KeyLen) { 21913251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor // Record the location of the key data. This is used when generating 21923251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor // the mapping from persistent IDs to strings. 21933251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor Writer.SetIdentifierOffset(II, Out.tell()); 2194e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar Out.write(II->getNameStart(), KeyLen); 21953251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 21961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void EmitData(llvm::raw_ostream& Out, const IdentifierInfo* II, 21988538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID ID, unsigned) { 2199a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor if (!isInterestingIdentifier(II)) { 2200a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor clang::io::Emit32(Out, ID << 1); 2201a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor return; 2202a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor } 22035998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor 2204a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor clang::io::Emit32(Out, (ID << 1) | 0x01); 22053251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor uint32_t Bits = 0; 22061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasMacroDefinition = 22071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump II->hasMacroDefinition() && 220837e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro(); 22095998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor Bits = (uint32_t)II->getObjCOrBuiltinID(); 2210b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(hasMacroDefinition); 2211b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(II->isExtensionToken()); 2212b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(II->isPoisoned()); 2213646395bbcaa849c94bc2a3246c71d809ca719f01Argyrios Kyrtzidis Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); 2214b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); 22155998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor clang::io::Emit16(Out, Bits); 22163251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 221737e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor if (hasMacroDefinition) 22185998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor clang::io::Emit32(Out, Writer.getMacroOffset(II)); 221937e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor 2220668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // Emit the declaration IDs in reverse order, because the 2221668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // IdentifierResolver provides the declarations as they would be 2222668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // visible (e.g., the function "stat" would come before the struct 2223668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // "stat"), but IdentifierResolver::AddDeclToIdentifierChain() 2224668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // adds declarations to the end of the list (so we need to see the 2225668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // struct "status" before the function "status"). 2226f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // Only emit declarations that aren't from a chained PCH, though. 22271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::SmallVector<Decl *, 16> Decls(IdentifierResolver::begin(II), 2228668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor IdentifierResolver::end()); 2229668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor for (llvm::SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), 2230668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor DEnd = Decls.rend(); 22313251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor D != DEnd; ++D) 2232d8c5abb096a5f6babb3709180fe304be5462bcc1Sebastian Redl clang::io::Emit32(Out, Writer.getDeclID(*D)); 22333251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 22343251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor}; 22353251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor} // end anonymous namespace 22363251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 22373397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the identifier table into the AST file. 2238afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// 2239afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// The identifier table consists of a blob containing string data 2240afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// (the actual identifiers themselves) and a separate "offsets" index 2241afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// that maps identifier IDs to locations within the blob. 2242a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteIdentifierTable(Preprocessor &PP) { 2243afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor using namespace llvm; 2244afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2245afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Create and write out the blob that contains the identifier 2246afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // strings. 2247afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor { 22483397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; 22495d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ASTIdentifierTableTrait Trait(*this, PP); 22501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 225192b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // Look for any identifiers that were named while processing the 225292b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // headers, but are otherwise not needed. We add these to the hash 225392b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // table to enable checking of the predefines buffer in the case 22543397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // where the user adds new macro definitions when building the AST 225592b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // file. 225692b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), 225792b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor IDEnd = PP.getIdentifierTable().end(); 225892b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor ID != IDEnd; ++ID) 225992b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor getIdentifierRef(ID->second); 226092b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor 2261f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // Create the on-disk hash table representation. We only store offsets 2262f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // for identifiers that appear here for the first time. 2263f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl IdentifierOffsets.resize(NextIdentID - FirstIdentID); 22648538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator 2265afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); 2266afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor ID != IDEnd; ++ID) { 2267afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor assert(ID->first && "NULL identifier in identifier table"); 22683c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl if (!Chain || !ID->first->isFromAST()) 22695d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Generator.insert(ID->first, ID->second, Trait); 22703251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 2271afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 22723251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor // Create the on-disk hash table in a buffer. 22731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::SmallString<4096> IdentifierTable; 2274668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor uint32_t BucketOffset; 22753251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor { 22763397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTIdentifierTableTrait Trait(*this, PP); 22773251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor llvm::raw_svector_ostream Out(IdentifierTable); 2278f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Make sure that no bucket is at offset 0 2279a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor clang::io::Emit32(Out, 0); 2280668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor BucketOffset = Generator.Emit(Out, Trait); 2281afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor } 2282afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2283afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Create a blob abbreviation 2284afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 22858538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); 2286668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 22873251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2288c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); 2289afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2290afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Write the identifier table 2291afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor RecordData Record; 22928538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(IDENTIFIER_TABLE); 2293668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor Record.push_back(BucketOffset); 2294ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); 2295afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor } 2296afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2297afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Write the offsets table for identifier IDs. 22982b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 22998538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); 23002b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers 23012b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 23022b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 23032b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor 23042b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor RecordData Record; 23058538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(IDENTIFIER_OFFSET); 23062b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Record.push_back(IdentifierOffsets.size()); 23072b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, 2308ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(IdentifierOffsets), 23092b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor IdentifierOffsets.size() * sizeof(uint32_t)); 2310afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor} 2311afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 23124fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 23135d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis// DeclContext's Name Lookup Table Serialization 23145d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 23155d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23165d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidisnamespace { 23175d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis// Trait used for the on-disk hash table used in the method pool. 23185d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidisclass ASTDeclContextNameLookupTrait { 23195d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ASTWriter &Writer; 23205d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23215d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidispublic: 23225d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef DeclarationName key_type; 23235d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef key_type key_type_ref; 23245d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23255d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef DeclContext::lookup_result data_type; 23265d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef const data_type& data_type_ref; 23275d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23285d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } 23295d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23305d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis unsigned ComputeHash(DeclarationName Name) { 23315d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis llvm::FoldingSetNodeID ID; 23325d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(Name.getNameKind()); 23335d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23345d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis switch (Name.getNameKind()) { 23355d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::Identifier: 23365d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddString(Name.getAsIdentifierInfo()->getName()); 23375d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23385d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 23395d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 23405d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 23415d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); 23425d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23435d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 23445d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 23455d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 23465d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(Writer.GetOrCreateTypeID(Name.getCXXNameType())); 23475d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23485d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 23495d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(Name.getCXXOverloadedOperator()); 23505d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23515d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 23525d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddString(Name.getCXXLiteralIdentifier()->getName()); 23535d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 23545d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23555d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 23565d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23575d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis return ID.ComputeHash(); 23585d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 23595d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23605d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis std::pair<unsigned,unsigned> 23615d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis EmitKeyDataLength(llvm::raw_ostream& Out, DeclarationName Name, 23625d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis data_type_ref Lookup) { 23635d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis unsigned KeyLen = 1; 23645d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis switch (Name.getNameKind()) { 23655d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::Identifier: 23665d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 23675d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 23685d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 23695d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 23705d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 23715d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 23725d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 23735d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis KeyLen += 4; 23745d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23755d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 23765d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis KeyLen += 1; 23775d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23785d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 23795d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23805d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 23815d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit16(Out, KeyLen); 23825d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23835d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis // 2 bytes for num of decls and 4 for each DeclID. 23845d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis unsigned DataLen = 2 + 4 * (Lookup.second - Lookup.first); 23855d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit16(Out, DataLen); 23865d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23875d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis return std::make_pair(KeyLen, DataLen); 23885d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 23895d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23905d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis void EmitKey(llvm::raw_ostream& Out, DeclarationName Name, unsigned) { 23915d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis using namespace clang::io; 23925d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23935d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(Name.getNameKind() < 0x100 && "Invalid name kind ?"); 23945d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit8(Out, Name.getNameKind()); 23955d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis switch (Name.getNameKind()) { 23965d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::Identifier: 23975d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); 23985d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23995d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 24005d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 24015d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 24025d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); 24035d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24045d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 24055d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 24065d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 24075d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getTypeID(Name.getCXXNameType())); 24085d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24095d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 24105d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(Name.getCXXOverloadedOperator() < 0x100 && "Invalid operator ?"); 24115d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit8(Out, Name.getCXXOverloadedOperator()); 24125d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24135d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 24145d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); 24155d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24165d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 24175d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24185d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24195d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24205d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24215d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis void EmitData(llvm::raw_ostream& Out, key_type_ref, 24225d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis data_type Lookup, unsigned DataLen) { 24235d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis uint64_t Start = Out.tell(); (void)Start; 24245d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit16(Out, Lookup.second - Lookup.first); 24255d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis for (; Lookup.first != Lookup.second; ++Lookup.first) 24265d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first)); 24275d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24285d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(Out.tell() - Start == DataLen && "Data length is wrong"); 24295d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24305d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis}; 24315d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis} // end anonymous namespace 24325d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 2433074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// \brief Write the block containing all of the declaration IDs 2434074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// visible from the given DeclContext. 2435074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// 2436074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// \returns the offset of the DECL_CONTEXT_VISIBLE block within the 24371d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// bitstream, or 0 if no block was written. 2438074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidisuint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, 2439074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis DeclContext *DC) { 2440074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (DC->getPrimaryContext() != DC) 2441074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 2442074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2443074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Since there is no name lookup into functions or methods, don't bother to 2444074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // build a visible-declarations table for these entities. 2445074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (DC->isFunctionOrMethod()) 2446074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 2447074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2448074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // If not in C++, we perform name lookup for the translation unit via the 2449074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // IdentifierInfo chains, don't bother to build a visible-declarations table. 2450074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // FIXME: In C++ we need the visible declarations in order to "see" the 2451074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // friend declarations, is there a way to do this without writing the table ? 2452074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (DC->isTranslationUnit() && !Context.getLangOptions().CPlusPlus) 2453074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 2454074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2455074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Force the DeclContext to build a its name-lookup table. 2456a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis if (DC->hasExternalVisibleStorage()) 2457a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis DC->MaterializeVisibleDeclsFromExternalStorage(); 2458a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis else 2459a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis DC->lookup(DeclarationName()); 2460074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2461074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Serialize the contents of the mapping used for lookup. Note that, 2462074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // although we have two very different code paths, the serialized 2463074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // representation is the same for both cases: a declaration name, 2464074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // followed by a size, followed by references to the visible 2465074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // declarations that have that name. 2466074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis uint64_t Offset = Stream.GetCurrentBitNo(); 2467074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); 2468074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (!Map || Map->empty()) 2469074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 2470074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2471074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; 2472074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis ASTDeclContextNameLookupTrait Trait(*this); 2473074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2474074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Create the on-disk hash table representation. 2475074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); 2476074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis D != DEnd; ++D) { 2477074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis DeclarationName Name = D->first; 2478074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis DeclContext::lookup_result Result = D->second.getLookupResult(); 2479074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Generator.insert(Name, Result, Trait); 2480074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis } 2481074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2482074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Create the on-disk hash table in a buffer. 2483074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis llvm::SmallString<4096> LookupTable; 2484074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis uint32_t BucketOffset; 2485074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis { 2486074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis llvm::raw_svector_ostream Out(LookupTable); 2487074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Make sure that no bucket is at offset 0 2488074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis clang::io::Emit32(Out, 0); 2489074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis BucketOffset = Generator.Emit(Out, Trait); 2490074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis } 2491074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2492074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Write the lookup table 2493074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis RecordData Record; 2494074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Record.push_back(DECL_CONTEXT_VISIBLE); 2495074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Record.push_back(BucketOffset); 2496074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, 2497074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis LookupTable.str()); 2498074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2499074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); 2500074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis ++NumVisibleDeclContexts; 2501074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return Offset; 2502074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis} 2503074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 25041d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// \brief Write an UPDATE_VISIBLE block for the given context. 25051d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// 25061d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// UPDATE_VISIBLE blocks contain the declarations that are added to an existing 25071d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// DeclContext in a dependent AST file. As such, they only exist for the TU 25081d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// (in C++) and for namespaces. 25091d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redlvoid ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { 25101d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); 25111d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl if (!Map || Map->empty()) 25121d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl return; 25131d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 25141d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; 25151d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl ASTDeclContextNameLookupTrait Trait(*this); 25161d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 25171d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Create the hash table. 25181d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); 25191d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl D != DEnd; ++D) { 25201d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl DeclarationName Name = D->first; 25211d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl DeclContext::lookup_result Result = D->second.getLookupResult(); 25225967d6228f183a5fa384f2f1918df679ed2d8666Sebastian Redl // For any name that appears in this table, the results are complete, i.e. 25235967d6228f183a5fa384f2f1918df679ed2d8666Sebastian Redl // they overwrite results from previous PCHs. Merging is always a mess. 25245967d6228f183a5fa384f2f1918df679ed2d8666Sebastian Redl Generator.insert(Name, Result, Trait); 25251d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl } 25261d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 25271d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Create the on-disk hash table in a buffer. 25281d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl llvm::SmallString<4096> LookupTable; 25291d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl uint32_t BucketOffset; 25301d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl { 25311d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl llvm::raw_svector_ostream Out(LookupTable); 25321d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Make sure that no bucket is at offset 0 25331d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl clang::io::Emit32(Out, 0); 25341d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl BucketOffset = Generator.Emit(Out, Trait); 25351d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl } 25361d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 25371d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Write the lookup table 25381d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl RecordData Record; 25391d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Record.push_back(UPDATE_VISIBLE); 25401d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Record.push_back(getDeclID(cast<Decl>(DC))); 25411d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Record.push_back(BucketOffset); 25421d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); 25431d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl} 25441d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 254584bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne/// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. 254684bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbournevoid ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { 254784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RecordData Record; 254884bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Record.push_back(Opts.fp_contract); 254984bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); 255084bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne} 255184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 255284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne/// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. 255384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbournevoid ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { 255484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne if (!SemaRef.Context.getLangOptions().OpenCL) 255584bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne return; 255684bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 255784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); 255884bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RecordData Record; 255984bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne#define OPENCLEXT(nm) Record.push_back(Opts.nm); 256084bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne#include "clang/Basic/OpenCLExtensions.def" 256184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Stream.EmitRecord(OPENCL_EXTENSIONS, Record); 256284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne} 256384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 25645d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 25654fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// General Serialization Routines 25664fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 25674fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 256868a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor/// \brief Write a record containing the given attributes. 256989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::WriteAttributes(const AttrVec &Attrs, RecordDataImpl &Record) { 25704eb9fc0449ddbd5239ddc3ae6b6e52880f47dcf7Argyrios Kyrtzidis Record.push_back(Attrs.size()); 2571cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt for (AttrVec::const_iterator i = Attrs.begin(), e = Attrs.end(); i != e; ++i){ 2572cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt const Attr * A = *i; 2573cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs 2574cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt AddSourceLocation(A->getLocation(), Record); 257568a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor 2576cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt#include "clang/Serialization/AttrPCHWrite.inc" 25775b160927672440076aa53c31d84149f70fd8d40eFariborz Jahanian 257868a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor } 257968a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor} 258068a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor 258189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddString(llvm::StringRef Str, RecordDataImpl &Record) { 258268a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor Record.push_back(Str.size()); 258368a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor Record.insert(Record.end(), Str.begin(), Str.end()); 258468a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor} 258568a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor 25863251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor/// \brief Note that the identifier II occurs at the given offset 25873251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor/// within the identifier table. 2588a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { 25898538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID ID = IdentifierIDs[II]; 25903397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Only store offsets new to this AST file. Other identifier names are looked 2591f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // up earlier in the chain and thus don't need an offset. 2592f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl if (ID >= FirstIdentID) 2593f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl IdentifierOffsets[ID - FirstIdentID] = Offset; 25943251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor} 25953251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 259683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor/// \brief Note that the selector Sel occurs at the given offset 259783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor/// within the method pool/selector table. 2598a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { 259983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor unsigned ID = SelectorIDs[Sel]; 260083941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor assert(ID && "Unknown selector"); 2601e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // Don't record offsets for selectors that are also available in a different 2602e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // file. 2603e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (ID < FirstSelectorID) 2604e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl return; 2605e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl SelectorOffsets[ID - FirstSelectorID] = Offset; 260683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor} 260783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor 2608a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian RedlASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) 260989d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor : Stream(Stream), Chain(0), SerializationListener(0), 261089d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor FirstDeclID(1), NextDeclID(FirstDeclID), 26118538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), 2612e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl FirstIdentID(1), NextIdentID(FirstIdentID), FirstSelectorID(1), 261377424bc3794f569816dba52e423b57486a98e5baDouglas Gregor NextSelectorID(FirstSelectorID), FirstMacroID(1), NextMacroID(FirstMacroID), 261477424bc3794f569816dba52e423b57486a98e5baDouglas Gregor CollectedStmts(&StmtsToEmit), 2615e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), 26167c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor NumVisibleDeclContexts(0), FirstCXXBaseSpecifiersID(1), 26177c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor NextCXXBaseSpecifiersID(1) 26187c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor{ 261930c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl} 26202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2621a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, 26228e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis const std::string &OutputFile, 262330c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl const char *isysroot) { 26242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Emit the file header. 2625c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'C', 8); 2626c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'P', 8); 2627c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'C', 8); 2628c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'H', 8); 26291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2630b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner WriteBlockInfoBlock(); 26312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 26321dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl if (Chain) 2633a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl WriteASTChain(SemaRef, StatCalls, isysroot); 26341dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl else 26358e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile); 26361dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl} 26371dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 2638a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, 26398e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis const char *isysroot, 26408e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis const std::string &OutputFile) { 26411dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl using namespace llvm; 26421dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 26431dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl ASTContext &Context = SemaRef.Context; 26441dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Preprocessor &PP = SemaRef.PP; 26451dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 26462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // The translation unit is the first declaration we'll emit. 26472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor DeclIDs[Context.getTranslationUnitDecl()] = 1; 2648f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl ++NextDeclID; 264961d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.push(Context.getTranslationUnitDecl()); 26502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 26512deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor // Make sure that we emit IdentifierInfos (and any attached 26522deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor // declarations) for builtins. 26532deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor { 26542deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor IdentifierTable &Table = PP.getIdentifierTable(); 26552deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor llvm::SmallVector<const char *, 32> BuiltinNames; 26562deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, 26572deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor Context.getLangOptions().NoBuiltin); 26582deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) 26592deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor getIdentifierRef(&Table.get(BuiltinNames[I])); 26602deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor } 26612deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor 266263d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner // Build a record containing all of the tentative definitions in this file, in 2663e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // TentativeDefinitions order. Generally, this record will be empty for 266463d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner // headers. 26654c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor RecordData TentativeDefinitions; 2666e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) { 2667e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions); 266863d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner } 26694c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor 267049b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Build a record containing all of the file scoped decls in this file. 267149b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis RecordData UnusedFileScopedDecls; 267249b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i) 267349b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis AddDeclRef(SemaRef.UnusedFileScopedDecls[i], UnusedFileScopedDecls); 26744056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 267572b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis RecordData WeakUndeclaredIdentifiers; 267672b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { 267772b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis WeakUndeclaredIdentifiers.push_back( 267872b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis SemaRef.WeakUndeclaredIdentifiers.size()); 267972b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis for (llvm::DenseMap<IdentifierInfo*,Sema::WeakInfo>::iterator 268072b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis I = SemaRef.WeakUndeclaredIdentifiers.begin(), 268172b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { 268272b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); 268372b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); 268472b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); 268572b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); 268672b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis } 268772b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis } 268811a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 268914c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // Build a record containing all of the locally-scoped external 269014c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // declarations in this header file. Generally, this record will be 269114c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // empty. 269214c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor RecordData LocallyScopedExternalDecls; 26933397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // FIXME: This is filling in the AST file in densemap order which is 269463d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner // nondeterminstic! 26951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator 269614c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor TD = SemaRef.LocallyScopedExternalDecls.begin(), 269714c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor TDEnd = SemaRef.LocallyScopedExternalDecls.end(); 269814c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor TD != TDEnd; ++TD) 269914c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor AddDeclRef(TD->second, LocallyScopedExternalDecls); 270014c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor 2701b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor // Build a record containing all of the ext_vector declarations. 2702b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor RecordData ExtVectorDecls; 2703b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I) 2704b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls); 2705b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor 2706d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Build a record containing all of the VTable uses information. 2707d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis RecordData VTableUses; 2708be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis if (!SemaRef.VTableUses.empty()) { 2709be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis VTableUses.push_back(SemaRef.VTableUses.size()); 2710be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { 2711be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); 2712be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); 2713be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); 2714be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis } 2715d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis } 2716d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 2717d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Build a record containing all of dynamic classes declarations. 2718d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis RecordData DynamicClasses; 2719d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis for (unsigned I = 0, N = SemaRef.DynamicClasses.size(); I != N; ++I) 2720d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis AddDeclRef(SemaRef.DynamicClasses[I], DynamicClasses); 2721d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 27220e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis // Build a record containing all of pending implicit instantiations. 272362c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth RecordData PendingInstantiations; 27240e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis for (std::deque<Sema::PendingImplicitInstantiation>::iterator 272562c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth I = SemaRef.PendingInstantiations.begin(), 272662c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth N = SemaRef.PendingInstantiations.end(); I != N; ++I) { 272762c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth AddDeclRef(I->first, PendingInstantiations); 272862c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth AddSourceLocation(I->second, PendingInstantiations); 27290e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis } 27300e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis assert(SemaRef.PendingLocalImplicitInstantiations.empty() && 27310e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis "There are local ones at end of translation unit!"); 27320e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis 273376c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis // Build a record containing some declaration references. 273476c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis RecordData SemaDeclRefs; 273576c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { 273676c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); 273776c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); 273876c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis } 273976c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis 274014b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne RecordData CUDASpecialDeclRefs; 274114b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne if (Context.getcudaConfigureCallDecl()) { 274214b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); 274314b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne } 274414b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne 27453397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Write the remaining AST contents. 2746ad1de006ea080b540e480efc6b86c2e201dbf1ecDouglas Gregor RecordData Record; 27478538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(AST_BLOCK_ID, 5); 27488e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis WriteMetadata(Context, isysroot, OutputFile); 27491dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl WriteLanguageOptions(Context.getLangOptions()); 2750e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (StatCalls && !isysroot) 2751dd41ed59cf7aefabd40bf766d8fcc7ebd759c8e5Douglas Gregor WriteStatCache(*StatCalls); 2752e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); 2753c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // Write the record of special types. 2754c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff Record.clear(); 27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2756c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getBuiltinVaListType(), Record); 2757c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getObjCIdType(), Record); 2758c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getObjCSelType(), Record); 2759c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getObjCProtoType(), Record); 2760c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getObjCClassType(), Record); 2761c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getRawCFConstantStringType(), Record); 2762c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getRawObjCFastEnumerationStateType(), Record); 2763c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getFILEType(), Record); 2764782fa308a765aeac2acb39c4e697c937ec21185bMike Stump AddTypeRef(Context.getjmp_bufType(), Record); 2765782fa308a765aeac2acb39c4e697c937ec21185bMike Stump AddTypeRef(Context.getsigjmp_bufType(), Record); 2766d1571acc700b652a52c766e36a6c688d9bf6f3a1Douglas Gregor AddTypeRef(Context.ObjCIdRedefinitionType, Record); 2767d1571acc700b652a52c766e36a6c688d9bf6f3a1Douglas Gregor AddTypeRef(Context.ObjCClassRedefinitionType, Record); 2768adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump AddTypeRef(Context.getRawBlockdescriptorType(), Record); 2769083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump AddTypeRef(Context.getRawBlockdescriptorExtendedType(), Record); 27702bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian AddTypeRef(Context.ObjCSelRedefinitionType, Record); 27712bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian AddTypeRef(Context.getRawNSConstantStringType(), Record); 2772006113841bdae1edb77aef75ba1ffdf2e55a3094Argyrios Kyrtzidis Record.push_back(Context.isInt128Installed()); 27738538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SPECIAL_TYPES, Record); 27741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2775366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor // Keep writing types and declarations until all types and 2776366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor // declarations have been written. 27778538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(DECLTYPES_BLOCK_ID, 3); 277861d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor WriteDeclsBlockAbbrevs(); 277961d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor while (!DeclTypesToEmit.empty()) { 278061d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclOrType DOT = DeclTypesToEmit.front(); 278161d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.pop(); 278261d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor if (DOT.isType()) 278361d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor WriteType(DOT.getType()); 278461d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor else 278561d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor WriteDecl(Context, DOT.getDecl()); 278661d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor } 278761d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor Stream.ExitBlock(); 278811a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 2789813a97b3eee957eac3ac1fb111b8892fb9afd0d4Douglas Gregor WritePreprocessor(PP); 2790cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); 2791059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl WriteSelectors(SemaRef); 2792320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian WriteReferencedSelectorsPool(SemaRef); 279337e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor WriteIdentifierTable(PP); 279484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteFPPragmaOptions(SemaRef.getFPOptions()); 279584bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteOpenCLExtensions(SemaRef); 27968f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor 27971476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl WriteTypeDeclOffsets(); 27983efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis WritePragmaDiagnosticMappings(Context.getDiagnostics()); 2799ad1de006ea080b540e480efc6b86c2e201dbf1ecDouglas Gregor 28007c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor // Write the C++ base-specifier set offsets. 28017c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (!CXXBaseSpecifiersOffsets.empty()) { 28027c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor // Create a blob abbreviation for the C++ base specifiers offsets. 28037c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor using namespace llvm; 28047c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 28057c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 28067c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); 28077c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size 28087c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 28097c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 28107c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 28117c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor // Write the selector offsets table. 28127c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.clear(); 28137c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); 28147c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.push_back(CXXBaseSpecifiersOffsets.size()); 28157c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, 28167c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor (const char *)CXXBaseSpecifiersOffsets.data(), 28177c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets.size() * sizeof(uint32_t)); 28187c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor } 28197c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 28204c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor // Write the record containing external, unnamed definitions. 2821fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor if (!ExternalDefinitions.empty()) 28228538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); 28234c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor 28244c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor // Write the record containing tentative definitions. 28254c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor if (!TentativeDefinitions.empty()) 28268538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); 282714c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor 282849b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Write the record containing unused file scoped decls. 282949b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis if (!UnusedFileScopedDecls.empty()) 28308538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); 283111a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 283272b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis // Write the record containing weak undeclared identifiers. 283372b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis if (!WeakUndeclaredIdentifiers.empty()) 28348538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, 283572b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis WeakUndeclaredIdentifiers); 283672b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis 283714c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // Write the record containing locally-scoped external definitions. 283814c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor if (!LocallyScopedExternalDecls.empty()) 28398538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, 284014c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor LocallyScopedExternalDecls); 2841b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor 2842b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor // Write the record containing ext_vector type names. 2843b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor if (!ExtVectorDecls.empty()) 28448538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); 28451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2846d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Write the record containing VTable uses information. 2847d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis if (!VTableUses.empty()) 28488538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(VTABLE_USES, VTableUses); 2849d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 2850d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Write the record containing dynamic classes declarations. 2851d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis if (!DynamicClasses.empty()) 28528538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); 2853d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 28540e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis // Write the record containing pending implicit instantiations. 285562c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth if (!PendingInstantiations.empty()) 285662c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); 28570e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis 285876c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis // Write the record containing declaration references of Sema. 285976c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis if (!SemaDeclRefs.empty()) 28608538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); 286176c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis 286214b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne // Write the record containing CUDA-specific declaration references. 286314b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne if (!CUDASpecialDeclRefs.empty()) 286414b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); 286514b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne 28663e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor // Some simple statistics 2867ad1de006ea080b540e480efc6b86c2e201dbf1ecDouglas Gregor Record.clear(); 28683e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor Record.push_back(NumStatements); 286937e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor Record.push_back(NumMacros); 28702512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor Record.push_back(NumLexicalDeclContexts); 28712512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor Record.push_back(NumVisibleDeclContexts); 28728538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(STATISTICS, Record); 2873c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.ExitBlock(); 28742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 28752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2876a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls, 287730c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl const char *isysroot) { 28781dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl using namespace llvm; 28791dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 28801dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl ASTContext &Context = SemaRef.Context; 28811dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Preprocessor &PP = SemaRef.PP; 28821476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 28831dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl RecordData Record; 28848538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(AST_BLOCK_ID, 5); 28858e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis WriteMetadata(Context, isysroot, ""); 28861476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl if (StatCalls && !isysroot) 28871476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl WriteStatCache(*StatCalls); 28881476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // FIXME: Source manager block should only write new stuff, which could be 28891476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // done by tracking the largest ID in the chain 28901476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); 28911dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 28921dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl // The special types are in the chained PCH. 28931dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 28941dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl // We don't start with the translation unit, but with its decls that 28953c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // don't come from the chained PCH. 28961dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); 2897eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis llvm::SmallVector<KindDeclIDPair, 64> NewGlobalDecls; 2898681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl for (DeclContext::decl_iterator I = TU->noload_decls_begin(), 2899681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl E = TU->noload_decls_end(); 29001dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl I != E; ++I) { 2901d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl if ((*I)->getPCHLevel() == 0) 2902eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); 29030b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl else if ((*I)->isChangedSinceDeserialization()) 29040b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl (void)GetDeclRef(*I); // Make sure it's written, but don't record it. 29051dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl } 2906681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl // We also need to write a lexical updates block for the TU. 2907d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); 29088538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); 2909d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); 2910d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); 2911d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl Record.clear(); 29128538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(TU_UPDATE_LEXICAL); 2913d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, 2914d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl reinterpret_cast<const char*>(NewGlobalDecls.data()), 2915eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis NewGlobalDecls.size() * sizeof(KindDeclIDPair)); 2916100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis // And a visible updates block for the DeclContexts. 2917100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv = new llvm::BitCodeAbbrev(); 2918100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); 2919100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); 2920100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); 2921100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); 2922100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); 2923100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis WriteDeclContextVisibleUpdate(TU); 29241dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 2925083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Build a record containing all of the new tentative definitions in this 2926083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // file, in TentativeDefinitions order. 2927083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl RecordData TentativeDefinitions; 2928083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) { 2929083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (SemaRef.TentativeDefinitions[i]->getPCHLevel() == 0) 2930083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions); 2931083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl } 2932083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 293349b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Build a record containing all of the file scoped decls in this file. 293449b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis RecordData UnusedFileScopedDecls; 293549b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i) { 293649b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis if (SemaRef.UnusedFileScopedDecls[i]->getPCHLevel() == 0) 293749b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis AddDeclRef(SemaRef.UnusedFileScopedDecls[i], UnusedFileScopedDecls); 2938083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl } 2939083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 29404056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // We write the entire table, overwriting the tables from the chain. 29414056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl RecordData WeakUndeclaredIdentifiers; 29424056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { 29434056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl WeakUndeclaredIdentifiers.push_back( 29444056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl SemaRef.WeakUndeclaredIdentifiers.size()); 29454056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl for (llvm::DenseMap<IdentifierInfo*,Sema::WeakInfo>::iterator 29464056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl I = SemaRef.WeakUndeclaredIdentifiers.begin(), 29474056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { 29484056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); 29494056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); 29504056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); 29514056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); 29524056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 29534056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 29544056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 2955083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Build a record containing all of the locally-scoped external 2956083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // declarations in this header file. Generally, this record will be 2957083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // empty. 2958083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl RecordData LocallyScopedExternalDecls; 29593397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // FIXME: This is filling in the AST file in densemap order which is 2960083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // nondeterminstic! 2961083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator 2962083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl TD = SemaRef.LocallyScopedExternalDecls.begin(), 2963083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl TDEnd = SemaRef.LocallyScopedExternalDecls.end(); 2964083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl TD != TDEnd; ++TD) { 2965083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (TD->second->getPCHLevel() == 0) 2966083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl AddDeclRef(TD->second, LocallyScopedExternalDecls); 2967083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl } 2968083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 2969083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Build a record containing all of the ext_vector declarations. 2970083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl RecordData ExtVectorDecls; 2971083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I) { 2972083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (SemaRef.ExtVectorDecls[I]->getPCHLevel() == 0) 2973083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls); 2974083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl } 2975083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 29764056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Build a record containing all of the VTable uses information. 29774056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // We write everything here, because it's too hard to determine whether 29784056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // a use is new to this part. 29794056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl RecordData VTableUses; 29804056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!SemaRef.VTableUses.empty()) { 29814056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl VTableUses.push_back(SemaRef.VTableUses.size()); 29824056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { 29834056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); 29844056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); 29854056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); 29864056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 29874056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 29884056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 29894056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Build a record containing all of dynamic classes declarations. 29904056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl RecordData DynamicClasses; 29914056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl for (unsigned I = 0, N = SemaRef.DynamicClasses.size(); I != N; ++I) 29924056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (SemaRef.DynamicClasses[I]->getPCHLevel() == 0) 29934056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddDeclRef(SemaRef.DynamicClasses[I], DynamicClasses); 29944056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 29954056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Build a record containing all of pending implicit instantiations. 299662c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth RecordData PendingInstantiations; 29974056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl for (std::deque<Sema::PendingImplicitInstantiation>::iterator 299862c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth I = SemaRef.PendingInstantiations.begin(), 299962c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth N = SemaRef.PendingInstantiations.end(); I != N; ++I) { 30004056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (I->first->getPCHLevel() == 0) { 300162c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth AddDeclRef(I->first, PendingInstantiations); 300262c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth AddSourceLocation(I->second, PendingInstantiations); 30034056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 30044056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 30054056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl assert(SemaRef.PendingLocalImplicitInstantiations.empty() && 30064056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl "There are local ones at end of translation unit!"); 30074056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 30084056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Build a record containing some declaration references. 30094056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // It's not worth the effort to avoid duplication here. 30104056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl RecordData SemaDeclRefs; 30114056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { 30124056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); 30134056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); 30144056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 30154056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 30168538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(DECLTYPES_BLOCK_ID, 3); 30171dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl WriteDeclsBlockAbbrevs(); 3018d3d0755a4220d3fa6c125eb3f8ce29fc1424eac3Argyrios Kyrtzidis for (DeclsToRewriteTy::iterator 3019d3d0755a4220d3fa6c125eb3f8ce29fc1424eac3Argyrios Kyrtzidis I = DeclsToRewrite.begin(), E = DeclsToRewrite.end(); I != E; ++I) 3020d3d0755a4220d3fa6c125eb3f8ce29fc1424eac3Argyrios Kyrtzidis DeclTypesToEmit.push(const_cast<Decl*>(*I)); 30211dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl while (!DeclTypesToEmit.empty()) { 30221dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl DeclOrType DOT = DeclTypesToEmit.front(); 30231dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl DeclTypesToEmit.pop(); 30241dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl if (DOT.isType()) 30251dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl WriteType(DOT.getType()); 30261dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl else 30271dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl WriteDecl(Context, DOT.getDecl()); 30281dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl } 30291dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Stream.ExitBlock(); 30301dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 3031083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl WritePreprocessor(PP); 3032a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl WriteSelectors(SemaRef); 3033a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl WriteReferencedSelectorsPool(SemaRef); 3034f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl WriteIdentifierTable(PP); 303584bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteFPPragmaOptions(SemaRef.getFPOptions()); 303684bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteOpenCLExtensions(SemaRef); 303784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 30381476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl WriteTypeDeclOffsets(); 3039f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis // FIXME: For chained PCH only write the new mappings (we currently 3040f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis // write all of them again). 30413efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis WritePragmaDiagnosticMappings(Context.getDiagnostics()); 3042083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3043a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis /// Build a record containing first declarations from a chained PCH and the 30443397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl /// most recent declarations in this AST that they point to. 3045a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis RecordData FirstLatestDeclIDs; 3046a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis for (FirstLatestDeclMap::iterator 3047a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis I = FirstLatestDecls.begin(), E = FirstLatestDecls.end(); I != E; ++I) { 3048a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis assert(I->first->getPCHLevel() > I->second->getPCHLevel() && 3049a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis "Expected first & second to be in different PCHs"); 3050a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis AddDeclRef(I->first, FirstLatestDeclIDs); 3051a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis AddDeclRef(I->second, FirstLatestDeclIDs); 3052a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis } 3053a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis if (!FirstLatestDeclIDs.empty()) 30548538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(REDECLS_UPDATE_LATEST, FirstLatestDeclIDs); 3055a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis 3056083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing external, unnamed definitions. 3057083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!ExternalDefinitions.empty()) 30588538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); 3059083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3060083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing tentative definitions. 3061083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!TentativeDefinitions.empty()) 30628538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); 3063083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 306449b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Write the record containing unused file scoped decls. 306549b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis if (!UnusedFileScopedDecls.empty()) 30668538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); 3067083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 30684056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing weak undeclared identifiers. 30694056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!WeakUndeclaredIdentifiers.empty()) 30708538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, 30714056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl WeakUndeclaredIdentifiers); 30724056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 3073083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing locally-scoped external definitions. 3074083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!LocallyScopedExternalDecls.empty()) 30758538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, 3076083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl LocallyScopedExternalDecls); 3077083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3078083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing ext_vector type names. 3079083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!ExtVectorDecls.empty()) 30808538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); 3081083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 30824056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing VTable uses information. 30834056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!VTableUses.empty()) 30848538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(VTABLE_USES, VTableUses); 30854056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 30864056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing dynamic classes declarations. 30874056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!DynamicClasses.empty()) 30888538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); 30894056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 30904056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing pending implicit instantiations. 309162c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth if (!PendingInstantiations.empty()) 309262c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); 30934056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 30944056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing declaration references of Sema. 30954056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!SemaDeclRefs.empty()) 30968538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); 3097083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3098100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis // Write the updates to DeclContexts. 3099100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator 3100100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis I = UpdatedDeclContexts.begin(), 3101100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis E = UpdatedDeclContexts.end(); 31021d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl I != E; ++I) 31031d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl WriteDeclContextVisibleUpdate(*I); 31041d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 3105aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidis WriteDeclUpdatesBlocks(); 31067b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 3107083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.clear(); 3108083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumStatements); 3109083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumMacros); 3110083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumLexicalDeclContexts); 3111083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumVisibleDeclContexts); 3112aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidis WriteDeclReplacementsBlock(); 31138538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(STATISTICS, Record); 31141dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Stream.ExitBlock(); 31151dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl} 31161dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 3117aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidisvoid ASTWriter::WriteDeclUpdatesBlocks() { 31187b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis if (DeclUpdates.empty()) 31197b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis return; 31207b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 31217b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis RecordData OffsetsRecord; 31227b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, 3); 31237b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis for (DeclUpdateMap::iterator 31247b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { 31257b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis const Decl *D = I->first; 31267b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis UpdateRecord &URec = I->second; 31277b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 3128ba901b507fc36408fe6f8478e8ac90b554f1d230Argyrios Kyrtzidis if (DeclsToRewrite.count(D)) 3129ba901b507fc36408fe6f8478e8ac90b554f1d230Argyrios Kyrtzidis continue; // The decl will be written completely,no need to store updates. 3130ba901b507fc36408fe6f8478e8ac90b554f1d230Argyrios Kyrtzidis 31317b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis uint64_t Offset = Stream.GetCurrentBitNo(); 31327b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.EmitRecord(DECL_UPDATES, URec); 31337b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 31347b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis OffsetsRecord.push_back(GetDeclRef(D)); 31357b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis OffsetsRecord.push_back(Offset); 31367b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis } 31377b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.ExitBlock(); 31387b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); 31397b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis} 31407b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 3141aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidisvoid ASTWriter::WriteDeclReplacementsBlock() { 31420b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl if (ReplacedDecls.empty()) 31430b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl return; 31440b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 31450b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl RecordData Record; 31468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl for (llvm::SmallVector<std::pair<DeclID, uint64_t>, 16>::iterator 31470b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { 31480b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl Record.push_back(I->first); 31490b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl Record.push_back(I->second); 31500b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl } 31518538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(DECL_REPLACEMENTS, Record); 31520b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl} 31530b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 315489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { 31552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Loc.getRawEncoding()); 31562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 31572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 315889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { 31596ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddSourceLocation(Range.getBegin(), Record); 31606ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddSourceLocation(Range.getEnd(), Record); 31616ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner} 31626ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 316389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { 31642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Value.getBitWidth()); 31654ea884b429445aa6f1af5bc6e51d0b65a4043e24Benjamin Kramer const uint64_t *Words = Value.getRawData(); 31664ea884b429445aa6f1af5bc6e51d0b65a4043e24Benjamin Kramer Record.append(Words, Words + Value.getNumWords()); 31672cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 31682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 316989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { 31700a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor Record.push_back(Value.isUnsigned()); 31710a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor AddAPInt(Value, Record); 31720a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor} 31730a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor 317489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { 317517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor AddAPInt(Value.bitcastToAPInt(), Record); 317617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor} 317717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 317889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { 31792deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor Record.push_back(getIdentifierRef(II)); 31802deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor} 31812deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor 31828538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlIdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { 31832deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor if (II == 0) 31842deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor return 0; 3185afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 31868538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID &ID = IdentifierIDs[II]; 3187afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor if (ID == 0) 3188f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl ID = NextIdentID++; 31892deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor return ID; 31902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 31912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3192f73c93fea0d4b447585bc7459499ba6b822e045cSebastian RedlMacroID ASTWriter::getMacroDefinitionID(MacroDefinition *MD) { 31936a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor if (MD == 0) 31946a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor return 0; 3195f73c93fea0d4b447585bc7459499ba6b822e045cSebastian Redl 3196f73c93fea0d4b447585bc7459499ba6b822e045cSebastian Redl MacroID &ID = MacroDefinitions[MD]; 31976a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor if (ID == 0) 319877424bc3794f569816dba52e423b57486a98e5baDouglas Gregor ID = NextMacroID++; 31996a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor return ID; 32006a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor} 32016a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor 320289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { 32035d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Record.push_back(getSelectorRef(SelRef)); 32045d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl} 32055d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl 32068538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlSelectorID ASTWriter::getSelectorRef(Selector Sel) { 32075d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl if (Sel.getAsOpaquePtr() == 0) { 32085d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl return 0; 320990cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff } 321090cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff 32118538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl SelectorID &SID = SelectorIDs[Sel]; 3212e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (SID == 0 && Chain) { 3213e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // This might trigger a ReadSelector callback, which will set the ID for 3214e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // this selector. 3215e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl Chain->LoadSelector(Sel); 3216e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 321790cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff if (SID == 0) { 3218e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl SID = NextSelectorID++; 321990cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff } 32205d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl return SID; 322190cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff} 322290cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff 322389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { 3224d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner AddDeclRef(Temp->getDestructor(), Record); 3225d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner} 3226d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner 32277c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregorvoid ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, 32287c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifier const *BasesEnd, 32297c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor RecordDataImpl &Record) { 32307c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); 32317c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersToWrite.push_back( 32327c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, 32337c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Bases, BasesEnd)); 32347c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.push_back(NextCXXBaseSpecifiersID++); 32357c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor} 32367c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 3237a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, 323844f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis const TemplateArgumentLocInfo &Arg, 323989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 324044f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis switch (Kind) { 3241833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 324244f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddStmt(Arg.getAsExpr()); 3243833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 3244833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 324544f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); 3246833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 3247788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 324817cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis AddSourceRange(Arg.getTemplateQualifierRange(), Record); 324917cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis AddSourceLocation(Arg.getTemplateNameLoc(), Record); 3250a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 3251a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 3252a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor AddSourceRange(Arg.getTemplateQualifierRange(), Record); 3253a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor AddSourceLocation(Arg.getTemplateNameLoc(), Record); 3254ba68eca7582a62e3e2ff4b0eba1b2b73a6b80895Douglas Gregor AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); 3255788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor break; 3256833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 3257833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 3258833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 3259833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 3260833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 3261833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 3262833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 3263833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3264a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, 326589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 326644f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddTemplateArgument(Arg.getArgument(), Record); 326717cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis 326817cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis if (Arg.getArgument().getKind() == TemplateArgument::Expression) { 326917cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis bool InfoHasSameExpr 327017cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); 327117cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis Record.push_back(InfoHasSameExpr); 327217cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis if (InfoHasSameExpr) 327317cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis return; // Avoid storing the same expr twice. 327417cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis } 327544f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), 327644f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis Record); 327744f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis} 327844f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis 327989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, RecordDataImpl &Record) { 3280a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall if (TInfo == 0) { 3281a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall AddTypeRef(QualType(), Record); 3282a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall return; 3283a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall } 3284a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 3285a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall AddTypeRef(TInfo->getType(), Record); 3286a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall TypeLocWriter TLW(*this, Record); 3287a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) 328811a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam TLW.Visit(TL); 3289a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 3290a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 329189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { 32927fb35182f43392cea4517c203bbabb22364a19fcArgyrios Kyrtzidis Record.push_back(GetOrCreateTypeID(T)); 32937fb35182f43392cea4517c203bbabb22364a19fcArgyrios Kyrtzidis} 32947fb35182f43392cea4517c203bbabb22364a19fcArgyrios Kyrtzidis 32957fb35182f43392cea4517c203bbabb22364a19fcArgyrios KyrtzidisTypeID ASTWriter::GetOrCreateTypeID(QualType T) { 3296eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis return MakeTypeID(T, 3297eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); 3298eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis} 32992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33005d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios KyrtzidisTypeID ASTWriter::getTypeID(QualType T) const { 3301eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis return MakeTypeID(T, 3302eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); 330326fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis} 330426fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis 330526fca90786af17f97e1a5ecc310d4bf39b831595Argyrios KyrtzidisTypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { 330626fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis if (T.isNull()) 330726fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis return TypeIdx(); 330826fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis assert(!T.getLocalFastQualifiers()); 330926fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis 331001b81c4d074bba9c18372d521405dfe32fc4f552Argyrios Kyrtzidis TypeIdx &Idx = TypeIdxs[T]; 3311c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis if (Idx.getIndex() == 0) { 3312366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor // We haven't seen this type before. Assign it a new ID and put it 33130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into the queue of types to emit. 3314c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis Idx = TypeIdx(NextTypeID++); 331561d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.push(T); 3316366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor } 331726fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis return Idx; 331826fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis} 33192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33205d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios KyrtzidisTypeIdx ASTWriter::getTypeIdx(QualType T) const { 332126fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis if (T.isNull()) 332226fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis return TypeIdx(); 332326fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis assert(!T.getLocalFastQualifiers()); 332426fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis 33255d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis TypeIdxMap::const_iterator I = TypeIdxs.find(T); 33265d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(I != TypeIdxs.end() && "Type not emitted!"); 33275d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis return I->second; 33282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 33292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33307b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisvoid ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { 3331681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl Record.push_back(GetDeclRef(D)); 3332681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl} 3333681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl 33348538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlDeclID ASTWriter::GetDeclRef(const Decl *D) { 33352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor if (D == 0) { 3336681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl return 0; 33372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 333897475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); 33398538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl DeclID &ID = DeclIDs[D]; 33401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (ID == 0) { 33412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // We haven't seen this declaration before. Give it a new ID and 33422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // enqueue it in the list of declarations to emit. 3343f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl ID = NextDeclID++; 334461d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.push(const_cast<Decl *>(D)); 33450b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl } else if (ID < FirstDeclID && D->isChangedSinceDeserialization()) { 33460b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl // We don't add it to the replacement collection here, because we don't 33470b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl // have the offset yet. 33480b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl DeclTypesToEmit.push(const_cast<Decl *>(D)); 33490b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl // Reset the flag, so that we don't add this decl multiple times. 33500b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl const_cast<Decl *>(D)->setChangedSinceDeserialization(false); 33512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 33522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3353681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl return ID; 33542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 33552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33568538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlDeclID ASTWriter::getDeclID(const Decl *D) { 33573251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor if (D == 0) 33583251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor return 0; 33593251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 33603251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); 33613251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor return DeclIDs[D]; 33623251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor} 33633251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 336489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { 3365ea5ce4705df0743093925585d8edc80e0d8fe3ffChris Lattner // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. 33662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Name.getNameKind()); 33672cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor switch (Name.getNameKind()) { 33682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::Identifier: 33692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor AddIdentifierRef(Name.getAsIdentifierInfo(), Record); 33702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 33712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 33732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::ObjCOneArgSelector: 33742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 337590cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff AddSelectorRef(Name.getObjCSelector(), Record); 33762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 33772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXConstructorName: 33792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXDestructorName: 33802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXConversionFunctionName: 33812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor AddTypeRef(Name.getCXXNameType(), Record); 33822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 33832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXOperatorName: 33852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Name.getCXXOverloadedOperator()); 33862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 33872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33883e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 33893e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); 33903e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt break; 33913e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 33922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXUsingDirective: 33932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // No extra data to emit 33942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 33952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 33962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 33976ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 33984045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidisvoid ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, 339989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis DeclarationName Name, RecordDataImpl &Record) { 34004045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis switch (Name.getNameKind()) { 34014045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 34024045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 34034045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 34044045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); 34054045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 34064045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34074045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 34084045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation( 34094045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), 34104045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record); 34114045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation( 34124045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), 34134045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record); 34144045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 34154045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34164045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 34174045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation( 34184045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), 34194045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record); 34204045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 34214045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34224045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::Identifier: 34234045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 34244045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 34254045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 34264045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 34274045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 34284045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis } 34294045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis} 34304045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34314045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidisvoid ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 343289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 34334045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddDeclarationName(NameInfo.getName(), Record); 34344045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation(NameInfo.getLoc(), Record); 34354045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); 34364045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis} 34374045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34384045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidisvoid ASTWriter::AddQualifierInfo(const QualifierInfo &Info, 343989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 34404045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddNestedNameSpecifier(Info.NNS, Record); 34414045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceRange(Info.NNSRange, Record); 34424045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record.push_back(Info.NumTemplParamLists); 34434045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) 34444045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddTemplateParameterList(Info.TemplParamLists[i], Record); 34454045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis} 34464045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 3447a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, 344889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 34496ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // Nested name specifiers usually aren't too long. I think that 8 would 34506ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // typically accomodate the vast majority. 34516ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner llvm::SmallVector<NestedNameSpecifier *, 8> NestedNames; 34526ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 34536ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // Push each of the NNS's onto a stack for serialization in reverse order. 34546ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner while (NNS) { 34556ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NestedNames.push_back(NNS); 34566ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NNS = NNS->getPrefix(); 34576ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner } 34586ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 34596ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner Record.push_back(NestedNames.size()); 34606ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner while(!NestedNames.empty()) { 34616ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NNS = NestedNames.pop_back_val(); 34626ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); 34636ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner Record.push_back(Kind); 34646ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner switch (Kind) { 34656ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::Identifier: 34666ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddIdentifierRef(NNS->getAsIdentifier(), Record); 34676ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 34686ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 34696ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::Namespace: 34706ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddDeclRef(NNS->getAsNamespace(), Record); 34716ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 34726ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 34736ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::TypeSpec: 34746ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::TypeSpecWithTemplate: 34756ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddTypeRef(QualType(NNS->getAsType(), 0), Record); 34766ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); 34776ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 34786ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 34796ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::Global: 34806ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // Don't need to write an associated value. 34816ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 34826ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner } 34836ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner } 34846ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner} 348590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 348689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { 348720249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer TemplateName::NameKind Kind = Name.getKind(); 348890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(Kind); 348990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis switch (Kind) { 349090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::Template: 349190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(Name.getAsTemplateDecl(), Record); 349290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 349390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 349490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::OverloadedTemplate: { 349590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); 349690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(OvT->size()); 349790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); 349890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis I != E; ++I) 349990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(*I, Record); 350090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 350190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 350220249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 350390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::QualifiedTemplate: { 350490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); 350590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddNestedNameSpecifier(QualT->getQualifier(), Record); 350690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(QualT->hasTemplateKeyword()); 350790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(QualT->getTemplateDecl(), Record); 350890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 350990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 351020249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 351190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::DependentTemplate: { 351290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis DependentTemplateName *DepT = Name.getAsDependentTemplateName(); 351390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddNestedNameSpecifier(DepT->getQualifier(), Record); 351490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(DepT->isIdentifier()); 351590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis if (DepT->isIdentifier()) 351690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddIdentifierRef(DepT->getIdentifier(), Record); 351790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis else 351890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(DepT->getOperator()); 351990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 352090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 35211aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 35221aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor case TemplateName::SubstTemplateTemplateParmPack: { 35231aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPackStorage *SubstPack 35241aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack(); 35251aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor AddDeclRef(SubstPack->getParameterPack(), Record); 35261aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor AddTemplateArgument(SubstPack->getArgumentPack(), Record); 35271aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor break; 35281aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 352990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 353090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 353190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 353220249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencervoid ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, 353389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 353490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(Arg.getKind()); 353590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis switch (Arg.getKind()) { 353690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Null: 353790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 353890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Type: 353990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddTypeRef(Arg.getAsType(), Record); 354090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 354190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Declaration: 354290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(Arg.getAsDecl(), Record); 354390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 354490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Integral: 354590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddAPSInt(*Arg.getAsIntegral(), Record); 354690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddTypeRef(Arg.getIntegralType(), Record); 354790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 354890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Template: 35492be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); 35502be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor break; 3551a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 3552a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); 35532be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) 35542be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor Record.push_back(*NumExpansions + 1); 35552be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor else 35562be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor Record.push_back(0); 355790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 355890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Expression: 355990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddStmt(Arg.getAsExpr()); 356090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 356190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Pack: 356290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(Arg.pack_size()); 356390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); 356490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis I != E; ++I) 356590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddTemplateArgument(*I, Record); 356690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 356790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 356890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 3569dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis 3570dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidisvoid 3571a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian RedlASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, 357289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 3573dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis assert(TemplateParams && "No TemplateParams!"); 3574dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddSourceLocation(TemplateParams->getTemplateLoc(), Record); 3575dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddSourceLocation(TemplateParams->getLAngleLoc(), Record); 3576dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddSourceLocation(TemplateParams->getRAngleLoc(), Record); 3577dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis Record.push_back(TemplateParams->size()); 3578dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis for (TemplateParameterList::const_iterator 3579dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis P = TemplateParams->begin(), PEnd = TemplateParams->end(); 3580dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis P != PEnd; ++P) 3581dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddDeclRef(*P, Record); 3582dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis} 3583dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis 3584dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis/// \brief Emit a template argument list. 3585dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidisvoid 3586a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian RedlASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, 358789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 3588dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis assert(TemplateArgs && "No TemplateArgs!"); 3589910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Record.push_back(TemplateArgs->size()); 3590910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor for (int i=0, e = TemplateArgs->size(); i != e; ++i) 3591dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddTemplateArgument(TemplateArgs->get(i), Record); 3592dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis} 359337ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis 359437ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis 359537ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidisvoid 359689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios KyrtzidisASTWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record) { 359737ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis Record.push_back(Set.size()); 359837ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis for (UnresolvedSetImpl::const_iterator 359937ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis I = Set.begin(), E = Set.end(); I != E; ++I) { 360037ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis AddDeclRef(I.getDecl(), Record); 360137ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis Record.push_back(I.getAccess()); 360237ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis } 360337ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis} 36040745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis 3605a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, 360689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 36070745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis Record.push_back(Base.isVirtual()); 36080745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis Record.push_back(Base.isBaseOfClass()); 36090745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis Record.push_back(Base.getAccessSpecifierAsWritten()); 3610f677ea3cc9598d9952ad7ffab5fb322ba4c5be31Sebastian Redl Record.push_back(Base.getInheritConstructors()); 36115606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); 36120745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis AddSourceRange(Base.getSourceRange(), Record); 3613f90b27ad077c3339b62befc892382845339f9490Douglas Gregor AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() 3614f90b27ad077c3339b62befc892382845339f9490Douglas Gregor : SourceLocation(), 3615f90b27ad077c3339b62befc892382845339f9490Douglas Gregor Record); 36160745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis} 361730c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl 36187c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregorvoid ASTWriter::FlushCXXBaseSpecifiers() { 36197c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor RecordData Record; 36207c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { 36217c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.clear(); 36227c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 36237c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor // Record the offset of this base-specifier set. 36247c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor unsigned Index = CXXBaseSpecifiersToWrite[I].ID - FirstCXXBaseSpecifiersID; 36257c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Index == CXXBaseSpecifiersOffsets.size()) 36267c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); 36277c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor else { 36287c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Index > CXXBaseSpecifiersOffsets.size()) 36297c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets.resize(Index + 1); 36307c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); 36317c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor } 36327c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 36337c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, 36347c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; 36357c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.push_back(BEnd - B); 36367c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor for (; B != BEnd; ++B) 36377c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor AddCXXBaseSpecifier(*B, Record); 36387c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); 3639acec34bda4a765fd05ed10e5aa83bc93dac072c1Douglas Gregor 3640acec34bda4a765fd05ed10e5aa83bc93dac072c1Douglas Gregor // Flush any expressions that were written as part of the base specifiers. 3641acec34bda4a765fd05ed10e5aa83bc93dac072c1Douglas Gregor FlushStmts(); 36427c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor } 36437c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 36447c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersToWrite.clear(); 36457c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor} 36467c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 3647cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntvoid ASTWriter::AddCXXCtorInitializers( 3648cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt const CXXCtorInitializer * const *CtorInitializers, 3649cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt unsigned NumCtorInitializers, 3650cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt RecordDataImpl &Record) { 3651cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt Record.push_back(NumCtorInitializers); 3652cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt for (unsigned i=0; i != NumCtorInitializers; ++i) { 3653cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt const CXXCtorInitializer *Init = CtorInitializers[i]; 36548e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis 36558e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->isBaseInitializer()); 36568e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis if (Init->isBaseInitializer()) { 36578e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddTypeSourceInfo(Init->getBaseClassInfo(), Record); 36588e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->isBaseVirtual()); 36598e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } else { 366000eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet Record.push_back(Init->isIndirectMemberInitializer()); 366100eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet if (Init->isIndirectMemberInitializer()) 366200eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet AddDeclRef(Init->getIndirectMember(), Record); 366300eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet else 366400eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet AddDeclRef(Init->getMember(), Record); 36658e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } 366600eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet 36678e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddSourceLocation(Init->getMemberLocation(), Record); 36688e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddStmt(Init->getInit()); 36698e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddSourceLocation(Init->getLParenLoc(), Record); 36708e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddSourceLocation(Init->getRParenLoc(), Record); 36718e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->isWritten()); 36728e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis if (Init->isWritten()) { 36738e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->getSourceOrder()); 36748e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } else { 36758e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->getNumArrayIndices()); 36768e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) 36778e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddDeclRef(Init->getArrayIndex(i), Record); 36788e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } 36798e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } 36808e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis} 36818e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis 368289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { 368389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis assert(D->DefinitionData); 368489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; 368589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredConstructor); 368689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredCopyConstructor); 368789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredCopyAssignment); 368889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredDestructor); 368989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Aggregate); 369089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.PlainOldData); 369189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Empty); 369289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Polymorphic); 369389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Abstract); 369489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialConstructor); 369589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialCopyConstructor); 369689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialCopyAssignment); 369789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialDestructor); 369889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.ComputedVisibleConversions); 369989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredDefaultConstructor); 370089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredCopyConstructor); 370189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredCopyAssignment); 370289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredDestructor); 370389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis 370489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.NumBases); 37057c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Data.NumBases > 0) 37067c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, 37077c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record); 37087c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 370989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis // FIXME: Make VBases lazily computed when needed to avoid storing them. 371089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.NumVBases); 37117c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Data.NumVBases > 0) 37127c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, 37137c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record); 371489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis 371589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis AddUnresolvedSet(Data.Conversions, Record); 371689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis AddUnresolvedSet(Data.VisibleConversions, Record); 371789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis // Data.Definition is the owning decl, no need to write it. 371889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis AddDeclRef(Data.FirstFriend, Record); 371989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis} 372089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis 37217b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisvoid ASTWriter::ReaderInitialized(ASTReader *Reader) { 3722ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl assert(Reader && "Cannot remove chain"); 37237b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis assert(!Chain && "Cannot replace chain"); 3724ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl assert(FirstDeclID == NextDeclID && 3725ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl FirstTypeID == NextTypeID && 3726ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl FirstIdentID == NextIdentID && 3727e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl FirstSelectorID == NextSelectorID && 372877424bc3794f569816dba52e423b57486a98e5baDouglas Gregor FirstMacroID == NextMacroID && 37297c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor FirstCXXBaseSpecifiersID == NextCXXBaseSpecifiersID && 3730ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl "Setting chain after writing has started."); 3731ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl Chain = Reader; 37327b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 37337b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstDeclID += Chain->getTotalNumDecls(); 37347b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstTypeID += Chain->getTotalNumTypes(); 37357b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstIdentID += Chain->getTotalNumIdentifiers(); 37367b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstSelectorID += Chain->getTotalNumSelectors(); 37377b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstMacroID += Chain->getTotalNumMacroDefinitions(); 37387c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor FirstCXXBaseSpecifiersID += Chain->getTotalNumCXXBaseSpecifiers(); 37397b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextDeclID = FirstDeclID; 37407b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextTypeID = FirstTypeID; 37417b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextIdentID = FirstIdentID; 37427b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextSelectorID = FirstSelectorID; 37437b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextMacroID = FirstMacroID; 37447c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor NextCXXBaseSpecifiersID = FirstCXXBaseSpecifiersID; 3745ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl} 3746ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl 37478538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { 3748f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl IdentifierIDs[II] = ID; 3749040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor if (II->hasMacroDefinition()) 3750040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor DeserializedMacroNames.push_back(II); 3751f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl} 3752f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl 3753c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidisvoid ASTWriter::TypeRead(TypeIdx Idx, QualType T) { 375497475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // Always take the highest-numbered type index. This copes with an interesting 375597475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // case for chained AST writing where we schedule writing the type and then, 375620249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer // later, deserialize the type from another AST. In this case, we want to 375797475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // keep the higher-numbered entry so that we can properly write it out to 375897475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // the AST file. 375997475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor TypeIdx &StoredIdx = TypeIdxs[T]; 376097475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor if (Idx.getIndex() >= StoredIdx.getIndex()) 376197475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor StoredIdx = Idx; 376230c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl} 376330c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl 37648538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ASTWriter::DeclRead(DeclID ID, const Decl *D) { 37651476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl DeclIDs[D] = ID; 376630c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl} 37675d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl 37688538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ASTWriter::SelectorRead(SelectorID ID, Selector S) { 37695d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl SelectorIDs[S] = ID; 37705d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl} 377177424bc3794f569816dba52e423b57486a98e5baDouglas Gregor 377220249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencervoid ASTWriter::MacroDefinitionRead(serialization::MacroID ID, 377377424bc3794f569816dba52e423b57486a98e5baDouglas Gregor MacroDefinition *MD) { 377477424bc3794f569816dba52e423b57486a98e5baDouglas Gregor MacroDefinitions[MD] = ID; 377577424bc3794f569816dba52e423b57486a98e5baDouglas Gregor} 3776565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis 3777565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidisvoid ASTWriter::CompletedTagDefinition(const TagDecl *D) { 3778565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis assert(D->isDefinition()); 3779565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { 3780565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // We are interested when a PCH decl is modified. 3781565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis if (RD->getPCHLevel() > 0) { 3782565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // A forward reference was mutated into a definition. Rewrite it. 3783565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // FIXME: This happens during template instantiation, should we 3784565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // have created a new definition decl instead ? 3785d3d0755a4220d3fa6c125eb3f8ce29fc1424eac3Argyrios Kyrtzidis RewriteDecl(RD); 3786565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 3787565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis 3788565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis for (CXXRecordDecl::redecl_iterator 3789565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis I = RD->redecls_begin(), E = RD->redecls_end(); I != E; ++I) { 3790565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis CXXRecordDecl *Redecl = cast<CXXRecordDecl>(*I); 3791565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis if (Redecl == RD) 3792565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis continue; 3793565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis 3794565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // We are interested when a PCH decl is modified. 3795565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis if (Redecl->getPCHLevel() > 0) { 3796565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis UpdateRecord &Record = DeclUpdates[Redecl]; 3797565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis Record.push_back(UPD_CXX_SET_DEFINITIONDATA); 3798565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis assert(Redecl->DefinitionData); 3799565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis assert(Redecl->DefinitionData->Definition == D); 3800565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis AddDeclRef(D, Record); // the DefinitionDecl 3801565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 3802565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 3803565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 3804565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis} 3805100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidisvoid ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { 3806100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis // TU and namespaces are handled elsewhere. 3807100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) 3808100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis return; 3809100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis 3810100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis if (!(D->getPCHLevel() == 0 && cast<Decl>(DC)->getPCHLevel() > 0)) 3811100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis return; // Not a source decl added to a DeclContext from PCH. 3812100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis 3813100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis AddUpdatedDeclContext(DC); 3814100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis} 3815b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis 3816b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidisvoid ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { 3817b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis assert(D->isImplicit()); 3818b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis if (!(D->getPCHLevel() == 0 && RD->getPCHLevel() > 0)) 3819b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis return; // Not a source member added to a class from PCH. 3820b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis if (!isa<CXXMethodDecl>(D)) 3821b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis return; // We are interested in lazily declared implicit methods. 3822b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis 3823b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis // A decl coming from PCH was modified. 3824b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis assert(RD->isDefinition()); 3825b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis UpdateRecord &Record = DeclUpdates[RD]; 3826b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); 3827b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis AddDeclRef(D, Record); 3828b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis} 3829bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis 3830bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidisvoid ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, 3831bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis const ClassTemplateSpecializationDecl *D) { 38320f04f69acd0a86ff78961933c13fe5aeda94e1b6Argyrios Kyrtzidis // The specializations set is kept in the canonical template. 38330f04f69acd0a86ff78961933c13fe5aeda94e1b6Argyrios Kyrtzidis TD = TD->getCanonicalDecl(); 3834bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0)) 3835bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis return; // Not a source specialization added to a template from PCH. 3836bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis 3837bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis UpdateRecord &Record = DeclUpdates[TD]; 3838bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); 3839bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis AddDeclRef(D, Record); 3840bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis} 384189d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 384289d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas GregorASTSerializationListener::~ASTSerializationListener() { } 3843