ASTWriter.cpp revision c1d3ffbbad742c90f22198d7909b0a98865bfefa
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" 400a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor#include "clang/Basic/VersionTuple.h" 4117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APFloat.h" 4217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APInt.h" 432596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar#include "llvm/ADT/StringExtras.h" 442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/Bitcode/BitstreamWriter.h" 45fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer#include "llvm/Support/FileSystem.h" 4614f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "llvm/Support/MemoryBuffer.h" 4703013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/Path.h" 483c304bd9ec2b4611572d4cbae9e1727bbecb5dc9Chris Lattner#include <cstdio> 49cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor#include <string.h> 502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorusing namespace clang; 518538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlusing namespace clang::serialization; 522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 53ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redltemplate <typename T, typename Allocator> 54ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian RedlT *data(std::vector<T, Allocator> &v) { 55ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl return v.empty() ? 0 : &v.front(); 56ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl} 57ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redltemplate <typename T, typename Allocator> 58ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redlconst T *data(const std::vector<T, Allocator> &v) { 59ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl return v.empty() ? 0 : &v.front(); 60ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl} 61ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl 622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// Type serialization 642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 6512b1c7615d4f9a2edc544be499f895f16ac100edChris Lattner 662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace { 673397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl class ASTTypeWriter { 68a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 6989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record; 702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor public: 722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Type code that corresponds to the record generated. 738538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl TypeCode Code; 742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 7589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) 768538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } 772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor void VisitArrayType(const ArrayType *T); 792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor void VisitFunctionType(const FunctionType *T); 802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor void VisitTagType(const TagType *T); 812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); 832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define ABSTRACT_TYPE(Class, Base) 842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/TypeNodes.def" 852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor }; 862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 883397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { 892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor assert(false && "Built-in types are never serialized"); 902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 923397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitComplexType(const ComplexType *T) { 932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getElementType(), Record); 948538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_COMPLEX; 952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 973397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitPointerType(const PointerType *T) { 982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getPointeeType(), Record); 998538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_POINTER; 1002cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1023397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { 1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(T->getPointeeType(), Record); 1048538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_BLOCK_POINTER; 1052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1073397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { 108df1550fc59b51681d37225934fe4e3acac321621Richard Smith Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); 109df1550fc59b51681d37225934fe4e3acac321621Richard Smith Record.push_back(T->isSpelledAsLValue()); 1108538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_LVALUE_REFERENCE; 1112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1133397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { 114df1550fc59b51681d37225934fe4e3acac321621Richard Smith Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); 1158538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_RVALUE_REFERENCE; 1162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1183397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { 1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(T->getPointeeType(), Record); 1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(QualType(T->getClass(), 0), Record); 1218538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_MEMBER_POINTER; 1222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1243397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitArrayType(const ArrayType *T) { 1252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getElementType(), Record); 1262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getSizeModifier()); // FIXME: stable values 1270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values 1282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1303397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { 1312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitArrayType(T); 1322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddAPInt(T->getSize(), Record); 1338538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_CONSTANT_ARRAY; 1342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1363397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { 1372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitArrayType(T); 1388538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_INCOMPLETE_ARRAY; 1392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1413397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { 1422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitArrayType(T); 1437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Writer.AddSourceLocation(T->getLBracketLoc(), Record); 1447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Writer.AddSourceLocation(T->getRBracketLoc(), Record); 145c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Writer.AddStmt(T->getSizeExpr()); 1468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_VARIABLE_ARRAY; 1472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1493397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitVectorType(const VectorType *T) { 1502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getElementType(), Record); 1512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getNumElements()); 152e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson Record.push_back(T->getVectorKind()); 1538538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_VECTOR; 1542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1563397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { 1572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitVectorType(T); 1588538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_EXT_VECTOR; 1592cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1613397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionType(const FunctionType *T) { 1622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getResultType(), Record); 163264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionType::ExtInfo C = T->getExtInfo(); 164264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Record.push_back(C.getNoReturn()); 165a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman Record.push_back(C.getHasRegParm()); 166425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola Record.push_back(C.getRegParm()); 167ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor // FIXME: need to stabilize encoding of calling convention... 168264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Record.push_back(C.getCC()); 1692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1713397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { 1722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitFunctionType(T); 1738538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_FUNCTION_NO_PROTO; 1742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1763397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { 1772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitFunctionType(T); 1782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getNumArgs()); 1792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) 1802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getArgType(I), Record); 1812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->isVariadic()); 1822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getTypeQuals()); 183c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor Record.push_back(static_cast<unsigned>(T->getRefQualifier())); 18460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Record.push_back(T->getExceptionSpecType()); 18560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (T->getExceptionSpecType() == EST_Dynamic) { 18660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Record.push_back(T->getNumExceptions()); 18760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) 18860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Writer.AddTypeRef(T->getExceptionType(I), Record); 18960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { 19060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Writer.AddStmt(T->getNoexceptExpr()); 19160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 1928538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_FUNCTION_PROTO; 1932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1953397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { 196ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Writer.AddDeclRef(T->getDecl(), Record); 1978538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_UNRESOLVED_USING; 198ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 199ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2003397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypedefType(const TypedefType *T) { 2012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddDeclRef(T->getDecl(), Record); 2029763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); 2039763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); 2048538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TYPEDEF; 2052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2073397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { 208c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Writer.AddStmt(T->getUnderlyingExpr()); 2098538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TYPEOF_EXPR; 2102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2123397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { 2132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getUnderlyingType(), Record); 2148538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TYPEOF; 2152cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2173397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { 218395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Writer.AddStmt(T->getUnderlyingExpr()); 2198538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DECLTYPE; 220395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 221395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 22234b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid ASTTypeWriter::VisitAutoType(const AutoType *T) { 22334b41d939a1328f484511c6002ba2456db879a29Richard Smith Writer.AddTypeRef(T->getDeducedType(), Record); 22434b41d939a1328f484511c6002ba2456db879a29Richard Smith Code = TYPE_AUTO; 22534b41d939a1328f484511c6002ba2456db879a29Richard Smith} 22634b41d939a1328f484511c6002ba2456db879a29Richard Smith 2273397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTagType(const TagType *T) { 228be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis Record.push_back(T->isDependentType()); 2292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddDeclRef(T->getDecl(), Record); 2301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!T->isBeingDefined() && 2312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor "Cannot serialize in the middle of a type definition"); 2322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2343397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitRecordType(const RecordType *T) { 2352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitTagType(T); 2368538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_RECORD; 2372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2393397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitEnumType(const EnumType *T) { 2402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitTagType(T); 2418538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_ENUM; 2422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid ASTTypeWriter::VisitAttributedType(const AttributedType *T) { 2459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddTypeRef(T->getModifiedType(), Record); 2469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddTypeRef(T->getEquivalentType(), Record); 2479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Record.push_back(T->getAttrKind()); 2489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Code = TYPE_ATTRIBUTED; 2499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 2509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 2511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 2523397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitSubstTemplateTypeParmType( 25349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const SubstTemplateTypeParmType *T) { 25449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); 25549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Writer.AddTypeRef(T->getReplacementType(), Record); 2568538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; 25749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 25849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 25949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallvoid 260c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorASTTypeWriter::VisitSubstTemplateTypeParmPackType( 261c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const SubstTemplateTypeParmPackType *T) { 262c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); 263c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Writer.AddTemplateArgument(T->getArgumentPack(), Record); 264c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; 265c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 266c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 267c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid 2683397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitTemplateSpecializationType( 2692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor const TemplateSpecializationType *T) { 270be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis Record.push_back(T->isDependentType()); 27190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Writer.AddTemplateName(T->getTemplateName(), Record); 27290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->getNumArgs()); 27390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); 27490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis ArgI != ArgE; ++ArgI) 27590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Writer.AddTemplateArgument(*ArgI, Record); 2769763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() 2779763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis : T->getCanonicalTypeInternal(), 2789763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Record); 2798538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TEMPLATE_SPECIALIZATION; 28090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 28190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 28290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 2833397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { 284ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis VisitArrayType(T); 285ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis Writer.AddStmt(T->getSizeExpr()); 286ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis Writer.AddSourceRange(T->getBracketsRange(), Record); 2878538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DEPENDENT_SIZED_ARRAY; 28890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 28990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 29090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 2913397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentSizedExtVectorType( 29290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis const DependentSizedExtVectorType *T) { 29390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis // FIXME: Serialize this type (C++ only) 29490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis assert(false && "Cannot serialize dependent sized extended vector types"); 29590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 29690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 29790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 2983397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { 29990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->getDepth()); 30090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->getIndex()); 30190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->isParameterPack()); 30290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Writer.AddIdentifierRef(T->getName(), Record); 3038538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TEMPLATE_TYPE_PARM; 30490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 30590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 30690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 3073397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { 3088dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Record.push_back(T->getKeyword()); 3098dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Writer.AddNestedNameSpecifier(T->getQualifier(), Record); 3108dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Writer.AddIdentifierRef(T->getIdentifier(), Record); 311f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() 312f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis : T->getCanonicalTypeInternal(), 313f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis Record); 3148538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DEPENDENT_NAME; 31590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 31690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 31790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 3183397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentTemplateSpecializationType( 31990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis const DependentTemplateSpecializationType *T) { 3203acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Record.push_back(T->getKeyword()); 3213acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddNestedNameSpecifier(T->getQualifier(), Record); 3223acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddIdentifierRef(T->getIdentifier(), Record); 3233acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Record.push_back(T->getNumArgs()); 3243acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis for (DependentTemplateSpecializationType::iterator 3253acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis I = T->begin(), E = T->end(); I != E; ++I) 3263acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddTemplateArgument(*I, Record); 3278538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; 3282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3307536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorvoid ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { 3317536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Writer.AddTypeRef(T->getPattern(), Record); 332cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (llvm::Optional<unsigned> NumExpansions = T->getNumExpansions()) 333cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Record.push_back(*NumExpansions + 1); 334cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor else 335cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Record.push_back(0); 3367536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Code = TYPE_PACK_EXPANSION; 3377536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 3387536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 339075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaravoid ASTTypeWriter::VisitParenType(const ParenType *T) { 340075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Writer.AddTypeRef(T->getInnerType(), Record); 341075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Code = TYPE_PAREN; 342075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 343075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 3443397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { 345465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Record.push_back(T->getKeyword()); 3463acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddNestedNameSpecifier(T->getQualifier(), Record); 3473acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddTypeRef(T->getNamedType(), Record); 3488538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_ELABORATED; 3492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3513397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { 3523cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Writer.AddDeclRef(T->getDecl(), Record); 35331f17ecbef57b5679c017c375db330546b7b5145John McCall Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); 3548538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_INJECTED_CLASS_NAME; 3553cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 3563cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 3573397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { 358deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor Writer.AddDeclRef(T->getDecl(), Record); 3598538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_OBJC_INTERFACE; 360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 361c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3623397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { 363c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Writer.AddTypeRef(T->getBaseType(), Record); 3642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getNumProtocols()); 365c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (ObjCObjectType::qual_iterator I = T->qual_begin(), 366446ee4eb4fc4c705a59365252df7a5c253daafa1Steve Naroff E = T->qual_end(); I != E; ++I) 367446ee4eb4fc4c705a59365252df7a5c253daafa1Steve Naroff Writer.AddDeclRef(*I, Record); 3688538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_OBJC_OBJECT; 3692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 371d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffvoid 3723397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { 3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(T->getPointeeType(), Record); 3748538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_OBJC_OBJECT_POINTER; 3752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 377a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallnamespace { 378a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 379a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallclass TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { 380a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 38189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record; 382a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 383a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallpublic: 38489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) 385a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall : Writer(Writer), Record(Record) { } 386a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 38751bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 388a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#define TYPELOC(CLASS, PARENT) \ 38951bd803fbdade51d674598ed45da3d54190a656cJohn McCall void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); 390a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#include "clang/AST/TypeLocNodes.def" 391a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 39251bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); 39351bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); 394a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}; 395a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 396a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 397a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 39851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { 39951bd803fbdade51d674598ed45da3d54190a656cJohn McCall // nothing to do 40051bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 40151bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { 402ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); 403ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (TL.needsExtraLocalData()) { 404ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.getWrittenTypeSpec()); 405ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.getWrittenSignSpec()); 406ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.getWrittenWidthSpec()); 407ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.hasModeAttr()); 408ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 40951bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 41051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { 41151bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 41251bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 41351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { 41451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getStarLoc(), Record); 41551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 41651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { 41751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getCaretLoc(), Record); 41851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 41951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { 42051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getAmpLoc(), Record); 42151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 42251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { 42351bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); 42451bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 42551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { 42651bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getStarLoc(), Record); 427b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); 42851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 42951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { 43051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getLBracketLoc(), Record); 43151bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getRBracketLoc(), Record); 43251bd803fbdade51d674598ed45da3d54190a656cJohn McCall Record.push_back(TL.getSizeExpr() ? 1 : 0); 43351bd803fbdade51d674598ed45da3d54190a656cJohn McCall if (TL.getSizeExpr()) 43451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddStmt(TL.getSizeExpr()); 43551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 43651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { 43751bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 43851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 43951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { 44051bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 44151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { 44351bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 44451bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDependentSizedArrayTypeLoc( 44651bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedArrayTypeLoc TL) { 44751bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 44851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( 45051bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedExtVectorTypeLoc TL) { 45151bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 45251bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 45351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { 45451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 45551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 45651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { 45751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 45851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 45951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { 460796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); 461796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); 462dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor Record.push_back(TL.getTrailingReturn()); 46351bd803fbdade51d674598ed45da3d54190a656cJohn McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) 46451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddDeclRef(TL.getArg(i), Record); 46551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 46651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { 46751bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitFunctionTypeLoc(TL); 46851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 46951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { 47051bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitFunctionTypeLoc(TL); 47151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 472ed97649e9574b9d854fa4d6109c9333ae0993554John McCallvoid TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { 473ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 474ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 47551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { 47651bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 47751bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 47851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { 479cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getTypeofLoc(), Record); 480cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getLParenLoc(), Record); 481cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getRParenLoc(), Record); 48251bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 48351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { 484cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getTypeofLoc(), Record); 485cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getLParenLoc(), Record); 486cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getRParenLoc(), Record); 487cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); 48851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 48951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { 49051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 491a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 49234b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { 49334b41d939a1328f484511c6002ba2456db879a29Richard Smith Writer.AddSourceLocation(TL.getNameLoc(), Record); 49434b41d939a1328f484511c6002ba2456db879a29Richard Smith} 49551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { 49651bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 497a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 49851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { 49951bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 500a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 5019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { 5029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); 5039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) { 5049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceRange range = TL.getAttrOperandParensRange(); 5059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(range.getBegin(), Record); 5069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(range.getEnd(), Record); 5079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 5089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) { 5099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Expr *operand = TL.getAttrExprOperand(); 5109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Record.push_back(operand ? 1 : 0); 5119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (operand) Writer.AddStmt(operand); 5129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } else if (TL.hasAttrEnumOperand()) { 5139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); 5149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 5159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 51651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { 51751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 518a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 51949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallvoid TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( 52049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmTypeLoc TL) { 52149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 52249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 523c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( 524c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 525c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Writer.AddSourceLocation(TL.getNameLoc(), Record); 526c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 52751bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTemplateSpecializationTypeLoc( 52851bd803fbdade51d674598ed45da3d54190a656cJohn McCall TemplateSpecializationTypeLoc TL) { 529833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); 530833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Writer.AddSourceLocation(TL.getLAngleLoc(), Record); 531833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Writer.AddSourceLocation(TL.getRAngleLoc(), Record); 532833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) 53344f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), 53444f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis TL.getArgLoc(i).getLocInfo(), Record); 535a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 536075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaravoid TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { 537075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Writer.AddSourceLocation(TL.getLParenLoc(), Record); 538075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Writer.AddSourceLocation(TL.getRParenLoc(), Record); 539075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 540465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaravoid TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { 541e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara Writer.AddSourceLocation(TL.getKeywordLoc(), Record); 5429e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); 543a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 5443cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallvoid TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { 5453cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 5463cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 5474714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregorvoid TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { 548e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara Writer.AddSourceLocation(TL.getKeywordLoc(), Record); 5492494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); 55051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 551a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 55233500955d731c73717af52088b7fc0e7a85681e7John McCallvoid TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( 55333500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypeLoc TL) { 55433500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getKeywordLoc(), Record); 55594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); 55633500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 55733500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getLAngleLoc(), Record); 55833500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getRAngleLoc(), Record); 55933500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) 56044f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), 56144f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis TL.getArgLoc(I).getLocInfo(), Record); 56233500955d731c73717af52088b7fc0e7a85681e7John McCall} 5637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorvoid TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { 5647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); 5657536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 56651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { 56751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 568c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 569c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { 570c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Record.push_back(TL.hasBaseTypeAsWritten()); 57154e14c4db764c0636160d26c5bbf491637c83a76John McCall Writer.AddSourceLocation(TL.getLAngleLoc(), Record); 57254e14c4db764c0636160d26c5bbf491637c83a76John McCall Writer.AddSourceLocation(TL.getRAngleLoc(), Record); 57354e14c4db764c0636160d26c5bbf491637c83a76John McCall for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) 57454e14c4db764c0636160d26c5bbf491637c83a76John McCall Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); 575a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 57651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { 57751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getStarLoc(), Record); 578a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 579a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 5804dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner//===----------------------------------------------------------------------===// 581a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl// ASTWriter Implementation 5822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 5832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 584b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattnerstatic void EmitBlockID(unsigned ID, const char *Name, 585b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner llvm::BitstreamWriter &Stream, 58689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record) { 587b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.clear(); 588b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(ID); 589b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); 590b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 591b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner // Emit the block name if present. 592b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner if (Name == 0 || Name[0] == 0) return; 593b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.clear(); 594b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner while (*Name) 595b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(*Name++); 596b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); 597b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner} 598b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 599b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattnerstatic void EmitRecordID(unsigned ID, const char *Name, 600b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner llvm::BitstreamWriter &Stream, 60189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record) { 602b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.clear(); 603b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(ID); 604b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner while (*Name) 605b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(*Name++); 606b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); 6070558df2da807646e65d4fa290f4e92114af1a746Chris Lattner} 6080558df2da807646e65d4fa290f4e92114af1a746Chris Lattner 6090558df2da807646e65d4fa290f4e92114af1a746Chris Lattnerstatic void AddStmtsExprs(llvm::BitstreamWriter &Stream, 61089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record) { 6118538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define RECORD(X) EmitRecordID(X, #X, Stream, Record) 6120558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_STOP); 6130558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_NULL_PTR); 6140558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_NULL); 6150558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_COMPOUND); 6160558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_CASE); 6170558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_DEFAULT); 6180558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_LABEL); 6190558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_IF); 6200558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_SWITCH); 6210558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_WHILE); 6220558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_DO); 6230558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_FOR); 6240558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_GOTO); 6250558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_INDIRECT_GOTO); 6260558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_CONTINUE); 6270558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_BREAK); 6280558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_RETURN); 6290558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_DECL); 6300558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_ASM); 6310558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_PREDEFINED); 6320558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_DECL_REF); 6330558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_INTEGER_LITERAL); 6340558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_FLOATING_LITERAL); 6350558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_IMAGINARY_LITERAL); 6360558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_STRING_LITERAL); 6370558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CHARACTER_LITERAL); 6380558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_PAREN); 6390558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_UNARY_OPERATOR); 6400558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_SIZEOF_ALIGN_OF); 6410558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_ARRAY_SUBSCRIPT); 6420558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CALL); 6430558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_MEMBER); 6440558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_BINARY_OPERATOR); 6450558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); 6460558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CONDITIONAL_OPERATOR); 6470558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_IMPLICIT_CAST); 6480558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CSTYLE_CAST); 6490558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_COMPOUND_LITERAL); 6500558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_EXT_VECTOR_ELEMENT); 6510558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_INIT_LIST); 6520558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_DESIGNATED_INIT); 6530558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_IMPLICIT_VALUE_INIT); 6540558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_VA_ARG); 6550558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_ADDR_LABEL); 6560558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_STMT); 6570558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CHOOSE); 6580558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_GNU_NULL); 6590558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_SHUFFLE_VECTOR); 6600558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_BLOCK); 6610558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_BLOCK_DECL_REF); 662f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne RECORD(EXPR_GENERIC_SELECTION); 6630558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_STRING_LITERAL); 6640558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_ENCODE); 6650558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_SELECTOR_EXPR); 6660558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_PROTOCOL_EXPR); 6670558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_IVAR_REF_EXPR); 6680558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); 6690558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_KVC_REF_EXPR); 6700558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_MESSAGE_EXPR); 6710558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_FOR_COLLECTION); 6720558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_CATCH); 6730558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_FINALLY); 6740558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_AT_TRY); 6750558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_AT_SYNCHRONIZED); 6760558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_AT_THROW); 677eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_OPERATOR_CALL); 678eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_CONSTRUCT); 679eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_STATIC_CAST); 680eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_DYNAMIC_CAST); 681eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_REINTERPRET_CAST); 682eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_CONST_CAST); 683eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_FUNCTIONAL_CAST); 684eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_BOOL_LITERAL); 685eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_NULL_PTR_LITERAL); 686b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_TYPEID_EXPR); 687b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_TYPEID_TYPE); 688b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UUIDOF_EXPR); 689b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UUIDOF_TYPE); 690b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_THIS); 691b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_THROW); 692b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DEFAULT_ARG); 693b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_BIND_TEMPORARY); 694b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_SCALAR_VALUE_INIT); 695b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_NEW); 696b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DELETE); 697b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); 698b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_EXPR_WITH_CLEANUPS); 699b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); 700b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); 701b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); 702b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNRESOLVED_MEMBER); 703b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); 704b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); 705b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_NOEXCEPT); 706b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_OPAQUE_VALUE); 707b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_BINARY_TYPE_TRAIT); 708b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_PACK_EXPANSION); 709b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_SIZEOF_PACK); 710b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); 711e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne RECORD(EXPR_CUDA_KERNEL_CALL); 7120558df2da807646e65d4fa290f4e92114af1a746Chris Lattner#undef RECORD 713b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner} 7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 715a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteBlockInfoBlock() { 716b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RecordData Record; 717b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); 7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7198538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) 7208538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define RECORD(X) EmitRecordID(X, #X, Stream, Record) 7211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7223397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // AST Top-Level Block. 723f29f0a28c4d9599b389bbb6d186e14af753dc5a3Sebastian Redl BLOCK(AST_BLOCK); 72451e774d42269e3b22d746184c0b9076fc13b32e6Zhongxing Xu RECORD(ORIGINAL_FILE_NAME); 725b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_OFFSET); 726b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_OFFSET); 727b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(LANGUAGE_OPTIONS); 728ab41e63821dc60ad144d0684df8d79a9eef86b75Douglas Gregor RECORD(METADATA); 729b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(IDENTIFIER_OFFSET); 730b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(IDENTIFIER_TABLE); 731b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(EXTERNAL_DEFINITIONS); 732b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SPECIAL_TYPES); 733b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(STATISTICS); 734b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TENTATIVE_DEFINITIONS); 73549b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis RECORD(UNUSED_FILESCOPED_DECLS); 736b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); 737b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SELECTOR_OFFSETS); 738b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(METHOD_POOL); 739b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_COUNTER_VALUE); 7407f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RECORD(SOURCE_LOCATION_OFFSETS); 7417f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RECORD(SOURCE_LOCATION_PRELOADS); 7424fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor RECORD(STAT_CACHE); 743b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor RECORD(EXT_VECTOR_DECLS); 7445b4ec636637c9d876102240127cc0dca9280e83aTed Kremenek RECORD(VERSION_CONTROL_BRANCH_REVISION); 7456a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor RECORD(MACRO_DEFINITION_OFFSETS); 746a93e3b5bde9f0a7b59215f19f176f7d69881b81cSebastian Redl RECORD(CHAINED_METADATA); 747320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian RECORD(REFERENCED_SELECTOR_POOL); 748b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TU_UPDATE_LEXICAL); 749b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(REDECLS_UPDATE_LATEST); 750b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(SEMA_DECL_REFS); 751b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(WEAK_UNDECLARED_IDENTIFIERS); 752b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(PENDING_IMPLICIT_INSTANTIATIONS); 753b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_REPLACEMENTS); 754b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(UPDATE_VISIBLE); 755b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UPDATE_OFFSETS); 756b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UPDATES); 757b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(CXX_BASE_SPECIFIER_OFFSETS); 758b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DIAG_PRAGMA_MAPPINGS); 75984bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RECORD(CUDA_SPECIAL_DECL_REFS); 760cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor RECORD(HEADER_SEARCH_TABLE); 76184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RECORD(FP_PRAGMA_OPTIONS); 76284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RECORD(OPENCL_EXTENSIONS); 763cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 764b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner // SourceManager Block. 7652f4efd10c805cb779618c1a22a35eb07b5043c4eChris Lattner BLOCK(SOURCE_MANAGER_BLOCK); 766b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_FILE_ENTRY); 767b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_BUFFER_ENTRY); 768b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_BUFFER_BLOB); 769b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_INSTANTIATION_ENTRY); 770b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_LINE_TABLE); 7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 772b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner // Preprocessor Block. 7732f4efd10c805cb779618c1a22a35eb07b5043c4eChris Lattner BLOCK(PREPROCESSOR_BLOCK); 774b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_MACRO_OBJECT_LIKE); 775b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_MACRO_FUNCTION_LIKE); 776b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_TOKEN); 777b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor 77861d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor // Decls and Types block. 77961d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor BLOCK(DECLTYPES_BLOCK); 780b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_EXT_QUAL); 781b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_COMPLEX); 782b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_POINTER); 783b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_BLOCK_POINTER); 784b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_LVALUE_REFERENCE); 785b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_RVALUE_REFERENCE); 786b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_MEMBER_POINTER); 787b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_CONSTANT_ARRAY); 788b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_INCOMPLETE_ARRAY); 789b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_VARIABLE_ARRAY); 790b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_VECTOR); 791b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_EXT_VECTOR); 792b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_FUNCTION_PROTO); 793b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_FUNCTION_NO_PROTO); 794b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_TYPEDEF); 795b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_TYPEOF_EXPR); 796b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_TYPEOF); 797b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_RECORD); 798b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_ENUM); 799b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_OBJC_INTERFACE); 800a53d2cbe37e4be0d95b9d3e09f74eafae31fc940John McCall RECORD(TYPE_OBJC_OBJECT); 801d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff RECORD(TYPE_OBJC_OBJECT_POINTER); 802b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DECLTYPE); 803b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_ELABORATED); 804b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); 805b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_UNRESOLVED_USING); 806b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_INJECTED_CLASS_NAME); 807b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_OBJC_OBJECT); 808b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_TEMPLATE_TYPE_PARM); 809b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_TEMPLATE_SPECIALIZATION); 810b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DEPENDENT_NAME); 811b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); 812b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DEPENDENT_SIZED_ARRAY); 813b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_PAREN); 814b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_PACK_EXPANSION); 815b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_ATTRIBUTED); 816b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); 8170ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_TRANSLATION_UNIT); 8180ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_TYPEDEF); 8190ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_ENUM); 8200ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_RECORD); 8210ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_ENUM_CONSTANT); 8220ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_FUNCTION); 8230ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_METHOD); 8240ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_INTERFACE); 8250ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_PROTOCOL); 8260ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_IVAR); 8270ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_AT_DEFS_FIELD); 8280ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_CLASS); 8290ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_FORWARD_PROTOCOL); 8300ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_CATEGORY); 8310ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_CATEGORY_IMPL); 8320ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_IMPLEMENTATION); 8330ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_COMPATIBLE_ALIAS); 8340ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_PROPERTY); 8350ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_PROPERTY_IMPL); 836b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_FIELD); 837b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_VAR); 8380ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_IMPLICIT_PARAM); 839b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_PARM_VAR); 8400ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_FILE_SCOPE_ASM); 8410ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_BLOCK); 8420ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_CONTEXT_LEXICAL); 8430ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_CONTEXT_VISIBLE); 844b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_NAMESPACE); 845b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_NAMESPACE_ALIAS); 846b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_USING); 847b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_USING_SHADOW); 848b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_USING_DIRECTIVE); 849b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UNRESOLVED_USING_VALUE); 850b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UNRESOLVED_USING_TYPENAME); 851b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_LINKAGE_SPEC); 852b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_RECORD); 853b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_METHOD); 854b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_CONSTRUCTOR); 855b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_DESTRUCTOR); 856b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_CONVERSION); 857b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_ACCESS_SPEC); 858b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_FRIEND); 859b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_FRIEND_TEMPLATE); 860b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CLASS_TEMPLATE); 861b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); 862b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); 863b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_FUNCTION_TEMPLATE); 864b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_TEMPLATE_TYPE_PARM); 865b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_NON_TYPE_TEMPLATE_PARM); 866b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_TEMPLATE_TEMPLATE_PARM); 867b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_STATIC_ASSERT); 868b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_BASE_SPECIFIERS); 869b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_INDIRECTFIELD); 870b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); 871b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor 8724800a5c79023271408af49797e09be32aca93232Douglas Gregor BLOCK(PREPROCESSOR_DETAIL_BLOCK); 8734800a5c79023271408af49797e09be32aca93232Douglas Gregor RECORD(PPD_MACRO_INSTANTIATION); 8744800a5c79023271408af49797e09be32aca93232Douglas Gregor RECORD(PPD_MACRO_DEFINITION); 8754800a5c79023271408af49797e09be32aca93232Douglas Gregor RECORD(PPD_INCLUSION_DIRECTIVE); 8764800a5c79023271408af49797e09be32aca93232Douglas Gregor 87761d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor // Statements and Exprs can occur in the Decls and Types block. 8780558df2da807646e65d4fa290f4e92114af1a746Chris Lattner AddStmtsExprs(Stream, Record); 879b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner#undef RECORD 880b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner#undef BLOCK 881b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.ExitBlock(); 882b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner} 883b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 884e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \brief Adjusts the given filename to only write out the portion of the 885e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// filename that is not part of the system root directory. 8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 887e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \param Filename the file name to adjust. 888e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// 889e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and 890e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// the returned filename will be adjusted by this system root. 891e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// 892e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \returns either the original filename (if it needs no adjustment) or the 893e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// adjusted filename (which points into the @p Filename parameter). 8941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpstatic const char * 895e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas GregoradjustFilenameForRelocatablePCH(const char *Filename, const char *isysroot) { 896e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor assert(Filename && "No file name to adjust?"); 8971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 898e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (!isysroot) 899e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename; 9001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 901e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // Verify that the filename and the system root have the same prefix. 902e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor unsigned Pos = 0; 903e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor for (; Filename[Pos] && isysroot[Pos]; ++Pos) 904e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (Filename[Pos] != isysroot[Pos]) 905e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename; // Prefixes don't match. 9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 907e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // We hit the end of the filename before we hit the end of the system root. 908e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (!Filename[Pos]) 909e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename; 9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 911e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // If the file name has a '/' at the current position, skip over the '/'. 912e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // We distinguish sysroot-based includes from absolute includes by the 913e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // absence of '/' at the beginning of sysroot-based includes. 914e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (Filename[Pos] == '/') 915e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor ++Pos; 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 917e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename + Pos; 918e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor} 919b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 9203397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the AST metadata (e.g., i686-apple-darwin9). 9218e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidisvoid ASTWriter::WriteMetadata(ASTContext &Context, const char *isysroot, 9228e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis const std::string &OutputFile) { 9232bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor using namespace llvm; 924b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor 925e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // Metadata 926e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const TargetInfo &Target = Context.Target; 927e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor BitCodeAbbrev *MetaAbbrev = new BitCodeAbbrev(); 92877f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl MetaAbbrev->Add(BitCodeAbbrevOp( 9298538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Chain ? CHAINED_METADATA : METADATA)); 9303397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST major 9313397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // AST minor 932e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major 933e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor 934e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable 93577f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl // Target triple or chained PCH name 93677f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 937e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor unsigned MetaAbbrevCode = Stream.EmitAbbrev(MetaAbbrev); 9381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 939e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor RecordData Record; 9408538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(Chain ? CHAINED_METADATA : METADATA); 9418538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(VERSION_MAJOR); 9428538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(VERSION_MINOR); 943e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Record.push_back(CLANG_VERSION_MAJOR); 944e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Record.push_back(CLANG_VERSION_MINOR); 945e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Record.push_back(isysroot != 0); 94677f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl // FIXME: This writes the absolute path for chained headers. 94777f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl const std::string &BlobStr = Chain ? Chain->getFileName() : Target.getTriple().getTriple(); 94877f4603c8b142e642300959a601ecec2b7c8e288Sebastian Redl Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, BlobStr); 9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 950b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor // Original file name 951b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor SourceManager &SM = Context.getSourceManager(); 952b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { 953b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); 9548538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE_NAME)); 955b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name 956b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); 957b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor 958fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer llvm::SmallString<128> MainFilePath(MainFile->getName()); 9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 960fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer llvm::sys::fs::make_absolute(MainFilePath); 961b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor 962aba54a95e9d5e4dc9056abec6bb70ea777c4a7bcKovarththanan Rajaratnam const char *MainFileNameStr = MainFilePath.c_str(); 9631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, 964e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor isysroot); 965b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor RecordData Record; 9668538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(ORIGINAL_FILE_NAME); 967ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); 968b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor } 96911a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 9708e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis // Original PCH directory 9718e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis if (!OutputFile.empty() && OutputFile != "-") { 9728e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 9738e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); 9748e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name 9758e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); 9768e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 9778e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis llvm::SmallString<128> OutputPath(OutputFile); 9788e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 9798e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis llvm::sys::fs::make_absolute(OutputPath); 9808e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis StringRef origDir = llvm::sys::path::parent_path(OutputPath); 9818e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 9828e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis RecordData Record; 9838e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Record.push_back(ORIGINAL_PCH_DIR); 9848e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); 9858e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis } 9868e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 987f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek // Repository branch/version information. 988f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); 9898538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl RepoAbbrev->Add(BitCodeAbbrevOp(VERSION_CONTROL_BRANCH_REVISION)); 990f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag 991f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); 992445e23e9b909ec8e21303c7dd82c90b72fc09ac4Douglas Gregor Record.clear(); 9938538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(VERSION_CONTROL_BRANCH_REVISION); 994f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, 995f7a96a39958b3f919f26764777eec948b43d74bcTed Kremenek getClangFullRepositoryVersion()); 9962bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor} 9972bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor 9982bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor/// \brief Write the LangOptions structure. 999a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) { 10000a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor RecordData Record; 10010a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Trigraphs); 10020a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.BCPLComment); // BCPL-style '//' comments. 10030a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.DollarIdents); // '$' allowed in identifiers. 10040a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.AsmPreprocessor); // Preprocessor in asm mode. 10050a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.GNUMode); // True in gnu99 mode false in c99 mode (etc) 1006eb5d7b752651283de5abfcc2f91df7227582a08dChandler Carruth Record.push_back(LangOpts.GNUKeywords); // Allow GNU-extension keywords 10070a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.ImplicitInt); // C89 implicit 'int'. 10080a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Digraphs); // C94, C99 and C++ 10090a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.HexFloats); // C99 Hexadecimal float constants. 10100a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.C99); // C99 Support 10117e7fbd05a5dfdb0addfc8b5af2fcbed8c7b5fb87Peter Collingbourne Record.push_back(LangOpts.C1X); // C1X Support 10120a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Microsoft); // Microsoft extensions. 1013dae4ac4fe56ec60fc93b3e3c9f51e79e682084b9Michael J. Spencer // LangOpts.MSCVersion is ignored because all it does it set a macro, which is 1014dae4ac4fe56ec60fc93b3e3c9f51e79e682084b9Michael J. Spencer // already saved elsewhere. 10150a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.CPlusPlus); // C++ Support 10160a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.CPlusPlus0x); // C++0x Support 10170a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.CXXOperatorNames); // Treat C++ operator names as keywords. 10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10190a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.ObjC1); // Objective-C 1 support enabled. 10200a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.ObjC2); // Objective-C 2 support enabled. 102111a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam Record.push_back(LangOpts.ObjCNonFragileABI); // Objective-C 1022412e798941ca64e2e6b084323915fa9aa5f6bdf3Fariborz Jahanian // modern abi enabled. 102311a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam Record.push_back(LangOpts.ObjCNonFragileABI2); // Objective-C enhanced 1024412e798941ca64e2e6b084323915fa9aa5f6bdf3Fariborz Jahanian // modern abi enabled. 1025f84109ee6aeffb09366bd70c8593ce1b7818b1adFariborz Jahanian Record.push_back(LangOpts.AppleKext); // Apple's kernel extensions ABI 1026c32647d111e516593b9ba242cad7b8ff4016c155Ted Kremenek Record.push_back(LangOpts.ObjCDefaultSynthProperties); // Objective-C auto-synthesized 1027c32647d111e516593b9ba242cad7b8ff4016c155Ted Kremenek // properties enabled. 10284c9d8d0eca5ca635d9a30222f690db9140e98325Fariborz Jahanian Record.push_back(LangOpts.NoConstantCFStrings); // non cfstring generation enabled.. 10291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10300a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.PascalStrings); // Allow Pascal strings 10310a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.WritableStrings); // Allow writable strings 10320a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.LaxVectorConversions); 1033b9e7e63ae2098bc02e79c032df0a3124d09a4b4eNate Begeman Record.push_back(LangOpts.AltiVec); 10340a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Exceptions); // Support exception handling. 1035da4b7cf09ebfd4e4098b516081fa9dae2f5c99e0Anders Carlsson Record.push_back(LangOpts.ObjCExceptions); 10367da99b05aa9482e76b2954223b5652469004aec2Anders Carlsson Record.push_back(LangOpts.CXXExceptions); 10377da99b05aa9482e76b2954223b5652469004aec2Anders Carlsson Record.push_back(LangOpts.SjLjExceptions); 10380a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 10396f75550e40a9177db9979fc130ce3ece026b137dDouglas Gregor Record.push_back(LangOpts.MSBitfields); // MS-compatible structure layout 10400a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.NeXTRuntime); // Use NeXT runtime. 10410a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Freestanding); // Freestanding implementation 10420a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.NoBuiltin); // Do not use builtin functions (-fno-builtin) 10430a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 1044ea5ce4705df0743093925585d8edc80e0d8fe3ffChris Lattner // Whether static initializers are protected by locks. 1045ea5ce4705df0743093925585d8edc80e0d8fe3ffChris Lattner Record.push_back(LangOpts.ThreadsafeStatics); 1046972d954bd216c86a961bb7f81c53af85de17c2f0Douglas Gregor Record.push_back(LangOpts.POSIXThreads); 10470a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Blocks); // block extension to C 10480a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.EmitAllDecls); // Emit all declarations, even if 10490a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // they are unused. 10500a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.MathErrno); // Math functions must respect errno 10510a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // (modulo the platform support). 10520a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 1053a4d71455f0d418e16cc0c5c5aa55a3bad3494aeeChris Lattner Record.push_back(LangOpts.getSignedOverflowBehavior()); 1054a4d71455f0d418e16cc0c5c5aa55a3bad3494aeeChris Lattner Record.push_back(LangOpts.HeinousExtensions); 10550a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 10560a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Optimize); // Whether __OPTIMIZE__ should be defined. 10571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Record.push_back(LangOpts.OptimizeSize); // Whether __OPTIMIZE_SIZE__ should be 10580a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // defined. 10590a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.Static); // Should __STATIC__ be defined (as 10600a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // opposed to __DYNAMIC__). 10610a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.PICLevel); // The value for __PIC__, if non-zero. 10620a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 10630a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.GNUInline); // Should GNU inline semantics be 10640a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor // used (instead of C99 semantics). 10650a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined. 10660d2d1bcef51993ca3fd957e45fb7ec85e45016e5Chandler Carruth Record.push_back(LangOpts.Deprecated); // Should __DEPRECATED be defined. 1067a33d9b4ebf732a5da6d56fd7319ff6c020789b1cAnders Carlsson Record.push_back(LangOpts.AccessControl); // Whether C++ access control should 1068a33d9b4ebf732a5da6d56fd7319ff6c020789b1cAnders Carlsson // be enabled. 106915b91764d08e886391c865c4a444d7b51141c284Eli Friedman Record.push_back(LangOpts.CharIsSigned); // Whether char is a signed or 107015b91764d08e886391c865c4a444d7b51141c284Eli Friedman // unsigned type 1071a6fda124bf380479529d6a80b84b62cacd3cb707John Thompson Record.push_back(LangOpts.ShortWChar); // force wchar_t to be unsigned short 1072b1bdced5967c54d029cd12907e8939c78decf14cArgyrios Kyrtzidis Record.push_back(LangOpts.ShortEnums); // Should the enum type be equivalent 1073b1bdced5967c54d029cd12907e8939c78decf14cArgyrios Kyrtzidis // to the smallest integer type with 1074b1bdced5967c54d029cd12907e8939c78decf14cArgyrios Kyrtzidis // enough room. 10750a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.getGCMode()); 10760a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.getVisibilityMode()); 1077ab8e281b32a3d3b9b18257d26844362bf806ecdcDaniel Dunbar Record.push_back(LangOpts.getStackProtectorMode()); 10780a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor Record.push_back(LangOpts.InstantiationDepth); 1079b9e7e63ae2098bc02e79c032df0a3124d09a4b4eNate Begeman Record.push_back(LangOpts.OpenCL); 108008a53269b1f8241e2e6797e845abbe640fb18253Peter Collingbourne Record.push_back(LangOpts.CUDA); 10819c276ae0f24d4cee8f7954069d4b8eae45d0447dMike Stump Record.push_back(LangOpts.CatchUndefined); 108284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Record.push_back(LangOpts.DefaultFPContract); 108392f5822df6a0d7571df44b5d279ed4f017fbb0e6Anders Carlsson Record.push_back(LangOpts.ElideConstructors); 1084a0068fc64351db9c47916566e3b85ab733cd8d6dDouglas Gregor Record.push_back(LangOpts.SpellChecking); 1085cfe9af250f466e7e38becea4428990448ae07737Roman Divacky Record.push_back(LangOpts.MRTD); 10868538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(LANGUAGE_OPTIONS, Record); 10870a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor} 10880a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 108914f79002e58556798e86168c63e48d533287eda5Douglas Gregor//===----------------------------------------------------------------------===// 10904fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// stat cache Serialization 10914fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 10924fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 10934fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregornamespace { 10944fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Trait used for the on-disk hash table of stat cache results. 10953397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlclass ASTStatCacheTrait { 10964fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregorpublic: 10974fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor typedef const char * key_type; 10984fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor typedef key_type key_type_ref; 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 110074e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner typedef struct stat data_type; 110174e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner typedef const data_type &data_type_ref; 11024fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11034fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor static unsigned ComputeHash(const char *path) { 11042596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar return llvm::HashString(path); 11054fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<unsigned,unsigned> 11084fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor EmitKeyDataLength(llvm::raw_ostream& Out, const char *path, 11094fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor data_type_ref Data) { 11104fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor unsigned StrLen = strlen(path); 11114fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor clang::io::Emit16(Out, StrLen); 111274e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner unsigned DataLen = 4 + 4 + 2 + 8 + 8; 11134fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor clang::io::Emit8(Out, DataLen); 11144fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor return std::make_pair(StrLen + 1, DataLen); 11154fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11174fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor void EmitKey(llvm::raw_ostream& Out, const char *path, unsigned KeyLen) { 11184fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Out.write(path, KeyLen); 11194fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112174e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner void EmitData(llvm::raw_ostream &Out, key_type_ref, 11224fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor data_type_ref Data, unsigned DataLen) { 11234fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor using namespace clang::io; 11244fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor uint64_t Start = Out.tell(); (void)Start; 11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112674e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit32(Out, (uint32_t) Data.st_ino); 112774e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit32(Out, (uint32_t) Data.st_dev); 112874e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit16(Out, (uint16_t) Data.st_mode); 112974e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit64(Out, (uint64_t) Data.st_mtime); 113074e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit64(Out, (uint64_t) Data.st_size); 11314fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11324fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor assert(Out.tell() - Start == DataLen && "Wrong data length"); 11334fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 11344fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor}; 11354fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor} // end anonymous namespace 11364fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11373397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the stat() system call cache to the AST file. 1138a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteStatCache(MemorizeStatCalls &StatCalls) { 11394fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Build the on-disk hash table containing information about every 11404fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // stat() call. 11413397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl OnDiskChainedHashTableGenerator<ASTStatCacheTrait> Generator; 11424fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor unsigned NumStatEntries = 0; 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), 11444fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor StatEnd = StatCalls.end(); 1145e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Stat != StatEnd; ++Stat, ++NumStatEntries) { 1146e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const char *Filename = Stat->first(); 1147e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Generator.insert(Filename, Stat->second); 1148e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor } 11491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11504fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Create the on-disk hash table in a buffer. 11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::SmallString<4096> StatCacheData; 11524fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor uint32_t BucketOffset; 11534fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor { 11544fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor llvm::raw_svector_ostream Out(StatCacheData); 11554fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Make sure that no bucket is at offset 0 11564fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor clang::io::Emit32(Out, 0); 11574fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor BucketOffset = Generator.Emit(Out); 11584fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 11594fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11604fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Create a blob abbreviation 11614fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor using namespace llvm; 11624fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 11638538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(STAT_CACHE)); 11644fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 11654fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 11664fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 11674fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); 11684fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11694fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor // Write the stat cache 11704fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor RecordData Record; 11718538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(STAT_CACHE); 11724fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Record.push_back(BucketOffset); 11734fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Record.push_back(NumStatEntries); 1174ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); 11754fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor} 11764fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 11774fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 117814f79002e58556798e86168c63e48d533287eda5Douglas Gregor// Source Manager Serialization 117914f79002e58556798e86168c63e48d533287eda5Douglas Gregor//===----------------------------------------------------------------------===// 118014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 118114f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to a 118214f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// file. 1183c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { 118414f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 118514f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 11868538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); 118714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset 118814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location 118914f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic 119014f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives 11912d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor // FileEntry fields. 11922d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size 11932d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time 119414f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name 1195c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 119614f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 119714f79002e58556798e86168c63e48d533287eda5Douglas Gregor 119814f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to a 119914f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// buffer. 1200c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { 120114f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 120214f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 12038538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); 120414f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset 120514f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location 120614f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic 120714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives 120814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob 1209c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 121014f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 121114f79002e58556798e86168c63e48d533287eda5Douglas Gregor 121214f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to a 121314f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// buffer's blob. 1214c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { 121514f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 121614f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 12178538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); 121814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob 1219c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 122014f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 122114f79002e58556798e86168c63e48d533287eda5Douglas Gregor 122214f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to an 122314f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// buffer. 1224c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocInstantiationAbbrev(llvm::BitstreamWriter &Stream) { 122514f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 122614f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 12278538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_INSTANTIATION_ENTRY)); 122814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset 122914f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location 123014f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location 123114f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location 1232f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length 1233c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 123414f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 123514f79002e58556798e86168c63e48d533287eda5Douglas Gregor 1236cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregornamespace { 1237cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Trait used for the on-disk hash table of header search information. 1238cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor class HeaderFileInfoTrait { 1239cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ASTWriter &Writer; 1240cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor HeaderSearch &HS; 1241cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1242cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor public: 1243cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor HeaderFileInfoTrait(ASTWriter &Writer, HeaderSearch &HS) 1244cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor : Writer(Writer), HS(HS) { } 1245cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1246cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef const char *key_type; 1247cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef key_type key_type_ref; 1248cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1249cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef HeaderFileInfo data_type; 1250cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef const data_type &data_type_ref; 1251cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1252cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor static unsigned ComputeHash(const char *path) { 1253cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // The hash is based only on the filename portion of the key, so that the 1254cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // reader can match based on filenames when symlinking or excess path 1255cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // elements ("foo/../", "../") change the form of the name. However, 1256cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // complete path is still the key. 1257cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor return llvm::HashString(llvm::sys::path::filename(path)); 1258cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1259cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1260cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor std::pair<unsigned,unsigned> 1261cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor EmitKeyDataLength(llvm::raw_ostream& Out, const char *path, 1262cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor data_type_ref Data) { 1263cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned StrLen = strlen(path); 1264cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor clang::io::Emit16(Out, StrLen); 1265cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned DataLen = 1 + 2 + 4; 1266cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor clang::io::Emit8(Out, DataLen); 1267cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor return std::make_pair(StrLen + 1, DataLen); 1268cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1269cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1270cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor void EmitKey(llvm::raw_ostream& Out, const char *path, unsigned KeyLen) { 1271cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Out.write(path, KeyLen); 1272cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1273cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1274cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor void EmitData(llvm::raw_ostream &Out, key_type_ref, 1275cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor data_type_ref Data, unsigned DataLen) { 1276cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor using namespace clang::io; 1277cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor uint64_t Start = Out.tell(); (void)Start; 1278cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1279cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned char Flags = (Data.isImport << 3) 1280cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor | (Data.DirInfo << 1) 1281cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor | Data.Resolved; 1282cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit8(Out, (uint8_t)Flags); 1283cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit16(Out, (uint16_t) Data.NumIncludes); 1284cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1285cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (!Data.ControllingMacro) 1286cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit32(Out, (uint32_t)Data.ControllingMacroID); 1287cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor else 1288cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); 1289cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor assert(Out.tell() - Start == DataLen && "Wrong data length"); 1290cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1291cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor }; 1292cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor} // end anonymous namespace 1293cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1294cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \brief Write the header search block for the list of files that 1295cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// 1296cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \param HS The header search structure to save. 1297cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// 1298cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \param Chain Whether we're creating a chained AST file. 1299cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregorvoid ASTWriter::WriteHeaderSearch(HeaderSearch &HS, const char* isysroot) { 1300cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor llvm::SmallVector<const FileEntry *, 16> FilesByUID; 1301cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor HS.getFileMgr().GetUniqueIDMapping(FilesByUID); 1302cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1303cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (FilesByUID.size() > HS.header_file_size()) 1304cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor FilesByUID.resize(HS.header_file_size()); 1305cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1306cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor HeaderFileInfoTrait GeneratorTrait(*this, HS); 1307cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; 1308cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor llvm::SmallVector<const char *, 4> SavedStrings; 1309cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned NumHeaderSearchEntries = 0; 1310cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { 1311cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor const FileEntry *File = FilesByUID[UID]; 1312cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (!File) 1313cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor continue; 1314cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1315cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor const HeaderFileInfo &HFI = HS.header_file_begin()[UID]; 1316cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (HFI.External && Chain) 1317cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor continue; 1318cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1319cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Turn the file name into an absolute path, if it isn't already. 1320cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor const char *Filename = File->getName(); 1321cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); 1322cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1323cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // If we performed any translation on the file name at all, we need to 1324cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // save this string, since the generator will refer to it later. 1325cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (Filename != File->getName()) { 1326cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Filename = strdup(Filename); 1327cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor SavedStrings.push_back(Filename); 1328cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1329cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1330cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Generator.insert(Filename, HFI, GeneratorTrait); 1331cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ++NumHeaderSearchEntries; 1332cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1333cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1334cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Create the on-disk hash table in a buffer. 1335cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor llvm::SmallString<4096> TableData; 1336cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor uint32_t BucketOffset; 1337cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor { 1338cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor llvm::raw_svector_ostream Out(TableData); 1339cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Make sure that no bucket is at offset 0 1340cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor clang::io::Emit32(Out, 0); 1341cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor BucketOffset = Generator.Emit(Out, GeneratorTrait); 1342cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1343cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1344cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Create a blob abbreviation 1345cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor using namespace llvm; 1346cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 1347cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); 1348cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 1349cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 1350cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 1351cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); 1352cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1353cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Write the stat cache 1354cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor RecordData Record; 1355cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Record.push_back(HEADER_SEARCH_TABLE); 1356cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Record.push_back(BucketOffset); 1357cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Record.push_back(NumHeaderSearchEntries); 1358cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); 1359cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1360cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Free all of the strings we had to duplicate. 1361cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) 1362cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor free((void*)SavedStrings[I]); 1363cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor} 1364cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 136514f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Writes the block containing the serialized form of the 136614f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// source manager. 136714f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// 136814f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// TODO: We should probably use an on-disk hash table (stored in a 136914f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// blob), indexed based on the file name, so that we only create 137014f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// entries for files that we actually need. In the common case (no 137114f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// errors), we probably won't have to create file entries for any of 137214f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// the files in the AST. 1373a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, 1374e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const Preprocessor &PP, 1375e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const char *isysroot) { 13767f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RecordData Record; 13777f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 1378f04ad69fed38d26fc0d6f7d6fd0a4631ddfbc7feChris Lattner // Enter the source manager block. 13798538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); 138014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 138114f79002e58556798e86168c63e48d533287eda5Douglas Gregor // Abbreviations for the various kinds of source-location entries. 1382828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); 1383828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); 1384828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); 1385828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocInstantiationAbbrv = CreateSLocInstantiationAbbrev(Stream); 13867f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 13877f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Write the line table. 13887f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor if (SourceMgr.hasLineTable()) { 13897f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor LineTableInfo &LineTable = SourceMgr.getLineTable(); 13907f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 13917f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the file names 13927f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LineTable.getNumFilenames()); 13937f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { 13947f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the file name 13957f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor const char *Filename = LineTable.getFilename(I); 1396e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); 13977f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor unsigned FilenameLen = Filename? strlen(Filename) : 0; 13987f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(FilenameLen); 13997f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor if (FilenameLen) 14007f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.insert(Record.end(), Filename, Filename + FilenameLen); 14017f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor } 14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14037f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the line entries 14047f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); 14057f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor L != LEnd; ++L) { 14067f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the file ID 14077f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(L->first); 14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14097f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Emit the line entries 14107f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(L->second.size()); 14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (std::vector<LineEntry>::iterator LE = L->second.begin(), 14127f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor LEEnd = L->second.end(); 14137f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor LE != LEEnd; ++LE) { 14147f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LE->FileOffset); 14157f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LE->LineNo); 14167f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LE->FilenameID); 14177f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back((unsigned)LE->FileKind); 14187f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(LE->IncludeOffset); 14197f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor } 14207f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor } 14218538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SM_LINE_TABLE, Record); 14227f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor } 14237f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 142414f79002e58556798e86168c63e48d533287eda5Douglas Gregor // Write out the source location entry table. We skip the first 142514f79002e58556798e86168c63e48d533287eda5Douglas Gregor // entry, which is always the same dummy entry. 1426090d9b53e32bb30d9e74de895bb59b409bd49e00Chris Lattner std::vector<uint32_t> SLocEntryOffsets; 14277f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RecordData PreloadSLocs; 14280fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl unsigned BaseSLocID = Chain ? Chain->getTotalNumSLocs() : 0; 14290fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl SLocEntryOffsets.reserve(SourceMgr.sloc_entry_size() - 1 - BaseSLocID); 14300fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl for (unsigned I = BaseSLocID + 1, N = SourceMgr.sloc_entry_size(); 14310fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl I != N; ++I) { 1432bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor // Get this source location entry. 1433bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor const SrcMgr::SLocEntry *SLoc = &SourceMgr.getSLocEntry(I); 143411a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 14357f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Record the offset of this source-location entry. 14367f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); 14377f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 143814f79002e58556798e86168c63e48d533287eda5Douglas Gregor // Figure out which record code to use. 143914f79002e58556798e86168c63e48d533287eda5Douglas Gregor unsigned Code; 144014f79002e58556798e86168c63e48d533287eda5Douglas Gregor if (SLoc->isFile()) { 1441b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis if (SLoc->getFile().getContentCache()->OrigEntry) 14428538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = SM_SLOC_FILE_ENTRY; 144314f79002e58556798e86168c63e48d533287eda5Douglas Gregor else 14448538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = SM_SLOC_BUFFER_ENTRY; 144514f79002e58556798e86168c63e48d533287eda5Douglas Gregor } else 14468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = SM_SLOC_INSTANTIATION_ENTRY; 14477f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.clear(); 144814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(Code); 144914f79002e58556798e86168c63e48d533287eda5Douglas Gregor 145014f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(SLoc->getOffset()); 145114f79002e58556798e86168c63e48d533287eda5Douglas Gregor if (SLoc->isFile()) { 145214f79002e58556798e86168c63e48d533287eda5Douglas Gregor const SrcMgr::FileInfo &File = SLoc->getFile(); 145314f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(File.getIncludeLoc().getRawEncoding()); 145414f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding 1455bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor Record.push_back(File.hasLineDirectives()); 145614f79002e58556798e86168c63e48d533287eda5Douglas Gregor 145714f79002e58556798e86168c63e48d533287eda5Douglas Gregor const SrcMgr::ContentCache *Content = File.getContentCache(); 1458b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis if (Content->OrigEntry) { 1459b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis assert(Content->OrigEntry == Content->ContentsEntry && 1460b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis "Writing to AST an overriden file is not supported"); 1461b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis 146214f79002e58556798e86168c63e48d533287eda5Douglas Gregor // The source location entry is a file. The blob associated 146314f79002e58556798e86168c63e48d533287eda5Douglas Gregor // with this entry is the file name. 14641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14652d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor // Emit size/modification time for this file. 1466b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis Record.push_back(Content->OrigEntry->getSize()); 1467b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis Record.push_back(Content->OrigEntry->getModificationTime()); 14682d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor 1469e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // Turn the file name into an absolute path, if it isn't already. 1470b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis const char *Filename = Content->OrigEntry->getName(); 1471fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer llvm::SmallString<128> FilePath(Filename); 14722c10c8072cabeb22651462e435e8b81f3221b6a5Anders Carlsson 14732c10c8072cabeb22651462e435e8b81f3221b6a5Anders Carlsson // Ask the file manager to fixup the relative path for us. This will 14742c10c8072cabeb22651462e435e8b81f3221b6a5Anders Carlsson // honor the working directory. 14752c10c8072cabeb22651462e435e8b81f3221b6a5Anders Carlsson SourceMgr.getFileManager().FixupRelativePath(FilePath); 14762c10c8072cabeb22651462e435e8b81f3221b6a5Anders Carlsson 14772c10c8072cabeb22651462e435e8b81f3221b6a5Anders Carlsson // FIXME: This call to make_absolute shouldn't be necessary, the 14782c10c8072cabeb22651462e435e8b81f3221b6a5Anders Carlsson // call to FixupRelativePath should always return an absolute path. 1479fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer llvm::sys::fs::make_absolute(FilePath); 1480aba54a95e9d5e4dc9056abec6bb70ea777c4a7bcKovarththanan Rajaratnam Filename = FilePath.c_str(); 14811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1482e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); 1483ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); 148414f79002e58556798e86168c63e48d533287eda5Douglas Gregor } else { 148514f79002e58556798e86168c63e48d533287eda5Douglas Gregor // The source location entry is a buffer. The blob associated 148614f79002e58556798e86168c63e48d533287eda5Douglas Gregor // with this entry contains the contents of the buffer. 148714f79002e58556798e86168c63e48d533287eda5Douglas Gregor 148814f79002e58556798e86168c63e48d533287eda5Douglas Gregor // We add one to the size so that we capture the trailing NULL 148914f79002e58556798e86168c63e48d533287eda5Douglas Gregor // that is required by llvm::MemoryBuffer::getMemBuffer (on 149014f79002e58556798e86168c63e48d533287eda5Douglas Gregor // the reader side). 149136c35ba0aca641e60e5dbee8efbc620c08b9bd61Douglas Gregor const llvm::MemoryBuffer *Buffer 1492e127a0d80155b45dafe77f2b4380e5fa111a3345Chris Lattner = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); 149314f79002e58556798e86168c63e48d533287eda5Douglas Gregor const char *Name = Buffer->getBufferIdentifier(); 1494ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, 1495ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar llvm::StringRef(Name, strlen(Name) + 1)); 149614f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.clear(); 14978538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(SM_SLOC_BUFFER_BLOB); 1498c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, 1499ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar llvm::StringRef(Buffer->getBufferStart(), 1500ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Buffer->getBufferSize() + 1)); 15017f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 15027f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor if (strcmp(Name, "<built-in>") == 0) 15030fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl PreloadSLocs.push_back(BaseSLocID + SLocEntryOffsets.size()); 150414f79002e58556798e86168c63e48d533287eda5Douglas Gregor } 150514f79002e58556798e86168c63e48d533287eda5Douglas Gregor } else { 150614f79002e58556798e86168c63e48d533287eda5Douglas Gregor // The source location entry is an instantiation. 150714f79002e58556798e86168c63e48d533287eda5Douglas Gregor const SrcMgr::InstantiationInfo &Inst = SLoc->getInstantiation(); 150814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(Inst.getSpellingLoc().getRawEncoding()); 150914f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(Inst.getInstantiationLocStart().getRawEncoding()); 151014f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(Inst.getInstantiationLocEnd().getRawEncoding()); 151114f79002e58556798e86168c63e48d533287eda5Douglas Gregor 1512f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor // Compute the token length for this macro expansion. 1513f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor unsigned NextOffset = SourceMgr.getNextOffset(); 1514bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor if (I + 1 != N) 1515bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor NextOffset = SourceMgr.getSLocEntry(I + 1).getOffset(); 1516f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor Record.push_back(NextOffset - SLoc->getOffset() - 1); 1517c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecordWithAbbrev(SLocInstantiationAbbrv, Record); 151814f79002e58556798e86168c63e48d533287eda5Douglas Gregor } 151914f79002e58556798e86168c63e48d533287eda5Douglas Gregor } 152014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 15217f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Stream.ExitBlock(); 1522bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor 15237f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor if (SLocEntryOffsets.empty()) 15247f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor return; 15252eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor 15263397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Write the source-location offsets table into the AST block. This 15277f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // table is used for lazily loading source-location information. 15287f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor using namespace llvm; 15297f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 15308538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); 15317f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs 15327f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // next offset 15337f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets 15347f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); 15351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15367f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.clear(); 15378538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(SOURCE_LOCATION_OFFSETS); 15387f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(SLocEntryOffsets.size()); 15398db9faed418ea743f55c31e1ccecadbb23bd55b7Sebastian Redl unsigned BaseOffset = Chain ? Chain->getNextSLocOffset() : 0; 15408db9faed418ea743f55c31e1ccecadbb23bd55b7Sebastian Redl Record.push_back(SourceMgr.getNextOffset() - BaseOffset); 15417f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, 1542ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(SLocEntryOffsets), 1543090d9b53e32bb30d9e74de895bb59b409bd49e00Chris Lattner SLocEntryOffsets.size()*sizeof(SLocEntryOffsets[0])); 15447f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 15453397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Write the source location entry preloads array, telling the AST 15467f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // reader which source locations entries it should load eagerly. 15478538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); 154814f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 154914f79002e58556798e86168c63e48d533287eda5Douglas Gregor 15504fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 15514fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Preprocessor Serialization 15524fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 15534fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 15549c7361006b8cd95333958150dd0c803261807b68Douglas Gregorstatic int compareMacroDefinitions(const void *XPtr, const void *YPtr) { 15559c7361006b8cd95333958150dd0c803261807b68Douglas Gregor const std::pair<const IdentifierInfo *, MacroInfo *> &X = 15569c7361006b8cd95333958150dd0c803261807b68Douglas Gregor *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; 15579c7361006b8cd95333958150dd0c803261807b68Douglas Gregor const std::pair<const IdentifierInfo *, MacroInfo *> &Y = 15589c7361006b8cd95333958150dd0c803261807b68Douglas Gregor *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; 15599c7361006b8cd95333958150dd0c803261807b68Douglas Gregor return X.first->getName().compare(Y.first->getName()); 15609c7361006b8cd95333958150dd0c803261807b68Douglas Gregor} 15619c7361006b8cd95333958150dd0c803261807b68Douglas Gregor 15620b1fb988012da21d996c43e36867787a7a07b889Chris Lattner/// \brief Writes the block containing the serialized form of the 15630b1fb988012da21d996c43e36867787a7a07b889Chris Lattner/// preprocessor. 15640b1fb988012da21d996c43e36867787a7a07b889Chris Lattner/// 1565a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WritePreprocessor(const Preprocessor &PP) { 15667c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner RecordData Record; 15677c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner 1568c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner // If the preprocessor __COUNTER__ value has been bumped, remember it. 1569c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner if (PP.getCounterValue() != 0) { 1570c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner Record.push_back(PP.getCounterValue()); 15718538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(PP_COUNTER_VALUE, Record); 1572c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner Record.clear(); 15732eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor } 15742eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor 15752eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor // Enter the preprocessor block. 1576ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); 15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15783397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // If the AST file contains __DATE__ or __TIME__ emit a warning about this. 15792eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor // FIXME: use diagnostics subsystem for localization etc. 15802eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor if (PP.SawDateOrTime()) 15812eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); 15821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1583ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor 15847c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner // Loop over all the macro definitions that are live at the end of the file, 15857c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner // emitting each to the PP section. 15866a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); 158720249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 15889c7361006b8cd95333958150dd0c803261807b68Douglas Gregor // Construct the list of macro definitions that need to be serialized. 15899c7361006b8cd95333958150dd0c803261807b68Douglas Gregor llvm::SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> 15909c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacrosToEmit; 15919c7361006b8cd95333958150dd0c803261807b68Douglas Gregor llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; 1592040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), 1593040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor E = PP.macro_end(Chain == 0); 15947c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner I != E; ++I) { 15959c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacroDefinitionsSeen.insert(I->first); 15969c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacrosToEmit.push_back(std::make_pair(I->first, I->second)); 15979c7361006b8cd95333958150dd0c803261807b68Douglas Gregor } 15989c7361006b8cd95333958150dd0c803261807b68Douglas Gregor 15999c7361006b8cd95333958150dd0c803261807b68Douglas Gregor // Sort the set of macro definitions that need to be serialized by the 16009c7361006b8cd95333958150dd0c803261807b68Douglas Gregor // name of the macro, to provide a stable ordering. 16019c7361006b8cd95333958150dd0c803261807b68Douglas Gregor llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), 16029c7361006b8cd95333958150dd0c803261807b68Douglas Gregor &compareMacroDefinitions); 16039c7361006b8cd95333958150dd0c803261807b68Douglas Gregor 1604040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor // Resolve any identifiers that defined macros at the time they were 1605040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor // deserialized, adding them to the list of macros to emit (if appropriate). 1606040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor for (unsigned I = 0, N = DeserializedMacroNames.size(); I != N; ++I) { 1607040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor IdentifierInfo *Name 1608040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor = const_cast<IdentifierInfo *>(DeserializedMacroNames[I]); 1609040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor if (Name->hasMacroDefinition() && MacroDefinitionsSeen.insert(Name)) 1610040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor MacrosToEmit.push_back(std::make_pair(Name, PP.getMacroInfo(Name))); 1611040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor } 1612040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor 16139c7361006b8cd95333958150dd0c803261807b68Douglas Gregor for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { 16149c7361006b8cd95333958150dd0c803261807b68Douglas Gregor const IdentifierInfo *Name = MacrosToEmit[I].first; 16159c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacroInfo *MI = MacrosToEmit[I].second; 1616040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor if (!MI) 1617040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor continue; 1618040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor 16193397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Don't emit builtin macros like __LINE__ to the AST file unless they have 16207c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner // been redefined by the header (in which case they are not isBuiltinMacro). 16213397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Also skip macros from a AST file if we're chaining. 1622ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor 1623ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor // FIXME: There is a (probably minor) optimization we could do here, if 1624ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor // the macro comes from the original PCH but the identifier comes from a 1625ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor // chained PCH, by storing the offset into the original PCH rather than 1626ee9b0ba29094eb177a285e726ab96e979e5b9c61Douglas Gregor // writing the macro definition a second time. 162720249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer if (MI->isBuiltinMacro() || 16289c7361006b8cd95333958150dd0c803261807b68Douglas Gregor (Chain && Name->isFromAST() && MI->isFromAST())) 16297c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner continue; 16307c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner 16319c7361006b8cd95333958150dd0c803261807b68Douglas Gregor AddIdentifierRef(Name, Record); 16329c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacroOffsets[Name] = Stream.GetCurrentBitNo(); 16337c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->getDefinitionLoc().getRawEncoding()); 16347c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->isUsed()); 16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16367c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner unsigned Code; 16377c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner if (MI->isObjectLike()) { 16388538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = PP_MACRO_OBJECT_LIKE; 16397c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner } else { 16408538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = PP_MACRO_FUNCTION_LIKE; 16411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16427c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->isC99Varargs()); 16437c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->isGNUVarargs()); 16447c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.push_back(MI->getNumArgs()); 16457c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); 16467c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner I != E; ++I) 16477356a31327be9b3c3434a0c88746028980da5684Chris Lattner AddIdentifierRef(*I, Record); 16487c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner } 164920249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 16506a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // If we have a detailed preprocessing record, record the macro definition 16516a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // ID that corresponds to this macro. 16526a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor if (PPRec) 16536a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Record.push_back(getMacroDefinitionID(PPRec->findMacroDefinition(MI))); 165420249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 1655c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecord(Code, Record); 16567c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner Record.clear(); 1657f04ad69fed38d26fc0d6f7d6fd0a4631ddfbc7feChris Lattner 1658df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // Emit the tokens array. 1659df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { 1660df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // Note that we know that the preprocessor does not have any annotation 1661df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // tokens in it because they are created by the parser, and thus can't be 1662df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // in a macro definition. 1663df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner const Token &Tok = MI->getReplacementToken(TokNo); 16641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1665df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.push_back(Tok.getLocation().getRawEncoding()); 1666df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.push_back(Tok.getLength()); 1667df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner 1668df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // FIXME: When reading literal tokens, reconstruct the literal pointer if 1669df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // it is needed. 16707356a31327be9b3c3434a0c88746028980da5684Chris Lattner AddIdentifierRef(Tok.getIdentifierInfo(), Record); 1671df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // FIXME: Should translate token kind to a stable encoding. 1672df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.push_back(Tok.getKind()); 1673df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner // FIXME: Should translate token flags to a stable encoding. 1674df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.push_back(Tok.getFlags()); 16751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16768538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(PP_TOKEN, Record); 1677df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.clear(); 1678df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner } 167937e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor ++NumMacros; 16807c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner } 16814800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.ExitBlock(); 16824800a5c79023271408af49797e09be32aca93232Douglas Gregor 16834800a5c79023271408af49797e09be32aca93232Douglas Gregor if (PPRec) 16844800a5c79023271408af49797e09be32aca93232Douglas Gregor WritePreprocessorDetail(*PPRec); 16854800a5c79023271408af49797e09be32aca93232Douglas Gregor} 16864800a5c79023271408af49797e09be32aca93232Douglas Gregor 16874800a5c79023271408af49797e09be32aca93232Douglas Gregorvoid ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { 16884800a5c79023271408af49797e09be32aca93232Douglas Gregor if (PPRec.begin(Chain) == PPRec.end(Chain)) 16894800a5c79023271408af49797e09be32aca93232Douglas Gregor return; 16904800a5c79023271408af49797e09be32aca93232Douglas Gregor 16914800a5c79023271408af49797e09be32aca93232Douglas Gregor // Enter the preprocessor block. 16924800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); 169320249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 16946a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // If the preprocessor has a preprocessing record, emit it. 16956a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor unsigned NumPreprocessingRecords = 0; 16964800a5c79023271408af49797e09be32aca93232Douglas Gregor using namespace llvm; 16974800a5c79023271408af49797e09be32aca93232Douglas Gregor 16984800a5c79023271408af49797e09be32aca93232Douglas Gregor // Set up the abbreviation for 16994800a5c79023271408af49797e09be32aca93232Douglas Gregor unsigned InclusionAbbrev = 0; 17004800a5c79023271408af49797e09be32aca93232Douglas Gregor { 17014800a5c79023271408af49797e09be32aca93232Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 17024800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); 17034800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index 17044800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // start location 17054800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // end location 17064800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length 17074800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes 17084800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind 17094800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 17104800a5c79023271408af49797e09be32aca93232Douglas Gregor InclusionAbbrev = Stream.EmitAbbrev(Abbrev); 17114800a5c79023271408af49797e09be32aca93232Douglas Gregor } 17124800a5c79023271408af49797e09be32aca93232Douglas Gregor 17134800a5c79023271408af49797e09be32aca93232Douglas Gregor unsigned IndexBase = Chain ? PPRec.getNumPreallocatedEntities() : 0; 17144800a5c79023271408af49797e09be32aca93232Douglas Gregor RecordData Record; 17154800a5c79023271408af49797e09be32aca93232Douglas Gregor for (PreprocessingRecord::iterator E = PPRec.begin(Chain), 17164800a5c79023271408af49797e09be32aca93232Douglas Gregor EEnd = PPRec.end(Chain); 17174800a5c79023271408af49797e09be32aca93232Douglas Gregor E != EEnd; ++E) { 17184800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.clear(); 171920249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 17204800a5c79023271408af49797e09be32aca93232Douglas Gregor if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { 17214800a5c79023271408af49797e09be32aca93232Douglas Gregor // Record this macro definition's location. 17224800a5c79023271408af49797e09be32aca93232Douglas Gregor MacroID ID = getMacroDefinitionID(MD); 17234800a5c79023271408af49797e09be32aca93232Douglas Gregor 17244800a5c79023271408af49797e09be32aca93232Douglas Gregor // Don't write the macro definition if it is from another AST file. 17254800a5c79023271408af49797e09be32aca93232Douglas Gregor if (ID < FirstMacroID) 17266a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor continue; 17274800a5c79023271408af49797e09be32aca93232Douglas Gregor 172889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor // Notify the serialization listener that we're serializing this entity. 172989d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor if (SerializationListener) 173089d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor SerializationListener->SerializedPreprocessedEntity(*E, 17314800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.GetCurrentBitNo()); 173289d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 17334800a5c79023271408af49797e09be32aca93232Douglas Gregor unsigned Position = ID - FirstMacroID; 17344800a5c79023271408af49797e09be32aca93232Douglas Gregor if (Position != MacroDefinitionOffsets.size()) { 17354800a5c79023271408af49797e09be32aca93232Douglas Gregor if (Position > MacroDefinitionOffsets.size()) 17364800a5c79023271408af49797e09be32aca93232Douglas Gregor MacroDefinitionOffsets.resize(Position + 1); 17374800a5c79023271408af49797e09be32aca93232Douglas Gregor 17384800a5c79023271408af49797e09be32aca93232Douglas Gregor MacroDefinitionOffsets[Position] = Stream.GetCurrentBitNo(); 17394800a5c79023271408af49797e09be32aca93232Douglas Gregor } else 17404800a5c79023271408af49797e09be32aca93232Douglas Gregor MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo()); 174189d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 17424800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(IndexBase + NumPreprocessingRecords++); 17434800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(ID); 17444800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MD->getSourceRange().getBegin(), Record); 17454800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MD->getSourceRange().getEnd(), Record); 17464800a5c79023271408af49797e09be32aca93232Douglas Gregor AddIdentifierRef(MD->getName(), Record); 17474800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MD->getLocation(), Record); 17484800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); 17494800a5c79023271408af49797e09be32aca93232Douglas Gregor continue; 17504800a5c79023271408af49797e09be32aca93232Douglas Gregor } 17514800a5c79023271408af49797e09be32aca93232Douglas Gregor 17524800a5c79023271408af49797e09be32aca93232Douglas Gregor // Notify the serialization listener that we're serializing this entity. 17534800a5c79023271408af49797e09be32aca93232Douglas Gregor if (SerializationListener) 17544800a5c79023271408af49797e09be32aca93232Douglas Gregor SerializationListener->SerializedPreprocessedEntity(*E, 17554800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.GetCurrentBitNo()); 17564800a5c79023271408af49797e09be32aca93232Douglas Gregor 17574800a5c79023271408af49797e09be32aca93232Douglas Gregor if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) { 17584800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(IndexBase + NumPreprocessingRecords++); 17594800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MI->getSourceRange().getBegin(), Record); 17604800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(MI->getSourceRange().getEnd(), Record); 17614800a5c79023271408af49797e09be32aca93232Douglas Gregor AddIdentifierRef(MI->getName(), Record); 17624800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(getMacroDefinitionID(MI->getDefinition())); 17634800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EmitRecord(PPD_MACRO_INSTANTIATION, Record); 17644800a5c79023271408af49797e09be32aca93232Douglas Gregor continue; 17656a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor } 176620249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 17674800a5c79023271408af49797e09be32aca93232Douglas Gregor if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { 17684800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(PPD_INCLUSION_DIRECTIVE); 17694800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(IndexBase + NumPreprocessingRecords++); 17704800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(ID->getSourceRange().getBegin(), Record); 17714800a5c79023271408af49797e09be32aca93232Douglas Gregor AddSourceLocation(ID->getSourceRange().getEnd(), Record); 17724800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(ID->getFileName().size()); 17734800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(ID->wasInQuotes()); 17744800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(static_cast<unsigned>(ID->getKind())); 17754800a5c79023271408af49797e09be32aca93232Douglas Gregor llvm::SmallString<64> Buffer; 17764800a5c79023271408af49797e09be32aca93232Douglas Gregor Buffer += ID->getFileName(); 17774800a5c79023271408af49797e09be32aca93232Douglas Gregor Buffer += ID->getFile()->getName(); 17784800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); 17794800a5c79023271408af49797e09be32aca93232Douglas Gregor continue; 17804800a5c79023271408af49797e09be32aca93232Douglas Gregor } 17814800a5c79023271408af49797e09be32aca93232Douglas Gregor 17824800a5c79023271408af49797e09be32aca93232Douglas Gregor llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); 17834800a5c79023271408af49797e09be32aca93232Douglas Gregor } 1784c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.ExitBlock(); 178520249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 17866a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // Write the offsets table for the preprocessing record. 17876a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor if (NumPreprocessingRecords > 0) { 17886a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // Write the offsets table for identifier IDs. 17896a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor using namespace llvm; 17906a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 17918538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(MACRO_DEFINITION_OFFSETS)); 17926a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of records 17936a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macro defs 17946a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 17956a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor unsigned MacroDefOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 179620249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 17976a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Record.clear(); 17988538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(MACRO_DEFINITION_OFFSETS); 17996a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Record.push_back(NumPreprocessingRecords); 18006a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Record.push_back(MacroDefinitionOffsets.size()); 18016a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record, 1802ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(MacroDefinitionOffsets), 18036a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor MacroDefinitionOffsets.size() * sizeof(uint32_t)); 18046a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor } 18050b1fb988012da21d996c43e36867787a7a07b889Chris Lattner} 18060b1fb988012da21d996c43e36867787a7a07b889Chris Lattner 18073efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidisvoid ASTWriter::WritePragmaDiagnosticMappings(const Diagnostic &Diag) { 1808f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis RecordData Record; 18093efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis for (Diagnostic::DiagStatePointsTy::const_iterator 18103efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); 18113efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis I != E; ++I) { 18123efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis const Diagnostic::DiagStatePoint &point = *I; 18133efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis if (point.Loc.isInvalid()) 18143efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis continue; 18153efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis 18163efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Record.push_back(point.Loc.getRawEncoding()); 18173efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis for (Diagnostic::DiagState::iterator 18183efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis I = point.State->begin(), E = point.State->end(); I != E; ++I) { 18193efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis unsigned diag = I->first, map = I->second; 18203efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis if (map & 0x10) { // mapping from a diagnostic pragma. 18213efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Record.push_back(diag); 18223efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Record.push_back(map & 0x7); 18233efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis } 1824f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis } 18253efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Record.push_back(-1); // mark the end of the diag/map pairs for this 18263efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis // location. 1827f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis } 1828f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis 182960f7684881f9f6bc779e91212aea89d9afc723ddArgyrios Kyrtzidis if (!Record.empty()) 18303efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); 1831f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis} 1832f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis 1833c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlssonvoid ASTWriter::WriteCXXBaseSpecifiersOffsets() { 1834c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson if (CXXBaseSpecifiersOffsets.empty()) 1835c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson return; 1836c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 1837c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson RecordData Record; 1838c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 1839c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson // Create a blob abbreviation for the C++ base specifiers offsets. 1840c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson using namespace llvm; 1841c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 1842c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 1843c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); 1844c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size 1845c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 1846c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 1847c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 1848c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson // Write the selector offsets table. 1849c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Record.clear(); 1850c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); 1851c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Record.push_back(CXXBaseSpecifiersOffsets.size()); 1852c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, 1853c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson (const char *)CXXBaseSpecifiersOffsets.data(), 1854c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson CXXBaseSpecifiersOffsets.size() * sizeof(uint32_t)); 1855c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson} 1856c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 18574fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 18584fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Type Serialization 18594fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 18600b1fb988012da21d996c43e36867787a7a07b889Chris Lattner 18613397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the representation of a type to the AST stream. 1862a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteType(QualType T) { 186301b81c4d074bba9c18372d521405dfe32fc4f552Argyrios Kyrtzidis TypeIdx &Idx = TypeIdxs[T]; 1864c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis if (Idx.getIndex() == 0) // we haven't seen this type before. 1865c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis Idx = TypeIdx(NextTypeID++); 18661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 186797475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); 186855f48de5f6b10b50f4d88a9f7235f4532f799550Douglas Gregor 18692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Record the offset for this type. 1870c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis unsigned Index = Idx.getIndex() - FirstTypeID; 1871681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl if (TypeOffsets.size() == Index) 1872c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor TypeOffsets.push_back(Stream.GetCurrentBitNo()); 1873681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl else if (TypeOffsets.size() < Index) { 1874681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl TypeOffsets.resize(Index + 1); 1875681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl TypeOffsets[Index] = Stream.GetCurrentBitNo(); 18762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 18772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 18782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor RecordData Record; 18791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Emit the type's representation. 18813397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTTypeWriter W(*this, Record); 18820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1883a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (T.hasLocalNonFastQualifiers()) { 1884a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Qs = T.getLocalQualifiers(); 1885a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor AddTypeRef(T.getLocalUnqualifiedType(), Record); 18860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Record.push_back(Qs.getAsOpaqueValue()); 18878538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl W.Code = TYPE_EXT_QUAL; 18880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } else { 18890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall switch (T->getTypeClass()) { 18900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // For all of the concrete, non-dependent types, call the 18910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // appropriate visitor function. 18922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define TYPE(Class, Base) \ 1893b7166334d897e1e4e6a5b428fe2d0ec752ef187fMike Stump case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; 18942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define ABSTRACT_TYPE(Class, Base) 18952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/TypeNodes.def" 18960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 18972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 18982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 18992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Emit the serialized record. 1900c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecord(W.Code, Record); 19010b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 19020b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor // Flush any expressions that were written as part of this type. 1903c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor FlushStmts(); 19042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 19052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 19064fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 19074fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Declaration Serialization 19084fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 19094fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 19102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// \brief Write the block containing all of the declaration IDs 19112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// lexically declared within the given DeclContext. 19122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// 19132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// \returns the offset of the DECL_CONTEXT_LEXICAL block within the 19142cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// bistream, or 0 if no block was written. 1915a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redluint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, 19162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor DeclContext *DC) { 191717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis if (DC->decls_empty()) 19182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor return 0; 19192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1920c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor uint64_t Offset = Stream.GetCurrentBitNo(); 19212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor RecordData Record; 19228538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(DECL_CONTEXT_LEXICAL); 1923eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis llvm::SmallVector<KindDeclIDPair, 64> Decls; 192417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); 192517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis D != DEnd; ++D) 1926eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); 19272cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 19282512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor ++NumLexicalDeclContexts; 1929681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, 1930eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis reinterpret_cast<char*>(Decls.data()), 1931eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis Decls.size() * sizeof(KindDeclIDPair)); 19322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor return Offset; 19332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 19342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1935a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteTypeDeclOffsets() { 19361476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl using namespace llvm; 19371476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl RecordData Record; 19381476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 19391476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // Write the type offsets array 19401476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 19418538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); 19421476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types 19431476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block 19441476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 19451476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.clear(); 19468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(TYPE_OFFSET); 19471476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.push_back(TypeOffsets.size()); 19481476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, 1949ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(TypeOffsets), 19501476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl TypeOffsets.size() * sizeof(TypeOffsets[0])); 19511476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 19521476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // Write the declaration offsets array 19531476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev = new BitCodeAbbrev(); 19548538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); 19551476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations 19561476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block 19571476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 19581476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.clear(); 19598538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(DECL_OFFSET); 19601476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.push_back(DeclOffsets.size()); 19611476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, 1962ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(DeclOffsets), 19631476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl DeclOffsets.size() * sizeof(DeclOffsets[0])); 19641476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl} 19651476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 19664fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 19674fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Global Method Pool and Selector Serialization 19684fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 19694fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 19703251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregornamespace { 1971f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor// Trait used for the on-disk hash table used in the method pool. 19723397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlclass ASTMethodPoolTrait { 1973a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 1974f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 1975f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregorpublic: 1976f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor typedef Selector key_type; 1977f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor typedef key_type key_type_ref; 19781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19795d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl struct data_type { 19808538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl SelectorID ID; 19815d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl ObjCMethodList Instance, Factory; 19825d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl }; 1983f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor typedef const data_type& data_type_ref; 1984f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 19853397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } 19861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1987f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor static unsigned ComputeHash(Selector Sel) { 19880eca89e9890db4d8336ce762a5b359a1d58ca02bArgyrios Kyrtzidis return serialization::ComputeHash(Sel); 1989f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 19901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<unsigned,unsigned> 1992f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor EmitKeyDataLength(llvm::raw_ostream& Out, Selector Sel, 1993f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor data_type_ref Methods) { 1994f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); 1995f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, KeyLen); 19965d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts 19975d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Instance; Method; 1998f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 1999f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2000f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor DataLen += 4; 20015d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Factory; Method; 2002f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2003f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2004f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor DataLen += 4; 2005f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, DataLen); 2006f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor return std::make_pair(KeyLen, DataLen); 2007f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 20081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 200983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor void EmitKey(llvm::raw_ostream& Out, Selector Sel, unsigned) { 20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump uint64_t Start = Out.tell(); 201183941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor assert((Start >> 32) == 0 && "Selector key offset too large"); 201283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Writer.SetSelectorOffset(Sel, Start); 2013f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned N = Sel.getNumArgs(); 2014f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, N); 2015f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (N == 0) 2016f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor N = 1; 2017f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor for (unsigned I = 0; I != N; ++I) 20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump clang::io::Emit32(Out, 2019f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); 2020f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 20211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2022f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor void EmitData(llvm::raw_ostream& Out, key_type_ref, 2023a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor data_type_ref Methods, unsigned DataLen) { 2024a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor uint64_t Start = Out.tell(); (void)Start; 20255d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl clang::io::Emit32(Out, Methods.ID); 2026f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned NumInstanceMethods = 0; 20275d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Instance; Method; 2028f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2029f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2030f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ++NumInstanceMethods; 2031f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2032f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned NumFactoryMethods = 0; 20335d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Factory; Method; 2034f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2035f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2036f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ++NumFactoryMethods; 2037f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2038f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, NumInstanceMethods); 2039f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, NumFactoryMethods); 20405d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Instance; Method; 2041f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2042f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2043f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); 20445d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Factory; Method; 2045f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2046f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2047f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); 2048a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor 2049a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor assert(Out.tell() - Start == DataLen && "Data length is wrong"); 2050f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2051f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor}; 2052f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor} // end anonymous namespace 2053f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2054059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl/// \brief Write ObjC data: selectors and the method pool. 2055f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor/// 2056f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor/// The method pool contains both instance and factory methods, stored 2057059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl/// in an on-disk hash table indexed by the selector. The hash table also 2058059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl/// contains an empty entry for every other selector known to Sema. 2059a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteSelectors(Sema &SemaRef) { 2060f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor using namespace llvm; 2061f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2062059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // Do we have to do anything at all? 20635d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) 2064059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl return; 2065e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl unsigned NumTableEntries = 0; 2066059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // Create and write out the blob that contains selectors and the method pool. 2067f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor { 20683397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; 20695d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ASTMethodPoolTrait Trait(*this); 20701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2071059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // Create the on-disk hash table representation. We walk through every 2072059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // selector we've seen and look it up in the method pool. 2073e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl SelectorOffsets.resize(NextSelectorID - FirstSelectorID); 20748538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl for (llvm::DenseMap<Selector, SelectorID>::iterator 20755d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl I = SelectorIDs.begin(), E = SelectorIDs.end(); 20765d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl I != E; ++I) { 20775d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Selector S = I->first; 2078059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); 20793397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTMethodPoolTrait::data_type Data = { 20805d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl I->second, 20815d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl ObjCMethodList(), 20825d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl ObjCMethodList() 20835d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl }; 20845d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl if (F != SemaRef.MethodPool.end()) { 20855d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Data.Instance = F->second.first; 20865d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Data.Factory = F->second.second; 20875d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl } 20883397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Only write this selector if it's not in an existing AST or something 2089e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // changed. 2090e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (Chain && I->second < FirstSelectorID) { 2091e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // Selector already exists. Did it change? 2092e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl bool changed = false; 2093e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; 2094e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl M = M->Next) { 2095e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (M->Method->getPCHLevel() == 0) 2096e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl changed = true; 2097e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 2098e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; 2099e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl M = M->Next) { 2100e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (M->Method->getPCHLevel() == 0) 2101e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl changed = true; 2102e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 2103e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (!changed) 2104e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl continue; 2105fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl } else if (Data.Instance.Method || Data.Factory.Method) { 2106fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl // A new method pool entry. 2107fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl ++NumTableEntries; 2108e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 21095d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Generator.insert(S, Data, Trait); 2110f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2111f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2112f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Create the on-disk hash table in a buffer. 21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::SmallString<4096> MethodPool; 2114f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor uint32_t BucketOffset; 2115f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor { 21163397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTMethodPoolTrait Trait(*this); 2117f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor llvm::raw_svector_ostream Out(MethodPool); 2118f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Make sure that no bucket is at offset 0 2119a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor clang::io::Emit32(Out, 0); 2120f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor BucketOffset = Generator.Emit(Out, Trait); 2121f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2122f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2123f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Create a blob abbreviation 2124f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 21258538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); 2126f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 212783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 2128f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2129f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); 2130f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 213183941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor // Write the method pool 2132f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor RecordData Record; 21338538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(METHOD_POOL); 2134f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Record.push_back(BucketOffset); 2135e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl Record.push_back(NumTableEntries); 2136ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); 213783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor 213883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor // Create a blob abbreviation for the selector table offsets. 213983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Abbrev = new BitCodeAbbrev(); 21408538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); 21417c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size 214283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 214383941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 214483941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor 214583941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor // Write the selector offsets table. 214683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Record.clear(); 21478538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(SELECTOR_OFFSETS); 214883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Record.push_back(SelectorOffsets.size()); 214983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, 2150ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(SelectorOffsets), 215183941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor SelectorOffsets.size() * 4); 2152f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2153f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor} 2154f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 21553397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the selectors referenced in @selector expression into AST file. 2156a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { 2157320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian using namespace llvm; 2158320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian if (SemaRef.ReferencedSelectors.empty()) 2159320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian return; 2160725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl 2161320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian RecordData Record; 2162725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl 21633397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Note: this writes out all references even for a dependent AST. But it is 2164a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl // very tricky to fix, and given that @selector shouldn't really appear in 2165a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl // headers, probably not worth it. It's not a correctness issue. 2166320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian for (DenseMap<Selector, SourceLocation>::iterator S = 2167320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian SemaRef.ReferencedSelectors.begin(), 2168320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { 2169320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian Selector Sel = (*S).first; 2170320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian SourceLocation Loc = (*S).second; 2171320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian AddSelectorRef(Sel, Record); 2172320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian AddSourceLocation(Loc, Record); 2173320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian } 21748538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); 2175320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian} 2176320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian 21774fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 21784fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Identifier Table Serialization 21794fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 21804fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 2181f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregornamespace { 21823397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlclass ASTIdentifierTableTrait { 2183a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 218437e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor Preprocessor &PP; 21853251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 2186a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor /// \brief Determines whether this is an "interesting" identifier 2187a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor /// that needs a full IdentifierInfo structure written into the hash 2188a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor /// table. 2189a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor static bool isInterestingIdentifier(const IdentifierInfo *II) { 2190a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor return II->isPoisoned() || 2191a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor II->isExtensionToken() || 2192a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor II->hasMacroDefinition() || 2193a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor II->getObjCOrBuiltinID() || 2194a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor II->getFETokenInfo<void>(); 2195a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor } 2196a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor 21973251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregorpublic: 21983251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor typedef const IdentifierInfo* key_type; 21993251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor typedef key_type key_type_ref; 22001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22018538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl typedef IdentID data_type; 22023251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor typedef data_type data_type_ref; 22031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22043397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP) 220537e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor : Writer(Writer), PP(PP) { } 22063251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 22073251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor static unsigned ComputeHash(const IdentifierInfo* II) { 22082596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar return llvm::HashString(II->getName()); 22093251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 22101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<unsigned,unsigned> 22121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EmitKeyDataLength(llvm::raw_ostream& Out, const IdentifierInfo* II, 22138538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID ID) { 2214e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar unsigned KeyLen = II->getLength() + 1; 2215a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 2216a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor if (isInterestingIdentifier(II)) { 22175998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor DataLen += 2; // 2 bytes for builtin ID, flags 22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (II->hasMacroDefinition() && 2219a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro()) 22205998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor DataLen += 4; 2221a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor for (IdentifierResolver::iterator D = IdentifierResolver::begin(II), 2222a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor DEnd = IdentifierResolver::end(); 2223a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor D != DEnd; ++D) 22248538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl DataLen += sizeof(DeclID); 2225a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor } 2226668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor clang::io::Emit16(Out, DataLen); 222702fc75169afe785c114e795ec4d24edfb4073c42Douglas Gregor // We emit the key length after the data length so that every 222802fc75169afe785c114e795ec4d24edfb4073c42Douglas Gregor // string is preceded by a 16-bit length. This matches the PTH 222902fc75169afe785c114e795ec4d24edfb4073c42Douglas Gregor // format for storing identifiers. 2230d6595a40fe12e3d5ffe5ce48987b379d547439a4Douglas Gregor clang::io::Emit16(Out, KeyLen); 22313251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor return std::make_pair(KeyLen, DataLen); 22323251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 22331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void EmitKey(llvm::raw_ostream& Out, const IdentifierInfo* II, 22353251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor unsigned KeyLen) { 22363251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor // Record the location of the key data. This is used when generating 22373251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor // the mapping from persistent IDs to strings. 22383251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor Writer.SetIdentifierOffset(II, Out.tell()); 2239e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar Out.write(II->getNameStart(), KeyLen); 22403251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 22411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void EmitData(llvm::raw_ostream& Out, const IdentifierInfo* II, 22438538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID ID, unsigned) { 2244a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor if (!isInterestingIdentifier(II)) { 2245a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor clang::io::Emit32(Out, ID << 1); 2246a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor return; 2247a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor } 22485998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor 2249a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor clang::io::Emit32(Out, (ID << 1) | 0x01); 22503251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor uint32_t Bits = 0; 22511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasMacroDefinition = 22521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump II->hasMacroDefinition() && 225337e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro(); 22545998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor Bits = (uint32_t)II->getObjCOrBuiltinID(); 2255b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(hasMacroDefinition); 2256b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(II->isExtensionToken()); 2257b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(II->isPoisoned()); 2258646395bbcaa849c94bc2a3246c71d809ca719f01Argyrios Kyrtzidis Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); 2259b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); 22605998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor clang::io::Emit16(Out, Bits); 22613251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 226237e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor if (hasMacroDefinition) 22635998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor clang::io::Emit32(Out, Writer.getMacroOffset(II)); 226437e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor 2265668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // Emit the declaration IDs in reverse order, because the 2266668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // IdentifierResolver provides the declarations as they would be 2267668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // visible (e.g., the function "stat" would come before the struct 2268668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // "stat"), but IdentifierResolver::AddDeclToIdentifierChain() 2269668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // adds declarations to the end of the list (so we need to see the 2270668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // struct "status" before the function "status"). 2271f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // Only emit declarations that aren't from a chained PCH, though. 22721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::SmallVector<Decl *, 16> Decls(IdentifierResolver::begin(II), 2273668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor IdentifierResolver::end()); 2274668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor for (llvm::SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), 2275668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor DEnd = Decls.rend(); 22763251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor D != DEnd; ++D) 2277d8c5abb096a5f6babb3709180fe304be5462bcc1Sebastian Redl clang::io::Emit32(Out, Writer.getDeclID(*D)); 22783251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 22793251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor}; 22803251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor} // end anonymous namespace 22813251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 22823397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the identifier table into the AST file. 2283afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// 2284afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// The identifier table consists of a blob containing string data 2285afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// (the actual identifiers themselves) and a separate "offsets" index 2286afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// that maps identifier IDs to locations within the blob. 2287a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteIdentifierTable(Preprocessor &PP) { 2288afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor using namespace llvm; 2289afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2290afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Create and write out the blob that contains the identifier 2291afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // strings. 2292afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor { 22933397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; 22945d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ASTIdentifierTableTrait Trait(*this, PP); 22951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 229692b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // Look for any identifiers that were named while processing the 229792b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // headers, but are otherwise not needed. We add these to the hash 229892b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // table to enable checking of the predefines buffer in the case 22993397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // where the user adds new macro definitions when building the AST 230092b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // file. 230192b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), 230292b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor IDEnd = PP.getIdentifierTable().end(); 230392b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor ID != IDEnd; ++ID) 230492b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor getIdentifierRef(ID->second); 230592b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor 2306f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // Create the on-disk hash table representation. We only store offsets 2307f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // for identifiers that appear here for the first time. 2308f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl IdentifierOffsets.resize(NextIdentID - FirstIdentID); 23098538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator 2310afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); 2311afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor ID != IDEnd; ++ID) { 2312afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor assert(ID->first && "NULL identifier in identifier table"); 23133c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl if (!Chain || !ID->first->isFromAST()) 23145d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Generator.insert(ID->first, ID->second, Trait); 23153251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 2316afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 23173251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor // Create the on-disk hash table in a buffer. 23181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::SmallString<4096> IdentifierTable; 2319668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor uint32_t BucketOffset; 23203251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor { 23213397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTIdentifierTableTrait Trait(*this, PP); 23223251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor llvm::raw_svector_ostream Out(IdentifierTable); 2323f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Make sure that no bucket is at offset 0 2324a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor clang::io::Emit32(Out, 0); 2325668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor BucketOffset = Generator.Emit(Out, Trait); 2326afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor } 2327afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2328afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Create a blob abbreviation 2329afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 23308538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); 2331668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 23323251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2333c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); 2334afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2335afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Write the identifier table 2336afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor RecordData Record; 23378538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(IDENTIFIER_TABLE); 2338668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor Record.push_back(BucketOffset); 2339ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); 2340afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor } 2341afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2342afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Write the offsets table for identifier IDs. 23432b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 23448538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); 23452b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers 23462b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 23472b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 23482b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor 23492b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor RecordData Record; 23508538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(IDENTIFIER_OFFSET); 23512b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Record.push_back(IdentifierOffsets.size()); 23522b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, 2353ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl (const char *)data(IdentifierOffsets), 23542b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor IdentifierOffsets.size() * sizeof(uint32_t)); 2355afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor} 2356afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 23574fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 23585d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis// DeclContext's Name Lookup Table Serialization 23595d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 23605d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23615d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidisnamespace { 23625d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis// Trait used for the on-disk hash table used in the method pool. 23635d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidisclass ASTDeclContextNameLookupTrait { 23645d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ASTWriter &Writer; 23655d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23665d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidispublic: 23675d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef DeclarationName key_type; 23685d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef key_type key_type_ref; 23695d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23705d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef DeclContext::lookup_result data_type; 23715d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef const data_type& data_type_ref; 23725d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23735d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } 23745d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23755d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis unsigned ComputeHash(DeclarationName Name) { 23765d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis llvm::FoldingSetNodeID ID; 23775d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(Name.getNameKind()); 23785d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 23795d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis switch (Name.getNameKind()) { 23805d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::Identifier: 23815d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddString(Name.getAsIdentifierInfo()->getName()); 23825d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23835d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 23845d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 23855d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 23865d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); 23875d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23885d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 23895d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 23905d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 23915d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(Writer.GetOrCreateTypeID(Name.getCXXNameType())); 23925d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23935d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 23945d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(Name.getCXXOverloadedOperator()); 23955d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 23965d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 23975d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddString(Name.getCXXLiteralIdentifier()->getName()); 23985d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 23995d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24005d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24015d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24025d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis return ID.ComputeHash(); 24035d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24045d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24055d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis std::pair<unsigned,unsigned> 24065d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis EmitKeyDataLength(llvm::raw_ostream& Out, DeclarationName Name, 24075d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis data_type_ref Lookup) { 24085d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis unsigned KeyLen = 1; 24095d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis switch (Name.getNameKind()) { 24105d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::Identifier: 24115d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 24125d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 24135d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 24145d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 24155d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 24165d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 24175d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 24185d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis KeyLen += 4; 24195d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24205d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 24215d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis KeyLen += 1; 24225d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24235d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 24245d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24255d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24265d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit16(Out, KeyLen); 24275d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24285d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis // 2 bytes for num of decls and 4 for each DeclID. 24295d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis unsigned DataLen = 2 + 4 * (Lookup.second - Lookup.first); 24305d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit16(Out, DataLen); 24315d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24325d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis return std::make_pair(KeyLen, DataLen); 24335d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24345d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24355d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis void EmitKey(llvm::raw_ostream& Out, DeclarationName Name, unsigned) { 24365d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis using namespace clang::io; 24375d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24385d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(Name.getNameKind() < 0x100 && "Invalid name kind ?"); 24395d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit8(Out, Name.getNameKind()); 24405d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis switch (Name.getNameKind()) { 24415d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::Identifier: 24425d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); 24435d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24445d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 24455d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 24465d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 24475d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); 24485d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24495d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 24505d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 24515d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 24525d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getTypeID(Name.getCXXNameType())); 24535d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24545d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 24555d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(Name.getCXXOverloadedOperator() < 0x100 && "Invalid operator ?"); 24565d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit8(Out, Name.getCXXOverloadedOperator()); 24575d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24585d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 24595d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); 24605d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24615d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 24625d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 24635d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24645d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24655d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24665d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis void EmitData(llvm::raw_ostream& Out, key_type_ref, 24675d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis data_type Lookup, unsigned DataLen) { 24685d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis uint64_t Start = Out.tell(); (void)Start; 24695d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit16(Out, Lookup.second - Lookup.first); 24705d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis for (; Lookup.first != Lookup.second; ++Lookup.first) 24715d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first)); 24725d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 24735d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(Out.tell() - Start == DataLen && "Data length is wrong"); 24745d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 24755d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis}; 24765d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis} // end anonymous namespace 24775d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 2478074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// \brief Write the block containing all of the declaration IDs 2479074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// visible from the given DeclContext. 2480074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// 2481074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// \returns the offset of the DECL_CONTEXT_VISIBLE block within the 24821d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// bitstream, or 0 if no block was written. 2483074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidisuint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, 2484074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis DeclContext *DC) { 2485074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (DC->getPrimaryContext() != DC) 2486074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 2487074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2488074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Since there is no name lookup into functions or methods, don't bother to 2489074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // build a visible-declarations table for these entities. 2490074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (DC->isFunctionOrMethod()) 2491074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 2492074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2493074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // If not in C++, we perform name lookup for the translation unit via the 2494074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // IdentifierInfo chains, don't bother to build a visible-declarations table. 2495074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // FIXME: In C++ we need the visible declarations in order to "see" the 2496074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // friend declarations, is there a way to do this without writing the table ? 2497074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (DC->isTranslationUnit() && !Context.getLangOptions().CPlusPlus) 2498074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 2499074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2500074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Force the DeclContext to build a its name-lookup table. 2501a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis if (DC->hasExternalVisibleStorage()) 2502a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis DC->MaterializeVisibleDeclsFromExternalStorage(); 2503a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis else 2504a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis DC->lookup(DeclarationName()); 2505074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2506074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Serialize the contents of the mapping used for lookup. Note that, 2507074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // although we have two very different code paths, the serialized 2508074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // representation is the same for both cases: a declaration name, 2509074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // followed by a size, followed by references to the visible 2510074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // declarations that have that name. 2511074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis uint64_t Offset = Stream.GetCurrentBitNo(); 2512074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); 2513074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (!Map || Map->empty()) 2514074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 2515074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2516074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; 2517074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis ASTDeclContextNameLookupTrait Trait(*this); 2518074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2519074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Create the on-disk hash table representation. 2520074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); 2521074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis D != DEnd; ++D) { 2522074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis DeclarationName Name = D->first; 2523074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis DeclContext::lookup_result Result = D->second.getLookupResult(); 2524074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Generator.insert(Name, Result, Trait); 2525074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis } 2526074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2527074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Create the on-disk hash table in a buffer. 2528074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis llvm::SmallString<4096> LookupTable; 2529074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis uint32_t BucketOffset; 2530074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis { 2531074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis llvm::raw_svector_ostream Out(LookupTable); 2532074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Make sure that no bucket is at offset 0 2533074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis clang::io::Emit32(Out, 0); 2534074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis BucketOffset = Generator.Emit(Out, Trait); 2535074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis } 2536074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2537074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Write the lookup table 2538074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis RecordData Record; 2539074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Record.push_back(DECL_CONTEXT_VISIBLE); 2540074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Record.push_back(BucketOffset); 2541074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, 2542074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis LookupTable.str()); 2543074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 2544074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); 2545074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis ++NumVisibleDeclContexts; 2546074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return Offset; 2547074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis} 2548074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 25491d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// \brief Write an UPDATE_VISIBLE block for the given context. 25501d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// 25511d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// UPDATE_VISIBLE blocks contain the declarations that are added to an existing 25521d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// DeclContext in a dependent AST file. As such, they only exist for the TU 25531d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// (in C++) and for namespaces. 25541d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redlvoid ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { 25551d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); 25561d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl if (!Map || Map->empty()) 25571d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl return; 25581d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 25591d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; 25601d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl ASTDeclContextNameLookupTrait Trait(*this); 25611d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 25621d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Create the hash table. 25631d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); 25641d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl D != DEnd; ++D) { 25651d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl DeclarationName Name = D->first; 25661d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl DeclContext::lookup_result Result = D->second.getLookupResult(); 25675967d6228f183a5fa384f2f1918df679ed2d8666Sebastian Redl // For any name that appears in this table, the results are complete, i.e. 25685967d6228f183a5fa384f2f1918df679ed2d8666Sebastian Redl // they overwrite results from previous PCHs. Merging is always a mess. 25695967d6228f183a5fa384f2f1918df679ed2d8666Sebastian Redl Generator.insert(Name, Result, Trait); 25701d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl } 25711d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 25721d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Create the on-disk hash table in a buffer. 25731d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl llvm::SmallString<4096> LookupTable; 25741d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl uint32_t BucketOffset; 25751d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl { 25761d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl llvm::raw_svector_ostream Out(LookupTable); 25771d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Make sure that no bucket is at offset 0 25781d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl clang::io::Emit32(Out, 0); 25791d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl BucketOffset = Generator.Emit(Out, Trait); 25801d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl } 25811d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 25821d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Write the lookup table 25831d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl RecordData Record; 25841d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Record.push_back(UPDATE_VISIBLE); 25851d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Record.push_back(getDeclID(cast<Decl>(DC))); 25861d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Record.push_back(BucketOffset); 25871d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); 25881d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl} 25891d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 259084bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne/// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. 259184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbournevoid ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { 259284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RecordData Record; 259384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Record.push_back(Opts.fp_contract); 259484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); 259584bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne} 259684bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 259784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne/// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. 259884bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbournevoid ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { 259984bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne if (!SemaRef.Context.getLangOptions().OpenCL) 260084bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne return; 260184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 260284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); 260384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RecordData Record; 260484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne#define OPENCLEXT(nm) Record.push_back(Opts.nm); 260584bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne#include "clang/Basic/OpenCLExtensions.def" 260684bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Stream.EmitRecord(OPENCL_EXTENSIONS, Record); 260784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne} 260884bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 26095d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 26104fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// General Serialization Routines 26114fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 26124fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 261368a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor/// \brief Write a record containing the given attributes. 261489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::WriteAttributes(const AttrVec &Attrs, RecordDataImpl &Record) { 26154eb9fc0449ddbd5239ddc3ae6b6e52880f47dcf7Argyrios Kyrtzidis Record.push_back(Attrs.size()); 2616cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt for (AttrVec::const_iterator i = Attrs.begin(), e = Attrs.end(); i != e; ++i){ 2617cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt const Attr * A = *i; 2618cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs 2619cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt AddSourceLocation(A->getLocation(), Record); 262068a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor 2621cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt#include "clang/Serialization/AttrPCHWrite.inc" 26225b160927672440076aa53c31d84149f70fd8d40eFariborz Jahanian 262368a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor } 262468a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor} 262568a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor 262689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddString(llvm::StringRef Str, RecordDataImpl &Record) { 262768a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor Record.push_back(Str.size()); 262868a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor Record.insert(Record.end(), Str.begin(), Str.end()); 262968a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor} 263068a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor 26310a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregorvoid ASTWriter::AddVersionTuple(const VersionTuple &Version, 26320a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor RecordDataImpl &Record) { 26330a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(Version.getMajor()); 26340a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor if (llvm::Optional<unsigned> Minor = Version.getMinor()) 26350a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(*Minor + 1); 26360a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor else 26370a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(0); 26380a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor if (llvm::Optional<unsigned> Subminor = Version.getSubminor()) 26390a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(*Subminor + 1); 26400a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor else 26410a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(0); 26420a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor} 26430a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 26443251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor/// \brief Note that the identifier II occurs at the given offset 26453251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor/// within the identifier table. 2646a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { 26478538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID ID = IdentifierIDs[II]; 26483397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Only store offsets new to this AST file. Other identifier names are looked 2649f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // up earlier in the chain and thus don't need an offset. 2650f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl if (ID >= FirstIdentID) 2651f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl IdentifierOffsets[ID - FirstIdentID] = Offset; 26523251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor} 26533251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 265483941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor/// \brief Note that the selector Sel occurs at the given offset 265583941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor/// within the method pool/selector table. 2656a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { 265783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor unsigned ID = SelectorIDs[Sel]; 265883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor assert(ID && "Unknown selector"); 2659e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // Don't record offsets for selectors that are also available in a different 2660e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // file. 2661e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (ID < FirstSelectorID) 2662e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl return; 2663e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl SelectorOffsets[ID - FirstSelectorID] = Offset; 266483941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor} 266583941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor 2666a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian RedlASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) 266789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor : Stream(Stream), Chain(0), SerializationListener(0), 266889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor FirstDeclID(1), NextDeclID(FirstDeclID), 26698538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), 2670e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl FirstIdentID(1), NextIdentID(FirstIdentID), FirstSelectorID(1), 267177424bc3794f569816dba52e423b57486a98e5baDouglas Gregor NextSelectorID(FirstSelectorID), FirstMacroID(1), NextMacroID(FirstMacroID), 267277424bc3794f569816dba52e423b57486a98e5baDouglas Gregor CollectedStmts(&StmtsToEmit), 2673e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), 26747c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor NumVisibleDeclContexts(0), FirstCXXBaseSpecifiersID(1), 26757c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor NextCXXBaseSpecifiersID(1) 26767c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor{ 267730c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl} 26782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2679a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls, 26808e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis const std::string &OutputFile, 268130c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl const char *isysroot) { 26822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Emit the file header. 2683c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'C', 8); 2684c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'P', 8); 2685c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'C', 8); 2686c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'H', 8); 26871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2688b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner WriteBlockInfoBlock(); 26892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 26901dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl if (Chain) 2691a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl WriteASTChain(SemaRef, StatCalls, isysroot); 26921dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl else 26938e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile); 26941dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl} 26951dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 2696a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, 26978e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis const char *isysroot, 26988e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis const std::string &OutputFile) { 26991dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl using namespace llvm; 27001dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 27011dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl ASTContext &Context = SemaRef.Context; 27021dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Preprocessor &PP = SemaRef.PP; 27031dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 27042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // The translation unit is the first declaration we'll emit. 27052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor DeclIDs[Context.getTranslationUnitDecl()] = 1; 2706f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl ++NextDeclID; 270761d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.push(Context.getTranslationUnitDecl()); 27082cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 27092deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor // Make sure that we emit IdentifierInfos (and any attached 27102deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor // declarations) for builtins. 27112deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor { 27122deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor IdentifierTable &Table = PP.getIdentifierTable(); 27132deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor llvm::SmallVector<const char *, 32> BuiltinNames; 27142deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, 27152deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor Context.getLangOptions().NoBuiltin); 27162deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) 27172deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor getIdentifierRef(&Table.get(BuiltinNames[I])); 27182deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor } 27192deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor 272063d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner // Build a record containing all of the tentative definitions in this file, in 2721e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // TentativeDefinitions order. Generally, this record will be empty for 272263d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner // headers. 27234c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor RecordData TentativeDefinitions; 2724e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) { 2725e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions); 272663d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner } 27274c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor 272849b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Build a record containing all of the file scoped decls in this file. 272949b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis RecordData UnusedFileScopedDecls; 273049b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i) 273149b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis AddDeclRef(SemaRef.UnusedFileScopedDecls[i], UnusedFileScopedDecls); 27324056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 273372b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis RecordData WeakUndeclaredIdentifiers; 273472b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { 273572b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis WeakUndeclaredIdentifiers.push_back( 273672b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis SemaRef.WeakUndeclaredIdentifiers.size()); 273772b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis for (llvm::DenseMap<IdentifierInfo*,Sema::WeakInfo>::iterator 273872b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis I = SemaRef.WeakUndeclaredIdentifiers.begin(), 273972b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { 274072b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); 274172b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); 274272b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); 274372b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); 274472b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis } 274572b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis } 274611a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 274714c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // Build a record containing all of the locally-scoped external 274814c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // declarations in this header file. Generally, this record will be 274914c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // empty. 275014c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor RecordData LocallyScopedExternalDecls; 27513397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // FIXME: This is filling in the AST file in densemap order which is 275263d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner // nondeterminstic! 27531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator 275414c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor TD = SemaRef.LocallyScopedExternalDecls.begin(), 275514c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor TDEnd = SemaRef.LocallyScopedExternalDecls.end(); 275614c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor TD != TDEnd; ++TD) 275714c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor AddDeclRef(TD->second, LocallyScopedExternalDecls); 275814c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor 2759b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor // Build a record containing all of the ext_vector declarations. 2760b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor RecordData ExtVectorDecls; 2761b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I) 2762b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls); 2763b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor 2764d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Build a record containing all of the VTable uses information. 2765d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis RecordData VTableUses; 2766be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis if (!SemaRef.VTableUses.empty()) { 2767be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis VTableUses.push_back(SemaRef.VTableUses.size()); 2768be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { 2769be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); 2770be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); 2771be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); 2772be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis } 2773d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis } 2774d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 2775d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Build a record containing all of dynamic classes declarations. 2776d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis RecordData DynamicClasses; 2777d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis for (unsigned I = 0, N = SemaRef.DynamicClasses.size(); I != N; ++I) 2778d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis AddDeclRef(SemaRef.DynamicClasses[I], DynamicClasses); 2779d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 27800e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis // Build a record containing all of pending implicit instantiations. 278162c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth RecordData PendingInstantiations; 27820e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis for (std::deque<Sema::PendingImplicitInstantiation>::iterator 278362c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth I = SemaRef.PendingInstantiations.begin(), 278462c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth N = SemaRef.PendingInstantiations.end(); I != N; ++I) { 278562c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth AddDeclRef(I->first, PendingInstantiations); 278662c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth AddSourceLocation(I->second, PendingInstantiations); 27870e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis } 27880e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis assert(SemaRef.PendingLocalImplicitInstantiations.empty() && 27890e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis "There are local ones at end of translation unit!"); 27900e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis 279176c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis // Build a record containing some declaration references. 279276c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis RecordData SemaDeclRefs; 279376c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { 279476c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); 279576c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); 279676c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis } 279776c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis 279814b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne RecordData CUDASpecialDeclRefs; 279914b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne if (Context.getcudaConfigureCallDecl()) { 280014b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); 280114b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne } 280214b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne 28033397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Write the remaining AST contents. 2804ad1de006ea080b540e480efc6b86c2e201dbf1ecDouglas Gregor RecordData Record; 28058538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(AST_BLOCK_ID, 5); 28068e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis WriteMetadata(Context, isysroot, OutputFile); 28071dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl WriteLanguageOptions(Context.getLangOptions()); 2808e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (StatCalls && !isysroot) 2809dd41ed59cf7aefabd40bf766d8fcc7ebd759c8e5Douglas Gregor WriteStatCache(*StatCalls); 2810e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); 2811c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // Write the record of special types. 2812c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff Record.clear(); 28131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2814c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getBuiltinVaListType(), Record); 2815c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getObjCIdType(), Record); 2816c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getObjCSelType(), Record); 2817c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getObjCProtoType(), Record); 2818c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getObjCClassType(), Record); 2819c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getRawCFConstantStringType(), Record); 2820c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getRawObjCFastEnumerationStateType(), Record); 2821c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff AddTypeRef(Context.getFILEType(), Record); 2822782fa308a765aeac2acb39c4e697c937ec21185bMike Stump AddTypeRef(Context.getjmp_bufType(), Record); 2823782fa308a765aeac2acb39c4e697c937ec21185bMike Stump AddTypeRef(Context.getsigjmp_bufType(), Record); 2824d1571acc700b652a52c766e36a6c688d9bf6f3a1Douglas Gregor AddTypeRef(Context.ObjCIdRedefinitionType, Record); 2825d1571acc700b652a52c766e36a6c688d9bf6f3a1Douglas Gregor AddTypeRef(Context.ObjCClassRedefinitionType, Record); 2826adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump AddTypeRef(Context.getRawBlockdescriptorType(), Record); 2827083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump AddTypeRef(Context.getRawBlockdescriptorExtendedType(), Record); 28282bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian AddTypeRef(Context.ObjCSelRedefinitionType, Record); 28292bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian AddTypeRef(Context.getRawNSConstantStringType(), Record); 2830006113841bdae1edb77aef75ba1ffdf2e55a3094Argyrios Kyrtzidis Record.push_back(Context.isInt128Installed()); 2831ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith AddTypeRef(Context.AutoDeductTy, Record); 2832ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith AddTypeRef(Context.AutoRRefDeductTy, Record); 28338538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SPECIAL_TYPES, Record); 28341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2835366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor // Keep writing types and declarations until all types and 2836366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor // declarations have been written. 28378538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(DECLTYPES_BLOCK_ID, 3); 283861d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor WriteDeclsBlockAbbrevs(); 283961d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor while (!DeclTypesToEmit.empty()) { 284061d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclOrType DOT = DeclTypesToEmit.front(); 284161d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.pop(); 284261d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor if (DOT.isType()) 284361d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor WriteType(DOT.getType()); 284461d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor else 284561d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor WriteDecl(Context, DOT.getDecl()); 284661d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor } 284761d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor Stream.ExitBlock(); 284811a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 2849813a97b3eee957eac3ac1fb111b8892fb9afd0d4Douglas Gregor WritePreprocessor(PP); 2850cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); 2851059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl WriteSelectors(SemaRef); 2852320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian WriteReferencedSelectorsPool(SemaRef); 285337e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor WriteIdentifierTable(PP); 285484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteFPPragmaOptions(SemaRef.getFPOptions()); 285584bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteOpenCLExtensions(SemaRef); 28568f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor 28571476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl WriteTypeDeclOffsets(); 28583efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis WritePragmaDiagnosticMappings(Context.getDiagnostics()); 2859ad1de006ea080b540e480efc6b86c2e201dbf1ecDouglas Gregor 2860c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson WriteCXXBaseSpecifiersOffsets(); 28617c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 28624c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor // Write the record containing external, unnamed definitions. 2863fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor if (!ExternalDefinitions.empty()) 28648538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); 28654c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor 28664c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor // Write the record containing tentative definitions. 28674c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor if (!TentativeDefinitions.empty()) 28688538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); 286914c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor 287049b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Write the record containing unused file scoped decls. 287149b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis if (!UnusedFileScopedDecls.empty()) 28728538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); 287311a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 287472b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis // Write the record containing weak undeclared identifiers. 287572b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis if (!WeakUndeclaredIdentifiers.empty()) 28768538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, 287772b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis WeakUndeclaredIdentifiers); 287872b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis 287914c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // Write the record containing locally-scoped external definitions. 288014c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor if (!LocallyScopedExternalDecls.empty()) 28818538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, 288214c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor LocallyScopedExternalDecls); 2883b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor 2884b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor // Write the record containing ext_vector type names. 2885b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor if (!ExtVectorDecls.empty()) 28868538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); 28871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2888d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Write the record containing VTable uses information. 2889d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis if (!VTableUses.empty()) 28908538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(VTABLE_USES, VTableUses); 2891d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 2892d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Write the record containing dynamic classes declarations. 2893d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis if (!DynamicClasses.empty()) 28948538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); 2895d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 28960e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis // Write the record containing pending implicit instantiations. 289762c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth if (!PendingInstantiations.empty()) 289862c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); 28990e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis 290076c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis // Write the record containing declaration references of Sema. 290176c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis if (!SemaDeclRefs.empty()) 29028538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); 290376c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis 290414b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne // Write the record containing CUDA-specific declaration references. 290514b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne if (!CUDASpecialDeclRefs.empty()) 290614b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); 290714b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne 29083e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor // Some simple statistics 2909ad1de006ea080b540e480efc6b86c2e201dbf1ecDouglas Gregor Record.clear(); 29103e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor Record.push_back(NumStatements); 291137e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor Record.push_back(NumMacros); 29122512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor Record.push_back(NumLexicalDeclContexts); 29132512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor Record.push_back(NumVisibleDeclContexts); 29148538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(STATISTICS, Record); 2915c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.ExitBlock(); 29162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 29172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2918a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls, 291930c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl const char *isysroot) { 29201dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl using namespace llvm; 29211dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 29221dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl ASTContext &Context = SemaRef.Context; 29231dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Preprocessor &PP = SemaRef.PP; 29241476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 29251dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl RecordData Record; 29268538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(AST_BLOCK_ID, 5); 29278e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis WriteMetadata(Context, isysroot, ""); 29281476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl if (StatCalls && !isysroot) 29291476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl WriteStatCache(*StatCalls); 29301476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // FIXME: Source manager block should only write new stuff, which could be 29311476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // done by tracking the largest ID in the chain 29321476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); 29331dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 29341dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl // The special types are in the chained PCH. 29351dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 29361dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl // We don't start with the translation unit, but with its decls that 29373c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl // don't come from the chained PCH. 29381dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); 2939eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis llvm::SmallVector<KindDeclIDPair, 64> NewGlobalDecls; 2940681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl for (DeclContext::decl_iterator I = TU->noload_decls_begin(), 2941681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl E = TU->noload_decls_end(); 29421dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl I != E; ++I) { 2943d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl if ((*I)->getPCHLevel() == 0) 2944eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); 29450b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl else if ((*I)->isChangedSinceDeserialization()) 29460b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl (void)GetDeclRef(*I); // Make sure it's written, but don't record it. 29471dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl } 2948681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl // We also need to write a lexical updates block for the TU. 2949d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); 29508538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); 2951d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); 2952d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); 2953d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl Record.clear(); 29548538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(TU_UPDATE_LEXICAL); 2955d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, 2956d692af71226d2fb537d86c670af96114ddd485c3Sebastian Redl reinterpret_cast<const char*>(NewGlobalDecls.data()), 2957eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis NewGlobalDecls.size() * sizeof(KindDeclIDPair)); 2958100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis // And a visible updates block for the DeclContexts. 2959100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv = new llvm::BitCodeAbbrev(); 2960100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); 2961100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); 2962100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); 2963100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); 2964100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); 2965100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis WriteDeclContextVisibleUpdate(TU); 29661dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 2967083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Build a record containing all of the new tentative definitions in this 2968083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // file, in TentativeDefinitions order. 2969083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl RecordData TentativeDefinitions; 2970083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) { 2971083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (SemaRef.TentativeDefinitions[i]->getPCHLevel() == 0) 2972083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions); 2973083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl } 2974083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 297549b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Build a record containing all of the file scoped decls in this file. 297649b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis RecordData UnusedFileScopedDecls; 297749b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i) { 297849b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis if (SemaRef.UnusedFileScopedDecls[i]->getPCHLevel() == 0) 297949b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis AddDeclRef(SemaRef.UnusedFileScopedDecls[i], UnusedFileScopedDecls); 2980083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl } 2981083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 29824056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // We write the entire table, overwriting the tables from the chain. 29834056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl RecordData WeakUndeclaredIdentifiers; 29844056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { 29854056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl WeakUndeclaredIdentifiers.push_back( 29864056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl SemaRef.WeakUndeclaredIdentifiers.size()); 29874056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl for (llvm::DenseMap<IdentifierInfo*,Sema::WeakInfo>::iterator 29884056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl I = SemaRef.WeakUndeclaredIdentifiers.begin(), 29894056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { 29904056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); 29914056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); 29924056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); 29934056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); 29944056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 29954056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 29964056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 2997083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Build a record containing all of the locally-scoped external 2998083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // declarations in this header file. Generally, this record will be 2999083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // empty. 3000083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl RecordData LocallyScopedExternalDecls; 30013397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // FIXME: This is filling in the AST file in densemap order which is 3002083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // nondeterminstic! 3003083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator 3004083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl TD = SemaRef.LocallyScopedExternalDecls.begin(), 3005083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl TDEnd = SemaRef.LocallyScopedExternalDecls.end(); 3006083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl TD != TDEnd; ++TD) { 3007083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (TD->second->getPCHLevel() == 0) 3008083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl AddDeclRef(TD->second, LocallyScopedExternalDecls); 3009083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl } 3010083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3011083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Build a record containing all of the ext_vector declarations. 3012083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl RecordData ExtVectorDecls; 3013083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I) { 3014083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (SemaRef.ExtVectorDecls[I]->getPCHLevel() == 0) 3015083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls); 3016083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl } 3017083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 30184056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Build a record containing all of the VTable uses information. 30194056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // We write everything here, because it's too hard to determine whether 30204056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // a use is new to this part. 30214056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl RecordData VTableUses; 30224056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!SemaRef.VTableUses.empty()) { 30234056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl VTableUses.push_back(SemaRef.VTableUses.size()); 30244056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { 30254056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); 30264056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); 30274056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); 30284056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 30294056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 30304056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 30314056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Build a record containing all of dynamic classes declarations. 30324056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl RecordData DynamicClasses; 30334056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl for (unsigned I = 0, N = SemaRef.DynamicClasses.size(); I != N; ++I) 30344056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (SemaRef.DynamicClasses[I]->getPCHLevel() == 0) 30354056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddDeclRef(SemaRef.DynamicClasses[I], DynamicClasses); 30364056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 30374056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Build a record containing all of pending implicit instantiations. 303862c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth RecordData PendingInstantiations; 30394056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl for (std::deque<Sema::PendingImplicitInstantiation>::iterator 304062c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth I = SemaRef.PendingInstantiations.begin(), 304162c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth N = SemaRef.PendingInstantiations.end(); I != N; ++I) { 3042c1d3ffbbad742c90f22198d7909b0a98865bfefaSebastian Redl AddDeclRef(I->first, PendingInstantiations); 3043c1d3ffbbad742c90f22198d7909b0a98865bfefaSebastian Redl AddSourceLocation(I->second, PendingInstantiations); 30444056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 30454056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl assert(SemaRef.PendingLocalImplicitInstantiations.empty() && 30464056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl "There are local ones at end of translation unit!"); 30474056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 30484056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Build a record containing some declaration references. 30494056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // It's not worth the effort to avoid duplication here. 30504056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl RecordData SemaDeclRefs; 30514056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { 30524056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); 30534056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); 30544056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl } 30554056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 30568538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(DECLTYPES_BLOCK_ID, 3); 30571dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl WriteDeclsBlockAbbrevs(); 3058d3d0755a4220d3fa6c125eb3f8ce29fc1424eac3Argyrios Kyrtzidis for (DeclsToRewriteTy::iterator 3059d3d0755a4220d3fa6c125eb3f8ce29fc1424eac3Argyrios Kyrtzidis I = DeclsToRewrite.begin(), E = DeclsToRewrite.end(); I != E; ++I) 3060d3d0755a4220d3fa6c125eb3f8ce29fc1424eac3Argyrios Kyrtzidis DeclTypesToEmit.push(const_cast<Decl*>(*I)); 30611dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl while (!DeclTypesToEmit.empty()) { 30621dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl DeclOrType DOT = DeclTypesToEmit.front(); 30631dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl DeclTypesToEmit.pop(); 30641dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl if (DOT.isType()) 30651dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl WriteType(DOT.getType()); 30661dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl else 30671dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl WriteDecl(Context, DOT.getDecl()); 30681dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl } 30691dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Stream.ExitBlock(); 30701dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 3071083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl WritePreprocessor(PP); 3072a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl WriteSelectors(SemaRef); 3073a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl WriteReferencedSelectorsPool(SemaRef); 3074f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl WriteIdentifierTable(PP); 307584bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteFPPragmaOptions(SemaRef.getFPOptions()); 307684bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteOpenCLExtensions(SemaRef); 307784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 30781476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl WriteTypeDeclOffsets(); 3079f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis // FIXME: For chained PCH only write the new mappings (we currently 3080f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis // write all of them again). 30813efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis WritePragmaDiagnosticMappings(Context.getDiagnostics()); 3082083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3083c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson WriteCXXBaseSpecifiersOffsets(); 3084c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 3085a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis /// Build a record containing first declarations from a chained PCH and the 30863397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl /// most recent declarations in this AST that they point to. 3087a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis RecordData FirstLatestDeclIDs; 3088a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis for (FirstLatestDeclMap::iterator 3089a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis I = FirstLatestDecls.begin(), E = FirstLatestDecls.end(); I != E; ++I) { 3090a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis assert(I->first->getPCHLevel() > I->second->getPCHLevel() && 3091a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis "Expected first & second to be in different PCHs"); 3092a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis AddDeclRef(I->first, FirstLatestDeclIDs); 3093a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis AddDeclRef(I->second, FirstLatestDeclIDs); 3094a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis } 3095a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis if (!FirstLatestDeclIDs.empty()) 30968538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(REDECLS_UPDATE_LATEST, FirstLatestDeclIDs); 3097a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis 3098083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing external, unnamed definitions. 3099083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!ExternalDefinitions.empty()) 31008538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); 3101083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3102083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing tentative definitions. 3103083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!TentativeDefinitions.empty()) 31048538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); 3105083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 310649b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Write the record containing unused file scoped decls. 310749b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis if (!UnusedFileScopedDecls.empty()) 31088538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); 3109083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 31104056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing weak undeclared identifiers. 31114056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!WeakUndeclaredIdentifiers.empty()) 31128538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, 31134056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl WeakUndeclaredIdentifiers); 31144056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 3115083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing locally-scoped external definitions. 3116083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!LocallyScopedExternalDecls.empty()) 31178538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, 3118083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl LocallyScopedExternalDecls); 3119083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3120083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing ext_vector type names. 3121083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!ExtVectorDecls.empty()) 31228538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); 3123083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 31244056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing VTable uses information. 31254056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!VTableUses.empty()) 31268538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(VTABLE_USES, VTableUses); 31274056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 31284056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing dynamic classes declarations. 31294056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!DynamicClasses.empty()) 31308538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); 31314056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 31324056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing pending implicit instantiations. 313362c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth if (!PendingInstantiations.empty()) 313462c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); 31354056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 31364056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing declaration references of Sema. 31374056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!SemaDeclRefs.empty()) 31388538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); 3139083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3140100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis // Write the updates to DeclContexts. 3141100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator 3142100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis I = UpdatedDeclContexts.begin(), 3143100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis E = UpdatedDeclContexts.end(); 31441d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl I != E; ++I) 31451d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl WriteDeclContextVisibleUpdate(*I); 31461d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 3147aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidis WriteDeclUpdatesBlocks(); 31487b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 3149083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.clear(); 3150083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumStatements); 3151083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumMacros); 3152083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumLexicalDeclContexts); 3153083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumVisibleDeclContexts); 3154aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidis WriteDeclReplacementsBlock(); 31558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(STATISTICS, Record); 31561dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Stream.ExitBlock(); 31571dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl} 31581dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 3159aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidisvoid ASTWriter::WriteDeclUpdatesBlocks() { 31607b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis if (DeclUpdates.empty()) 31617b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis return; 31627b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 31637b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis RecordData OffsetsRecord; 31647b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, 3); 31657b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis for (DeclUpdateMap::iterator 31667b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { 31677b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis const Decl *D = I->first; 31687b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis UpdateRecord &URec = I->second; 31697b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 3170ba901b507fc36408fe6f8478e8ac90b554f1d230Argyrios Kyrtzidis if (DeclsToRewrite.count(D)) 3171ba901b507fc36408fe6f8478e8ac90b554f1d230Argyrios Kyrtzidis continue; // The decl will be written completely,no need to store updates. 3172ba901b507fc36408fe6f8478e8ac90b554f1d230Argyrios Kyrtzidis 31737b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis uint64_t Offset = Stream.GetCurrentBitNo(); 31747b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.EmitRecord(DECL_UPDATES, URec); 31757b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 31767b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis OffsetsRecord.push_back(GetDeclRef(D)); 31777b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis OffsetsRecord.push_back(Offset); 31787b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis } 31797b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.ExitBlock(); 31807b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); 31817b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis} 31827b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 3183aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidisvoid ASTWriter::WriteDeclReplacementsBlock() { 31840b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl if (ReplacedDecls.empty()) 31850b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl return; 31860b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 31870b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl RecordData Record; 31888538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl for (llvm::SmallVector<std::pair<DeclID, uint64_t>, 16>::iterator 31890b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { 31900b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl Record.push_back(I->first); 31910b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl Record.push_back(I->second); 31920b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl } 31938538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(DECL_REPLACEMENTS, Record); 31940b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl} 31950b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 319689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { 31972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Loc.getRawEncoding()); 31982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 31992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 320089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { 32016ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddSourceLocation(Range.getBegin(), Record); 32026ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddSourceLocation(Range.getEnd(), Record); 32036ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner} 32046ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 320589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { 32062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Value.getBitWidth()); 32074ea884b429445aa6f1af5bc6e51d0b65a4043e24Benjamin Kramer const uint64_t *Words = Value.getRawData(); 32084ea884b429445aa6f1af5bc6e51d0b65a4043e24Benjamin Kramer Record.append(Words, Words + Value.getNumWords()); 32092cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 32102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 321189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { 32120a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor Record.push_back(Value.isUnsigned()); 32130a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor AddAPInt(Value, Record); 32140a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor} 32150a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor 321689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { 321717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor AddAPInt(Value.bitcastToAPInt(), Record); 321817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor} 321917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 322089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { 32212deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor Record.push_back(getIdentifierRef(II)); 32222deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor} 32232deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor 32248538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlIdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { 32252deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor if (II == 0) 32262deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor return 0; 3227afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 32288538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID &ID = IdentifierIDs[II]; 3229afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor if (ID == 0) 3230f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl ID = NextIdentID++; 32312deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor return ID; 32322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 32332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3234f73c93fea0d4b447585bc7459499ba6b822e045cSebastian RedlMacroID ASTWriter::getMacroDefinitionID(MacroDefinition *MD) { 32356a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor if (MD == 0) 32366a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor return 0; 3237f73c93fea0d4b447585bc7459499ba6b822e045cSebastian Redl 3238f73c93fea0d4b447585bc7459499ba6b822e045cSebastian Redl MacroID &ID = MacroDefinitions[MD]; 32396a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor if (ID == 0) 324077424bc3794f569816dba52e423b57486a98e5baDouglas Gregor ID = NextMacroID++; 32416a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor return ID; 32426a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor} 32436a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor 324489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { 32455d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Record.push_back(getSelectorRef(SelRef)); 32465d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl} 32475d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl 32488538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlSelectorID ASTWriter::getSelectorRef(Selector Sel) { 32495d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl if (Sel.getAsOpaquePtr() == 0) { 32505d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl return 0; 325190cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff } 325290cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff 32538538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl SelectorID &SID = SelectorIDs[Sel]; 3254e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (SID == 0 && Chain) { 3255e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // This might trigger a ReadSelector callback, which will set the ID for 3256e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // this selector. 3257e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl Chain->LoadSelector(Sel); 3258e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 325990cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff if (SID == 0) { 3260e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl SID = NextSelectorID++; 326190cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff } 32625d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl return SID; 326390cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff} 326490cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff 326589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { 3266d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner AddDeclRef(Temp->getDestructor(), Record); 3267d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner} 3268d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner 32697c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregorvoid ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, 32707c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifier const *BasesEnd, 32717c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor RecordDataImpl &Record) { 32727c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); 32737c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersToWrite.push_back( 32747c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, 32757c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Bases, BasesEnd)); 32767c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.push_back(NextCXXBaseSpecifiersID++); 32777c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor} 32787c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 3279a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, 328044f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis const TemplateArgumentLocInfo &Arg, 328189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 328244f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis switch (Kind) { 3283833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 328444f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddStmt(Arg.getAsExpr()); 3285833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 3286833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 328744f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); 3288833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 3289788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 3290b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); 329117cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis AddSourceLocation(Arg.getTemplateNameLoc(), Record); 3292a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 3293a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 3294b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); 3295a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor AddSourceLocation(Arg.getTemplateNameLoc(), Record); 3296ba68eca7582a62e3e2ff4b0eba1b2b73a6b80895Douglas Gregor AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); 3297788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor break; 3298833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 3299833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 3300833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 3301833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 3302833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 3303833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 3304833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 3305833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3306a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, 330789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 330844f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddTemplateArgument(Arg.getArgument(), Record); 330917cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis 331017cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis if (Arg.getArgument().getKind() == TemplateArgument::Expression) { 331117cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis bool InfoHasSameExpr 331217cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); 331317cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis Record.push_back(InfoHasSameExpr); 331417cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis if (InfoHasSameExpr) 331517cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis return; // Avoid storing the same expr twice. 331617cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis } 331744f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), 331844f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis Record); 331944f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis} 332044f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis 3321dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregorvoid ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, 3322dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor RecordDataImpl &Record) { 3323a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall if (TInfo == 0) { 3324a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall AddTypeRef(QualType(), Record); 3325a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall return; 3326a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall } 3327a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 3328dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddTypeLoc(TInfo->getTypeLoc(), Record); 3329dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor} 3330dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 3331dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregorvoid ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { 3332dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddTypeRef(TL.getType(), Record); 3333dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 3334a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall TypeLocWriter TLW(*this, Record); 3335dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor for (; !TL.isNull(); TL = TL.getNextTypeLoc()) 333611a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam TLW.Visit(TL); 3337a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 3338a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 333989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { 33407fb35182f43392cea4517c203bbabb22364a19fcArgyrios Kyrtzidis Record.push_back(GetOrCreateTypeID(T)); 33417fb35182f43392cea4517c203bbabb22364a19fcArgyrios Kyrtzidis} 33427fb35182f43392cea4517c203bbabb22364a19fcArgyrios Kyrtzidis 33437fb35182f43392cea4517c203bbabb22364a19fcArgyrios KyrtzidisTypeID ASTWriter::GetOrCreateTypeID(QualType T) { 3344eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis return MakeTypeID(T, 3345eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); 3346eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis} 33472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33485d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios KyrtzidisTypeID ASTWriter::getTypeID(QualType T) const { 3349eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis return MakeTypeID(T, 3350eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); 335126fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis} 335226fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis 335326fca90786af17f97e1a5ecc310d4bf39b831595Argyrios KyrtzidisTypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { 335426fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis if (T.isNull()) 335526fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis return TypeIdx(); 335626fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis assert(!T.getLocalFastQualifiers()); 335726fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis 335801b81c4d074bba9c18372d521405dfe32fc4f552Argyrios Kyrtzidis TypeIdx &Idx = TypeIdxs[T]; 3359c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis if (Idx.getIndex() == 0) { 3360366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor // We haven't seen this type before. Assign it a new ID and put it 33610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into the queue of types to emit. 3362c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis Idx = TypeIdx(NextTypeID++); 336361d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.push(T); 3364366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor } 336526fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis return Idx; 336626fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis} 33672cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33685d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios KyrtzidisTypeIdx ASTWriter::getTypeIdx(QualType T) const { 336926fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis if (T.isNull()) 337026fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis return TypeIdx(); 337126fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis assert(!T.getLocalFastQualifiers()); 337226fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis 33735d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis TypeIdxMap::const_iterator I = TypeIdxs.find(T); 33745d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(I != TypeIdxs.end() && "Type not emitted!"); 33755d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis return I->second; 33762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 33772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33787b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisvoid ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { 3379681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl Record.push_back(GetDeclRef(D)); 3380681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl} 3381681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl 33828538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlDeclID ASTWriter::GetDeclRef(const Decl *D) { 33832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor if (D == 0) { 3384681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl return 0; 33852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 338697475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); 33878538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl DeclID &ID = DeclIDs[D]; 33881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (ID == 0) { 33892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // We haven't seen this declaration before. Give it a new ID and 33902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // enqueue it in the list of declarations to emit. 3391f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl ID = NextDeclID++; 339261d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.push(const_cast<Decl *>(D)); 33930b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl } else if (ID < FirstDeclID && D->isChangedSinceDeserialization()) { 33940b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl // We don't add it to the replacement collection here, because we don't 33950b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl // have the offset yet. 33960b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl DeclTypesToEmit.push(const_cast<Decl *>(D)); 33970b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl // Reset the flag, so that we don't add this decl multiple times. 33980b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl const_cast<Decl *>(D)->setChangedSinceDeserialization(false); 33992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 34002cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3401681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl return ID; 34022cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 34032cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 34048538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlDeclID ASTWriter::getDeclID(const Decl *D) { 34053251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor if (D == 0) 34063251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor return 0; 34073251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 34083251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); 34093251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor return DeclIDs[D]; 34103251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor} 34113251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 341289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { 3413ea5ce4705df0743093925585d8edc80e0d8fe3ffChris Lattner // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. 34142cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Name.getNameKind()); 34152cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor switch (Name.getNameKind()) { 34162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::Identifier: 34172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor AddIdentifierRef(Name.getAsIdentifierInfo(), Record); 34182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 34192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 34202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 34212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::ObjCOneArgSelector: 34222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 342390cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff AddSelectorRef(Name.getObjCSelector(), Record); 34242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 34252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 34262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXConstructorName: 34272cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXDestructorName: 34282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXConversionFunctionName: 34292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor AddTypeRef(Name.getCXXNameType(), Record); 34302cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 34312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 34322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXOperatorName: 34332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Name.getCXXOverloadedOperator()); 34342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 34352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 34363e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 34373e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); 34383e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt break; 34393e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 34402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXUsingDirective: 34412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // No extra data to emit 34422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 34432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 34442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 34456ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 34464045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidisvoid ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, 344789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis DeclarationName Name, RecordDataImpl &Record) { 34484045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis switch (Name.getNameKind()) { 34494045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 34504045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 34514045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 34524045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); 34534045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 34544045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34554045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 34564045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation( 34574045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), 34584045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record); 34594045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation( 34604045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), 34614045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record); 34624045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 34634045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34644045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 34654045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation( 34664045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), 34674045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record); 34684045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 34694045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34704045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::Identifier: 34714045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 34724045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 34734045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 34744045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 34754045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 34764045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis } 34774045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis} 34784045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34794045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidisvoid ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 348089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 34814045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddDeclarationName(NameInfo.getName(), Record); 34824045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation(NameInfo.getLoc(), Record); 34834045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); 34844045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis} 34854045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 34864045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidisvoid ASTWriter::AddQualifierInfo(const QualifierInfo &Info, 348789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 3488c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); 34894045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record.push_back(Info.NumTemplParamLists); 34904045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) 34914045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddTemplateParameterList(Info.TemplParamLists[i], Record); 34924045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis} 34934045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 3494a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, 349589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 34966ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // Nested name specifiers usually aren't too long. I think that 8 would 3497fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner // typically accommodate the vast majority. 34986ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner llvm::SmallVector<NestedNameSpecifier *, 8> NestedNames; 34996ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 35006ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // Push each of the NNS's onto a stack for serialization in reverse order. 35016ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner while (NNS) { 35026ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NestedNames.push_back(NNS); 35036ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NNS = NNS->getPrefix(); 35046ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner } 35056ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 35066ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner Record.push_back(NestedNames.size()); 35076ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner while(!NestedNames.empty()) { 35086ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NNS = NestedNames.pop_back_val(); 35096ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); 35106ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner Record.push_back(Kind); 35116ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner switch (Kind) { 35126ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::Identifier: 35136ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddIdentifierRef(NNS->getAsIdentifier(), Record); 35146ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 35156ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 35166ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::Namespace: 35176ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddDeclRef(NNS->getAsNamespace(), Record); 35186ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 35196ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 352014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor case NestedNameSpecifier::NamespaceAlias: 352114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor AddDeclRef(NNS->getAsNamespaceAlias(), Record); 352214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor break; 352314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 35246ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::TypeSpec: 35256ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::TypeSpecWithTemplate: 35266ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddTypeRef(QualType(NNS->getAsType(), 0), Record); 35276ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); 35286ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 35296ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 35306ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::Global: 35316ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // Don't need to write an associated value. 35326ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 35336ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner } 35346ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner } 35356ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner} 353690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 3537dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregorvoid ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 3538dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor RecordDataImpl &Record) { 3539dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor // Nested name specifiers usually aren't too long. I think that 8 would 3540fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner // typically accommodate the vast majority. 3541dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor llvm::SmallVector<NestedNameSpecifierLoc , 8> NestedNames; 3542dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 3543dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor // Push each of the nested-name-specifiers's onto a stack for 3544dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor // serialization in reverse order. 3545dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor while (NNS) { 3546dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor NestedNames.push_back(NNS); 3547dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor NNS = NNS.getPrefix(); 3548dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor } 3549dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 3550dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor Record.push_back(NestedNames.size()); 3551dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor while(!NestedNames.empty()) { 3552dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor NNS = NestedNames.pop_back_val(); 3553dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor NestedNameSpecifier::SpecifierKind Kind 3554dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor = NNS.getNestedNameSpecifier()->getKind(); 3555dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor Record.push_back(Kind); 3556dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor switch (Kind) { 3557dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::Identifier: 3558dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); 3559dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceRange(NNS.getLocalSourceRange(), Record); 3560dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 3561dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 3562dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::Namespace: 3563dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); 3564dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceRange(NNS.getLocalSourceRange(), Record); 3565dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 3566dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 3567dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::NamespaceAlias: 3568dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); 3569dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceRange(NNS.getLocalSourceRange(), Record); 3570dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 3571dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 3572dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::TypeSpec: 3573dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 3574dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); 3575dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddTypeLoc(NNS.getTypeLoc(), Record); 3576dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); 3577dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 3578dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 3579dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::Global: 3580dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); 3581dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 3582dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor } 3583dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor } 3584dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor} 3585dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 358689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { 358720249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer TemplateName::NameKind Kind = Name.getKind(); 358890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(Kind); 358990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis switch (Kind) { 359090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::Template: 359190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(Name.getAsTemplateDecl(), Record); 359290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 359390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 359490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::OverloadedTemplate: { 359590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); 359690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(OvT->size()); 359790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); 359890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis I != E; ++I) 359990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(*I, Record); 360090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 360190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 360220249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 360390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::QualifiedTemplate: { 360490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); 360590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddNestedNameSpecifier(QualT->getQualifier(), Record); 360690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(QualT->hasTemplateKeyword()); 360790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(QualT->getTemplateDecl(), Record); 360890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 360990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 361020249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 361190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::DependentTemplate: { 361290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis DependentTemplateName *DepT = Name.getAsDependentTemplateName(); 361390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddNestedNameSpecifier(DepT->getQualifier(), Record); 361490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(DepT->isIdentifier()); 361590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis if (DepT->isIdentifier()) 361690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddIdentifierRef(DepT->getIdentifier(), Record); 361790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis else 361890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(DepT->getOperator()); 361990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 362090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 36211aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 36221aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor case TemplateName::SubstTemplateTemplateParmPack: { 36231aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPackStorage *SubstPack 36241aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack(); 36251aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor AddDeclRef(SubstPack->getParameterPack(), Record); 36261aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor AddTemplateArgument(SubstPack->getArgumentPack(), Record); 36271aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor break; 36281aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 362990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 363090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 363190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 363220249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencervoid ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, 363389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 363490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(Arg.getKind()); 363590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis switch (Arg.getKind()) { 363690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Null: 363790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 363890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Type: 363990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddTypeRef(Arg.getAsType(), Record); 364090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 364190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Declaration: 364290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(Arg.getAsDecl(), Record); 364390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 364490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Integral: 364590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddAPSInt(*Arg.getAsIntegral(), Record); 364690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddTypeRef(Arg.getIntegralType(), Record); 364790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 364890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Template: 36492be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); 36502be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor break; 3651a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 3652a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); 36532be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) 36542be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor Record.push_back(*NumExpansions + 1); 36552be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor else 36562be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor Record.push_back(0); 365790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 365890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Expression: 365990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddStmt(Arg.getAsExpr()); 366090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 366190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Pack: 366290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(Arg.pack_size()); 366390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); 366490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis I != E; ++I) 366590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddTemplateArgument(*I, Record); 366690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 366790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 366890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 3669dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis 3670dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidisvoid 3671a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian RedlASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, 367289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 3673dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis assert(TemplateParams && "No TemplateParams!"); 3674dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddSourceLocation(TemplateParams->getTemplateLoc(), Record); 3675dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddSourceLocation(TemplateParams->getLAngleLoc(), Record); 3676dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddSourceLocation(TemplateParams->getRAngleLoc(), Record); 3677dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis Record.push_back(TemplateParams->size()); 3678dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis for (TemplateParameterList::const_iterator 3679dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis P = TemplateParams->begin(), PEnd = TemplateParams->end(); 3680dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis P != PEnd; ++P) 3681dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddDeclRef(*P, Record); 3682dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis} 3683dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis 3684dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis/// \brief Emit a template argument list. 3685dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidisvoid 3686a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian RedlASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, 368789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 3688dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis assert(TemplateArgs && "No TemplateArgs!"); 3689910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Record.push_back(TemplateArgs->size()); 3690910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor for (int i=0, e = TemplateArgs->size(); i != e; ++i) 3691dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddTemplateArgument(TemplateArgs->get(i), Record); 3692dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis} 369337ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis 369437ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis 369537ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidisvoid 369689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios KyrtzidisASTWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record) { 369737ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis Record.push_back(Set.size()); 369837ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis for (UnresolvedSetImpl::const_iterator 369937ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis I = Set.begin(), E = Set.end(); I != E; ++I) { 370037ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis AddDeclRef(I.getDecl(), Record); 370137ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis Record.push_back(I.getAccess()); 370237ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis } 370337ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis} 37040745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis 3705a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, 370689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 37070745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis Record.push_back(Base.isVirtual()); 37080745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis Record.push_back(Base.isBaseOfClass()); 37090745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis Record.push_back(Base.getAccessSpecifierAsWritten()); 3710f677ea3cc9598d9952ad7ffab5fb322ba4c5be31Sebastian Redl Record.push_back(Base.getInheritConstructors()); 37115606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); 37120745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis AddSourceRange(Base.getSourceRange(), Record); 3713f90b27ad077c3339b62befc892382845339f9490Douglas Gregor AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() 3714f90b27ad077c3339b62befc892382845339f9490Douglas Gregor : SourceLocation(), 3715f90b27ad077c3339b62befc892382845339f9490Douglas Gregor Record); 37160745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis} 371730c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl 37187c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregorvoid ASTWriter::FlushCXXBaseSpecifiers() { 37197c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor RecordData Record; 37207c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { 37217c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.clear(); 37227c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 37237c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor // Record the offset of this base-specifier set. 37247c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor unsigned Index = CXXBaseSpecifiersToWrite[I].ID - FirstCXXBaseSpecifiersID; 37257c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Index == CXXBaseSpecifiersOffsets.size()) 37267c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); 37277c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor else { 37287c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Index > CXXBaseSpecifiersOffsets.size()) 37297c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets.resize(Index + 1); 37307c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); 37317c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor } 37327c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 37337c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, 37347c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; 37357c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.push_back(BEnd - B); 37367c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor for (; B != BEnd; ++B) 37377c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor AddCXXBaseSpecifier(*B, Record); 37387c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); 3739acec34bda4a765fd05ed10e5aa83bc93dac072c1Douglas Gregor 3740acec34bda4a765fd05ed10e5aa83bc93dac072c1Douglas Gregor // Flush any expressions that were written as part of the base specifiers. 3741acec34bda4a765fd05ed10e5aa83bc93dac072c1Douglas Gregor FlushStmts(); 37427c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor } 37437c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 37447c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersToWrite.clear(); 37457c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor} 37467c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 3747cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntvoid ASTWriter::AddCXXCtorInitializers( 3748cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt const CXXCtorInitializer * const *CtorInitializers, 3749cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt unsigned NumCtorInitializers, 3750cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt RecordDataImpl &Record) { 3751cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt Record.push_back(NumCtorInitializers); 3752cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt for (unsigned i=0; i != NumCtorInitializers; ++i) { 3753cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt const CXXCtorInitializer *Init = CtorInitializers[i]; 37548e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis 37558e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->isBaseInitializer()); 37568e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis if (Init->isBaseInitializer()) { 37578e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddTypeSourceInfo(Init->getBaseClassInfo(), Record); 37588e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->isBaseVirtual()); 37598e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } else { 376000eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet Record.push_back(Init->isIndirectMemberInitializer()); 376100eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet if (Init->isIndirectMemberInitializer()) 376200eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet AddDeclRef(Init->getIndirectMember(), Record); 376300eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet else 376400eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet AddDeclRef(Init->getMember(), Record); 37658e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } 376600eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet 37678e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddSourceLocation(Init->getMemberLocation(), Record); 37688e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddStmt(Init->getInit()); 37698e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddSourceLocation(Init->getLParenLoc(), Record); 37708e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddSourceLocation(Init->getRParenLoc(), Record); 37718e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->isWritten()); 37728e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis if (Init->isWritten()) { 37738e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->getSourceOrder()); 37748e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } else { 37758e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->getNumArrayIndices()); 37768e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) 37778e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddDeclRef(Init->getArrayIndex(i), Record); 37788e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } 37798e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } 37808e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis} 37818e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis 378289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { 378389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis assert(D->DefinitionData); 378489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; 378589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredConstructor); 378689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredCopyConstructor); 378789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredCopyAssignment); 378889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredDestructor); 378989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Aggregate); 379089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.PlainOldData); 379189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Empty); 379289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Polymorphic); 379389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Abstract); 379489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialConstructor); 37959b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth Record.push_back(Data.HasConstExprNonCopyMoveConstructor); 379689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialCopyConstructor); 37974d6e5a22d9481bb83b82d911727540096d171c0bChandler Carruth Record.push_back(Data.HasTrivialMoveConstructor); 379889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialCopyAssignment); 37994d6e5a22d9481bb83b82d911727540096d171c0bChandler Carruth Record.push_back(Data.HasTrivialMoveAssignment); 380089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialDestructor); 38019b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); 380289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.ComputedVisibleConversions); 380389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredDefaultConstructor); 380489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredCopyConstructor); 380589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredCopyAssignment); 380689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredDestructor); 380789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis 380889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.NumBases); 38097c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Data.NumBases > 0) 38107c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, 38117c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record); 38127c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 381389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis // FIXME: Make VBases lazily computed when needed to avoid storing them. 381489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.NumVBases); 38157c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Data.NumVBases > 0) 38167c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, 38177c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record); 381889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis 381989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis AddUnresolvedSet(Data.Conversions, Record); 382089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis AddUnresolvedSet(Data.VisibleConversions, Record); 382189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis // Data.Definition is the owning decl, no need to write it. 382289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis AddDeclRef(Data.FirstFriend, Record); 382389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis} 382489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis 38257b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisvoid ASTWriter::ReaderInitialized(ASTReader *Reader) { 3826ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl assert(Reader && "Cannot remove chain"); 38277b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis assert(!Chain && "Cannot replace chain"); 3828ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl assert(FirstDeclID == NextDeclID && 3829ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl FirstTypeID == NextTypeID && 3830ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl FirstIdentID == NextIdentID && 3831e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl FirstSelectorID == NextSelectorID && 383277424bc3794f569816dba52e423b57486a98e5baDouglas Gregor FirstMacroID == NextMacroID && 38337c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor FirstCXXBaseSpecifiersID == NextCXXBaseSpecifiersID && 3834ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl "Setting chain after writing has started."); 3835ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl Chain = Reader; 38367b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 38377b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstDeclID += Chain->getTotalNumDecls(); 38387b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstTypeID += Chain->getTotalNumTypes(); 38397b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstIdentID += Chain->getTotalNumIdentifiers(); 38407b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstSelectorID += Chain->getTotalNumSelectors(); 38417b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis FirstMacroID += Chain->getTotalNumMacroDefinitions(); 38427c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor FirstCXXBaseSpecifiersID += Chain->getTotalNumCXXBaseSpecifiers(); 38437b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextDeclID = FirstDeclID; 38447b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextTypeID = FirstTypeID; 38457b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextIdentID = FirstIdentID; 38467b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextSelectorID = FirstSelectorID; 38477b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextMacroID = FirstMacroID; 38487c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor NextCXXBaseSpecifiersID = FirstCXXBaseSpecifiersID; 3849ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl} 3850ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl 38518538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { 3852f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl IdentifierIDs[II] = ID; 3853040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor if (II->hasMacroDefinition()) 3854040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor DeserializedMacroNames.push_back(II); 3855f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl} 3856f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl 3857c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidisvoid ASTWriter::TypeRead(TypeIdx Idx, QualType T) { 385897475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // Always take the highest-numbered type index. This copes with an interesting 385997475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // case for chained AST writing where we schedule writing the type and then, 386020249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer // later, deserialize the type from another AST. In this case, we want to 386197475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // keep the higher-numbered entry so that we can properly write it out to 386297475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // the AST file. 386397475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor TypeIdx &StoredIdx = TypeIdxs[T]; 386497475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor if (Idx.getIndex() >= StoredIdx.getIndex()) 386597475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor StoredIdx = Idx; 386630c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl} 386730c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl 38688538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ASTWriter::DeclRead(DeclID ID, const Decl *D) { 38691476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl DeclIDs[D] = ID; 387030c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl} 38715d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl 38728538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ASTWriter::SelectorRead(SelectorID ID, Selector S) { 38735d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl SelectorIDs[S] = ID; 38745d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl} 387577424bc3794f569816dba52e423b57486a98e5baDouglas Gregor 387620249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencervoid ASTWriter::MacroDefinitionRead(serialization::MacroID ID, 387777424bc3794f569816dba52e423b57486a98e5baDouglas Gregor MacroDefinition *MD) { 387877424bc3794f569816dba52e423b57486a98e5baDouglas Gregor MacroDefinitions[MD] = ID; 387977424bc3794f569816dba52e423b57486a98e5baDouglas Gregor} 3880565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis 3881565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidisvoid ASTWriter::CompletedTagDefinition(const TagDecl *D) { 3882565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis assert(D->isDefinition()); 3883565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { 3884565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // We are interested when a PCH decl is modified. 3885565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis if (RD->getPCHLevel() > 0) { 3886565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // A forward reference was mutated into a definition. Rewrite it. 3887565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // FIXME: This happens during template instantiation, should we 3888565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // have created a new definition decl instead ? 3889d3d0755a4220d3fa6c125eb3f8ce29fc1424eac3Argyrios Kyrtzidis RewriteDecl(RD); 3890565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 3891565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis 3892565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis for (CXXRecordDecl::redecl_iterator 3893565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis I = RD->redecls_begin(), E = RD->redecls_end(); I != E; ++I) { 3894565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis CXXRecordDecl *Redecl = cast<CXXRecordDecl>(*I); 3895565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis if (Redecl == RD) 3896565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis continue; 3897565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis 3898565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // We are interested when a PCH decl is modified. 3899565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis if (Redecl->getPCHLevel() > 0) { 3900565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis UpdateRecord &Record = DeclUpdates[Redecl]; 3901565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis Record.push_back(UPD_CXX_SET_DEFINITIONDATA); 3902565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis assert(Redecl->DefinitionData); 3903565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis assert(Redecl->DefinitionData->Definition == D); 3904565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis AddDeclRef(D, Record); // the DefinitionDecl 3905565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 3906565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 3907565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 3908565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis} 3909100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidisvoid ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { 3910100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis // TU and namespaces are handled elsewhere. 3911100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) 3912100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis return; 3913100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis 3914100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis if (!(D->getPCHLevel() == 0 && cast<Decl>(DC)->getPCHLevel() > 0)) 3915100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis return; // Not a source decl added to a DeclContext from PCH. 3916100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis 3917100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis AddUpdatedDeclContext(DC); 3918100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis} 3919b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis 3920b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidisvoid ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { 3921b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis assert(D->isImplicit()); 3922b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis if (!(D->getPCHLevel() == 0 && RD->getPCHLevel() > 0)) 3923b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis return; // Not a source member added to a class from PCH. 3924b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis if (!isa<CXXMethodDecl>(D)) 3925b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis return; // We are interested in lazily declared implicit methods. 3926b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis 3927b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis // A decl coming from PCH was modified. 3928b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis assert(RD->isDefinition()); 3929b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis UpdateRecord &Record = DeclUpdates[RD]; 3930b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); 3931b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis AddDeclRef(D, Record); 3932b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis} 3933bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis 3934bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidisvoid ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, 3935bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis const ClassTemplateSpecializationDecl *D) { 39360f04f69acd0a86ff78961933c13fe5aeda94e1b6Argyrios Kyrtzidis // The specializations set is kept in the canonical template. 39370f04f69acd0a86ff78961933c13fe5aeda94e1b6Argyrios Kyrtzidis TD = TD->getCanonicalDecl(); 3938bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0)) 3939bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis return; // Not a source specialization added to a template from PCH. 3940bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis 3941bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis UpdateRecord &Record = DeclUpdates[TD]; 3942bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); 3943bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis AddDeclRef(D, Record); 3944bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis} 394589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 39465bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redlvoid ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, 39475bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl const FunctionDecl *D) { 39485bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl // The specializations set is kept in the canonical template. 39495bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl TD = TD->getCanonicalDecl(); 39505bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0)) 39515bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl return; // Not a source specialization added to a template from PCH. 39525bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl 39535bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl UpdateRecord &Record = DeclUpdates[TD]; 39545bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); 39555bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl AddDeclRef(D, Record); 39565bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl} 39575bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl 395889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas GregorASTSerializationListener::~ASTSerializationListener() { } 3959