ASTWriter.cpp revision 2a82ca255b0f99f6201a75ed52b91fc024f6e9cf
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" 150eca89e9890db4d8336ce762a5b359a1d58ca02bArgyrios Kyrtzidis#include "ASTCommon.h" 16e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Sema.h" 17e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/IdentifierResolver.h" 182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/ASTContext.h" 192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/Decl.h" 202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/DeclContextInternals.h" 212a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall#include "clang/AST/DeclTemplate.h" 2289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis#include "clang/AST/DeclFriend.h" 230b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor#include "clang/AST/Expr.h" 247a1fad38256eb4c5129359be85ba1ea1678eb5c9John McCall#include "clang/AST/ExprCXX.h" 252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/Type.h" 26a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#include "clang/AST/TypeLocVisitor.h" 276ab7cd853e9c15cf986a8a7c3db1f8d20e275409Sebastian Redl#include "clang/Serialization/ASTReader.h" 28bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor#include "clang/Lex/HeaderSearchOptions.h" 297c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner#include "clang/Lex/MacroInfo.h" 306a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor#include "clang/Lex/PreprocessingRecord.h" 317c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner#include "clang/Lex/Preprocessor.h" 32a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor#include "clang/Lex/PreprocessorOptions.h" 3383d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff#include "clang/Lex/HeaderSearch.h" 3414f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "clang/Basic/FileManager.h" 3510e286aa8d39fb51a21412850265d9dae74613eeChris Lattner#include "clang/Basic/FileSystemStatCache.h" 363251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor#include "clang/Basic/OnDiskHashTable.h" 3714f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "clang/Basic/SourceManager.h" 38bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor#include "clang/Basic/SourceManagerInternals.h" 392bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor#include "clang/Basic/TargetInfo.h" 4057016dda61498294120b1a881d9e6606337b29d9Douglas Gregor#include "clang/Basic/TargetOptions.h" 41ab41e63821dc60ad144d0684df8d79a9eef86b75Douglas Gregor#include "clang/Basic/Version.h" 420a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor#include "clang/Basic/VersionTuple.h" 4317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APFloat.h" 4417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APInt.h" 452596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar#include "llvm/ADT/StringExtras.h" 462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/Bitcode/BitstreamWriter.h" 47fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer#include "llvm/Support/FileSystem.h" 4814f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "llvm/Support/MemoryBuffer.h" 4903013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/Path.h" 50f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor#include <algorithm> 513c304bd9ec2b4611572d4cbae9e1727bbecb5dc9Chris Lattner#include <cstdio> 52cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor#include <string.h> 53f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor#include <utility> 542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorusing namespace clang; 558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlusing namespace clang::serialization; 562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 57ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redltemplate <typename T, typename Allocator> 585f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnerstatic StringRef data(const std::vector<T, Allocator> &v) { 595f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner if (v.empty()) return StringRef(); 605f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner return StringRef(reinterpret_cast<const char*>(&v[0]), 616e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer sizeof(T) * v.size()); 62ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl} 636e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer 646e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramertemplate <typename T> 655f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnerstatic StringRef data(const SmallVectorImpl<T> &v) { 665f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner return StringRef(reinterpret_cast<const char*>(v.data()), 676e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer sizeof(T) * v.size()); 68ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl} 69ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl 702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// Type serialization 722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 7312b1c7615d4f9a2edc544be499f895f16ac100edChris Lattner 742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace { 753397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl class ASTTypeWriter { 76a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 7789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record; 782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor public: 802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Type code that corresponds to the record generated. 818538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl TypeCode Code; 822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 8389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) 848538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { } 852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor void VisitArrayType(const ArrayType *T); 872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor void VisitFunctionType(const FunctionType *T); 882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor void VisitTagType(const TagType *T); 892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); 912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define ABSTRACT_TYPE(Class, Base) 922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/TypeNodes.def" 932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor }; 942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 963397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { 97b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Built-in types are never serialized"); 982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1003397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitComplexType(const ComplexType *T) { 1012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getElementType(), Record); 1028538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_COMPLEX; 1032cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1053397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitPointerType(const PointerType *T) { 1062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getPointeeType(), Record); 1078538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_POINTER; 1082cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1092cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1103397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { 1111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(T->getPointeeType(), Record); 1128538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_BLOCK_POINTER; 1132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1142cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1153397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { 116df1550fc59b51681d37225934fe4e3acac321621Richard Smith Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); 117df1550fc59b51681d37225934fe4e3acac321621Richard Smith Record.push_back(T->isSpelledAsLValue()); 1188538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_LVALUE_REFERENCE; 1192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1213397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { 122df1550fc59b51681d37225934fe4e3acac321621Richard Smith Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record); 1238538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_RVALUE_REFERENCE; 1242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1263397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { 1271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(T->getPointeeType(), Record); 1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(QualType(T->getClass(), 0), Record); 1298538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_MEMBER_POINTER; 1302cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1323397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitArrayType(const ArrayType *T) { 1332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getElementType(), Record); 1342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getSizeModifier()); // FIXME: stable values 1350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values 1362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1383397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { 1392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitArrayType(T); 1402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddAPInt(T->getSize(), Record); 1418538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_CONSTANT_ARRAY; 1422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1443397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { 1452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitArrayType(T); 1468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_INCOMPLETE_ARRAY; 1472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1493397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { 1502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitArrayType(T); 1517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Writer.AddSourceLocation(T->getLBracketLoc(), Record); 1527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Writer.AddSourceLocation(T->getRBracketLoc(), Record); 153c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Writer.AddStmt(T->getSizeExpr()); 1548538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_VARIABLE_ARRAY; 1552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1573397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitVectorType(const VectorType *T) { 1582cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getElementType(), Record); 1592cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getNumElements()); 160e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson Record.push_back(T->getVectorKind()); 1618538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_VECTOR; 1622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1643397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) { 1652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitVectorType(T); 1668538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_EXT_VECTOR; 1672cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1693397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionType(const FunctionType *T) { 1702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getResultType(), Record); 171264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionType::ExtInfo C = T->getExtInfo(); 172264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Record.push_back(C.getNoReturn()); 173a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman Record.push_back(C.getHasRegParm()); 174425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola Record.push_back(C.getRegParm()); 175ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor // FIXME: need to stabilize encoding of calling convention... 176264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Record.push_back(C.getCC()); 177f85e193739c953358c865005855253af4f68a497John McCall Record.push_back(C.getProducesResult()); 1782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1803397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { 1812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitFunctionType(T); 1828538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_FUNCTION_NO_PROTO; 1832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1853397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { 1862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitFunctionType(T); 1872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getNumArgs()); 1882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) 1892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getArgType(I), Record); 1902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->isVariadic()); 191eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith Record.push_back(T->hasTrailingReturn()); 1922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getTypeQuals()); 193c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor Record.push_back(static_cast<unsigned>(T->getRefQualifier())); 19460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Record.push_back(T->getExceptionSpecType()); 19560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (T->getExceptionSpecType() == EST_Dynamic) { 19660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Record.push_back(T->getNumExceptions()); 19760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) 19860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Writer.AddTypeRef(T->getExceptionType(I), Record); 19960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) { 20060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Writer.AddStmt(T->getNoexceptExpr()); 2017bb698aa054de4c0e0aa23973b2c62dac9611262Richard Smith } else if (T->getExceptionSpecType() == EST_Uninstantiated) { 2027bb698aa054de4c0e0aa23973b2c62dac9611262Richard Smith Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); 2037bb698aa054de4c0e0aa23973b2c62dac9611262Richard Smith Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record); 204b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (T->getExceptionSpecType() == EST_Unevaluated) { 205b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith Writer.AddDeclRef(T->getExceptionSpecDecl(), Record); 20660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2078538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_FUNCTION_PROTO; 2082cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2092cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2103397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { 211ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Writer.AddDeclRef(T->getDecl(), Record); 2128538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_UNRESOLVED_USING; 213ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 214ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 2153397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypedefType(const TypedefType *T) { 2162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddDeclRef(T->getDecl(), Record); 2179763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); 2189763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record); 2198538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TYPEDEF; 2202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2223397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { 223c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Writer.AddStmt(T->getUnderlyingExpr()); 2248538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TYPEOF_EXPR; 2252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2273397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) { 2282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Writer.AddTypeRef(T->getUnderlyingType(), Record); 2298538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TYPEOF; 2302cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2323397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) { 233f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregor Writer.AddTypeRef(T->getUnderlyingType(), Record); 234395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Writer.AddStmt(T->getUnderlyingExpr()); 2358538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DECLTYPE; 236395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 237395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 238ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntvoid ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) { 239ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Writer.AddTypeRef(T->getBaseType(), Record); 240ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Writer.AddTypeRef(T->getUnderlyingType(), Record); 241ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Record.push_back(T->getUTTKind()); 242ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Code = TYPE_UNARY_TRANSFORM; 243ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 244ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 24534b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid ASTTypeWriter::VisitAutoType(const AutoType *T) { 24634b41d939a1328f484511c6002ba2456db879a29Richard Smith Writer.AddTypeRef(T->getDeducedType(), Record); 24734b41d939a1328f484511c6002ba2456db879a29Richard Smith Code = TYPE_AUTO; 24834b41d939a1328f484511c6002ba2456db879a29Richard Smith} 24934b41d939a1328f484511c6002ba2456db879a29Richard Smith 2503397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTagType(const TagType *T) { 251be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis Record.push_back(T->isDependentType()); 25256ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); 2531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!T->isBeingDefined() && 2542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor "Cannot serialize in the middle of a type definition"); 2552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2573397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitRecordType(const RecordType *T) { 2582cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitTagType(T); 2598538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_RECORD; 2602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2612cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2623397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitEnumType(const EnumType *T) { 2632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor VisitTagType(T); 2648538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_ENUM; 2652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 2662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid ASTTypeWriter::VisitAttributedType(const AttributedType *T) { 2689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddTypeRef(T->getModifiedType(), Record); 2699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddTypeRef(T->getEquivalentType(), Record); 2709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Record.push_back(T->getAttrKind()); 2719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Code = TYPE_ATTRIBUTED; 2729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 2739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 2741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 2753397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitSubstTemplateTypeParmType( 27649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall const SubstTemplateTypeParmType *T) { 27749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); 27849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Writer.AddTypeRef(T->getReplacementType(), Record); 2798538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_SUBST_TEMPLATE_TYPE_PARM; 28049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 28149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 28249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallvoid 283c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorASTTypeWriter::VisitSubstTemplateTypeParmPackType( 284c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const SubstTemplateTypeParmPackType *T) { 285c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); 286c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Writer.AddTemplateArgument(T->getArgumentPack(), Record); 287c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK; 288c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 289c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 290c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid 2913397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitTemplateSpecializationType( 2922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor const TemplateSpecializationType *T) { 293be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis Record.push_back(T->isDependentType()); 29490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Writer.AddTemplateName(T->getTemplateName(), Record); 29590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->getNumArgs()); 29690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end(); 29790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis ArgI != ArgE; ++ArgI) 29890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Writer.AddTemplateArgument(*ArgI, Record); 2993e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() : 3003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith T->isCanonicalUnqualified() ? QualType() 3019763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis : T->getCanonicalTypeInternal(), 3029763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Record); 3038538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TEMPLATE_SPECIALIZATION; 30490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 30590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 30690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 3073397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) { 308ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis VisitArrayType(T); 309ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis Writer.AddStmt(T->getSizeExpr()); 310ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis Writer.AddSourceRange(T->getBracketsRange(), Record); 3118538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DEPENDENT_SIZED_ARRAY; 31290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 31390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 31490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 3153397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentSizedExtVectorType( 31690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis const DependentSizedExtVectorType *T) { 31790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis // FIXME: Serialize this type (C++ only) 318b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Cannot serialize dependent sized extended vector types"); 31990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 32090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 32190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 3223397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { 32390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->getDepth()); 32490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->getIndex()); 32590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(T->isParameterPack()); 3264fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth Writer.AddDeclRef(T->getDecl(), Record); 3278538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_TEMPLATE_TYPE_PARM; 32890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 32990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 33090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 3313397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentNameType(const DependentNameType *T) { 3328dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Record.push_back(T->getKeyword()); 3338dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Writer.AddNestedNameSpecifier(T->getQualifier(), Record); 3348dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Writer.AddIdentifierRef(T->getIdentifier(), Record); 335f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() 336f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis : T->getCanonicalTypeInternal(), 337f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis Record); 3388538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DEPENDENT_NAME; 33990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 34090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 34190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid 3423397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentTemplateSpecializationType( 34390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis const DependentTemplateSpecializationType *T) { 3443acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Record.push_back(T->getKeyword()); 3453acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddNestedNameSpecifier(T->getQualifier(), Record); 3463acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddIdentifierRef(T->getIdentifier(), Record); 3473acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Record.push_back(T->getNumArgs()); 3483acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis for (DependentTemplateSpecializationType::iterator 3493acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis I = T->begin(), E = T->end(); I != E; ++I) 3503acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddTemplateArgument(*I, Record); 3518538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION; 3522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3547536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorvoid ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) { 3557536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Writer.AddTypeRef(T->getPattern(), Record); 356cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor if (llvm::Optional<unsigned> NumExpansions = T->getNumExpansions()) 357cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Record.push_back(*NumExpansions + 1); 358cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor else 359cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Record.push_back(0); 3607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Code = TYPE_PACK_EXPANSION; 3617536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 3627536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 363075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaravoid ASTTypeWriter::VisitParenType(const ParenType *T) { 364075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Writer.AddTypeRef(T->getInnerType(), Record); 365075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Code = TYPE_PAREN; 366075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 367075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 3683397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) { 369465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Record.push_back(T->getKeyword()); 3703acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddNestedNameSpecifier(T->getQualifier(), Record); 3713acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis Writer.AddTypeRef(T->getNamedType(), Record); 3728538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_ELABORATED; 3732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3753397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { 376a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); 37731f17ecbef57b5679c017c375db330546b7b5145John McCall Writer.AddTypeRef(T->getInjectedSpecializationType(), Record); 3788538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_INJECTED_CLASS_NAME; 3793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 3803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 3813397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { 38256ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record); 3838538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_OBJC_INTERFACE; 384c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 385c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3863397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) { 387c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Writer.AddTypeRef(T->getBaseType(), Record); 3882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(T->getNumProtocols()); 389c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (ObjCObjectType::qual_iterator I = T->qual_begin(), 390446ee4eb4fc4c705a59365252df7a5c253daafa1Steve Naroff E = T->qual_end(); I != E; ++I) 391446ee4eb4fc4c705a59365252df7a5c253daafa1Steve Naroff Writer.AddDeclRef(*I, Record); 3928538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_OBJC_OBJECT; 3932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 3942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 395d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffvoid 3963397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { 3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Writer.AddTypeRef(T->getPointeeType(), Record); 3988538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = TYPE_OBJC_OBJECT_POINTER; 3992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 4002cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 401b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanvoid 402b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanASTTypeWriter::VisitAtomicType(const AtomicType *T) { 403b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Writer.AddTypeRef(T->getValueType(), Record); 404b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Code = TYPE_ATOMIC; 405b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 406b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 407a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallnamespace { 408a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 409a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallclass TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { 410a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 41189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record; 412a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 413a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallpublic: 41489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record) 415a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall : Writer(Writer), Record(Record) { } 416a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 41751bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 418a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#define TYPELOC(CLASS, PARENT) \ 41951bd803fbdade51d674598ed45da3d54190a656cJohn McCall void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); 420a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#include "clang/AST/TypeLocNodes.def" 421a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 42251bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); 42351bd803fbdade51d674598ed45da3d54190a656cJohn McCall void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); 424a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}; 425a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 426a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 427a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 42851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { 42951bd803fbdade51d674598ed45da3d54190a656cJohn McCall // nothing to do 43051bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 43151bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { 432ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); 433ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (TL.needsExtraLocalData()) { 434ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.getWrittenTypeSpec()); 435ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.getWrittenSignSpec()); 436ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.getWrittenWidthSpec()); 437ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor Record.push_back(TL.hasModeAttr()); 438ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 43951bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { 44151bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 44251bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { 44451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getStarLoc(), Record); 44551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { 44751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getCaretLoc(), Record); 44851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 44951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { 45051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getAmpLoc(), Record); 45151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 45251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { 45351bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); 45451bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 45551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { 45651bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getStarLoc(), Record); 457b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record); 45851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 45951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { 46051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getLBracketLoc(), Record); 46151bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getRBracketLoc(), Record); 46251bd803fbdade51d674598ed45da3d54190a656cJohn McCall Record.push_back(TL.getSizeExpr() ? 1 : 0); 46351bd803fbdade51d674598ed45da3d54190a656cJohn McCall if (TL.getSizeExpr()) 46451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddStmt(TL.getSizeExpr()); 46551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 46651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { 46751bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 46851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 46951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { 47051bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 47151bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 47251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { 47351bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 47451bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 47551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDependentSizedArrayTypeLoc( 47651bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedArrayTypeLoc TL) { 47751bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitArrayTypeLoc(TL); 47851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 47951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( 48051bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedExtVectorTypeLoc TL) { 48151bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 48251bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 48351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { 48451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 48551bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 48651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { 48751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 48851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 48951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { 490796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record); 49159c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara Writer.AddSourceLocation(TL.getLParenLoc(), Record); 49259c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara Writer.AddSourceLocation(TL.getRParenLoc(), Record); 493796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record); 49451bd803fbdade51d674598ed45da3d54190a656cJohn McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) 49551bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddDeclRef(TL.getArg(i), Record); 49651bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 49751bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { 49851bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitFunctionTypeLoc(TL); 49951bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 50051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { 50151bd803fbdade51d674598ed45da3d54190a656cJohn McCall VisitFunctionTypeLoc(TL); 50251bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 503ed97649e9574b9d854fa4d6109c9333ae0993554John McCallvoid TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { 504ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 505ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 50651bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { 50751bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 50851bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 50951bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { 510cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getTypeofLoc(), Record); 511cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getLParenLoc(), Record); 512cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getRParenLoc(), Record); 51351bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 51451bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { 515cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getTypeofLoc(), Record); 516cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getLParenLoc(), Record); 517cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddSourceLocation(TL.getRParenLoc(), Record); 518cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); 51951bd803fbdade51d674598ed45da3d54190a656cJohn McCall} 52051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { 52151bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 522a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 523ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntvoid TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { 524ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Writer.AddSourceLocation(TL.getKWLoc(), Record); 525ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Writer.AddSourceLocation(TL.getLParenLoc(), Record); 526ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Writer.AddSourceLocation(TL.getRParenLoc(), Record); 527ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); 528ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 52934b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { 53034b41d939a1328f484511c6002ba2456db879a29Richard Smith Writer.AddSourceLocation(TL.getNameLoc(), Record); 53134b41d939a1328f484511c6002ba2456db879a29Richard Smith} 53251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { 53351bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 534a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 53551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { 53651bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 537a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 5389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { 5399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(TL.getAttrNameLoc(), Record); 5409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) { 5419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceRange range = TL.getAttrOperandParensRange(); 5429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(range.getBegin(), Record); 5439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(range.getEnd(), Record); 5449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 5459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) { 5469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Expr *operand = TL.getAttrExprOperand(); 5479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Record.push_back(operand ? 1 : 0); 5489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (operand) Writer.AddStmt(operand); 5499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } else if (TL.hasAttrEnumOperand()) { 5509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record); 5519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 5529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 55351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { 55451bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 555a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 55649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallvoid TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( 55749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmTypeLoc TL) { 55849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 55949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 560c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( 561c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 562c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Writer.AddSourceLocation(TL.getNameLoc(), Record); 563c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 56451bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTemplateSpecializationTypeLoc( 56551bd803fbdade51d674598ed45da3d54190a656cJohn McCall TemplateSpecializationTypeLoc TL) { 56655d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); 567833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); 568833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Writer.AddSourceLocation(TL.getLAngleLoc(), Record); 569833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Writer.AddSourceLocation(TL.getRAngleLoc(), Record); 570833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) 57144f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), 57244f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis TL.getArgLoc(i).getLocInfo(), Record); 573a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 574075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaravoid TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { 575075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Writer.AddSourceLocation(TL.getLParenLoc(), Record); 576075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Writer.AddSourceLocation(TL.getRParenLoc(), Record); 577075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 578465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaravoid TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { 57938a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); 5809e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); 581a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 5823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallvoid TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { 5833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 5843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 5854714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregorvoid TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { 58638a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); 5872494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); 58851bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 589a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 59033500955d731c73717af52088b7fc0e7a85681e7John McCallvoid TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( 59133500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypeLoc TL) { 59255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record); 59394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record); 59466581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record); 59555d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); 59633500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getLAngleLoc(), Record); 59733500955d731c73717af52088b7fc0e7a85681e7John McCall Writer.AddSourceLocation(TL.getRAngleLoc(), Record); 59833500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) 59944f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), 60044f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis TL.getArgLoc(I).getLocInfo(), Record); 60133500955d731c73717af52088b7fc0e7a85681e7John McCall} 6027536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorvoid TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { 6037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Writer.AddSourceLocation(TL.getEllipsisLoc(), Record); 6047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 60551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { 60651bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getNameLoc(), Record); 607c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 608c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { 609c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Record.push_back(TL.hasBaseTypeAsWritten()); 61054e14c4db764c0636160d26c5bbf491637c83a76John McCall Writer.AddSourceLocation(TL.getLAngleLoc(), Record); 61154e14c4db764c0636160d26c5bbf491637c83a76John McCall Writer.AddSourceLocation(TL.getRAngleLoc(), Record); 61254e14c4db764c0636160d26c5bbf491637c83a76John McCall for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) 61354e14c4db764c0636160d26c5bbf491637c83a76John McCall Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); 614a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 61551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { 61651bd803fbdade51d674598ed45da3d54190a656cJohn McCall Writer.AddSourceLocation(TL.getStarLoc(), Record); 617a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 618b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanvoid TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { 619b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Writer.AddSourceLocation(TL.getKWLoc(), Record); 620b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Writer.AddSourceLocation(TL.getLParenLoc(), Record); 621b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Writer.AddSourceLocation(TL.getRParenLoc(), Record); 622b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 623a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 6244dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner//===----------------------------------------------------------------------===// 625a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl// ASTWriter Implementation 6262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===// 6272cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 628b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattnerstatic void EmitBlockID(unsigned ID, const char *Name, 629b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner llvm::BitstreamWriter &Stream, 63089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record) { 631b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.clear(); 632b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(ID); 633b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); 634b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 635b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner // Emit the block name if present. 636b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner if (Name == 0 || Name[0] == 0) return; 637b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.clear(); 638b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner while (*Name) 639b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(*Name++); 640b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); 641b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner} 642b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 643b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattnerstatic void EmitRecordID(unsigned ID, const char *Name, 644b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner llvm::BitstreamWriter &Stream, 64589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record) { 646b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.clear(); 647b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(ID); 648b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner while (*Name) 649b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Record.push_back(*Name++); 650b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); 6510558df2da807646e65d4fa290f4e92114af1a746Chris Lattner} 6520558df2da807646e65d4fa290f4e92114af1a746Chris Lattner 6530558df2da807646e65d4fa290f4e92114af1a746Chris Lattnerstatic void AddStmtsExprs(llvm::BitstreamWriter &Stream, 65489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis ASTWriter::RecordDataImpl &Record) { 6558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define RECORD(X) EmitRecordID(X, #X, Stream, Record) 6560558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_STOP); 6570558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_NULL_PTR); 6580558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_NULL); 6590558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_COMPOUND); 6600558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_CASE); 6610558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_DEFAULT); 6620558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_LABEL); 663534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith RECORD(STMT_ATTRIBUTED); 6640558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_IF); 6650558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_SWITCH); 6660558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_WHILE); 6670558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_DO); 6680558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_FOR); 6690558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_GOTO); 6700558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_INDIRECT_GOTO); 6710558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_CONTINUE); 6720558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_BREAK); 6730558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_RETURN); 6740558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_DECL); 675df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier RECORD(STMT_GCCASM); 676cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier RECORD(STMT_MSASM); 6770558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_PREDEFINED); 6780558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_DECL_REF); 6790558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_INTEGER_LITERAL); 6800558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_FLOATING_LITERAL); 6810558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_IMAGINARY_LITERAL); 6820558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_STRING_LITERAL); 6830558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CHARACTER_LITERAL); 6840558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_PAREN); 6850558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_UNARY_OPERATOR); 6860558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_SIZEOF_ALIGN_OF); 6870558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_ARRAY_SUBSCRIPT); 6880558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CALL); 6890558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_MEMBER); 6900558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_BINARY_OPERATOR); 6910558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); 6920558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CONDITIONAL_OPERATOR); 6930558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_IMPLICIT_CAST); 6940558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CSTYLE_CAST); 6950558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_COMPOUND_LITERAL); 6960558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_EXT_VECTOR_ELEMENT); 6970558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_INIT_LIST); 6980558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_DESIGNATED_INIT); 6990558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_IMPLICIT_VALUE_INIT); 7000558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_VA_ARG); 7010558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_ADDR_LABEL); 7020558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_STMT); 7030558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_CHOOSE); 7040558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_GNU_NULL); 7050558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_SHUFFLE_VECTOR); 7060558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_BLOCK); 707f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne RECORD(EXPR_GENERIC_SELECTION); 7080558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_STRING_LITERAL); 709eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard RECORD(EXPR_OBJC_BOXED_EXPRESSION); 710ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek RECORD(EXPR_OBJC_ARRAY_LITERAL); 711ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek RECORD(EXPR_OBJC_DICTIONARY_LITERAL); 7120558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_ENCODE); 7130558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_SELECTOR_EXPR); 7140558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_PROTOCOL_EXPR); 7150558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_IVAR_REF_EXPR); 7160558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); 7170558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_KVC_REF_EXPR); 7180558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(EXPR_OBJC_MESSAGE_EXPR); 7190558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_FOR_COLLECTION); 7200558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_CATCH); 7210558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_FINALLY); 7220558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_AT_TRY); 7230558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_AT_SYNCHRONIZED); 7240558df2da807646e65d4fa290f4e92114af1a746Chris Lattner RECORD(STMT_OBJC_AT_THROW); 725ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek RECORD(EXPR_OBJC_BOOL_LITERAL); 726eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_OPERATOR_CALL); 727eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_CONSTRUCT); 728eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_STATIC_CAST); 729eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_DYNAMIC_CAST); 730eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_REINTERPRET_CAST); 731eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_CONST_CAST); 732eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_FUNCTIONAL_CAST); 7339fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith RECORD(EXPR_USER_DEFINED_LITERAL); 734eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_BOOL_LITERAL); 735eb7f96141f754150a92433286fa385910a22f494Sam Weinig RECORD(EXPR_CXX_NULL_PTR_LITERAL); 736b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_TYPEID_EXPR); 737b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_TYPEID_TYPE); 738b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UUIDOF_EXPR); 739b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UUIDOF_TYPE); 740b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_THIS); 741b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_THROW); 742b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DEFAULT_ARG); 743b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_BIND_TEMPORARY); 744b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_SCALAR_VALUE_INIT); 745b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_NEW); 746b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DELETE); 747b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); 748b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_EXPR_WITH_CLEANUPS); 749b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); 750b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); 751b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); 752b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNRESOLVED_MEMBER); 753b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); 754b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_UNARY_TYPE_TRAIT); 755b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_CXX_NOEXCEPT); 756b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_OPAQUE_VALUE); 757b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_BINARY_TYPE_TRAIT); 758b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_PACK_EXPANSION); 759b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_SIZEOF_PACK); 760b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); 761e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne RECORD(EXPR_CUDA_KERNEL_CALL); 7620558df2da807646e65d4fa290f4e92114af1a746Chris Lattner#undef RECORD 763b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner} 7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 765a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteBlockInfoBlock() { 766b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RecordData Record; 767b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); 7681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7698538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) 7708538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define RECORD(X) EmitRecordID(X, #X, Stream, Record) 7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7727ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor // Control Block. 7737ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor BLOCK(CONTROL_BLOCK); 7747ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor RECORD(METADATA); 7757ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor RECORD(IMPORTS); 7767ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor RECORD(LANGUAGE_OPTIONS); 7777ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor RECORD(TARGET_OPTIONS); 77839c497b6d5e99acecbe03ee173249ee21933e855Douglas Gregor RECORD(ORIGINAL_FILE); 7797ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor RECORD(ORIGINAL_PCH_DIR); 780992d91742129c1f77563df0b3d0a40b36fd13e3eArgyrios Kyrtzidis RECORD(ORIGINAL_FILE_ID); 781a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor RECORD(INPUT_FILE_OFFSETS); 7825f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor RECORD(DIAGNOSTIC_OPTIONS); 7831b2c3c0884e917ae5d59edde7d93b2af33c6a1b6Douglas Gregor RECORD(FILE_SYSTEM_OPTIONS); 784bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor RECORD(HEADER_SEARCH_OPTIONS); 785a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor RECORD(PREPROCESSOR_OPTIONS); 786a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor 787c337fefd7317714d365a2acf4f1d2939bbcf8e3bDouglas Gregor BLOCK(INPUT_FILES_BLOCK); 788c337fefd7317714d365a2acf4f1d2939bbcf8e3bDouglas Gregor RECORD(INPUT_FILE); 789c337fefd7317714d365a2acf4f1d2939bbcf8e3bDouglas Gregor 7907ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor // AST Top-Level Block. 7917ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor BLOCK(AST_BLOCK); 792b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_OFFSET); 793b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_OFFSET); 794b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(IDENTIFIER_OFFSET); 795b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(IDENTIFIER_TABLE); 796b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(EXTERNAL_DEFINITIONS); 797b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SPECIAL_TYPES); 798b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(STATISTICS); 799b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TENTATIVE_DEFINITIONS); 80049b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis RECORD(UNUSED_FILESCOPED_DECLS); 801b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); 802b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SELECTOR_OFFSETS); 803b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(METHOD_POOL); 804b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_COUNTER_VALUE); 8057f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RECORD(SOURCE_LOCATION_OFFSETS); 8067f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RECORD(SOURCE_LOCATION_PRELOADS); 807b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor RECORD(EXT_VECTOR_DECLS); 808e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis RECORD(PPD_ENTITIES_OFFSETS); 809320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian RECORD(REFERENCED_SELECTOR_POOL); 810b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TU_UPDATE_LEXICAL); 8112171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor RECORD(LOCAL_REDECLARATIONS_MAP); 812b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(SEMA_DECL_REFS); 813b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(WEAK_UNDECLARED_IDENTIFIERS); 814b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(PENDING_IMPLICIT_INSTANTIATIONS); 815b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_REPLACEMENTS); 816b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(UPDATE_VISIBLE); 817b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UPDATE_OFFSETS); 818b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UPDATES); 819b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(CXX_BASE_SPECIFIER_OFFSETS); 820b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DIAG_PRAGMA_MAPPINGS); 82184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RECORD(CUDA_SPECIAL_DECL_REFS); 822cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor RECORD(HEADER_SEARCH_TABLE); 82384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RECORD(FP_PRAGMA_OPTIONS); 82484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RECORD(OPENCL_EXTENSIONS); 825ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt RECORD(DELEGATING_CTORS); 826d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor RECORD(KNOWN_NAMESPACES); 827837593fec8389eea3143920d7f2180b079b609e8Douglas Gregor RECORD(MODULE_OFFSET_MAP); 828837593fec8389eea3143920d7f2180b079b609e8Douglas Gregor RECORD(SOURCE_MANAGER_LINE_TABLE); 829cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor RECORD(OBJC_CATEGORIES_MAP); 830a126651270acf17c434f60f86a3ab3687f87813aDouglas Gregor RECORD(FILE_SORTED_DECLS); 831a126651270acf17c434f60f86a3ab3687f87813aDouglas Gregor RECORD(IMPORTED_MODULES); 8322171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor RECORD(MERGED_DECLARATIONS); 8332171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor RECORD(LOCAL_REDECLARATIONS); 834cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor RECORD(OBJC_CATEGORIES); 835a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor RECORD(MACRO_OFFSET); 836a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor RECORD(MACRO_UPDATES); 8372171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 838b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner // SourceManager Block. 8392f4efd10c805cb779618c1a22a35eb07b5043c4eChris Lattner BLOCK(SOURCE_MANAGER_BLOCK); 840b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_FILE_ENTRY); 841b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_BUFFER_ENTRY); 842b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(SM_SLOC_BUFFER_BLOB); 843f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth RECORD(SM_SLOC_EXPANSION_ENTRY); 8441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 845b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner // Preprocessor Block. 8462f4efd10c805cb779618c1a22a35eb07b5043c4eChris Lattner BLOCK(PREPROCESSOR_BLOCK); 847b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_MACRO_OBJECT_LIKE); 848b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_MACRO_FUNCTION_LIKE); 849b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(PP_TOKEN); 850b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor 85161d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor // Decls and Types block. 85261d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor BLOCK(DECLTYPES_BLOCK); 853b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_EXT_QUAL); 854b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_COMPLEX); 855b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_POINTER); 856b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_BLOCK_POINTER); 857b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_LVALUE_REFERENCE); 858b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_RVALUE_REFERENCE); 859b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_MEMBER_POINTER); 860b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_CONSTANT_ARRAY); 861b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_INCOMPLETE_ARRAY); 862b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_VARIABLE_ARRAY); 863b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_VECTOR); 864b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_EXT_VECTOR); 865b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_FUNCTION_PROTO); 866b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_FUNCTION_NO_PROTO); 867b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_TYPEDEF); 868b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_TYPEOF_EXPR); 869b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_TYPEOF); 870b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_RECORD); 871b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_ENUM); 872b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(TYPE_OBJC_INTERFACE); 873a53d2cbe37e4be0d95b9d3e09f74eafae31fc940John McCall RECORD(TYPE_OBJC_OBJECT); 874d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff RECORD(TYPE_OBJC_OBJECT_POINTER); 875b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DECLTYPE); 876b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_ELABORATED); 877b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); 878b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_UNRESOLVED_USING); 879b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_INJECTED_CLASS_NAME); 880b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_OBJC_OBJECT); 881b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_TEMPLATE_TYPE_PARM); 882b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_TEMPLATE_SPECIALIZATION); 883b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DEPENDENT_NAME); 884b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); 885b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_DEPENDENT_SIZED_ARRAY); 886b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_PAREN); 887b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_PACK_EXPANSION); 888b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_ATTRIBUTED); 889b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); 890b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman RECORD(TYPE_ATOMIC); 8910ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_TYPEDEF); 8920ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_ENUM); 8930ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_RECORD); 8940ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_ENUM_CONSTANT); 8950ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_FUNCTION); 8960ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_METHOD); 8970ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_INTERFACE); 8980ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_PROTOCOL); 8990ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_IVAR); 9000ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_AT_DEFS_FIELD); 9010ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_CATEGORY); 9020ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_CATEGORY_IMPL); 9030ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_IMPLEMENTATION); 9040ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_COMPATIBLE_ALIAS); 9050ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_PROPERTY); 9060ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_OBJC_PROPERTY_IMPL); 907b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_FIELD); 908b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_VAR); 9090ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_IMPLICIT_PARAM); 910b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner RECORD(DECL_PARM_VAR); 9110ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_FILE_SCOPE_ASM); 9120ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_BLOCK); 9130ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_CONTEXT_LEXICAL); 9140ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner RECORD(DECL_CONTEXT_VISIBLE); 915b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_NAMESPACE); 916b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_NAMESPACE_ALIAS); 917b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_USING); 918b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_USING_SHADOW); 919b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_USING_DIRECTIVE); 920b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UNRESOLVED_USING_VALUE); 921b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_UNRESOLVED_USING_TYPENAME); 922b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_LINKAGE_SPEC); 923b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_RECORD); 924b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_METHOD); 925b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_CONSTRUCTOR); 926b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_DESTRUCTOR); 927b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_CONVERSION); 928b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_ACCESS_SPEC); 929b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_FRIEND); 930b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_FRIEND_TEMPLATE); 931b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CLASS_TEMPLATE); 932b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); 933b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); 934b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_FUNCTION_TEMPLATE); 935b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_TEMPLATE_TYPE_PARM); 936b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_NON_TYPE_TEMPLATE_PARM); 937b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_TEMPLATE_TEMPLATE_PARM); 938b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_STATIC_ASSERT); 939b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_CXX_BASE_SPECIFIERS); 940b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_INDIRECTFIELD); 941b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); 942b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor 943a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor // Statements and Exprs can occur in the Decls and Types block. 944a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor AddStmtsExprs(Stream, Record); 945a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor 9464800a5c79023271408af49797e09be32aca93232Douglas Gregor BLOCK(PREPROCESSOR_DETAIL_BLOCK); 947f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth RECORD(PPD_MACRO_EXPANSION); 9484800a5c79023271408af49797e09be32aca93232Douglas Gregor RECORD(PPD_MACRO_DEFINITION); 9494800a5c79023271408af49797e09be32aca93232Douglas Gregor RECORD(PPD_INCLUSION_DIRECTIVE); 9504800a5c79023271408af49797e09be32aca93232Douglas Gregor 951b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner#undef RECORD 952b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner#undef BLOCK 953b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner Stream.ExitBlock(); 954b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner} 955b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 956e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \brief Adjusts the given filename to only write out the portion of the 957e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// filename that is not part of the system root directory. 9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 959e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \param Filename the file name to adjust. 960e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// 961e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and 962e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// the returned filename will be adjusted by this system root. 963e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// 964e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \returns either the original filename (if it needs no adjustment) or the 965e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// adjusted filename (which points into the @p Filename parameter). 9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpstatic const char * 967832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas GregoradjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) { 968e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor assert(Filename && "No file name to adjust?"); 9691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 970832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor if (isysroot.empty()) 971e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename; 9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 973e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // Verify that the filename and the system root have the same prefix. 974e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor unsigned Pos = 0; 975832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor for (; Filename[Pos] && Pos < isysroot.size(); ++Pos) 976e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (Filename[Pos] != isysroot[Pos]) 977e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename; // Prefixes don't match. 9781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 979e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // We hit the end of the filename before we hit the end of the system root. 980e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (!Filename[Pos]) 981e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename; 9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 983e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // If the file name has a '/' at the current position, skip over the '/'. 984e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // We distinguish sysroot-based includes from absolute includes by the 985e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // absence of '/' at the beginning of sysroot-based includes. 986e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor if (Filename[Pos] == '/') 987e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor ++Pos; 9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 989e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor return Filename + Pos; 990e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor} 991b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner 9921d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor/// \brief Write the control block. 993bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregorvoid ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, 994bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor StringRef isysroot, 9951d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor const std::string &OutputFile) { 9962bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor using namespace llvm; 9977ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); 9987ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor RecordData Record; 9991d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor 1000e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor // Metadata 10017ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor BitCodeAbbrev *MetadataAbbrev = new BitCodeAbbrev(); 10027ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); 10037ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major 10047ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor 10057ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. 10067ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. 10077ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable 10087ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors 10097ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag 10107ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev); 10117ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor Record.push_back(METADATA); 10128538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(VERSION_MAJOR); 10138538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(VERSION_MINOR); 1014e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Record.push_back(CLANG_VERSION_MAJOR); 1015e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor Record.push_back(CLANG_VERSION_MINOR); 1016832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor Record.push_back(!isysroot.empty()); 1017bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis Record.push_back(ASTHasCompilerErrors); 10187ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, 10197ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor getClangFullRepositoryVersion()); 1020e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor 10211d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor // Imports 1022e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor if (Chain) { 1023e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor serialization::ModuleManager &Mgr = Chain->getModuleManager(); 1024e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor llvm::SmallVector<char, 128> ModulePaths; 1025e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor Record.clear(); 102610bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor 102710bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor for (ModuleManager::ModuleIterator M = Mgr.begin(), MEnd = Mgr.end(); 102810bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor M != MEnd; ++M) { 102910bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor // Skip modules that weren't directly imported. 103010bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor if (!(*M)->isDirectlyImported()) 103110bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor continue; 103210bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor 103310bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor Record.push_back((unsigned)(*M)->Kind); // FIXME: Stable encoding 1034958bcaf3d4e0c1ae46de3e84e7c2a7638c3c5286Argyrios Kyrtzidis AddSourceLocation((*M)->ImportLoc, Record); 103510bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor // FIXME: This writes the absolute path for AST files we depend on. 103610bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor const std::string &FileName = (*M)->FileName; 103710bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor Record.push_back(FileName.size()); 103810bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor Record.append(FileName.begin(), FileName.end()); 103910bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor } 1040e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor Stream.EmitRecord(IMPORTS, Record); 1041e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor } 10421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10431d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor // Language options. 10441d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor Record.clear(); 10451d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor const LangOptions &LangOpts = Context.getLangOpts(); 10461d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor#define LANGOPT(Name, Bits, Default, Description) \ 10471d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor Record.push_back(LangOpts.Name); 10481d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ 10491d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); 10501d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor#include "clang/Basic/LangOptions.def" 10511d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor 10521d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); 10531d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); 10541d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor 10551d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor Record.push_back(LangOpts.CurrentModule.size()); 10561d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor Record.append(LangOpts.CurrentModule.begin(), LangOpts.CurrentModule.end()); 10571d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor Stream.EmitRecord(LANGUAGE_OPTIONS, Record); 10581d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor 1059ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor // Target options. 1060ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor Record.clear(); 10617ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor const TargetInfo &Target = Context.getTargetInfo(); 10627ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor const TargetOptions &TargetOpts = Target.getTargetOpts(); 1063ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor AddString(TargetOpts.Triple, Record); 1064ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor AddString(TargetOpts.CPU, Record); 1065ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor AddString(TargetOpts.ABI, Record); 1066ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor AddString(TargetOpts.CXXABI, Record); 1067ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor AddString(TargetOpts.LinkerVersion, Record); 1068ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor Record.push_back(TargetOpts.FeaturesAsWritten.size()); 1069ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { 1070ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor AddString(TargetOpts.FeaturesAsWritten[I], Record); 1071ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor } 1072ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor Record.push_back(TargetOpts.Features.size()); 1073ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { 1074ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor AddString(TargetOpts.Features[I], Record); 1075ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor } 1076ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor Stream.EmitRecord(TARGET_OPTIONS, Record); 1077ee097c1a3f5e02605dd585c0a9bf22976f09ccc2Douglas Gregor 10785f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor // Diagnostic options. 10795f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor Record.clear(); 10805f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor const DiagnosticOptions &DiagOpts 10815f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor = Context.getDiagnostics().getDiagnosticOptions(); 10825f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor#define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); 10835f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor#define ENUM_DIAGOPT(Name, Type, Bits, Default) \ 10845f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); 10855f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor#include "clang/Basic/DiagnosticOptions.def" 10865f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor Record.push_back(DiagOpts.Warnings.size()); 10875f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) 10885f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor AddString(DiagOpts.Warnings[I], Record); 10895f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor // Note: we don't serialize the log or serialization file names, because they 10905f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor // are generally transient files and will almost always be overridden. 10915f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); 10925f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor 10931b2c3c0884e917ae5d59edde7d93b2af33c6a1b6Douglas Gregor // File system options. 10941b2c3c0884e917ae5d59edde7d93b2af33c6a1b6Douglas Gregor Record.clear(); 10951b2c3c0884e917ae5d59edde7d93b2af33c6a1b6Douglas Gregor const FileSystemOptions &FSOpts 10961b2c3c0884e917ae5d59edde7d93b2af33c6a1b6Douglas Gregor = Context.getSourceManager().getFileManager().getFileSystemOptions(); 10971b2c3c0884e917ae5d59edde7d93b2af33c6a1b6Douglas Gregor AddString(FSOpts.WorkingDir, Record); 10981b2c3c0884e917ae5d59edde7d93b2af33c6a1b6Douglas Gregor Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); 10991b2c3c0884e917ae5d59edde7d93b2af33c6a1b6Douglas Gregor 1100bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor // Header search options. 1101bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.clear(); 1102bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor const HeaderSearchOptions &HSOpts 1103bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor = PP.getHeaderSearchInfo().getHeaderSearchOpts(); 1104bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor AddString(HSOpts.Sysroot, Record); 1105bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor 1106bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor // Include entries. 1107bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(HSOpts.UserEntries.size()); 1108bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { 1109bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; 1110bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor AddString(Entry.Path, Record); 1111bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(static_cast<unsigned>(Entry.Group)); 1112bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(Entry.IsUserSupplied); 1113bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(Entry.IsFramework); 1114bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(Entry.IgnoreSysRoot); 1115bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(Entry.IsInternal); 1116bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(Entry.ImplicitExternC); 1117bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor } 1118bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor 1119bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor // System header prefixes. 1120bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(HSOpts.SystemHeaderPrefixes.size()); 1121bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { 1122bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); 1123bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); 1124bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor } 1125bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor 1126bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor AddString(HSOpts.ResourceDir, Record); 1127bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor AddString(HSOpts.ModuleCachePath, Record); 1128bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(HSOpts.DisableModuleHash); 1129bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(HSOpts.UseBuiltinIncludes); 1130bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(HSOpts.UseStandardSystemIncludes); 1131bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(HSOpts.UseStandardCXXIncludes); 1132bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Record.push_back(HSOpts.UseLibcxx); 1133bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); 1134bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor 1135a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor // Preprocessor options. 1136a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor Record.clear(); 1137a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); 1138a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor 1139a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor // Macro definitions. 1140a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor Record.push_back(PPOpts.Macros.size()); 1141a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { 1142a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor AddString(PPOpts.Macros[I].first, Record); 1143a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor Record.push_back(PPOpts.Macros[I].second); 1144a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor } 1145a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor 1146a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor // Includes 1147a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor Record.push_back(PPOpts.Includes.size()); 1148a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) 1149a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor AddString(PPOpts.Includes[I], Record); 1150a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor 1151a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor // Macro includes 1152a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor Record.push_back(PPOpts.MacroIncludes.size()); 1153a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) 1154a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor AddString(PPOpts.MacroIncludes[I], Record); 1155a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor 11564c0c7e86645dfa1719d17d70e009ab49347aba62Douglas Gregor Record.push_back(PPOpts.UsePredefines); 1157a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor AddString(PPOpts.ImplicitPCHInclude, Record); 1158a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor AddString(PPOpts.ImplicitPTHInclude, Record); 1159a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); 1160a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); 1161a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor 116231d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor // Original file name and file ID 1163b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor SourceManager &SM = Context.getSourceManager(); 1164b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { 1165b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); 116639c497b6d5e99acecbe03ee173249ee21933e855Douglas Gregor FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); 116739c497b6d5e99acecbe03ee173249ee21933e855Douglas Gregor FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID 1168b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name 1169b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); 1170b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor 1171f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<128> MainFilePath(MainFile->getName()); 11721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1173fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer llvm::sys::fs::make_absolute(MainFilePath); 1174b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor 1175aba54a95e9d5e4dc9056abec6bb70ea777c4a7bcKovarththanan Rajaratnam const char *MainFileNameStr = MainFilePath.c_str(); 11761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, 1177e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor isysroot); 1178a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor Record.clear(); 117939c497b6d5e99acecbe03ee173249ee21933e855Douglas Gregor Record.push_back(ORIGINAL_FILE); 118039c497b6d5e99acecbe03ee173249ee21933e855Douglas Gregor Record.push_back(SM.getMainFileID().getOpaqueValue()); 1181ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); 1182b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor } 118311a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 1184992d91742129c1f77563df0b3d0a40b36fd13e3eArgyrios Kyrtzidis Record.clear(); 1185992d91742129c1f77563df0b3d0a40b36fd13e3eArgyrios Kyrtzidis Record.push_back(SM.getMainFileID().getOpaqueValue()); 1186992d91742129c1f77563df0b3d0a40b36fd13e3eArgyrios Kyrtzidis Stream.EmitRecord(ORIGINAL_FILE_ID, Record); 1187992d91742129c1f77563df0b3d0a40b36fd13e3eArgyrios Kyrtzidis 11888e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis // Original PCH directory 11898e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis if (!OutputFile.empty() && OutputFile != "-") { 11908e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 11918e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); 11928e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name 11938e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); 11948e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 1195f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<128> OutputPath(OutputFile); 11968e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 11978e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis llvm::sys::fs::make_absolute(OutputPath); 11988e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis StringRef origDir = llvm::sys::path::parent_path(OutputPath); 11998e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 12008e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis RecordData Record; 12018e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Record.push_back(ORIGINAL_PCH_DIR); 12028e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); 12038e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis } 12048e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis 1205745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor WriteInputFiles(Context.SourceMgr, isysroot); 1206745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor Stream.ExitBlock(); 1207745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor} 1208745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1209745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregorvoid ASTWriter::WriteInputFiles(SourceManager &SourceMgr, StringRef isysroot) { 1210745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor using namespace llvm; 1211745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); 1212745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor RecordData Record; 1213745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1214745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // Create input-file abbreviation. 1215745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor BitCodeAbbrev *IFAbbrev = new BitCodeAbbrev(); 1216745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); 1217a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID 1218745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size 1219745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time 1220a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden 1221745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name 1222745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor unsigned IFAbbrevCode = Stream.EmitAbbrev(IFAbbrev); 1223745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1224745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // Write out all of the input files. 1225745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor std::vector<uint32_t> InputFileOffsets; 1226745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { 1227745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // Get this source location entry. 1228745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); 1229bacc2c543c2236c5add893fabd8ecb798c1cdd76NAKAMURA Takumi assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); 1230745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1231745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // We only care about file entries that were not overridden. 1232745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor if (!SLoc->isFile()) 1233745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor continue; 1234745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); 1235a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor if (!Cache->OrigEntry) 1236745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor continue; 1237745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1238a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor // Record this entry's offset. 1239a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor InputFileOffsets.push_back(Stream.GetCurrentBitNo()); 1240a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor InputFileIDs[Cache->OrigEntry] = InputFileOffsets.size(); 1241a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor 1242745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor Record.clear(); 1243745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor Record.push_back(INPUT_FILE); 1244a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor Record.push_back(InputFileOffsets.size()); 1245745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1246745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // Emit size/modification time for this file. 1247745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor Record.push_back(Cache->OrigEntry->getSize()); 1248745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor Record.push_back(Cache->OrigEntry->getModificationTime()); 1249745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1250a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor // Whether this file was overridden. 1251a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor Record.push_back(Cache->BufferOverridden); 1252a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor 1253745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // Turn the file name into an absolute path, if it isn't already. 1254745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor const char *Filename = Cache->OrigEntry->getName(); 1255745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor SmallString<128> FilePath(Filename); 1256745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1257745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // Ask the file manager to fixup the relative path for us. This will 1258745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // honor the working directory. 1259745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor SourceMgr.getFileManager().FixupRelativePath(FilePath); 1260745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1261745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // FIXME: This call to make_absolute shouldn't be necessary, the 1262745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor // call to FixupRelativePath should always return an absolute path. 1263745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor llvm::sys::fs::make_absolute(FilePath); 1264745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor Filename = FilePath.c_str(); 1265745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1266745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); 1267745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 1268745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor Stream.EmitRecordWithBlob(IFAbbrevCode, Record, Filename); 1269745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor } 1270745e6f168d0276c15fb72f3d90e3d93d60282b1bDouglas Gregor 12711d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor Stream.ExitBlock(); 1272a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor 1273a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor // Create input file offsets abbreviation. 1274a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor BitCodeAbbrev *OffsetsAbbrev = new BitCodeAbbrev(); 1275a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); 1276a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files 1277a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Array 1278a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(OffsetsAbbrev); 1279a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor 1280a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor // Write input file offsets. 1281a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor Record.clear(); 1282a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor Record.push_back(INPUT_FILE_OFFSETS); 1283a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor Record.push_back(InputFileOffsets.size()); 1284a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, data(InputFileOffsets)); 12850a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor} 12860a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor 128714f79002e58556798e86168c63e48d533287eda5Douglas Gregor//===----------------------------------------------------------------------===// 12884fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// stat cache Serialization 12894fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 12904fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 12914fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregornamespace { 12924fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Trait used for the on-disk hash table of stat cache results. 12933397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlclass ASTStatCacheTrait { 12944fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregorpublic: 12954fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor typedef const char * key_type; 12964fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor typedef key_type key_type_ref; 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 129874e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner typedef struct stat data_type; 129974e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner typedef const data_type &data_type_ref; 13004fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 13014fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor static unsigned ComputeHash(const char *path) { 13022596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar return llvm::HashString(path); 13034fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 13041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<unsigned,unsigned> 13065f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner EmitKeyDataLength(raw_ostream& Out, const char *path, 13074fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor data_type_ref Data) { 13084fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor unsigned StrLen = strlen(path); 13094fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor clang::io::Emit16(Out, StrLen); 131074e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner unsigned DataLen = 4 + 4 + 2 + 8 + 8; 13114fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor clang::io::Emit8(Out, DataLen); 13124fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor return std::make_pair(StrLen + 1, DataLen); 13134fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 13141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13155f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { 13164fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor Out.write(path, KeyLen); 13174fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13195f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void EmitData(raw_ostream &Out, key_type_ref, 13204fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor data_type_ref Data, unsigned DataLen) { 13214fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor using namespace clang::io; 13224fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor uint64_t Start = Out.tell(); (void)Start; 13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 132474e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit32(Out, (uint32_t) Data.st_ino); 132574e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit32(Out, (uint32_t) Data.st_dev); 132674e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit16(Out, (uint16_t) Data.st_mode); 132774e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit64(Out, (uint64_t) Data.st_mtime); 132874e976ba4b0d407bb798ea26476f618e256fc8c7Chris Lattner Emit64(Out, (uint64_t) Data.st_size); 13294fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 13304fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor assert(Out.tell() - Start == DataLen && "Wrong data length"); 13314fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor } 13324fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor}; 13334fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor} // end anonymous namespace 13344fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 13354fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 133614f79002e58556798e86168c63e48d533287eda5Douglas Gregor// Source Manager Serialization 133714f79002e58556798e86168c63e48d533287eda5Douglas Gregor//===----------------------------------------------------------------------===// 133814f79002e58556798e86168c63e48d533287eda5Douglas Gregor 133914f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to a 134014f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// file. 1341c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { 134214f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 134314f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 13448538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); 134514f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset 134614f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location 134714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic 134814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives 13492d52be56ff595341be3c6cec337af6763804ce66Douglas Gregor // FileEntry fields. 1350a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID 1351d9d2b679d0728ea7f539f38aaea38e26b8b08043Argyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs 135210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex 135310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls 1354c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 135514f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 135614f79002e58556798e86168c63e48d533287eda5Douglas Gregor 135714f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to a 135814f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// buffer. 1359c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { 136014f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 136114f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 13628538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); 136314f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset 136414f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location 136514f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic 136614f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives 136714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob 1368c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 136914f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 137014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 137114f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Create an abbreviation for the SLocEntry that refers to a 137214f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// buffer's blob. 1373c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregorstatic unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { 137414f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 137514f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 13768538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_BLOB)); 137714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob 1378c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 137914f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 138014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 1381f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth/// \brief Create an abbreviation for the SLocEntry that refers to a macro 1382f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth/// expansion. 1383f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruthstatic unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { 138414f79002e58556798e86168c63e48d533287eda5Douglas Gregor using namespace llvm; 138514f79002e58556798e86168c63e48d533287eda5Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 1386f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); 138714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset 138814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location 138914f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location 139014f79002e58556798e86168c63e48d533287eda5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location 1391f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length 1392c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor return Stream.EmitAbbrev(Abbrev); 139314f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 139414f79002e58556798e86168c63e48d533287eda5Douglas Gregor 1395cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregornamespace { 1396cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Trait used for the on-disk hash table of header search information. 1397cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor class HeaderFileInfoTrait { 1398cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ASTWriter &Writer; 1399cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1400b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor // Keep track of the framework names we've used during serialization. 1401b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor SmallVector<char, 128> FrameworkStringData; 1402b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor llvm::StringMap<unsigned> FrameworkNameOffset; 1403b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor 1404cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor public: 1405facde171ae4b8926622a1bffa833732a06f1875bBenjamin Kramer HeaderFileInfoTrait(ASTWriter &Writer) 1406facde171ae4b8926622a1bffa833732a06f1875bBenjamin Kramer : Writer(Writer) { } 1407cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1408cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef const char *key_type; 1409cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef key_type key_type_ref; 1410cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1411cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef HeaderFileInfo data_type; 1412cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor typedef const data_type &data_type_ref; 1413cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1414cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor static unsigned ComputeHash(const char *path) { 1415cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // The hash is based only on the filename portion of the key, so that the 1416cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // reader can match based on filenames when symlinking or excess path 1417cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // elements ("foo/../", "../") change the form of the name. However, 1418cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // complete path is still the key. 1419cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor return llvm::HashString(llvm::sys::path::filename(path)); 1420cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1421cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1422cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor std::pair<unsigned,unsigned> 14235f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner EmitKeyDataLength(raw_ostream& Out, const char *path, 1424cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor data_type_ref Data) { 1425cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned StrLen = strlen(path); 1426cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor clang::io::Emit16(Out, StrLen); 1427b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor unsigned DataLen = 1 + 2 + 4 + 4; 1428cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor clang::io::Emit8(Out, DataLen); 1429cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor return std::make_pair(StrLen + 1, DataLen); 1430cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1431cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 14325f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void EmitKey(raw_ostream& Out, const char *path, unsigned KeyLen) { 1433cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Out.write(path, KeyLen); 1434cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1435cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 14365f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void EmitData(raw_ostream &Out, key_type_ref, 1437cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor data_type_ref Data, unsigned DataLen) { 1438cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor using namespace clang::io; 1439cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor uint64_t Start = Out.tell(); (void)Start; 1440cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1441b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor unsigned char Flags = (Data.isImport << 5) 1442b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor | (Data.isPragmaOnce << 4) 1443b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor | (Data.DirInfo << 2) 1444b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor | (Data.Resolved << 1) 1445b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor | Data.IndexHeaderMapHeader; 1446cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit8(Out, (uint8_t)Flags); 1447cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit16(Out, (uint16_t) Data.NumIncludes); 1448cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1449cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (!Data.ControllingMacro) 1450cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit32(Out, (uint32_t)Data.ControllingMacroID); 1451cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor else 1452cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Emit32(Out, (uint32_t)Writer.getIdentifierRef(Data.ControllingMacro)); 1453b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor 1454b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor unsigned Offset = 0; 1455b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor if (!Data.Framework.empty()) { 1456b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor // If this header refers into a framework, save the framework name. 1457b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor llvm::StringMap<unsigned>::iterator Pos 1458b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor = FrameworkNameOffset.find(Data.Framework); 1459b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor if (Pos == FrameworkNameOffset.end()) { 1460b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor Offset = FrameworkStringData.size() + 1; 1461b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor FrameworkStringData.append(Data.Framework.begin(), 1462b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor Data.Framework.end()); 1463b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor FrameworkStringData.push_back(0); 1464b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor 1465b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor FrameworkNameOffset[Data.Framework] = Offset; 1466b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor } else 1467b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor Offset = Pos->second; 1468b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor } 1469b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor Emit32(Out, Offset); 1470b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor 1471cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor assert(Out.tell() - Start == DataLen && "Wrong data length"); 1472cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1473b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor 1474b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor const char *strings_begin() const { return FrameworkStringData.begin(); } 1475b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor const char *strings_end() const { return FrameworkStringData.end(); } 1476cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor }; 1477cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor} // end anonymous namespace 1478cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1479cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \brief Write the header search block for the list of files that 1480cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// 1481cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor/// \param HS The header search structure to save. 1482590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidisvoid ASTWriter::WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot) { 14835f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<const FileEntry *, 16> FilesByUID; 1484cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor HS.getFileMgr().GetUniqueIDMapping(FilesByUID); 1485cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1486cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (FilesByUID.size() > HS.header_file_size()) 1487cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor FilesByUID.resize(HS.header_file_size()); 1488cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1489facde171ae4b8926622a1bffa833732a06f1875bBenjamin Kramer HeaderFileInfoTrait GeneratorTrait(*this); 1490cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; 14915f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<const char *, 4> SavedStrings; 1492cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned NumHeaderSearchEntries = 0; 1493cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { 1494cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor const FileEntry *File = FilesByUID[UID]; 1495cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (!File) 1496cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor continue; 1497cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1498590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis // Use HeaderSearch's getFileInfo to make sure we get the HeaderFileInfo 1499590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis // from the external source if it was not provided already. 1500590ad93bf59f4e5f6adcba0d78efc3a58cac15ceArgyrios Kyrtzidis const HeaderFileInfo &HFI = HS.getFileInfo(File); 1501cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (HFI.External && Chain) 1502cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor continue; 1503cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1504cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Turn the file name into an absolute path, if it isn't already. 1505cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor const char *Filename = File->getName(); 1506cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); 1507cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1508cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // If we performed any translation on the file name at all, we need to 1509cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // save this string, since the generator will refer to it later. 1510cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor if (Filename != File->getName()) { 1511cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Filename = strdup(Filename); 1512cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor SavedStrings.push_back(Filename); 1513cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1514cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1515cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Generator.insert(Filename, HFI, GeneratorTrait); 1516cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor ++NumHeaderSearchEntries; 1517cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1518cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1519cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Create the on-disk hash table in a buffer. 1520f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<4096> TableData; 1521cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor uint32_t BucketOffset; 1522cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor { 1523cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor llvm::raw_svector_ostream Out(TableData); 1524cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Make sure that no bucket is at offset 0 1525cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor clang::io::Emit32(Out, 0); 1526cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor BucketOffset = Generator.Emit(Out, GeneratorTrait); 1527cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor } 1528cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1529cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Create a blob abbreviation 1530cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor using namespace llvm; 1531cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 1532cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); 1533cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 1534cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 1535b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 1536cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 1537cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor unsigned TableAbbrev = Stream.EmitAbbrev(Abbrev); 1538cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1539b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor // Write the header search table 1540cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor RecordData Record; 1541cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Record.push_back(HEADER_SEARCH_TABLE); 1542cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Record.push_back(BucketOffset); 1543cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Record.push_back(NumHeaderSearchEntries); 1544b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor Record.push_back(TableData.size()); 1545b4dc485a2b38ea98ba7da01596fd0e8438120346Douglas Gregor TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); 1546cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData.str()); 1547cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 1548cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor // Free all of the strings we had to duplicate. 1549cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) 1550cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor free((void*)SavedStrings[I]); 1551cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor} 1552cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor 155314f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// \brief Writes the block containing the serialized form of the 155414f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// source manager. 155514f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// 155614f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// TODO: We should probably use an on-disk hash table (stored in a 155714f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// blob), indexed based on the file name, so that we only create 155814f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// entries for files that we actually need. In the common case (no 155914f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// errors), we probably won't have to create file entries for any of 156014f79002e58556798e86168c63e48d533287eda5Douglas Gregor/// the files in the AST. 1561a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, 1562e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor const Preprocessor &PP, 1563832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor StringRef isysroot) { 15647f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RecordData Record; 15657f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 1566f04ad69fed38d26fc0d6f7d6fd0a4631ddfbc7feChris Lattner // Enter the source manager block. 15678538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 3); 156814f79002e58556798e86168c63e48d533287eda5Douglas Gregor 156914f79002e58556798e86168c63e48d533287eda5Douglas Gregor // Abbreviations for the various kinds of source-location entries. 1570828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); 1571828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); 1572828e18cd80319c67b9b9776d1ed5411161d9f0bfChris Lattner unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); 1573f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); 15747f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 157514f79002e58556798e86168c63e48d533287eda5Douglas Gregor // Write out the source location entry table. We skip the first 157614f79002e58556798e86168c63e48d533287eda5Douglas Gregor // entry, which is always the same dummy entry. 1577090d9b53e32bb30d9e74de895bb59b409bd49e00Chris Lattner std::vector<uint32_t> SLocEntryOffsets; 15787f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor RecordData PreloadSLocs; 1579f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); 1580f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); 15810fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl I != N; ++I) { 1582bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor // Get this source location entry. 1583f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); 1584a2ea4d94f2133aad0d864cf1327af142a47ffb09Argyrios Kyrtzidis FileID FID = FileID::get(I); 1585a2ea4d94f2133aad0d864cf1327af142a47ffb09Argyrios Kyrtzidis assert(&SourceMgr.getSLocEntry(FID) == SLoc); 158611a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 15877f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // Record the offset of this source-location entry. 15887f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); 15897f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 159014f79002e58556798e86168c63e48d533287eda5Douglas Gregor // Figure out which record code to use. 159114f79002e58556798e86168c63e48d533287eda5Douglas Gregor unsigned Code; 159214f79002e58556798e86168c63e48d533287eda5Douglas Gregor if (SLoc->isFile()) { 1593a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); 1594a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor if (Cache->OrigEntry) { 15958538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = SM_SLOC_FILE_ENTRY; 15964cdb0e2a2e9d93805e5ceaf8bc7018bdd166aec1Argyrios Kyrtzidis } else 15978538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Code = SM_SLOC_BUFFER_ENTRY; 159814f79002e58556798e86168c63e48d533287eda5Douglas Gregor } else 1599f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth Code = SM_SLOC_EXPANSION_ENTRY; 16007f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.clear(); 160114f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(Code); 160214f79002e58556798e86168c63e48d533287eda5Douglas Gregor 1603f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor // Starting offset of this entry within this module, so skip the dummy. 1604f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back(SLoc->getOffset() - 2); 160514f79002e58556798e86168c63e48d533287eda5Douglas Gregor if (SLoc->isFile()) { 160614f79002e58556798e86168c63e48d533287eda5Douglas Gregor const SrcMgr::FileInfo &File = SLoc->getFile(); 160714f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(File.getIncludeLoc().getRawEncoding()); 160814f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding 1609bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor Record.push_back(File.hasLineDirectives()); 161014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 161114f79002e58556798e86168c63e48d533287eda5Douglas Gregor const SrcMgr::ContentCache *Content = File.getContentCache(); 1612b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis if (Content->OrigEntry) { 1613b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis assert(Content->OrigEntry == Content->ContentsEntry && 1614a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor "Writing to AST an overridden file is not supported"); 1615b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis 1616a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor // The source location entry is a file. Emit input file ID. 1617a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); 1618a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor Record.push_back(InputFileIDs[Content->OrigEntry]); 16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1620d9d2b679d0728ea7f539f38aaea38e26b8b08043Argyrios Kyrtzidis Record.push_back(File.NumCreatedFIDs); 162110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 1622a2ea4d94f2133aad0d864cf1327af142a47ffb09Argyrios Kyrtzidis FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); 162310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis if (FDI != FileDeclIDs.end()) { 162410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Record.push_back(FDI->second->FirstDeclIndex); 162510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Record.push_back(FDI->second->DeclIDs.size()); 162610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis } else { 162710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Record.push_back(0); 162810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Record.push_back(0); 162910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis } 1630a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor 1631a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); 1632a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor 1633a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor if (Content->BufferOverridden) { 1634a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor Record.clear(); 1635a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor Record.push_back(SM_SLOC_BUFFER_BLOB); 1636a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor const llvm::MemoryBuffer *Buffer 1637a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); 1638a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, 1639a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor StringRef(Buffer->getBufferStart(), 1640a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor Buffer->getBufferSize() + 1)); 1641a081da5e44600d02983d6562bed1b4fd61e410fdDouglas Gregor } 164214f79002e58556798e86168c63e48d533287eda5Douglas Gregor } else { 164314f79002e58556798e86168c63e48d533287eda5Douglas Gregor // The source location entry is a buffer. The blob associated 164414f79002e58556798e86168c63e48d533287eda5Douglas Gregor // with this entry contains the contents of the buffer. 164514f79002e58556798e86168c63e48d533287eda5Douglas Gregor 164614f79002e58556798e86168c63e48d533287eda5Douglas Gregor // We add one to the size so that we capture the trailing NULL 164714f79002e58556798e86168c63e48d533287eda5Douglas Gregor // that is required by llvm::MemoryBuffer::getMemBuffer (on 164814f79002e58556798e86168c63e48d533287eda5Douglas Gregor // the reader side). 164936c35ba0aca641e60e5dbee8efbc620c08b9bd61Douglas Gregor const llvm::MemoryBuffer *Buffer 1650e127a0d80155b45dafe77f2b4380e5fa111a3345Chris Lattner = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); 165114f79002e58556798e86168c63e48d533287eda5Douglas Gregor const char *Name = Buffer->getBufferIdentifier(); 1652ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, 16535f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef(Name, strlen(Name) + 1)); 165414f79002e58556798e86168c63e48d533287eda5Douglas Gregor Record.clear(); 16558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(SM_SLOC_BUFFER_BLOB); 1656c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, 16575f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef(Buffer->getBufferStart(), 1658ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Buffer->getBufferSize() + 1)); 16597f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 1660f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor if (strcmp(Name, "<built-in>") == 0) { 1661f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor PreloadSLocs.push_back(SLocEntryOffsets.size()); 1662f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor } 166314f79002e58556798e86168c63e48d533287eda5Douglas Gregor } 166414f79002e58556798e86168c63e48d533287eda5Douglas Gregor } else { 1665f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth // The source location entry is a macro expansion. 16661728762d5a8cfaf8d64385f47b311e84de1ae7a2Chandler Carruth const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); 166778df836808aee22c3157e1bc23bc4ec569b80568Chandler Carruth Record.push_back(Expansion.getSpellingLoc().getRawEncoding()); 166878df836808aee22c3157e1bc23bc4ec569b80568Chandler Carruth Record.push_back(Expansion.getExpansionLocStart().getRawEncoding()); 1669d21683cdc0ff4217bfd98a9d8d0c1083b642caacArgyrios Kyrtzidis Record.push_back(Expansion.isMacroArgExpansion() ? 0 1670d21683cdc0ff4217bfd98a9d8d0c1083b642caacArgyrios Kyrtzidis : Expansion.getExpansionLocEnd().getRawEncoding()); 167114f79002e58556798e86168c63e48d533287eda5Douglas Gregor 1672f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor // Compute the token length for this macro expansion. 1673f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor unsigned NextOffset = SourceMgr.getNextLocalOffset(); 1674bdfe48ac80573e026595af91e541474dbf02565fDouglas Gregor if (I + 1 != N) 1675f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); 1676f60e9918690fcf02974bc1ebecd42c99d561855eDouglas Gregor Record.push_back(NextOffset - SLoc->getOffset() - 1); 1677f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); 167814f79002e58556798e86168c63e48d533287eda5Douglas Gregor } 167914f79002e58556798e86168c63e48d533287eda5Douglas Gregor } 168014f79002e58556798e86168c63e48d533287eda5Douglas Gregor 16817f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Stream.ExitBlock(); 1682bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor 16837f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor if (SLocEntryOffsets.empty()) 16847f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor return; 16852eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor 16863397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Write the source-location offsets table into the AST block. This 16877f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // table is used for lazily loading source-location information. 16887f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor using namespace llvm; 16897f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 16908538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); 16917f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs 1692f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size 16937f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets 16947f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); 16951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16967f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.clear(); 16978538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(SOURCE_LOCATION_OFFSETS); 16987f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor Record.push_back(SLocEntryOffsets.size()); 1699f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back(SourceMgr.getNextLocalOffset() - 1); // skip dummy 17006e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, data(SLocEntryOffsets)); 17017f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor 17023397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Write the source location entry preloads array, telling the AST 17037f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor // reader which source locations entries it should load eagerly. 17048538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); 1705f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 1706f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor // Write the line table. It depends on remapping working, so it must come 1707f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor // after the source location offsets. 1708f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor if (SourceMgr.hasLineTable()) { 1709f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor LineTableInfo &LineTable = SourceMgr.getLineTable(); 1710f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 1711f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.clear(); 1712f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor // Emit the file names 1713f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back(LineTable.getNumFilenames()); 1714f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { 1715f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor // Emit the file name 1716f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor const char *Filename = LineTable.getFilename(I); 1717f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); 1718f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor unsigned FilenameLen = Filename? strlen(Filename) : 0; 1719f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back(FilenameLen); 1720f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor if (FilenameLen) 1721f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.insert(Record.end(), Filename, Filename + FilenameLen); 1722f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor } 1723f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 1724f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor // Emit the line entries 1725f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); 1726f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor L != LEnd; ++L) { 1727f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor // Only emit entries for local files. 172847d9de678162202786aa5f8aa153a7c58a4cebd4Douglas Gregor if (L->first.ID < 0) 1729f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor continue; 1730f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 1731f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor // Emit the file ID 173247d9de678162202786aa5f8aa153a7c58a4cebd4Douglas Gregor Record.push_back(L->first.ID); 1733f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 1734f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor // Emit the line entries 1735f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back(L->second.size()); 1736f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor for (std::vector<LineEntry>::iterator LE = L->second.begin(), 1737f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor LEEnd = L->second.end(); 1738f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor LE != LEEnd; ++LE) { 1739f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back(LE->FileOffset); 1740f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back(LE->LineNo); 1741f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back(LE->FilenameID); 1742f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back((unsigned)LE->FileKind); 1743f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Record.push_back(LE->IncludeOffset); 1744f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor } 1745f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor } 1746f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); 1747f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor } 174814f79002e58556798e86168c63e48d533287eda5Douglas Gregor} 174914f79002e58556798e86168c63e48d533287eda5Douglas Gregor 17504fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 17514fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Preprocessor Serialization 17524fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 17534fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 17549c7361006b8cd95333958150dd0c803261807b68Douglas Gregorstatic int compareMacroDefinitions(const void *XPtr, const void *YPtr) { 17559c7361006b8cd95333958150dd0c803261807b68Douglas Gregor const std::pair<const IdentifierInfo *, MacroInfo *> &X = 17569c7361006b8cd95333958150dd0c803261807b68Douglas Gregor *(const std::pair<const IdentifierInfo *, MacroInfo *>*)XPtr; 17579c7361006b8cd95333958150dd0c803261807b68Douglas Gregor const std::pair<const IdentifierInfo *, MacroInfo *> &Y = 17589c7361006b8cd95333958150dd0c803261807b68Douglas Gregor *(const std::pair<const IdentifierInfo *, MacroInfo *>*)YPtr; 17599c7361006b8cd95333958150dd0c803261807b68Douglas Gregor return X.first->getName().compare(Y.first->getName()); 17609c7361006b8cd95333958150dd0c803261807b68Douglas Gregor} 17619c7361006b8cd95333958150dd0c803261807b68Douglas Gregor 17620b1fb988012da21d996c43e36867787a7a07b889Chris Lattner/// \brief Writes the block containing the serialized form of the 17630b1fb988012da21d996c43e36867787a7a07b889Chris Lattner/// preprocessor. 17640b1fb988012da21d996c43e36867787a7a07b889Chris Lattner/// 17657143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregorvoid ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { 1766e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); 1767e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis if (PPRec) 1768e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis WritePreprocessorDetail(*PPRec); 1769e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis 17707c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner RecordData Record; 17717c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner 1772c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner // If the preprocessor __COUNTER__ value has been bumped, remember it. 1773c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner if (PP.getCounterValue() != 0) { 1774c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner Record.push_back(PP.getCounterValue()); 17758538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(PP_COUNTER_VALUE, Record); 1776c1f9d828c733ec1eba06d01070735d1f36fda733Chris Lattner Record.clear(); 17772eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor } 17782eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor 17792eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor // Enter the preprocessor block. 1780ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); 17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17823397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // If the AST file contains __DATE__ or __TIME__ emit a warning about this. 17832eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor // FIXME: use diagnostics subsystem for localization etc. 17842eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor if (PP.SawDateOrTime()) 17852eafc1b56347f772729e082e6bac824b0ef1b585Douglas Gregor fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); 17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1787ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor 17887c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner // Loop over all the macro definitions that are live at the end of the file, 17897c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner // emitting each to the PP section. 179020249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 17919c7361006b8cd95333958150dd0c803261807b68Douglas Gregor // Construct the list of macro definitions that need to be serialized. 17925f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> 17939c7361006b8cd95333958150dd0c803261807b68Douglas Gregor MacrosToEmit; 17949c7361006b8cd95333958150dd0c803261807b68Douglas Gregor llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; 17954d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), 1796040a804f852c45c8b8c371ce1d421fd4cd84b6fbDouglas Gregor E = PP.macro_end(Chain == 0); 17977c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner I != E; ++I) { 17984d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko if (!IsModule || I->second->isPublic()) { 17994d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko MacroDefinitionsSeen.insert(I->first); 18004d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko MacrosToEmit.push_back(std::make_pair(I->first, I->second)); 18017143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor } 18029c7361006b8cd95333958150dd0c803261807b68Douglas Gregor } 18034d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 18049c7361006b8cd95333958150dd0c803261807b68Douglas Gregor // Sort the set of macro definitions that need to be serialized by the 18059c7361006b8cd95333958150dd0c803261807b68Douglas Gregor // name of the macro, to provide a stable ordering. 18064d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(), 18079c7361006b8cd95333958150dd0c803261807b68Douglas Gregor &compareMacroDefinitions); 18084d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 1809a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor /// \brief Offsets of each of the macros into the bitstream, indexed by 1810a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor /// the local macro ID 1811a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor /// 1812a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor /// For each identifier that is associated with a macro, this map 1813a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor /// provides the offset into the bitstream where that macro is 1814a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor /// defined. 1815a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor std::vector<uint32_t> MacroOffsets; 1816a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 18179c7361006b8cd95333958150dd0c803261807b68Douglas Gregor for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { 18189c7361006b8cd95333958150dd0c803261807b68Douglas Gregor const IdentifierInfo *Name = MacrosToEmit[I].first; 18197c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner 1820a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor for (MacroInfo *MI = MacrosToEmit[I].second; MI; 1821a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor MI = MI->getPreviousDefinition()) { 1822a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor MacroID ID = getMacroRef(MI); 1823a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor if (!ID) 1824a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor continue; 1825a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 1826a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor // Skip macros from a AST file if we're chaining. 1827a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor if (Chain && MI->isFromAST() && !MI->hasChangedAfterLoad()) 1828a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor continue; 182920249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 1830a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor if (ID < FirstMacroID) { 1831a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor // This will have been dealt with via an update record. 1832a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor assert(MacroUpdates.count(MI) > 0 && "Missing macro update"); 18334d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko continue; 1834a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor } 1835a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 1836a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor // Record the local offset of this macro. 1837a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor unsigned Index = ID - FirstMacroID; 1838a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor if (Index == MacroOffsets.size()) 1839a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor MacroOffsets.push_back(Stream.GetCurrentBitNo()); 1840a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor else { 1841a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor if (Index > MacroOffsets.size()) 1842a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor MacroOffsets.resize(Index + 1); 1843a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 1844a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor MacroOffsets[Index] = Stream.GetCurrentBitNo(); 1845a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor } 184620249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 18474d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko AddIdentifierRef(Name, Record); 1848a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor addMacroRef(MI, Record); 18496c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); 18504d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko AddSourceLocation(MI->getDefinitionLoc(), Record); 18514d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko AddSourceLocation(MI->getUndefLoc(), Record); 18524d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(MI->isUsed()); 18534d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(MI->isPublic()); 18544d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko AddSourceLocation(MI->getVisibilityLocation(), Record); 18554d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko unsigned Code; 18564d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko if (MI->isObjectLike()) { 18574d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Code = PP_MACRO_OBJECT_LIKE; 18584d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko } else { 18594d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Code = PP_MACRO_FUNCTION_LIKE; 18604d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 18614d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(MI->isC99Varargs()); 18624d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(MI->isGNUVarargs()); 18634fa4b480270c14dfdcd0dfd4f76938e973082e3bEli Friedman Record.push_back(MI->hasCommaPasting()); 18644d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(MI->getNumArgs()); 18654d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); 18664d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko I != E; ++I) 18674d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko AddIdentifierRef(*I, Record); 18684d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko } 1869f04ad69fed38d26fc0d6f7d6fd0a4631ddfbc7feChris Lattner 18704d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // If we have a detailed preprocessing record, record the macro definition 18714d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // ID that corresponds to this macro. 18724d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko if (PPRec) 18734d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); 18744d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 18754d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Stream.EmitRecord(Code, Record); 1876df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner Record.clear(); 18774d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 18784d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // Emit the tokens array. 18794d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { 18804d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // Note that we know that the preprocessor does not have any annotation 18814d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // tokens in it because they are created by the parser, and thus can't 18824d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // be in a macro definition. 18834d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko const Token &Tok = MI->getReplacementToken(TokNo); 18844d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 18854d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(Tok.getLocation().getRawEncoding()); 18864d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(Tok.getLength()); 18874d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 18884d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // FIXME: When reading literal tokens, reconstruct the literal pointer 18894d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // if it is needed. 18904d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko AddIdentifierRef(Tok.getIdentifierInfo(), Record); 18914d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // FIXME: Should translate token kind to a stable encoding. 18924d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(Tok.getKind()); 18934d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko // FIXME: Should translate token flags to a stable encoding. 18944d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.push_back(Tok.getFlags()); 18954d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 18964d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Stream.EmitRecord(PP_TOKEN, Record); 18974d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Record.clear(); 18984d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko } 18994d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko ++NumMacros; 1900df961c28f84666051ad59d2da1f44023f6366d02Chris Lattner } 19017c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner } 19024800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.ExitBlock(); 1903a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 1904a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor // Write the offsets table for macro IDs. 1905a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor using namespace llvm; 1906a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 1907a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); 1908a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros 1909a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID 1910a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 1911a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 1912a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 1913a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Record.clear(); 1914a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Record.push_back(MACRO_OFFSET); 1915a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Record.push_back(MacroOffsets.size()); 1916a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Record.push_back(FirstMacroID - NUM_PREDEF_MACRO_IDS); 1917a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, 1918a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor data(MacroOffsets)); 19194800a5c79023271408af49797e09be32aca93232Douglas Gregor} 19204800a5c79023271408af49797e09be32aca93232Douglas Gregor 19214800a5c79023271408af49797e09be32aca93232Douglas Gregorvoid ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { 1922b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis if (PPRec.local_begin() == PPRec.local_end()) 19234800a5c79023271408af49797e09be32aca93232Douglas Gregor return; 1924e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis 19252dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; 1926e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis 19274800a5c79023271408af49797e09be32aca93232Douglas Gregor // Enter the preprocessor block. 19284800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); 192920249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 19306a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // If the preprocessor has a preprocessing record, emit it. 19316a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor unsigned NumPreprocessingRecords = 0; 19324800a5c79023271408af49797e09be32aca93232Douglas Gregor using namespace llvm; 19334800a5c79023271408af49797e09be32aca93232Douglas Gregor 19344800a5c79023271408af49797e09be32aca93232Douglas Gregor // Set up the abbreviation for 19354800a5c79023271408af49797e09be32aca93232Douglas Gregor unsigned InclusionAbbrev = 0; 19364800a5c79023271408af49797e09be32aca93232Douglas Gregor { 19374800a5c79023271408af49797e09be32aca93232Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 19384800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); 19394800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length 19404800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes 19414800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind 19428dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module 19434800a5c79023271408af49797e09be32aca93232Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 19444800a5c79023271408af49797e09be32aca93232Douglas Gregor InclusionAbbrev = Stream.EmitAbbrev(Abbrev); 19454800a5c79023271408af49797e09be32aca93232Douglas Gregor } 19464800a5c79023271408af49797e09be32aca93232Douglas Gregor 1947272b6bc6a6c8fc04f951ad850df68c44d137f513Douglas Gregor unsigned FirstPreprocessorEntityID 1948272b6bc6a6c8fc04f951ad850df68c44d137f513Douglas Gregor = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) 1949272b6bc6a6c8fc04f951ad850df68c44d137f513Douglas Gregor + NUM_PREDEF_PP_ENTITY_IDS; 1950272b6bc6a6c8fc04f951ad850df68c44d137f513Douglas Gregor unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; 19514800a5c79023271408af49797e09be32aca93232Douglas Gregor RecordData Record; 1952b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis for (PreprocessingRecord::iterator E = PPRec.local_begin(), 1953b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis EEnd = PPRec.local_end(); 19547338a922dd1164002922163200b18a2c24eb0209Douglas Gregor E != EEnd; 19557338a922dd1164002922163200b18a2c24eb0209Douglas Gregor (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { 19564800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.clear(); 195720249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 19582dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis PreprocessedEntityOffsets.push_back(PPEntityOffset((*E)->getSourceRange(), 19592dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis Stream.GetCurrentBitNo())); 1960e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis 19614800a5c79023271408af49797e09be32aca93232Douglas Gregor if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { 1962e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis // Record this macro definition's ID. 1963e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis MacroDefinitions[MD] = NextPreprocessorEntityID; 19644800a5c79023271408af49797e09be32aca93232Douglas Gregor 19654800a5c79023271408af49797e09be32aca93232Douglas Gregor AddIdentifierRef(MD->getName(), Record); 19664800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); 19674800a5c79023271408af49797e09be32aca93232Douglas Gregor continue; 19684800a5c79023271408af49797e09be32aca93232Douglas Gregor } 19694800a5c79023271408af49797e09be32aca93232Douglas Gregor 19709e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { 19718f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis Record.push_back(ME->isBuiltinMacro()); 19728f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis if (ME->isBuiltinMacro()) 19738f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis AddIdentifierRef(ME->getName(), Record); 19748f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis else 1975e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis Record.push_back(MacroDefinitions[ME->getDefinition()]); 1976f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); 19774800a5c79023271408af49797e09be32aca93232Douglas Gregor continue; 19786a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor } 197920249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 19804800a5c79023271408af49797e09be32aca93232Douglas Gregor if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) { 19814800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(PPD_INCLUSION_DIRECTIVE); 19824800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(ID->getFileName().size()); 19834800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(ID->wasInQuotes()); 19844800a5c79023271408af49797e09be32aca93232Douglas Gregor Record.push_back(static_cast<unsigned>(ID->getKind())); 19858dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis Record.push_back(ID->importedModule()); 1986f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<64> Buffer; 19874800a5c79023271408af49797e09be32aca93232Douglas Gregor Buffer += ID->getFileName(); 198829f98b40caabca1ec820d546c5c08206a1d4f520Argyrios Kyrtzidis // Check that the FileEntry is not null because it was not resolved and 198929f98b40caabca1ec820d546c5c08206a1d4f520Argyrios Kyrtzidis // we create a PCH even with compiler errors. 199029f98b40caabca1ec820d546c5c08206a1d4f520Argyrios Kyrtzidis if (ID->getFile()) 199129f98b40caabca1ec820d546c5c08206a1d4f520Argyrios Kyrtzidis Buffer += ID->getFile()->getName(); 19924800a5c79023271408af49797e09be32aca93232Douglas Gregor Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); 19934800a5c79023271408af49797e09be32aca93232Douglas Gregor continue; 19944800a5c79023271408af49797e09be32aca93232Douglas Gregor } 19954800a5c79023271408af49797e09be32aca93232Douglas Gregor 19964800a5c79023271408af49797e09be32aca93232Douglas Gregor llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); 19974800a5c79023271408af49797e09be32aca93232Douglas Gregor } 1998c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.ExitBlock(); 199920249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 20006a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // Write the offsets table for the preprocessing record. 20016a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor if (NumPreprocessingRecords > 0) { 2002e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); 2003e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis 20046a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor // Write the offsets table for identifier IDs. 20056a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor using namespace llvm; 20066a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 2007e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); 2008272b6bc6a6c8fc04f951ad850df68c44d137f513Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity 20096a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2010e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 201120249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 20126a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor Record.clear(); 2013e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis Record.push_back(PPD_ENTITIES_OFFSETS); 2014272b6bc6a6c8fc04f951ad850df68c44d137f513Douglas Gregor Record.push_back(FirstPreprocessorEntityID - NUM_PREDEF_PP_ENTITY_IDS); 2015e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, 2016e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis data(PreprocessedEntityOffsets)); 20176a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor } 20180b1fb988012da21d996c43e36867787a7a07b889Chris Lattner} 20190b1fb988012da21d996c43e36867787a7a07b889Chris Lattner 2020e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregorunsigned ASTWriter::getSubmoduleID(Module *Mod) { 2021e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); 2022e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor if (Known != SubmoduleIDs.end()) 2023e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor return Known->second; 2024e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor 2025e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor return SubmoduleIDs[Mod] = NextSubmoduleID++; 2026e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor} 2027e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor 202826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor/// \brief Compute the number of modules within the given tree (including the 202926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor/// given module). 203026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregorstatic unsigned getNumberOfModules(Module *Mod) { 203126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor unsigned ChildModules = 0; 2032b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor for (Module::submodule_iterator Sub = Mod->submodule_begin(), 2033b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor SubEnd = Mod->submodule_end(); 203426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor Sub != SubEnd; ++Sub) 2035b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor ChildModules += getNumberOfModules(*Sub); 203626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor 203726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor return ChildModules + 1; 203826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor} 203926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor 20401a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregorvoid ASTWriter::WriteSubmodules(Module *WritingModule) { 20414bc8738d837e5d401235f99e55277338e20e3651Douglas Gregor // Determine the dependencies of our module and each of it's submodules. 204255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor // FIXME: This feels like it belongs somewhere else, but there are no 204355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor // other consumers of this information. 204455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor SourceManager &SrcMgr = PP->getSourceManager(); 204555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); 204655988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor for (ASTContext::import_iterator I = Context->local_import_begin(), 204755988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor IEnd = Context->local_import_end(); 204855988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor I != IEnd; ++I) { 204955988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor if (Module *ImportedFrom 205055988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor = ModMap.inferModuleFromLocation(FullSourceLoc(I->getLocation(), 205155988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor SrcMgr))) { 205255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor ImportedFrom->Imports.push_back(I->getImportedModule()); 205355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor } 205455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor } 205555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor 2056392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor // Enter the submodule description block. 2057392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Stream.EnterSubblock(SUBMODULE_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); 2058392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor 2059392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor // Write the abbreviations needed for the submodules block. 2060392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor using namespace llvm; 2061392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 2062392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); 2063e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID 2064392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent 2065392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework 2066392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit 2067a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem 2068a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... 20691e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... 20701e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... 2071392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name 2072392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor unsigned DefinitionAbbrev = Stream.EmitAbbrev(Abbrev); 2073392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor 2074392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev = new BitCodeAbbrev(); 207577d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); 2076392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name 2077392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor unsigned UmbrellaAbbrev = Stream.EmitAbbrev(Abbrev); 2078392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor 2079392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev = new BitCodeAbbrev(); 2080392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); 2081392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name 2082392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev); 208377d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor 208477d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor Abbrev = new BitCodeAbbrev(); 2085c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); 2086c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name 2087c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev); 2088c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis 2089c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis Abbrev = new BitCodeAbbrev(); 209077d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); 209177d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name 209277d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); 209377d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor 209451f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor Abbrev = new BitCodeAbbrev(); 209551f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); 209651f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Feature 209751f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor unsigned RequiresAbbrev = Stream.EmitAbbrev(Abbrev); 209851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor 20992b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor Abbrev = new BitCodeAbbrev(); 21002b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); 21012b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name 21022b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(Abbrev); 21032b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor 210426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor // Write the submodule metadata block. 210526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor RecordData Record; 210626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor Record.push_back(getNumberOfModules(WritingModule)); 210726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor Record.push_back(FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS); 210826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor Stream.EmitRecord(SUBMODULE_METADATA, Record); 210926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor 2110392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor // Write all of the submodules. 21111a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor std::queue<Module *> Q; 2112392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Q.push(WritingModule); 2113392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor while (!Q.empty()) { 21141a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor Module *Mod = Q.front(); 2115392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Q.pop(); 2116e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor unsigned ID = getSubmoduleID(Mod); 2117392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor 2118392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor // Emit the definition of the block. 2119392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Record.clear(); 2120392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Record.push_back(SUBMODULE_DEFINITION); 2121e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor Record.push_back(ID); 2122392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor if (Mod->Parent) { 2123392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); 2124392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Record.push_back(SubmoduleIDs[Mod->Parent]); 2125392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor } else { 2126392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Record.push_back(0); 2127392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor } 2128392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Record.push_back(Mod->IsFramework); 2129392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Record.push_back(Mod->IsExplicit); 2130a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor Record.push_back(Mod->IsSystem); 21311e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor Record.push_back(Mod->InferSubmodules); 21321e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor Record.push_back(Mod->InferExplicitSubmodules); 21331e12368db12005ddd92fd9188c86383fe30ef443Douglas Gregor Record.push_back(Mod->InferExportWildcard); 2134392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); 2135392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor 213651f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor // Emit the requirements. 213751f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor for (unsigned I = 0, N = Mod->Requires.size(); I != N; ++I) { 213851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor Record.clear(); 213951f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor Record.push_back(SUBMODULE_REQUIRES); 214051f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor Stream.EmitRecordWithBlob(RequiresAbbrev, Record, 214151f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor Mod->Requires[I].data(), 214251f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor Mod->Requires[I].size()); 214351f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor } 214451f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor 2145392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor // Emit the umbrella header, if there is one. 214610694cee2588442bee1e717f5042c58ffee25279Douglas Gregor if (const FileEntry *UmbrellaHeader = Mod->getUmbrellaHeader()) { 2147392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Record.clear(); 214877d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor Record.push_back(SUBMODULE_UMBRELLA_HEADER); 2149392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, 215010694cee2588442bee1e717f5042c58ffee25279Douglas Gregor UmbrellaHeader->getName()); 215177d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor } else if (const DirectoryEntry *UmbrellaDir = Mod->getUmbrellaDir()) { 215277d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor Record.clear(); 215377d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor Record.push_back(SUBMODULE_UMBRELLA_DIR); 215477d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, 215577d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor UmbrellaDir->getName()); 2156392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor } 2157392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor 2158392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor // Emit the headers. 2159392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor for (unsigned I = 0, N = Mod->Headers.size(); I != N; ++I) { 2160392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Record.clear(); 2161392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Record.push_back(SUBMODULE_HEADER); 2162392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Stream.EmitRecordWithBlob(HeaderAbbrev, Record, 2163392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Mod->Headers[I]->getName()); 2164392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor } 21652b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor // Emit the excluded headers. 21662b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor for (unsigned I = 0, N = Mod->ExcludedHeaders.size(); I != N; ++I) { 21672b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor Record.clear(); 21682b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor Record.push_back(SUBMODULE_EXCLUDED_HEADER); 21692b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor Stream.EmitRecordWithBlob(ExcludedHeaderAbbrev, Record, 21702b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor Mod->ExcludedHeaders[I]->getName()); 21712b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor } 2172c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis for (unsigned I = 0, N = Mod->TopHeaders.size(); I != N; ++I) { 2173c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis Record.clear(); 2174c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis Record.push_back(SUBMODULE_TOPHEADER); 2175c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, 2176c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis Mod->TopHeaders[I]->getName()); 2177c7782d96c657eeb767bfea5117db49dc40e6356cArgyrios Kyrtzidis } 217855988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor 217955988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor // Emit the imports. 218055988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor if (!Mod->Imports.empty()) { 218155988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor Record.clear(); 218255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { 2183bab9f4afaeb99319ac3567239d41cc1be3fb7e8cDouglas Gregor unsigned ImportedID = getSubmoduleID(Mod->Imports[I]); 218455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor assert(ImportedID && "Unknown submodule!"); 218555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor Record.push_back(ImportedID); 218655988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor } 218755988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor Stream.EmitRecord(SUBMODULE_IMPORTS, Record); 218855988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor } 218955988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor 2190af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor // Emit the exports. 2191af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor if (!Mod->Exports.empty()) { 2192af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor Record.clear(); 2193af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { 2194bab9f4afaeb99319ac3567239d41cc1be3fb7e8cDouglas Gregor if (Module *Exported = Mod->Exports[I].getPointer()) { 2195bab9f4afaeb99319ac3567239d41cc1be3fb7e8cDouglas Gregor unsigned ExportedID = SubmoduleIDs[Exported]; 2196bab9f4afaeb99319ac3567239d41cc1be3fb7e8cDouglas Gregor assert(ExportedID > 0 && "Unknown submodule ID?"); 2197bab9f4afaeb99319ac3567239d41cc1be3fb7e8cDouglas Gregor Record.push_back(ExportedID); 2198bab9f4afaeb99319ac3567239d41cc1be3fb7e8cDouglas Gregor } else { 2199bab9f4afaeb99319ac3567239d41cc1be3fb7e8cDouglas Gregor Record.push_back(0); 2200bab9f4afaeb99319ac3567239d41cc1be3fb7e8cDouglas Gregor } 2201bab9f4afaeb99319ac3567239d41cc1be3fb7e8cDouglas Gregor 2202af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor Record.push_back(Mod->Exports[I].getInt()); 2203af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor } 2204af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor Stream.EmitRecord(SUBMODULE_EXPORTS, Record); 2205af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor } 2206af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor 2207392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor // Queue up the submodules of this module. 2208b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor for (Module::submodule_iterator Sub = Mod->submodule_begin(), 2209b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor SubEnd = Mod->submodule_end(); 2210392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Sub != SubEnd; ++Sub) 2211b7a7819473709c01ea024a2dc15e99d38f0f8760Douglas Gregor Q.push(*Sub); 2212392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor } 2213392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor 2214392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor Stream.ExitBlock(); 2215e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor 2216e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor assert((NextSubmoduleID - FirstSubmoduleID 2217e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor == getNumberOfModules(WritingModule)) && "Wrong # of submodules"); 2218392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor} 2219392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor 2220185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregorserialization::SubmoduleID 2221185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas GregorASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { 2222e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor if (Loc.isInvalid() || !WritingModule) 2223185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor return 0; // No submodule 222455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor 222555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor // Find the module that owns this location. 2226185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); 222755988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor Module *OwningMod 222855988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); 2229185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor if (!OwningMod) 2230185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor return 0; 2231185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor 2232e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor // Check whether this submodule is part of our own module. 2233e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule)) 2234185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor return 0; 2235185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor 2236e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor return getSubmoduleID(OwningMod); 2237185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor} 2238185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor 2239d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikievoid ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) { 224033e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis // FIXME: Make it work properly with modules. 224133e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> 224233e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis DiagStateIDMap; 224333e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis unsigned CurrID = 0; 224433e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis DiagStateIDMap[&Diag.DiagStates.front()] = ++CurrID; // the command-line one. 2245f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis RecordData Record; 2246d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie for (DiagnosticsEngine::DiagStatePointsTy::const_iterator 22473efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis I = Diag.DiagStatePoints.begin(), E = Diag.DiagStatePoints.end(); 22483efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis I != E; ++I) { 224933e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis const DiagnosticsEngine::DiagStatePoint &point = *I; 22503efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis if (point.Loc.isInvalid()) 22513efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis continue; 22523efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis 22533efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Record.push_back(point.Loc.getRawEncoding()); 225433e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis unsigned &DiagStateID = DiagStateIDMap[point.State]; 225533e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis Record.push_back(DiagStateID); 225633e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis 225733e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis if (DiagStateID == 0) { 225833e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis DiagStateID = ++CurrID; 225933e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis for (DiagnosticsEngine::DiagState::const_iterator 226033e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis I = point.State->begin(), E = point.State->end(); I != E; ++I) { 226133e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis if (I->second.isPragma()) { 226233e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis Record.push_back(I->first); 226333e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis Record.push_back(I->second.getMapping()); 226433e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis } 22653efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis } 226633e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis Record.push_back(-1); // mark the end of the diag/map pairs for this 226733e1576ef88ae6fcc4ed8686f34ed28b1a41bcceArgyrios Kyrtzidis // location. 2268f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis } 2269f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis } 2270f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis 227160f7684881f9f6bc779e91212aea89d9afc723ddArgyrios Kyrtzidis if (!Record.empty()) 22723efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); 2273f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis} 2274f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis 2275c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlssonvoid ASTWriter::WriteCXXBaseSpecifiersOffsets() { 2276c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson if (CXXBaseSpecifiersOffsets.empty()) 2277c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson return; 2278c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 2279c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson RecordData Record; 2280c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 2281c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson // Create a blob abbreviation for the C++ base specifiers offsets. 2282c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson using namespace llvm; 2283c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 2284c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 2285c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Abbrev->Add(BitCodeAbbrevOp(CXX_BASE_SPECIFIER_OFFSETS)); 2286c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size 2287c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2288c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson unsigned BaseSpecifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 2289c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 2290e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor // Write the base specifier offsets table. 2291c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Record.clear(); 2292c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Record.push_back(CXX_BASE_SPECIFIER_OFFSETS); 2293c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Record.push_back(CXXBaseSpecifiersOffsets.size()); 2294c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson Stream.EmitRecordWithBlob(BaseSpecifierOffsetAbbrev, Record, 22956e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer data(CXXBaseSpecifiersOffsets)); 2296c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson} 2297c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson 22984fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 22994fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Type Serialization 23004fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 23010b1fb988012da21d996c43e36867787a7a07b889Chris Lattner 23023397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the representation of a type to the AST stream. 2303a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteType(QualType T) { 230401b81c4d074bba9c18372d521405dfe32fc4f552Argyrios Kyrtzidis TypeIdx &Idx = TypeIdxs[T]; 2305c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis if (Idx.getIndex() == 0) // we haven't seen this type before. 2306c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis Idx = TypeIdx(NextTypeID++); 23071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 230897475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); 230955f48de5f6b10b50f4d88a9f7235f4532f799550Douglas Gregor 23102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Record the offset for this type. 2311c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis unsigned Index = Idx.getIndex() - FirstTypeID; 2312681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl if (TypeOffsets.size() == Index) 2313c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor TypeOffsets.push_back(Stream.GetCurrentBitNo()); 2314681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl else if (TypeOffsets.size() < Index) { 2315681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl TypeOffsets.resize(Index + 1); 2316681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl TypeOffsets[Index] = Stream.GetCurrentBitNo(); 23172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 23182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 23192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor RecordData Record; 23201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Emit the type's representation. 23223397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTTypeWriter W(*this, Record); 23230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 2324a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (T.hasLocalNonFastQualifiers()) { 2325a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Qs = T.getLocalQualifiers(); 2326a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor AddTypeRef(T.getLocalUnqualifiedType(), Record); 23270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Record.push_back(Qs.getAsOpaqueValue()); 23288538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl W.Code = TYPE_EXT_QUAL; 23290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } else { 23300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall switch (T->getTypeClass()) { 23310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // For all of the concrete, non-dependent types, call the 23320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // appropriate visitor function. 23332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define TYPE(Class, Base) \ 2334b7166334d897e1e4e6a5b428fe2d0ec752ef187fMike Stump case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; 23352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define ABSTRACT_TYPE(Class, Base) 23362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/TypeNodes.def" 23370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 23382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 23392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 23402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Emit the serialized record. 2341c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.EmitRecord(W.Code, Record); 23420b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 23430b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor // Flush any expressions that were written as part of this type. 2344c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor FlushStmts(); 23452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 23462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 23474fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 23484fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Declaration Serialization 23494fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 23504fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 23512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// \brief Write the block containing all of the declaration IDs 23522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// lexically declared within the given DeclContext. 23532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// 23542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// \returns the offset of the DECL_CONTEXT_LEXICAL block within the 23552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// bistream, or 0 if no block was written. 2356a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redluint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, 23572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor DeclContext *DC) { 235817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis if (DC->decls_empty()) 23592cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor return 0; 23602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2361c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor uint64_t Offset = Stream.GetCurrentBitNo(); 23622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor RecordData Record; 23638538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(DECL_CONTEXT_LEXICAL); 23645f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<KindDeclIDPair, 64> Decls; 236517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); 236617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis D != DEnd; ++D) 2367eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis Decls.push_back(std::make_pair((*D)->getKind(), GetDeclRef(*D))); 23682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 23692512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor ++NumLexicalDeclContexts; 23706e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, data(Decls)); 23712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor return Offset; 23722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 23732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 2374a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteTypeDeclOffsets() { 23751476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl using namespace llvm; 23761476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl RecordData Record; 23771476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 23781476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // Write the type offsets array 23791476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 23808538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); 23811476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types 2382a119da0761cb6b85f53857eaee50f6ad8c5ea0a0Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index 23831476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block 23841476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 23851476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.clear(); 23868538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(TYPE_OFFSET); 23871476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.push_back(TypeOffsets.size()); 2388a119da0761cb6b85f53857eaee50f6ad8c5ea0a0Douglas Gregor Record.push_back(FirstTypeID - NUM_PREDEF_TYPE_IDS); 23896e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, data(TypeOffsets)); 23901476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 23911476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl // Write the declaration offsets array 23921476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev = new BitCodeAbbrev(); 23938538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); 23941476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations 2395496c709a6f08f5c502b6f592ddd9ed40f953a5e5Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID 23961476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block 23971476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 23981476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.clear(); 23998538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(DECL_OFFSET); 24001476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl Record.push_back(DeclOffsets.size()); 24010a14e4bf604a91b035a479235adf4c2f6c9128a2Douglas Gregor Record.push_back(FirstDeclID - NUM_PREDEF_DECL_IDS); 24026e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, data(DeclOffsets)); 24031476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl} 24041476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl 240510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidisvoid ASTWriter::WriteFileDeclIDsMap() { 240610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis using namespace llvm; 240710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis RecordData Record; 240810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 240910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // Join the vectors of DeclIDs from all files. 241010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis SmallVector<DeclID, 256> FileSortedIDs; 241110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis for (FileDeclIDsTy::iterator 241210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis FI = FileDeclIDs.begin(), FE = FileDeclIDs.end(); FI != FE; ++FI) { 241310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis DeclIDInFileInfo &Info = *FI->second; 241410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Info.FirstDeclIndex = FileSortedIDs.size(); 241510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis for (LocDeclIDsTy::iterator 241610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis DI = Info.DeclIDs.begin(), DE = Info.DeclIDs.end(); DI != DE; ++DI) 241710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis FileSortedIDs.push_back(DI->second); 241810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis } 241910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 242010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 242110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); 24222093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 242310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 242410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev); 242510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Record.push_back(FILE_SORTED_DECLS); 24262093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis Record.push_back(FileSortedIDs.size()); 242710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Stream.EmitRecordWithBlob(AbbrevCode, Record, data(FileSortedIDs)); 242810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis} 242910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 2430aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenkovoid ASTWriter::WriteComments() { 2431aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); 2432811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko ArrayRef<RawComment *> RawComments = Context->Comments.getComments(); 2433aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko RecordData Record; 2434811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko for (ArrayRef<RawComment *>::iterator I = RawComments.begin(), 2435811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko E = RawComments.end(); 2436aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko I != E; ++I) { 2437aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko Record.clear(); 2438811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko AddSourceRange((*I)->getSourceRange(), Record); 2439811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko Record.push_back((*I)->getKind()); 2440811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko Record.push_back((*I)->isTrailingComment()); 2441811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko Record.push_back((*I)->isAlmostTrailingComment()); 2442aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); 2443aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 2444aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko Stream.ExitBlock(); 2445aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko} 2446aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 24474fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 24484fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Global Method Pool and Selector Serialization 24494fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 24504fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 24513251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregornamespace { 2452f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor// Trait used for the on-disk hash table used in the method pool. 24533397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlclass ASTMethodPoolTrait { 2454a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 2455f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2456f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregorpublic: 2457f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor typedef Selector key_type; 2458f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor typedef key_type key_type_ref; 24591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24605d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl struct data_type { 24618538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl SelectorID ID; 24625d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl ObjCMethodList Instance, Factory; 24635d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl }; 2464f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor typedef const data_type& data_type_ref; 2465f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 24663397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } 24671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2468f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor static unsigned ComputeHash(Selector Sel) { 24690eca89e9890db4d8336ce762a5b359a1d58ca02bArgyrios Kyrtzidis return serialization::ComputeHash(Sel); 2470f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 24711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<unsigned,unsigned> 24735f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner EmitKeyDataLength(raw_ostream& Out, Selector Sel, 2474f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor data_type_ref Methods) { 2475f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); 2476f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, KeyLen); 24775d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts 24785d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Instance; Method; 2479f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2480f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2481f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor DataLen += 4; 24825d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Factory; Method; 2483f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2484f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2485f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor DataLen += 4; 2486f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, DataLen); 2487f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor return std::make_pair(KeyLen, DataLen); 2488f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 24891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24905f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { 24911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump uint64_t Start = Out.tell(); 249283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor assert((Start >> 32) == 0 && "Selector key offset too large"); 249383941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Writer.SetSelectorOffset(Sel, Start); 2494f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned N = Sel.getNumArgs(); 2495f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, N); 2496f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (N == 0) 2497f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor N = 1; 2498f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor for (unsigned I = 0; I != N; ++I) 24991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump clang::io::Emit32(Out, 2500f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); 2501f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 25021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25035f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void EmitData(raw_ostream& Out, key_type_ref, 2504a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor data_type_ref Methods, unsigned DataLen) { 2505a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor uint64_t Start = Out.tell(); (void)Start; 25065d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl clang::io::Emit32(Out, Methods.ID); 2507f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned NumInstanceMethods = 0; 25085d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Instance; Method; 2509f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2510f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2511f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ++NumInstanceMethods; 2512f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2513f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned NumFactoryMethods = 0; 25145d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Factory; Method; 2515f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2516f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2517f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ++NumFactoryMethods; 2518f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2519f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, NumInstanceMethods); 2520f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit16(Out, NumFactoryMethods); 25215d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Instance; Method; 2522f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2523f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2524f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); 25255d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl for (const ObjCMethodList *Method = &Methods.Factory; Method; 2526f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = Method->Next) 2527f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor if (Method->Method) 2528f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); 2529a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor 2530a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor assert(Out.tell() - Start == DataLen && "Data length is wrong"); 2531f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2532f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor}; 2533f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor} // end anonymous namespace 2534f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2535059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl/// \brief Write ObjC data: selectors and the method pool. 2536f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor/// 2537f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor/// The method pool contains both instance and factory methods, stored 2538059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl/// in an on-disk hash table indexed by the selector. The hash table also 2539059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl/// contains an empty entry for every other selector known to Sema. 2540a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteSelectors(Sema &SemaRef) { 2541f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor using namespace llvm; 2542f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2543059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // Do we have to do anything at all? 25445d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) 2545059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl return; 2546e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl unsigned NumTableEntries = 0; 2547059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // Create and write out the blob that contains selectors and the method pool. 2548f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor { 25493397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; 25505d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ASTMethodPoolTrait Trait(*this); 25511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2552059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // Create the on-disk hash table representation. We walk through every 2553059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl // selector we've seen and look it up in the method pool. 2554e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl SelectorOffsets.resize(NextSelectorID - FirstSelectorID); 25558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl for (llvm::DenseMap<Selector, SelectorID>::iterator 25565d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl I = SelectorIDs.begin(), E = SelectorIDs.end(); 25575d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl I != E; ++I) { 25585d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Selector S = I->first; 2559059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); 25603397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTMethodPoolTrait::data_type Data = { 25615d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl I->second, 25625d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl ObjCMethodList(), 25635d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl ObjCMethodList() 25645d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl }; 25655d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl if (F != SemaRef.MethodPool.end()) { 25665d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Data.Instance = F->second.first; 25675d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Data.Factory = F->second.second; 25685d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl } 25693397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Only write this selector if it's not in an existing AST or something 2570e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // changed. 2571e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (Chain && I->second < FirstSelectorID) { 2572e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // Selector already exists. Did it change? 2573e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl bool changed = false; 2574e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method; 2575e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl M = M->Next) { 2576919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!M->Method->isFromASTFile()) 2577e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl changed = true; 2578e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 2579e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method; 2580e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl M = M->Next) { 2581919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!M->Method->isFromASTFile()) 2582e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl changed = true; 2583e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 2584e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (!changed) 2585e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl continue; 2586fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl } else if (Data.Instance.Method || Data.Factory.Method) { 2587fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl // A new method pool entry. 2588fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl ++NumTableEntries; 2589e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 25905d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Generator.insert(S, Data, Trait); 2591f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2592f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2593f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Create the on-disk hash table in a buffer. 2594f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<4096> MethodPool; 2595f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor uint32_t BucketOffset; 2596f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor { 25973397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl ASTMethodPoolTrait Trait(*this); 2598f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor llvm::raw_svector_ostream Out(MethodPool); 2599f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Make sure that no bucket is at offset 0 2600a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor clang::io::Emit32(Out, 0); 2601f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor BucketOffset = Generator.Emit(Out, Trait); 2602f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2603f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 2604f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Create a blob abbreviation 2605f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 26068538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); 2607f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 260883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 2609f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2610f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); 2611f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 261283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor // Write the method pool 2613f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor RecordData Record; 26148538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(METHOD_POOL); 2615f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Record.push_back(BucketOffset); 2616e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl Record.push_back(NumTableEntries); 2617ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); 261883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor 261983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor // Create a blob abbreviation for the selector table offsets. 262083941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Abbrev = new BitCodeAbbrev(); 26218538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); 26227c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size 2623b18b1fd33f958264630fbae2602c81275bae8c9aDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID 262483941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 262583941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 262683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor 262783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor // Write the selector offsets table. 262883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Record.clear(); 26298538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(SELECTOR_OFFSETS); 263083941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Record.push_back(SelectorOffsets.size()); 2631b18b1fd33f958264630fbae2602c81275bae8c9aDouglas Gregor Record.push_back(FirstSelectorID - NUM_PREDEF_SELECTOR_IDS); 263283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, 26336e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer data(SelectorOffsets)); 2634f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 2635f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor} 2636f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 26373397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the selectors referenced in @selector expression into AST file. 2638a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { 2639320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian using namespace llvm; 2640320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian if (SemaRef.ReferencedSelectors.empty()) 2641320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian return; 2642725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl 2643320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian RecordData Record; 2644725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl 26453397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Note: this writes out all references even for a dependent AST. But it is 2646a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl // very tricky to fix, and given that @selector shouldn't really appear in 2647a68340fd55e177a5849cb3adbf66aedce1f6e91bSebastian Redl // headers, probably not worth it. It's not a correctness issue. 2648320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian for (DenseMap<Selector, SourceLocation>::iterator S = 2649320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian SemaRef.ReferencedSelectors.begin(), 2650320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian E = SemaRef.ReferencedSelectors.end(); S != E; ++S) { 2651320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian Selector Sel = (*S).first; 2652320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian SourceLocation Loc = (*S).second; 2653320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian AddSelectorRef(Sel, Record); 2654320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian AddSourceLocation(Loc, Record); 2655320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian } 26568538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(REFERENCED_SELECTOR_POOL, Record); 2657320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian} 2658320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian 26594fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 26604fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// Identifier Table Serialization 26614fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 26624fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 2663f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregornamespace { 26643397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlclass ASTIdentifierTableTrait { 2665a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl ASTWriter &Writer; 266637e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor Preprocessor &PP; 2667eee242ff426bf79149f221798966e58688383c1eDouglas Gregor IdentifierResolver &IdResolver; 26687143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor bool IsModule; 26697143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor 2670a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor /// \brief Determines whether this is an "interesting" identifier 2671a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor /// that needs a full IdentifierInfo structure written into the hash 2672a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor /// table. 26737143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor bool isInterestingIdentifier(IdentifierInfo *II, MacroInfo *&Macro) { 26747143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor if (II->isPoisoned() || 26757143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor II->isExtensionToken() || 26767143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor II->getObjCOrBuiltinID() || 2677eee242ff426bf79149f221798966e58688383c1eDouglas Gregor II->hasRevertedTokenIDToIdentifier() || 26787143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor II->getFETokenInfo<void>()) 26797143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor return true; 26807143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor 26814d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko return hadMacroDefinition(II, Macro); 2682ce835df9301d5bee7fc2c70344e05541f21a5ddaDouglas Gregor } 26834d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 26844d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko bool hadMacroDefinition(IdentifierInfo *II, MacroInfo *&Macro) { 26854d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko if (!II->hadMacroDefinition()) 26867143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor return false; 26874d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 26884d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko if (Macro || (Macro = PP.getMacroInfoHistory(II))) 2689aa93a875605536d72a10359a0098396192b7d4ecDouglas Gregor return !Macro->isBuiltinMacro() && (!IsModule || Macro->isPublic()); 26904d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 26914d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko return false; 2692a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor } 2693a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor 26943251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregorpublic: 26957143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor typedef IdentifierInfo* key_type; 26963251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor typedef key_type key_type_ref; 26971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26988538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl typedef IdentID data_type; 26993251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor typedef data_type data_type_ref; 27001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2701eee242ff426bf79149f221798966e58688383c1eDouglas Gregor ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, 2702eee242ff426bf79149f221798966e58688383c1eDouglas Gregor IdentifierResolver &IdResolver, bool IsModule) 2703eee242ff426bf79149f221798966e58688383c1eDouglas Gregor : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule) { } 27043251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 27053251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor static unsigned ComputeHash(const IdentifierInfo* II) { 27062596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar return llvm::HashString(II->getName()); 27073251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 27081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<unsigned,unsigned> 2710eee242ff426bf79149f221798966e58688383c1eDouglas Gregor EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { 2711e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar unsigned KeyLen = II->getLength() + 1; 2712a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 2713ce835df9301d5bee7fc2c70344e05541f21a5ddaDouglas Gregor MacroInfo *Macro = 0; 27147143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor if (isInterestingIdentifier(II, Macro)) { 27154d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko DataLen += 2; // 2 bytes for builtin ID 27164d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko DataLen += 2; // 2 bytes for flags 27176c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor if (hadMacroDefinition(II, Macro)) { 27186c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { 27196c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor if (Writer.getMacroRef(M) != 0) 27206c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor DataLen += 4; 27216c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor } 27226c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor 27236c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor DataLen += 4; 27246c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor } 27254d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 2726eee242ff426bf79149f221798966e58688383c1eDouglas Gregor for (IdentifierResolver::iterator D = IdResolver.begin(II), 2727eee242ff426bf79149f221798966e58688383c1eDouglas Gregor DEnd = IdResolver.end(); 2728a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor D != DEnd; ++D) 27298538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl DataLen += sizeof(DeclID); 2730a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor } 2731668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor clang::io::Emit16(Out, DataLen); 273202fc75169afe785c114e795ec4d24edfb4073c42Douglas Gregor // We emit the key length after the data length so that every 273302fc75169afe785c114e795ec4d24edfb4073c42Douglas Gregor // string is preceded by a 16-bit length. This matches the PTH 273402fc75169afe785c114e795ec4d24edfb4073c42Douglas Gregor // format for storing identifiers. 2735d6595a40fe12e3d5ffe5ce48987b379d547439a4Douglas Gregor clang::io::Emit16(Out, KeyLen); 27363251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor return std::make_pair(KeyLen, DataLen); 27373251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 27381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27395f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void EmitKey(raw_ostream& Out, const IdentifierInfo* II, 27403251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor unsigned KeyLen) { 27413251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor // Record the location of the key data. This is used when generating 27423251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor // the mapping from persistent IDs to strings. 27433251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor Writer.SetIdentifierOffset(II, Out.tell()); 2744e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar Out.write(II->getNameStart(), KeyLen); 27453251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 27461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27477143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor void EmitData(raw_ostream& Out, IdentifierInfo* II, 27488538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID ID, unsigned) { 2749ce835df9301d5bee7fc2c70344e05541f21a5ddaDouglas Gregor MacroInfo *Macro = 0; 27507143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor if (!isInterestingIdentifier(II, Macro)) { 2751a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor clang::io::Emit32(Out, ID << 1); 2752a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor return; 2753a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor } 27545998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor 2755a92193ebd9840e5ce4de1b09e49f1b024c0f5c2fDouglas Gregor clang::io::Emit32(Out, (ID << 1) | 0x01); 27564d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); 27574d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); 27584d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko clang::io::Emit16(Out, Bits); 27594d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Bits = 0; 27604d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko bool HadMacroDefinition = hadMacroDefinition(II, Macro); 27614d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko Bits = (Bits << 1) | unsigned(HadMacroDefinition); 2762b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(II->isExtensionToken()); 2763b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(II->isPoisoned()); 2764646395bbcaa849c94bc2a3246c71d809ca719f01Argyrios Kyrtzidis Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); 2765b0b84385f0cb0ea4036579f5f384f1c19b917c7eDaniel Dunbar Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); 27665998da5c29dae3f654cb65738ff237203e2222c8Douglas Gregor clang::io::Emit16(Out, Bits); 27673251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 27684d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko if (HadMacroDefinition) { 27696c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor // Write all of the macro IDs associated with this identifier. 27706c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { 27716c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor if (MacroID ID = Writer.getMacroRef(M)) 27726c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor clang::io::Emit32(Out, ID); 27736c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor } 27746c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor 27756c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor clang::io::Emit32(Out, 0); 27761329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor } 27774d7e0ced7f16a04aabe2d8d91cbbb52fb1162810Alexander Kornienko 2778668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // Emit the declaration IDs in reverse order, because the 2779668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // IdentifierResolver provides the declarations as they would be 2780668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor // visible (e.g., the function "stat" would come before the struct 2781eee242ff426bf79149f221798966e58688383c1eDouglas Gregor // "stat"), but the ASTReader adds declarations to the end of the list 2782eee242ff426bf79149f221798966e58688383c1eDouglas Gregor // (so we need to see the struct "status" before the function "status"). 2783f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // Only emit declarations that aren't from a chained PCH, though. 2784eee242ff426bf79149f221798966e58688383c1eDouglas Gregor SmallVector<Decl *, 16> Decls(IdResolver.begin(II), 2785eee242ff426bf79149f221798966e58688383c1eDouglas Gregor IdResolver.end()); 27865f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner for (SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), 2787eee242ff426bf79149f221798966e58688383c1eDouglas Gregor DEnd = Decls.rend(); 27883251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor D != DEnd; ++D) 2789d8c5abb096a5f6babb3709180fe304be5462bcc1Sebastian Redl clang::io::Emit32(Out, Writer.getDeclID(*D)); 27903251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 27913251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor}; 27923251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor} // end anonymous namespace 27933251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 27943397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/// \brief Write the identifier table into the AST file. 2795afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// 2796afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// The identifier table consists of a blob containing string data 2797afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// (the actual identifiers themselves) and a separate "offsets" index 2798afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor/// that maps identifier IDs to locations within the blob. 2799eee242ff426bf79149f221798966e58688383c1eDouglas Gregorvoid ASTWriter::WriteIdentifierTable(Preprocessor &PP, 2800eee242ff426bf79149f221798966e58688383c1eDouglas Gregor IdentifierResolver &IdResolver, 2801eee242ff426bf79149f221798966e58688383c1eDouglas Gregor bool IsModule) { 2802afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor using namespace llvm; 2803afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2804afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Create and write out the blob that contains the identifier 2805afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // strings. 2806afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor { 28073397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; 2808eee242ff426bf79149f221798966e58688383c1eDouglas Gregor ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); 28091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 281092b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // Look for any identifiers that were named while processing the 281192b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // headers, but are otherwise not needed. We add these to the hash 281292b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // table to enable checking of the predefines buffer in the case 28133397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // where the user adds new macro definitions when building the AST 281492b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor // file. 281592b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), 281692b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor IDEnd = PP.getIdentifierTable().end(); 281792b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor ID != IDEnd; ++ID) 281892b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor getIdentifierRef(ID->second); 281992b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor 2820f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // Create the on-disk hash table representation. We only store offsets 2821f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // for identifiers that appear here for the first time. 2822f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl IdentifierOffsets.resize(NextIdentID - FirstIdentID); 28238538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl for (llvm::DenseMap<const IdentifierInfo *, IdentID>::iterator 2824afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); 2825afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor ID != IDEnd; ++ID) { 2826afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor assert(ID->first && "NULL identifier in identifier table"); 2827eee242ff426bf79149f221798966e58688383c1eDouglas Gregor if (!Chain || !ID->first->isFromAST() || 2828eee242ff426bf79149f221798966e58688383c1eDouglas Gregor ID->first->hasChangedSinceDeserialization()) 28297143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor Generator.insert(const_cast<IdentifierInfo *>(ID->first), ID->second, 28307143aab97c6e849a5a5005b7853b8c7d5af008edDouglas Gregor Trait); 28313251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor } 2832afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 28333251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor // Create the on-disk hash table in a buffer. 2834f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<4096> IdentifierTable; 2835668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor uint32_t BucketOffset; 28363251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor { 2837eee242ff426bf79149f221798966e58688383c1eDouglas Gregor ASTIdentifierTableTrait Trait(*this, PP, IdResolver, IsModule); 28383251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor llvm::raw_svector_ostream Out(IdentifierTable); 2839f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor // Make sure that no bucket is at offset 0 2840a67e58c8fa03c2f1aa7609bf5a436d1adba75eefDouglas Gregor clang::io::Emit32(Out, 0); 2841668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor BucketOffset = Generator.Emit(Out, Trait); 2842afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor } 2843afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2844afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Create a blob abbreviation 2845afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 28468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); 2847668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 28483251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 2849c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); 2850afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2851afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Write the identifier table 2852afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor RecordData Record; 28538538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(IDENTIFIER_TABLE); 2854668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor Record.push_back(BucketOffset); 2855ec312a1f0557b1d27f3eb6cf49acbf7e72696422Daniel Dunbar Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); 2856afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor } 2857afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 2858afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor // Write the offsets table for identifier IDs. 28592b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 28608538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); 28612b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers 28626ec60e00eeaaed78d98c85ce962d6f328094ca14Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID 28632b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 28642b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); 28652b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor 28662b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor RecordData Record; 28678538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Record.push_back(IDENTIFIER_OFFSET); 28682b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Record.push_back(IdentifierOffsets.size()); 28696ec60e00eeaaed78d98c85ce962d6f328094ca14Douglas Gregor Record.push_back(FirstIdentID - NUM_PREDEF_IDENT_IDS); 28702b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, 28716e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer data(IdentifierOffsets)); 2872afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor} 2873afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 28744fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 28755d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis// DeclContext's Name Lookup Table Serialization 28765d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 28775d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 28785d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidisnamespace { 28795d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis// Trait used for the on-disk hash table used in the method pool. 28805d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidisclass ASTDeclContextNameLookupTrait { 28815d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ASTWriter &Writer; 28825d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 28835d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidispublic: 28845d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef DeclarationName key_type; 28855d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef key_type key_type_ref; 28865d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 28875d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef DeclContext::lookup_result data_type; 28885d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis typedef const data_type& data_type_ref; 28895d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 28905d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } 28915d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 28925d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis unsigned ComputeHash(DeclarationName Name) { 28935d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis llvm::FoldingSetNodeID ID; 28945d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(Name.getNameKind()); 28955d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 28965d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis switch (Name.getNameKind()) { 28975d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::Identifier: 28985d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddString(Name.getAsIdentifierInfo()->getName()); 28995d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 29005d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 29015d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 29025d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 29035d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(serialization::ComputeHash(Name.getObjCSelector())); 29045d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 29055d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 29065d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 29075d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 29085d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 29095d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 29105d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddInteger(Name.getCXXOverloadedOperator()); 29115d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 29125d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 29135d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis ID.AddString(Name.getCXXLiteralIdentifier()->getName()); 29145d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 29155d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 29165d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 29175d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 29185d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis return ID.ComputeHash(); 29195d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 29205d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 29215d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis std::pair<unsigned,unsigned> 29225f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner EmitKeyDataLength(raw_ostream& Out, DeclarationName Name, 29235d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis data_type_ref Lookup) { 29245d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis unsigned KeyLen = 1; 29255d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis switch (Name.getNameKind()) { 29265d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::Identifier: 29275d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 29285d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 29295d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 29305d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 29315d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis KeyLen += 4; 29325d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 29335d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 29345d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis KeyLen += 1; 29355d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 2936e36050111e2bdb7efc014af9dd7f0009b492ac36Douglas Gregor case DeclarationName::CXXConstructorName: 2937e36050111e2bdb7efc014af9dd7f0009b492ac36Douglas Gregor case DeclarationName::CXXDestructorName: 2938e36050111e2bdb7efc014af9dd7f0009b492ac36Douglas Gregor case DeclarationName::CXXConversionFunctionName: 29395d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 29405d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis break; 29415d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 29425d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit16(Out, KeyLen); 29435d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 29445d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis // 2 bytes for num of decls and 4 for each DeclID. 29455d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis unsigned DataLen = 2 + 4 * (Lookup.second - Lookup.first); 29465d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit16(Out, DataLen); 29475d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 29485d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis return std::make_pair(KeyLen, DataLen); 29495d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 29505d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 29515f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void EmitKey(raw_ostream& Out, DeclarationName Name, unsigned) { 29525d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis using namespace clang::io; 29535d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 29545d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit8(Out, Name.getNameKind()); 29555d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis switch (Name.getNameKind()) { 29565d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::Identifier: 29575d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getIdentifierRef(Name.getAsIdentifierInfo())); 29585931331d4b99c8c602fa3ab6c82b94adb7e5552fBenjamin Kramer return; 29595d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 29605d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 29615d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 29625d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getSelectorRef(Name.getObjCSelector())); 29635931331d4b99c8c602fa3ab6c82b94adb7e5552fBenjamin Kramer return; 29645d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 29655931331d4b99c8c602fa3ab6c82b94adb7e5552fBenjamin Kramer assert(Name.getCXXOverloadedOperator() < NUM_OVERLOADED_OPERATORS && 29665931331d4b99c8c602fa3ab6c82b94adb7e5552fBenjamin Kramer "Invalid operator?"); 29675d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit8(Out, Name.getCXXOverloadedOperator()); 29685931331d4b99c8c602fa3ab6c82b94adb7e5552fBenjamin Kramer return; 29695d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 29705d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis Emit32(Out, Writer.getIdentifierRef(Name.getCXXLiteralIdentifier())); 29715931331d4b99c8c602fa3ab6c82b94adb7e5552fBenjamin Kramer return; 2972e36050111e2bdb7efc014af9dd7f0009b492ac36Douglas Gregor case DeclarationName::CXXConstructorName: 2973e36050111e2bdb7efc014af9dd7f0009b492ac36Douglas Gregor case DeclarationName::CXXDestructorName: 2974e36050111e2bdb7efc014af9dd7f0009b492ac36Douglas Gregor case DeclarationName::CXXConversionFunctionName: 29755d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 29765931331d4b99c8c602fa3ab6c82b94adb7e5552fBenjamin Kramer return; 29775d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 29785931331d4b99c8c602fa3ab6c82b94adb7e5552fBenjamin Kramer 29795931331d4b99c8c602fa3ab6c82b94adb7e5552fBenjamin Kramer llvm_unreachable("Invalid name kind?"); 29805d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 29815d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 29825f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void EmitData(raw_ostream& Out, key_type_ref, 29835d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis data_type Lookup, unsigned DataLen) { 29845d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis uint64_t Start = Out.tell(); (void)Start; 29855d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit16(Out, Lookup.second - Lookup.first); 29865d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis for (; Lookup.first != Lookup.second; ++Lookup.first) 29875d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis clang::io::Emit32(Out, Writer.GetDeclRef(*Lookup.first)); 29885d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 29895d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(Out.tell() - Start == DataLen && "Data length is wrong"); 29905d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis } 29915d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis}; 29925d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis} // end anonymous namespace 29935d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis 2994074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// \brief Write the block containing all of the declaration IDs 2995074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// visible from the given DeclContext. 2996074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// 2997074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis/// \returns the offset of the DECL_CONTEXT_VISIBLE block within the 29981d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// bitstream, or 0 if no block was written. 2999074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidisuint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, 3000074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis DeclContext *DC) { 3001074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (DC->getPrimaryContext() != DC) 3002074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 3003074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 3004074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Since there is no name lookup into functions or methods, don't bother to 3005074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // build a visible-declarations table for these entities. 3006074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (DC->isFunctionOrMethod()) 3007074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 3008074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 3009074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // If not in C++, we perform name lookup for the translation unit via the 3010074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // IdentifierInfo chains, don't bother to build a visible-declarations table. 3011074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // FIXME: In C++ we need the visible declarations in order to "see" the 3012074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // friend declarations, is there a way to do this without writing the table ? 30134e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) 3014074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 3015074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 3016074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Serialize the contents of the mapping used for lookup. Note that, 3017074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // although we have two very different code paths, the serialized 3018074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // representation is the same for both cases: a declaration name, 3019074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // followed by a size, followed by references to the visible 3020074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // declarations that have that name. 3021074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis uint64_t Offset = Stream.GetCurrentBitNo(); 3022c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith StoredDeclsMap *Map = DC->buildLookup(); 3023074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis if (!Map || Map->empty()) 3024074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return 0; 3025074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 3026074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; 3027074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis ASTDeclContextNameLookupTrait Trait(*this); 3028074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 3029074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Create the on-disk hash table representation. 3030e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor DeclarationName ConversionName; 3031e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor llvm::SmallVector<NamedDecl *, 4> ConversionDecls; 3032074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); 3033074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis D != DEnd; ++D) { 3034074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis DeclarationName Name = D->first; 3035074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis DeclContext::lookup_result Result = D->second.getLookupResult(); 3036e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor if (Result.first != Result.second) { 3037e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { 3038e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor // Hash all conversion function names to the same name. The actual 3039e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor // type information in conversion function name is not used in the 3040e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor // key (since such type information is not stable across different 3041e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor // modules), so the intended effect is to coalesce all of the conversion 3042e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor // functions under a single key. 3043e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor if (!ConversionName) 3044e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor ConversionName = Name; 3045e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor ConversionDecls.append(Result.first, Result.second); 3046e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor continue; 3047e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor } 3048e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor 304945118d8f2b50a37472dd03cd1d5b4abd7ae9f25bArgyrios Kyrtzidis Generator.insert(Name, Result, Trait); 3050e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor } 3051074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis } 3052074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 3053e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor // Add the conversion functions 3054e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor if (!ConversionDecls.empty()) { 3055e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor Generator.insert(ConversionName, 3056e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor DeclContext::lookup_result(ConversionDecls.begin(), 3057e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor ConversionDecls.end()), 3058e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor Trait); 3059e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor } 3060e5a54b600f74dcb6cca27543df2757115711d80aDouglas Gregor 3061074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Create the on-disk hash table in a buffer. 3062f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<4096> LookupTable; 3063074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis uint32_t BucketOffset; 3064074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis { 3065074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis llvm::raw_svector_ostream Out(LookupTable); 3066074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Make sure that no bucket is at offset 0 3067074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis clang::io::Emit32(Out, 0); 3068074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis BucketOffset = Generator.Emit(Out, Trait); 3069074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis } 3070074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 3071074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis // Write the lookup table 3072074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis RecordData Record; 3073074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Record.push_back(DECL_CONTEXT_VISIBLE); 3074074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Record.push_back(BucketOffset); 3075074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, 3076074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis LookupTable.str()); 3077074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 3078074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis Stream.EmitRecord(DECL_CONTEXT_VISIBLE, Record); 3079074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis ++NumVisibleDeclContexts; 3080074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis return Offset; 3081074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis} 3082074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis 30831d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// \brief Write an UPDATE_VISIBLE block for the given context. 30841d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// 30851d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// UPDATE_VISIBLE blocks contain the declarations that are added to an existing 30861d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl/// DeclContext in a dependent AST file. As such, they only exist for the TU 3087c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith/// (in C++), for namespaces, and for classes with forward-declared unscoped 3088c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith/// enumeration members (in C++11). 30891d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redlvoid ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { 30901d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); 30911d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl if (!Map || Map->empty()) 30921d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl return; 30931d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 30941d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl OnDiskChainedHashTableGenerator<ASTDeclContextNameLookupTrait> Generator; 30951d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl ASTDeclContextNameLookupTrait Trait(*this); 30961d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 30971d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Create the hash table. 30981d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); 30991d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl D != DEnd; ++D) { 31001d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl DeclarationName Name = D->first; 31011d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl DeclContext::lookup_result Result = D->second.getLookupResult(); 31025967d6228f183a5fa384f2f1918df679ed2d8666Sebastian Redl // For any name that appears in this table, the results are complete, i.e. 31035967d6228f183a5fa384f2f1918df679ed2d8666Sebastian Redl // they overwrite results from previous PCHs. Merging is always a mess. 310445118d8f2b50a37472dd03cd1d5b4abd7ae9f25bArgyrios Kyrtzidis if (Result.first != Result.second) 310545118d8f2b50a37472dd03cd1d5b4abd7ae9f25bArgyrios Kyrtzidis Generator.insert(Name, Result, Trait); 31061d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl } 31071d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 31081d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Create the on-disk hash table in a buffer. 3109f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<4096> LookupTable; 31101d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl uint32_t BucketOffset; 31111d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl { 31121d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl llvm::raw_svector_ostream Out(LookupTable); 31131d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Make sure that no bucket is at offset 0 31141d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl clang::io::Emit32(Out, 0); 31151d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl BucketOffset = Generator.Emit(Out, Trait); 31161d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl } 31171d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 31181d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl // Write the lookup table 31191d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl RecordData Record; 31201d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Record.push_back(UPDATE_VISIBLE); 31211d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Record.push_back(getDeclID(cast<Decl>(DC))); 31221d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Record.push_back(BucketOffset); 31231d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable.str()); 31241d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl} 31251d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 312684bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne/// \brief Write an FP_PRAGMA_OPTIONS block for the given FPOptions. 312784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbournevoid ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { 312884bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RecordData Record; 312984bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Record.push_back(Opts.fp_contract); 313084bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); 313184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne} 313284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 313384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne/// \brief Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. 313484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbournevoid ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { 31354e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!SemaRef.Context.getLangOpts().OpenCL) 313684bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne return; 313784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 313884bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); 313984bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne RecordData Record; 314084bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne#define OPENCLEXT(nm) Record.push_back(Opts.nm); 314184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne#include "clang/Basic/OpenCLExtensions.def" 314284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne Stream.EmitRecord(OPENCL_EXTENSIONS, Record); 314384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne} 314484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne 31452171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregorvoid ASTWriter::WriteRedeclarations() { 31462171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor RecordData LocalRedeclChains; 31472171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor SmallVector<serialization::LocalRedeclarationsInfo, 2> LocalRedeclsMap; 31482171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31492171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor for (unsigned I = 0, N = Redeclarations.size(); I != N; ++I) { 31502171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Decl *First = Redeclarations[I]; 31512171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor assert(First->getPreviousDecl() == 0 && "Not the first declaration?"); 31522171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31532171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Decl *MostRecent = First->getMostRecentDecl(); 31542171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31552171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // If we only have a single declaration, there is no point in storing 31562171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // a redeclaration chain. 31572171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor if (First == MostRecent) 31582171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor continue; 31592171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31602171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor unsigned Offset = LocalRedeclChains.size(); 31612171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor unsigned Size = 0; 31622171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor LocalRedeclChains.push_back(0); // Placeholder for the size. 31632171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31642171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // Collect the set of local redeclarations of this declaration. 31652171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor for (Decl *Prev = MostRecent; Prev != First; 31662171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Prev = Prev->getPreviousDecl()) { 31672171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor if (!Prev->isFromASTFile()) { 31682171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor AddDeclRef(Prev, LocalRedeclChains); 31692171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor ++Size; 31702171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor } 31712171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor } 31722171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor LocalRedeclChains[Offset] = Size; 31732171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31742171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // Reverse the set of local redeclarations, so that we store them in 31752171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // order (since we found them in reverse order). 31762171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor std::reverse(LocalRedeclChains.end() - Size, LocalRedeclChains.end()); 31772171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31782171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // Add the mapping from the first ID to the set of local declarations. 31792171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor LocalRedeclarationsInfo Info = { getDeclID(First), Offset }; 31802171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor LocalRedeclsMap.push_back(Info); 31812171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31822171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor assert(N == Redeclarations.size() && 31832171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor "Deserialized a declaration we shouldn't have"); 31842171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor } 31852171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31862171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor if (LocalRedeclChains.empty()) 31872171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor return; 31882171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31892171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // Sort the local redeclarations map by the first declaration ID, 31902171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // since the reader will be performing binary searches on this information. 31912171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor llvm::array_pod_sort(LocalRedeclsMap.begin(), LocalRedeclsMap.end()); 31922171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 31932171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // Emit the local redeclarations map. 31942171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor using namespace llvm; 31952171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 31962171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(LOCAL_REDECLARATIONS_MAP)); 31972171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries 31982171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 31992171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); 32002171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 32012171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor RecordData Record; 32022171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Record.push_back(LOCAL_REDECLARATIONS_MAP); 32032171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Record.push_back(LocalRedeclsMap.size()); 32042171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Stream.EmitRecordWithBlob(AbbrevID, Record, 32052171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor reinterpret_cast<char*>(LocalRedeclsMap.data()), 32062171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor LocalRedeclsMap.size() * sizeof(LocalRedeclarationsInfo)); 32072171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 32082171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor // Emit the redeclaration chains. 32092171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedeclChains); 32102171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor} 32112171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor 3212cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregorvoid ASTWriter::WriteObjCCategories() { 3213cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor llvm::SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; 3214cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor RecordData Categories; 3215cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3216cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { 3217cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor unsigned Size = 0; 3218cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor unsigned StartIndex = Categories.size(); 3219cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3220cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; 3221cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3222cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor // Allocate space for the size. 3223cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Categories.push_back(0); 3224cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3225cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor // Add the categories. 3226cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor for (ObjCCategoryDecl *Cat = Class->getCategoryList(); 3227cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Cat; Cat = Cat->getNextClassCategory(), ++Size) { 3228cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor assert(getDeclID(Cat) != 0 && "Bogus category"); 3229cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor AddDeclRef(Cat, Categories); 3230cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor } 3231cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3232cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor // Update the size. 3233cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Categories[StartIndex] = Size; 3234cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3235cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor // Record this interface -> category map. 3236cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; 3237cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor CategoriesMap.push_back(CatInfo); 3238cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor } 3239cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3240cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor // Sort the categories map by the definition ID, since the reader will be 3241cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor // performing binary searches on this information. 3242cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); 3243cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3244cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor // Emit the categories map. 3245cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor using namespace llvm; 3246cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 3247cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); 3248cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries 3249cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 3250cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor unsigned AbbrevID = Stream.EmitAbbrev(Abbrev); 3251cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3252cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor RecordData Record; 3253cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Record.push_back(OBJC_CATEGORIES_MAP); 3254cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Record.push_back(CategoriesMap.size()); 3255cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Stream.EmitRecordWithBlob(AbbrevID, Record, 3256cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor reinterpret_cast<char*>(CategoriesMap.data()), 3257cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); 3258cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3259cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor // Emit the category lists. 3260cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor Stream.EmitRecord(OBJC_CATEGORIES, Categories); 3261cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor} 3262cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 3263c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregorvoid ASTWriter::WriteMergedDecls() { 3264c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor if (!Chain || Chain->MergedDecls.empty()) 3265c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor return; 3266c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor 3267c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor RecordData Record; 3268c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor for (ASTReader::MergedDeclsMap::iterator I = Chain->MergedDecls.begin(), 3269c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor IEnd = Chain->MergedDecls.end(); 3270c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor I != IEnd; ++I) { 3271b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor DeclID CanonID = I->first->isFromASTFile()? I->first->getGlobalID() 3272c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor : getDeclID(I->first); 3273c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor assert(CanonID && "Merged declaration not known?"); 3274c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor 3275c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor Record.push_back(CanonID); 3276c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor Record.push_back(I->second.size()); 3277c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor Record.append(I->second.begin(), I->second.end()); 3278c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor } 3279c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor Stream.EmitRecord(MERGED_DECLARATIONS, Record); 3280c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor} 3281c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor 32825d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 32834fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor// General Serialization Routines 32844fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor//===----------------------------------------------------------------------===// 32854fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor 328668a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor/// \brief Write a record containing the given attributes. 32874990890fc9428f98bef90ba349203a648c592778Alexander Kornienkovoid ASTWriter::WriteAttributes(ArrayRef<const Attr*> Attrs, 32884990890fc9428f98bef90ba349203a648c592778Alexander Kornienko RecordDataImpl &Record) { 32894eb9fc0449ddbd5239ddc3ae6b6e52880f47dcf7Argyrios Kyrtzidis Record.push_back(Attrs.size()); 32904990890fc9428f98bef90ba349203a648c592778Alexander Kornienko for (ArrayRef<const Attr *>::iterator i = Attrs.begin(), 32914990890fc9428f98bef90ba349203a648c592778Alexander Kornienko e = Attrs.end(); i != e; ++i){ 32924990890fc9428f98bef90ba349203a648c592778Alexander Kornienko const Attr *A = *i; 3293cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs 3294768d6cae40ad4ff3aed5483269d068ff7a45e229Argyrios Kyrtzidis AddSourceRange(A->getRange(), Record); 329568a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor 3296cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt#include "clang/Serialization/AttrPCHWrite.inc" 32975b160927672440076aa53c31d84149f70fd8d40eFariborz Jahanian 329868a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor } 329968a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor} 330068a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor 33015f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { 330268a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor Record.push_back(Str.size()); 330368a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor Record.insert(Record.end(), Str.begin(), Str.end()); 330468a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor} 330568a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor 33060a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregorvoid ASTWriter::AddVersionTuple(const VersionTuple &Version, 33070a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor RecordDataImpl &Record) { 33080a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(Version.getMajor()); 33090a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor if (llvm::Optional<unsigned> Minor = Version.getMinor()) 33100a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(*Minor + 1); 33110a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor else 33120a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(0); 33130a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor if (llvm::Optional<unsigned> Subminor = Version.getSubminor()) 33140a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(*Subminor + 1); 33150a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor else 33160a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor Record.push_back(0); 33170a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor} 33180a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 33193251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor/// \brief Note that the identifier II occurs at the given offset 33203251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor/// within the identifier table. 3321a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { 33228538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID ID = IdentifierIDs[II]; 33233397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Only store offsets new to this AST file. Other identifier names are looked 3324f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl // up earlier in the chain and thus don't need an offset. 3325f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl if (ID >= FirstIdentID) 3326f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl IdentifierOffsets[ID - FirstIdentID] = Offset; 33273251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor} 33283251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 332983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor/// \brief Note that the selector Sel occurs at the given offset 333083941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor/// within the method pool/selector table. 3331a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { 333283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor unsigned ID = SelectorIDs[Sel]; 333383941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor assert(ID && "Unknown selector"); 3334e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // Don't record offsets for selectors that are also available in a different 3335e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // file. 3336e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (ID < FirstSelectorID) 3337e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl return; 3338e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl SelectorOffsets[ID - FirstSelectorID] = Offset; 333983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor} 334083941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor 3341a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian RedlASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) 3342e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor : Stream(Stream), Context(0), PP(0), Chain(0), WritingModule(0), 33437518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis WritingAST(false), DoneWritingDeclsAndTypes(false), 33447518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis ASTHasCompilerErrors(false), 33450a14e4bf604a91b035a479235adf4c2f6c9128a2Douglas Gregor FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), 33468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), 3347a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), 3348a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor FirstMacroID(NUM_PREDEF_MACRO_IDS), NextMacroID(FirstMacroID), 334926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor FirstSubmoduleID(NUM_PREDEF_SUBMODULE_IDS), 335026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor NextSubmoduleID(FirstSubmoduleID), 3351b18b1fd33f958264630fbae2602c81275bae8c9aDouglas Gregor FirstSelectorID(NUM_PREDEF_SELECTOR_IDS), NextSelectorID(FirstSelectorID), 335277424bc3794f569816dba52e423b57486a98e5baDouglas Gregor CollectedStmts(&StmtsToEmit), 3353e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), 3354a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor NumVisibleDeclContexts(0), 3355e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor NextCXXBaseSpecifiersID(1), 3356953c564288f2f376fed9c3540096bde3694bbb7aJonathan D. Turner DeclParmVarAbbrev(0), DeclContextLexicalAbbrev(0), 3357a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor DeclContextVisibleLookupAbbrev(0), UpdateVisibleAbbrev(0), 3358a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor DeclRefExprAbbrev(0), CharacterLiteralAbbrev(0), 3359a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor DeclRecordAbbrev(0), IntegerLiteralAbbrev(0), 3360953c564288f2f376fed9c3540096bde3694bbb7aJonathan D. Turner DeclTypedefAbbrev(0), 3361953c564288f2f376fed9c3540096bde3694bbb7aJonathan D. Turner DeclVarAbbrev(0), DeclFieldAbbrev(0), 3362953c564288f2f376fed9c3540096bde3694bbb7aJonathan D. Turner DeclEnumAbbrev(0), DeclObjCIvarAbbrev(0) 33637c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor{ 336430c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl} 33652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 336610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios KyrtzidisASTWriter::~ASTWriter() { 336710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis for (FileDeclIDsTy::iterator 336810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis I = FileDeclIDs.begin(), E = FileDeclIDs.end(); I != E; ++I) 336910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis delete I->second; 337010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis} 337110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 33724182ed686283b72736b287cbe28583cb641f8934Argyrios Kyrtzidisvoid ASTWriter::WriteAST(Sema &SemaRef, 33738e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis const std::string &OutputFile, 3374bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis Module *WritingModule, StringRef isysroot, 3375bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis bool hasErrors) { 337661c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor WritingAST = true; 337761c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor 3378bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis ASTHasCompilerErrors = hasErrors; 3379bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis 33802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // Emit the file header. 3381c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'C', 8); 3382c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'P', 8); 3383c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'C', 8); 3384c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor Stream.Emit((unsigned)'H', 8); 33851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3386b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner WriteBlockInfoBlock(); 33872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 33883b8043b49aff6e5d70f29ef5684214ce2473763cDouglas Gregor Context = &SemaRef.Context; 3389185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor PP = &SemaRef.PP; 3390e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor this->WritingModule = WritingModule; 33914182ed686283b72736b287cbe28583cb641f8934Argyrios Kyrtzidis WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); 33923b8043b49aff6e5d70f29ef5684214ce2473763cDouglas Gregor Context = 0; 3393185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor PP = 0; 3394e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor this->WritingModule = 0; 339561c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor 339661c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor WritingAST = false; 33971dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl} 33981dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 3399a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregortemplate<typename Vector> 3400a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregorstatic void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, 3401a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor ASTWriter::RecordData &Record) { 3402a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor for (typename Vector::iterator I = Vec.begin(0, true), E = Vec.end(); 3403a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor I != E; ++I) { 3404a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor Writer.AddDeclRef(*I, Record); 3405a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor } 3406a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor} 3407a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor 34084182ed686283b72736b287cbe28583cb641f8934Argyrios Kyrtzidisvoid ASTWriter::WriteASTCore(Sema &SemaRef, 3409832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor StringRef isysroot, 3410a8cc6ce36e70e2afa22ab6b4340035cb3941c2ebDouglas Gregor const std::string &OutputFile, 34111a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor Module *WritingModule) { 34121dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl using namespace llvm; 34131dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 3414ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor // Make sure that the AST reader knows to finalize itself. 3415ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor if (Chain) 3416ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor Chain->finalizeForWriting(); 3417ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor 34181dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl ASTContext &Context = SemaRef.Context; 34191dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Preprocessor &PP = SemaRef.PP; 34201dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 34216bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor // Set up predefined declaration IDs. 34226bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; 34234dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor if (Context.ObjCIdDecl) 34244dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID; 34257a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor if (Context.ObjCSelDecl) 34267a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID; 342779d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor if (Context.ObjCClassDecl) 342879d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID; 3429a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor if (Context.ObjCProtocolClassDecl) 3430a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor DeclIDs[Context.ObjCProtocolClassDecl] = PREDEF_DECL_OBJC_PROTOCOL_ID; 3431772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor if (Context.Int128Decl) 3432772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor DeclIDs[Context.Int128Decl] = PREDEF_DECL_INT_128_ID; 3433772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor if (Context.UInt128Decl) 3434772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor DeclIDs[Context.UInt128Decl] = PREDEF_DECL_UNSIGNED_INT_128_ID; 3435e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor if (Context.ObjCInstanceTypeDecl) 3436e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor DeclIDs[Context.ObjCInstanceTypeDecl] = PREDEF_DECL_OBJC_INSTANCETYPE_ID; 3437c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge if (Context.BuiltinVaListDecl) 3438c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge DeclIDs[Context.getBuiltinVaListDecl()] = PREDEF_DECL_BUILTIN_VA_LIST_ID; 3439c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 3440b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor if (!Chain) { 3441b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // Make sure that we emit IdentifierInfos (and any attached 3442b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // declarations) for builtins. We don't need to do this when we're 3443b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // emitting chained PCH files, because all of the builtins will be 3444b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // in the original PCH file. 3445b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // FIXME: Modules won't like this at all. 34462deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor IdentifierTable &Table = PP.getIdentifierTable(); 34475f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<const char *, 32> BuiltinNames; 34482deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, 34494e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie Context.getLangOpts().NoBuiltin); 34502deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) 34512deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor getIdentifierRef(&Table.get(BuiltinNames[I])); 34522deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor } 34532deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor 3454eee242ff426bf79149f221798966e58688383c1eDouglas Gregor // If there are any out-of-date identifiers, bring them up to date. 3455eee242ff426bf79149f221798966e58688383c1eDouglas Gregor if (ExternalPreprocessorSource *ExtSource = PP.getExternalSource()) { 3456eee242ff426bf79149f221798966e58688383c1eDouglas Gregor for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), 3457eee242ff426bf79149f221798966e58688383c1eDouglas Gregor IDEnd = PP.getIdentifierTable().end(); 3458eee242ff426bf79149f221798966e58688383c1eDouglas Gregor ID != IDEnd; ++ID) 3459eee242ff426bf79149f221798966e58688383c1eDouglas Gregor if (ID->second->isOutOfDate()) 3460eee242ff426bf79149f221798966e58688383c1eDouglas Gregor ExtSource->updateOutOfDateIdentifier(*ID->second); 3461eee242ff426bf79149f221798966e58688383c1eDouglas Gregor } 3462eee242ff426bf79149f221798966e58688383c1eDouglas Gregor 346363d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner // Build a record containing all of the tentative definitions in this file, in 3464e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // TentativeDefinitions order. Generally, this record will be empty for 346563d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner // headers. 34664c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor RecordData TentativeDefinitions; 3467a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); 3468a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor 346949b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Build a record containing all of the file scoped decls in this file. 347049b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis RecordData UnusedFileScopedDecls; 3471a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, 3472a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor UnusedFileScopedDecls); 34734056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 3474b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // Build a record containing all of the delegating constructors we still need 3475b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // to resolve. 3476ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt RecordData DelegatingCtorDecls; 34770129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); 3478ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt 3479b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // Write the set of weak, undeclared identifiers. We always write the 3480b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // entire table, since later PCH files in a PCH chain are only interested in 3481b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // the results at the end of the chain. 348272b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis RecordData WeakUndeclaredIdentifiers; 348372b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis if (!SemaRef.WeakUndeclaredIdentifiers.empty()) { 348431e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor for (llvm::DenseMap<IdentifierInfo*,WeakInfo>::iterator 348572b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis I = SemaRef.WeakUndeclaredIdentifiers.begin(), 348672b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis E = SemaRef.WeakUndeclaredIdentifiers.end(); I != E; ++I) { 348772b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis AddIdentifierRef(I->first, WeakUndeclaredIdentifiers); 348872b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis AddIdentifierRef(I->second.getAlias(), WeakUndeclaredIdentifiers); 348972b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis AddSourceLocation(I->second.getLocation(), WeakUndeclaredIdentifiers); 349072b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis WeakUndeclaredIdentifiers.push_back(I->second.getUsed()); 349172b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis } 349272b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis } 349311a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 349414c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // Build a record containing all of the locally-scoped external 349514c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // declarations in this header file. Generally, this record will be 349614c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor // empty. 349714c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor RecordData LocallyScopedExternalDecls; 34983397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // FIXME: This is filling in the AST file in densemap order which is 349963d65f873fdfcb04b216ea9c648d1df5992aed1cChris Lattner // nondeterminstic! 35001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator 350114c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor TD = SemaRef.LocallyScopedExternalDecls.begin(), 350214c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor TDEnd = SemaRef.LocallyScopedExternalDecls.end(); 3503ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor TD != TDEnd; ++TD) { 3504919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!TD->second->isFromASTFile()) 3505ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor AddDeclRef(TD->second, LocallyScopedExternalDecls); 3506ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor } 3507ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor 3508b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor // Build a record containing all of the ext_vector declarations. 3509b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor RecordData ExtVectorDecls; 3510d58a0a55e64a7c410a80e9d6dcd899e61e99cc4dDouglas Gregor AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); 3511b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor 3512d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Build a record containing all of the VTable uses information. 3513d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis RecordData VTableUses; 3514be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis if (!SemaRef.VTableUses.empty()) { 3515be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { 3516be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); 3517be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); 3518be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); 3519be4ebcdaa03a84d915b37f96d241b74eece67c92Argyrios Kyrtzidis } 3520d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis } 3521d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 3522d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis // Build a record containing all of dynamic classes declarations. 3523d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis RecordData DynamicClasses; 3524a126f17ca83b985300c1f65cee647bea108db657Douglas Gregor AddLazyVectorDecls(*this, SemaRef.DynamicClasses, DynamicClasses); 3525d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis 35260e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis // Build a record containing all of pending implicit instantiations. 352762c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth RecordData PendingInstantiations; 35280e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis for (std::deque<Sema::PendingImplicitInstantiation>::iterator 352962c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth I = SemaRef.PendingInstantiations.begin(), 353062c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth N = SemaRef.PendingInstantiations.end(); I != N; ++I) { 353162c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth AddDeclRef(I->first, PendingInstantiations); 353262c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth AddSourceLocation(I->second, PendingInstantiations); 35330e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis } 35340e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis assert(SemaRef.PendingLocalImplicitInstantiations.empty() && 35350e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis "There are local ones at end of translation unit!"); 35360e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis 353776c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis // Build a record containing some declaration references. 353876c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis RecordData SemaDeclRefs; 353976c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis if (SemaRef.StdNamespace || SemaRef.StdBadAlloc) { 354076c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); 354176c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); 354276c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis } 354376c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis 354414b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne RecordData CUDASpecialDeclRefs; 354514b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne if (Context.getcudaConfigureCallDecl()) { 354614b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); 354714b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne } 354814b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne 3549d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor // Build a record containing all of the known namespaces. 3550d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor RecordData KnownNamespaces; 3551d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor for (llvm::DenseMap<NamespaceDecl*, bool>::iterator 3552d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor I = SemaRef.KnownNamespaces.begin(), 3553d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor IEnd = SemaRef.KnownNamespaces.end(); 3554d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor I != IEnd; ++I) { 3555d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor if (!I->second) 3556d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor AddDeclRef(I->first, KnownNamespaces); 3557d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor } 35581d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor 35591d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor // Write the control block 3560bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor WriteControlBlock(PP, Context, isysroot, OutputFile); 35611d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor 35623397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl // Write the remaining AST contents. 3563ad1de006ea080b540e480efc6b86c2e201dbf1ecDouglas Gregor RecordData Record; 35648538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EnterSubblock(AST_BLOCK_ID, 5); 35651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3566b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // Create a lexical update block containing all of the declarations in the 3567b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // translation unit that do not come from other AST files. 35686bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); 35696bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor SmallVector<KindDeclIDPair, 64> NewGlobalDecls; 35706bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor for (DeclContext::decl_iterator I = TU->noload_decls_begin(), 3571b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor E = TU->noload_decls_end(); 35726bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor I != E; ++I) { 3573919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!(*I)->isFromASTFile()) 35746bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I))); 35756bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor } 3576b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor 35776bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev(); 35786bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); 35796bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); 35806bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv); 35816bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Record.clear(); 35826bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Record.push_back(TU_UPDATE_LEXICAL); 35836bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, 35846bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor data(NewGlobalDecls)); 35856bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor 3586b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // And a visible updates block for the translation unit. 35876bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Abv = new llvm::BitCodeAbbrev(); 35886bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); 35896bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); 35906bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, 32)); 35916bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); 35926bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor UpdateVisibleAbbrev = Stream.EmitAbbrev(Abv); 35936bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor WriteDeclContextVisibleUpdate(TU); 35946bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor 3595b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // If the translation unit has an anonymous namespace, and we don't already 3596b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // have an update block for it, write it as an update block. 35976bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { 35986bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; 3599b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor if (Record.empty()) { 3600b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE); 360161c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor Record.push_back(reinterpret_cast<uint64_t>(NS)); 3602b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor } 36036bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor } 36047518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis 36057518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis // Make sure visible decls, added to DeclContexts previously loaded from 36067518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis // an AST file, are registered for serialization. 36077518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis for (SmallVector<const Decl *, 16>::iterator 36087518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis I = UpdatingVisibleDecls.begin(), 36097518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis E = UpdatingVisibleDecls.end(); I != E; ++I) { 36107518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis GetDeclRef(*I); 36117518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis } 36127518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis 361367bc4ba9894506c461aeff11302c2d2471b82273Argyrios Kyrtzidis // Resolve any declaration pointers within the declaration updates block. 361461c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor ResolveDeclUpdatesBlocks(); 361561c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor 3616b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // Form the record of special types. 3617b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor RecordData SpecialTypes; 3618b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); 3619b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor AddTypeRef(Context.getFILEType(), SpecialTypes); 3620b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor AddTypeRef(Context.getjmp_bufType(), SpecialTypes); 3621b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); 3622b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); 3623b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); 3624b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); 3625e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola AddTypeRef(Context.getucontext_tType(), SpecialTypes); 3626185dbd7782a45d0f830218bfbc196c6b664ed8d9Douglas Gregor 3627366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor // Keep writing types and declarations until all types and 3628366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor // declarations have been written. 3629a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); 363061d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor WriteDeclsBlockAbbrevs(); 3631b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), 3632b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor E = DeclsToRewrite.end(); 3633b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor I != E; ++I) 3634b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor DeclTypesToEmit.push(const_cast<Decl*>(*I)); 363561d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor while (!DeclTypesToEmit.empty()) { 363661d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclOrType DOT = DeclTypesToEmit.front(); 363761d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.pop(); 363861d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor if (DOT.isType()) 363961d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor WriteType(DOT.getType()); 364061d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor else 364161d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor WriteDecl(Context, DOT.getDecl()); 364261d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor } 364361d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor Stream.ExitBlock(); 364411a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam 36457518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis DoneWritingDeclsAndTypes = true; 36467518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis 364710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis WriteFileDeclIDsMap(); 364810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); 3649aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko WriteComments(); 365010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 365110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis if (Chain) { 365210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // Write the mapping information describing our module dependencies and how 365310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // each of those modules were mapped into our own offset/ID space, so that 365410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // the reader can build the appropriate mapping to its own offset/ID space. 365510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // The map consists solely of a blob with the following format: 365610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // *(module-name-len:i16 module-name:len*i8 365710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // source-location-offset:i32 365810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // identifier-id:i32 365910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // preprocessed-entity-id:i32 366010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // macro-definition-id:i32 366126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor // submodule-id:i32 366210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // selector-id:i32 366310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // declaration-id:i32 366410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // c++-base-specifiers-id:i32 366510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // type-id:i32) 366610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // 366710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); 366810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); 366910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 367010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev); 3671f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<2048> Buffer; 367210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis { 367310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis llvm::raw_svector_ostream Out(Buffer); 367410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), 3675af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor MEnd = Chain->ModuleMgr.end(); 367610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis M != MEnd; ++M) { 367710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis StringRef FileName = (*M)->FileName; 367810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis io::Emit16(Out, FileName.size()); 367910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Out.write(FileName.data(), FileName.size()); 368010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis io::Emit32(Out, (*M)->SLocEntryBaseOffset); 368110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis io::Emit32(Out, (*M)->BaseIdentifierID); 3682a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor io::Emit32(Out, (*M)->BaseMacroID); 368310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis io::Emit32(Out, (*M)->BasePreprocessedEntityID); 368426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor io::Emit32(Out, (*M)->BaseSubmoduleID); 368510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis io::Emit32(Out, (*M)->BaseSelectorID); 368610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis io::Emit32(Out, (*M)->BaseDeclID); 368710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis io::Emit32(Out, (*M)->BaseTypeIndex); 368810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis } 368910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis } 369010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Record.clear(); 369110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Record.push_back(MODULE_OFFSET_MAP); 369210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, 369310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Buffer.data(), Buffer.size()); 369410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis } 3695a8cc6ce36e70e2afa22ab6b4340035cb3941c2ebDouglas Gregor WritePreprocessor(PP, WritingModule != 0); 3696cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); 3697059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl WriteSelectors(SemaRef); 3698320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian WriteReferencedSelectorsPool(SemaRef); 3699a8cc6ce36e70e2afa22ab6b4340035cb3941c2ebDouglas Gregor WriteIdentifierTable(PP, SemaRef.IdResolver, WritingModule != 0); 370084bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteFPPragmaOptions(SemaRef.getFPOptions()); 370184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne WriteOpenCLExtensions(SemaRef); 37028f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor 37031476ed40ef6ef144937821da888c7e4d9ea0acd7Sebastian Redl WriteTypeDeclOffsets(); 37043efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis WritePragmaDiagnosticMappings(Context.getDiagnostics()); 3705ad1de006ea080b540e480efc6b86c2e201dbf1ecDouglas Gregor 3706c850578dbfa68cf2d2776f59a5cb0009134d970eAnders Carlsson WriteCXXBaseSpecifiersOffsets(); 37077c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 3708e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor // If we're emitting a module, write out the submodule information. 3709e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor if (WritingModule) 3710e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor WriteSubmodules(WritingModule); 3711e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor 3712a119da0761cb6b85f53857eaee50f6ad8c5ea0a0Douglas Gregor Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); 3713a119da0761cb6b85f53857eaee50f6ad8c5ea0a0Douglas Gregor 3714083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing external, unnamed definitions. 3715083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!ExternalDefinitions.empty()) 37168538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); 3717083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3718083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing tentative definitions. 3719083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!TentativeDefinitions.empty()) 37208538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); 3721083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 372249b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis // Write the record containing unused file scoped decls. 372349b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis if (!UnusedFileScopedDecls.empty()) 37248538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); 3725083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 37264056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing weak undeclared identifiers. 37274056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!WeakUndeclaredIdentifiers.empty()) 37288538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, 37294056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl WeakUndeclaredIdentifiers); 37304056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 3731083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing locally-scoped external definitions. 3732083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!LocallyScopedExternalDecls.empty()) 37338538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(LOCALLY_SCOPED_EXTERNAL_DECLS, 3734083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl LocallyScopedExternalDecls); 3735083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3736083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl // Write the record containing ext_vector type names. 3737083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl if (!ExtVectorDecls.empty()) 37388538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); 3739083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 37404056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing VTable uses information. 37414056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!VTableUses.empty()) 37428538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(VTABLE_USES, VTableUses); 37434056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 37444056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing dynamic classes declarations. 37454056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!DynamicClasses.empty()) 37468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(DYNAMIC_CLASSES, DynamicClasses); 37474056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 37484056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing pending implicit instantiations. 374962c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth if (!PendingInstantiations.empty()) 375062c78d54bee499dd87f768f48b21c9b5ec15e516Chandler Carruth Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); 37514056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl 37524056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl // Write the record containing declaration references of Sema. 37534056680e3c154ef84874410eba55323f9b07aad6Sebastian Redl if (!SemaDeclRefs.empty()) 37548538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); 3755b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor 3756b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // Write the record containing CUDA-specific declaration references. 3757b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor if (!CUDASpecialDeclRefs.empty()) 3758b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); 3759ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt 3760ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt // Write the delegating constructors. 3761ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt if (!DelegatingCtorDecls.empty()) 3762ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); 3763083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl 3764b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // Write the known namespaces. 3765b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor if (!KnownNamespaces.empty()) 3766b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); 3767b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor 3768b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // Write the visible updates to DeclContexts. 3769100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator 3770b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor I = UpdatedDeclContexts.begin(), 3771b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor E = UpdatedDeclContexts.end(); 3772b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor I != E; ++I) 37731d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl WriteDeclContextVisibleUpdate(*I); 37741d1e42b17da6a53391d50b08068ecde04311e368Sebastian Redl 3775c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor if (!WritingModule) { 3776c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor // Write the submodules that were imported, if any. 3777c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor RecordData ImportedModules; 3778c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor for (ASTContext::import_iterator I = Context.local_import_begin(), 3779c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor IEnd = Context.local_import_end(); 3780c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor I != IEnd; ++I) { 3781c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); 3782c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor ImportedModules.push_back(SubmoduleIDs[I->getImportedModule()]); 3783c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor } 3784c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor if (!ImportedModules.empty()) { 3785c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor // Sort module IDs. 3786c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor llvm::array_pod_sort(ImportedModules.begin(), ImportedModules.end()); 3787c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor 3788c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor // Unique module IDs. 3789c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor ImportedModules.erase(std::unique(ImportedModules.begin(), 3790c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor ImportedModules.end()), 3791c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor ImportedModules.end()); 3792c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor 3793c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); 3794c5e0f9b44782204437de21594c1748b1405d90bcDouglas Gregor } 3795f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor } 3796a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 3797a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor WriteMacroUpdates(); 3798aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidis WriteDeclUpdatesBlocks(); 3799b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor WriteDeclReplacementsBlock(); 3800c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor WriteMergedDecls(); 38012171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor WriteRedeclarations(); 3802cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor WriteObjCCategories(); 3803a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor 3804b7c324f8581a55e2a918e5f3eb2e7418b09df0f2Douglas Gregor // Some simple statistics 3805083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.clear(); 3806083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumStatements); 3807083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumMacros); 3808083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumLexicalDeclContexts); 3809083abdf67f157e9d2ab5a8c9d5e71240479d3c99Sebastian Redl Record.push_back(NumVisibleDeclContexts); 38108538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(STATISTICS, Record); 38111dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl Stream.ExitBlock(); 38121dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl} 38131dc13a15e789a174e5e5855efe27036dd7a9d252Sebastian Redl 3814a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregorvoid ASTWriter::WriteMacroUpdates() { 3815a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor if (MacroUpdates.empty()) 3816a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor return; 3817a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 3818a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor RecordData Record; 3819a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor for (MacroUpdatesMap::iterator I = MacroUpdates.begin(), 3820a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor E = MacroUpdates.end(); 3821a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor I != E; ++I) { 3822a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor addMacroRef(I->first, Record); 3823a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor AddSourceLocation(I->second.UndefLoc, Record); 382454c8a40ed658676b1f3f983728feae488c501477Douglas Gregor Record.push_back(inferSubmoduleIDFromLocation(I->second.UndefLoc)); 3825a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor } 3826a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Stream.EmitRecord(MACRO_UPDATES, Record); 3827a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor} 3828a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 382961c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor/// \brief Go through the declaration update blocks and resolve declaration 383061c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor/// pointers into declaration IDs. 383161c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregorvoid ASTWriter::ResolveDeclUpdatesBlocks() { 383261c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor for (DeclUpdateMap::iterator 383361c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { 383461c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor const Decl *D = I->first; 383561c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor UpdateRecord &URec = I->second; 383661c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor 3837ad834d534e9a5db3d3baa09593775f83ceaff1f2Argyrios Kyrtzidis if (isRewritten(D)) 383861c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor continue; // The decl will be written completely 383961c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor 384061c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor unsigned Idx = 0, N = URec.size(); 384161c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor while (Idx < N) { 384261c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor switch ((DeclUpdateKind)URec[Idx++]) { 384361c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor case UPD_CXX_ADDED_IMPLICIT_MEMBER: 384461c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: 384561c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: 384661c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor URec[Idx] = GetDeclRef(reinterpret_cast<Decl *>(URec[Idx])); 384761c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor ++Idx; 384861c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor break; 384961c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor 385061c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: 385161c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor ++Idx; 385261c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor break; 385361c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor } 385461c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor } 385561c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor } 385661c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor} 385761c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor 3858aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidisvoid ASTWriter::WriteDeclUpdatesBlocks() { 38597b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis if (DeclUpdates.empty()) 38607b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis return; 38617b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 38627b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis RecordData OffsetsRecord; 3863a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); 38647b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis for (DeclUpdateMap::iterator 38657b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { 38667b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis const Decl *D = I->first; 38677b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis UpdateRecord &URec = I->second; 38687b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 3869ad834d534e9a5db3d3baa09593775f83ceaff1f2Argyrios Kyrtzidis if (isRewritten(D)) 3870ba901b507fc36408fe6f8478e8ac90b554f1d230Argyrios Kyrtzidis continue; // The decl will be written completely,no need to store updates. 3871ba901b507fc36408fe6f8478e8ac90b554f1d230Argyrios Kyrtzidis 38727b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis uint64_t Offset = Stream.GetCurrentBitNo(); 38737b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.EmitRecord(DECL_UPDATES, URec); 38747b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 38757b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis OffsetsRecord.push_back(GetDeclRef(D)); 38767b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis OffsetsRecord.push_back(Offset); 38777b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis } 38787b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.ExitBlock(); 38797b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); 38807b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis} 38817b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 3882aacdd02e5865aa410c1418d7ef77f445b5bb5cbaArgyrios Kyrtzidisvoid ASTWriter::WriteDeclReplacementsBlock() { 38830b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl if (ReplacedDecls.empty()) 38840b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl return; 38850b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 38860b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl RecordData Record; 3887ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis for (SmallVector<ReplacedDeclInfo, 16>::iterator 38880b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl I = ReplacedDecls.begin(), E = ReplacedDecls.end(); I != E; ++I) { 3889ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis Record.push_back(I->ID); 3890ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis Record.push_back(I->Offset); 3891ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis Record.push_back(I->Loc); 38920b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl } 38938538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl Stream.EmitRecord(DECL_REPLACEMENTS, Record); 38940b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl} 38950b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 389689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { 38972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Loc.getRawEncoding()); 38982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 38992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 390089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { 39016ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddSourceLocation(Range.getBegin(), Record); 39026ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddSourceLocation(Range.getEnd(), Record); 39036ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner} 39046ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 390589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddAPInt(const llvm::APInt &Value, RecordDataImpl &Record) { 39062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Value.getBitWidth()); 39074ea884b429445aa6f1af5bc6e51d0b65a4043e24Benjamin Kramer const uint64_t *Words = Value.getRawData(); 39084ea884b429445aa6f1af5bc6e51d0b65a4043e24Benjamin Kramer Record.append(Words, Words + Value.getNumWords()); 39092cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 39102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 391189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddAPSInt(const llvm::APSInt &Value, RecordDataImpl &Record) { 39120a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor Record.push_back(Value.isUnsigned()); 39130a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor AddAPInt(Value, Record); 39140a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor} 39150a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor 391689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddAPFloat(const llvm::APFloat &Value, RecordDataImpl &Record) { 391717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor AddAPInt(Value.bitcastToAPInt(), Record); 391817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor} 391917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 392089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { 39212deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor Record.push_back(getIdentifierRef(II)); 39222deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor} 39232deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor 3924a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregorvoid ASTWriter::addMacroRef(MacroInfo *MI, RecordDataImpl &Record) { 3925a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor Record.push_back(getMacroRef(MI)); 3926a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor} 3927a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 39288538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlIdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { 39292deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor if (II == 0) 39302deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor return 0; 3931afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor 39328538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl IdentID &ID = IdentifierIDs[II]; 3933afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor if (ID == 0) 3934f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl ID = NextIdentID++; 39352deaea37a637dd01221d0cced343702a39d8132cDouglas Gregor return ID; 39362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 39372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 3938a8235d6c4093cd38dcf742909651f867de62e55bDouglas GregorMacroID ASTWriter::getMacroRef(MacroInfo *MI) { 3939a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor // Don't emit builtin macros like __LINE__ to the AST file unless they 3940a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor // have been redefined by the header (in which case they are not 3941a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor // isBuiltinMacro). 3942a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor if (MI == 0 || MI->isBuiltinMacro()) 3943a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor return 0; 3944a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 3945a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor MacroID &ID = MacroIDs[MI]; 3946a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor if (ID == 0) 3947a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor ID = NextMacroID++; 3948a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor return ID; 3949a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor} 3950a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 395189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddSelectorRef(const Selector SelRef, RecordDataImpl &Record) { 39525d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl Record.push_back(getSelectorRef(SelRef)); 39535d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl} 39545d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl 39558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlSelectorID ASTWriter::getSelectorRef(Selector Sel) { 39565d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl if (Sel.getAsOpaquePtr() == 0) { 39575d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl return 0; 395890cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff } 395990cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff 39608538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl SelectorID &SID = SelectorIDs[Sel]; 3961e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl if (SID == 0 && Chain) { 3962e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // This might trigger a ReadSelector callback, which will set the ID for 3963e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl // this selector. 3964e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl Chain->LoadSelector(Sel); 3965e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl } 396690cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff if (SID == 0) { 3967e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl SID = NextSelectorID++; 396890cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff } 39695d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl return SID; 397090cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff} 397190cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff 397289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordDataImpl &Record) { 3973d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner AddDeclRef(Temp->getDestructor(), Record); 3974d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner} 3975d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner 39767c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregorvoid ASTWriter::AddCXXBaseSpecifiersRef(CXXBaseSpecifier const *Bases, 39777c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifier const *BasesEnd, 39787c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor RecordDataImpl &Record) { 39797c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor assert(Bases != BasesEnd && "Empty base-specifier sets are not recorded"); 39807c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersToWrite.push_back( 39817c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor QueuedCXXBaseSpecifiers(NextCXXBaseSpecifiersID, 39827c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Bases, BasesEnd)); 39837c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.push_back(NextCXXBaseSpecifiersID++); 39847c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor} 39857c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 3986a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind, 398744f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis const TemplateArgumentLocInfo &Arg, 398889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 398944f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis switch (Kind) { 3990833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 399144f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddStmt(Arg.getAsExpr()); 3992833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 3993833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 399444f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddTypeSourceInfo(Arg.getAsTypeSourceInfo(), Record); 3995833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 3996788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 3997b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); 399817cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis AddSourceLocation(Arg.getTemplateNameLoc(), Record); 3999a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 4000a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 4001b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc(), Record); 4002a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor AddSourceLocation(Arg.getTemplateNameLoc(), Record); 4003ba68eca7582a62e3e2ff4b0eba1b2b73a6b80895Douglas Gregor AddSourceLocation(Arg.getTemplateEllipsisLoc(), Record); 4004788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor break; 4005833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 4006833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 4007833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 4008d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman case TemplateArgument::NullPtr: 4009833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 4010d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman // FIXME: Is this right? 4011833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 4012833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 4013833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 4014833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 4015a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, 401689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 401744f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddTemplateArgument(Arg.getArgument(), Record); 401817cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis 401917cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis if (Arg.getArgument().getKind() == TemplateArgument::Expression) { 402017cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis bool InfoHasSameExpr 402117cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); 402217cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis Record.push_back(InfoHasSameExpr); 402317cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis if (InfoHasSameExpr) 402417cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis return; // Avoid storing the same expr twice. 402517cfdeda476aa8899f0ccedd9cb9cdb76e89b6b4Argyrios Kyrtzidis } 402644f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo(), 402744f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis Record); 402844f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis} 402944f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis 4030dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregorvoid ASTWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, 4031dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor RecordDataImpl &Record) { 4032a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall if (TInfo == 0) { 4033a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall AddTypeRef(QualType(), Record); 4034a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall return; 4035a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall } 4036a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 4037dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddTypeLoc(TInfo->getTypeLoc(), Record); 4038dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor} 4039dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 4040dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregorvoid ASTWriter::AddTypeLoc(TypeLoc TL, RecordDataImpl &Record) { 4041dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddTypeRef(TL.getType(), Record); 4042dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 4043a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall TypeLocWriter TLW(*this, Record); 4044dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor for (; !TL.isNull(); TL = TL.getNextTypeLoc()) 404511a18f115e8974ef24e8d5bb549ed3289871efa4Kovarththanan Rajaratnam TLW.Visit(TL); 4046a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall} 4047a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall 404889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { 40497fb35182f43392cea4517c203bbabb22364a19fcArgyrios Kyrtzidis Record.push_back(GetOrCreateTypeID(T)); 40507fb35182f43392cea4517c203bbabb22364a19fcArgyrios Kyrtzidis} 40517fb35182f43392cea4517c203bbabb22364a19fcArgyrios Kyrtzidis 40523b8043b49aff6e5d70f29ef5684214ce2473763cDouglas GregorTypeID ASTWriter::GetOrCreateTypeID( QualType T) { 40533b8043b49aff6e5d70f29ef5684214ce2473763cDouglas Gregor return MakeTypeID(*Context, T, 4054eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis std::bind1st(std::mem_fun(&ASTWriter::GetOrCreateTypeIdx), this)); 4055eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis} 40562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 40575d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios KyrtzidisTypeID ASTWriter::getTypeID(QualType T) const { 40583b8043b49aff6e5d70f29ef5684214ce2473763cDouglas Gregor return MakeTypeID(*Context, T, 4059eb3f04e60fa17dba27344ed89fd1b9134bb6839cArgyrios Kyrtzidis std::bind1st(std::mem_fun(&ASTWriter::getTypeIdx), this)); 406026fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis} 406126fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis 406226fca90786af17f97e1a5ecc310d4bf39b831595Argyrios KyrtzidisTypeIdx ASTWriter::GetOrCreateTypeIdx(QualType T) { 406326fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis if (T.isNull()) 406426fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis return TypeIdx(); 406526fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis assert(!T.getLocalFastQualifiers()); 406626fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis 406701b81c4d074bba9c18372d521405dfe32fc4f552Argyrios Kyrtzidis TypeIdx &Idx = TypeIdxs[T]; 4068c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis if (Idx.getIndex() == 0) { 40697518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis if (DoneWritingDeclsAndTypes) { 40707518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis assert(0 && "New type seen after serializing all the types to emit!"); 40717518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis return TypeIdx(); 40727518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis } 40737518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis 4074366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor // We haven't seen this type before. Assign it a new ID and put it 40750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into the queue of types to emit. 4076c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidis Idx = TypeIdx(NextTypeID++); 407761d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.push(T); 4078366809a4e9340b3458b471e2294a75a9f09ea304Douglas Gregor } 407926fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis return Idx; 408026fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis} 40812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 40825d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios KyrtzidisTypeIdx ASTWriter::getTypeIdx(QualType T) const { 408326fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis if (T.isNull()) 408426fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis return TypeIdx(); 408526fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis assert(!T.getLocalFastQualifiers()); 408626fca90786af17f97e1a5ecc310d4bf39b831595Argyrios Kyrtzidis 40875d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis TypeIdxMap::const_iterator I = TypeIdxs.find(T); 40885d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis assert(I != TypeIdxs.end() && "Type not emitted!"); 40895d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis return I->second; 40902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 40912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 40927b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisvoid ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { 4093681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl Record.push_back(GetDeclRef(D)); 4094681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl} 4095681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl 40968538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlDeclID ASTWriter::GetDeclRef(const Decl *D) { 409761c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor assert(WritingAST && "Cannot request a declaration ID before AST writing"); 409861c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor 40992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor if (D == 0) { 4100681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl return 0; 41012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 41021c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor 41031c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor // If D comes from an AST file, its declaration ID is already known and 41041c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor // fixed. 41051c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor if (D->isFromASTFile()) 41061c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor return D->getGlobalID(); 41071c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor 410897475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); 41098538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl DeclID &ID = DeclIDs[D]; 41101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (ID == 0) { 41117518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis if (DoneWritingDeclsAndTypes) { 41127518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis assert(0 && "New decl seen after serializing all the decls to emit!"); 41137518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis return 0; 41147518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis } 41157518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis 41162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // We haven't seen this declaration before. Give it a new ID and 41172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // enqueue it in the list of declarations to emit. 4118f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl ID = NextDeclID++; 411961d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor DeclTypesToEmit.push(const_cast<Decl *>(D)); 41202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 41212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 4122681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl return ID; 41232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 41242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 41258538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian RedlDeclID ASTWriter::getDeclID(const Decl *D) { 41263251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor if (D == 0) 41273251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor return 0; 41283251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 41291c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor // If D comes from an AST file, its declaration ID is already known and 41301c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor // fixed. 41311c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor if (D->isFromASTFile()) 41321c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor return D->getGlobalID(); 41331c7946a9fbba8671cc57f7dfd00721f8c035f913Douglas Gregor 41343251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); 41353251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor return DeclIDs[D]; 41363251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor} 41373251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor 413810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidisstatic inline bool compLocDecl(std::pair<unsigned, serialization::DeclID> L, 413910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis std::pair<unsigned, serialization::DeclID> R) { 414010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis return L.first < R.first; 414110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis} 414210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 414319645d2ae928580b62f9feff91c5aa5e19f5f20dArgyrios Kyrtzidisvoid ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { 414410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis assert(ID); 414519645d2ae928580b62f9feff91c5aa5e19f5f20dArgyrios Kyrtzidis assert(D); 414619645d2ae928580b62f9feff91c5aa5e19f5f20dArgyrios Kyrtzidis 414719645d2ae928580b62f9feff91c5aa5e19f5f20dArgyrios Kyrtzidis SourceLocation Loc = D->getLocation(); 414819645d2ae928580b62f9feff91c5aa5e19f5f20dArgyrios Kyrtzidis if (Loc.isInvalid()) 414919645d2ae928580b62f9feff91c5aa5e19f5f20dArgyrios Kyrtzidis return; 415010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 415110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis // We only keep track of the file-level declarations of each file. 415210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis if (!D->getLexicalDeclContext()->isFileContext()) 415310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis return; 415469015c22e1e3f96ff0e6e31965188e095297a744Argyrios Kyrtzidis // FIXME: ParmVarDecls that are part of a function type of a parameter of 415569015c22e1e3f96ff0e6e31965188e095297a744Argyrios Kyrtzidis // a function/objc method, should not have TU as lexical context. 41568cceefac395d476114b3d4ecd7e969b2e1c9271dArgyrios Kyrtzidis if (isa<ParmVarDecl>(D)) 41578cceefac395d476114b3d4ecd7e969b2e1c9271dArgyrios Kyrtzidis return; 415810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 415910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis SourceManager &SM = Context->getSourceManager(); 416019645d2ae928580b62f9feff91c5aa5e19f5f20dArgyrios Kyrtzidis SourceLocation FileLoc = SM.getFileLoc(Loc); 416110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis assert(SM.isLocalSourceLocation(FileLoc)); 4162fab8d5b478e6fb112b4414c4698a7cc2a350b0f0Argyrios Kyrtzidis FileID FID; 4163fab8d5b478e6fb112b4414c4698a7cc2a350b0f0Argyrios Kyrtzidis unsigned Offset; 4164fab8d5b478e6fb112b4414c4698a7cc2a350b0f0Argyrios Kyrtzidis llvm::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); 416510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis if (FID.isInvalid()) 416610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis return; 4167a2ea4d94f2133aad0d864cf1327af142a47ffb09Argyrios Kyrtzidis assert(SM.getSLocEntry(FID).isFile()); 416810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 4169a2ea4d94f2133aad0d864cf1327af142a47ffb09Argyrios Kyrtzidis DeclIDInFileInfo *&Info = FileDeclIDs[FID]; 417010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis if (!Info) 417110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Info = new DeclIDInFileInfo(); 417210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 4173fab8d5b478e6fb112b4414c4698a7cc2a350b0f0Argyrios Kyrtzidis std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); 417410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis LocDeclIDsTy &Decls = Info->DeclIDs; 417510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 4176fab8d5b478e6fb112b4414c4698a7cc2a350b0f0Argyrios Kyrtzidis if (Decls.empty() || Decls.back().first <= Offset) { 417710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Decls.push_back(LocDecl); 417810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis return; 417910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis } 418010f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 418110f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis LocDeclIDsTy::iterator 418210f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis I = std::upper_bound(Decls.begin(), Decls.end(), LocDecl, compLocDecl); 418310f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 418410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis Decls.insert(I, LocDecl); 418510f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis} 418610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis 418789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddDeclarationName(DeclarationName Name, RecordDataImpl &Record) { 4188ea5ce4705df0743093925585d8edc80e0d8fe3ffChris Lattner // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. 41892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Name.getNameKind()); 41902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor switch (Name.getNameKind()) { 41912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::Identifier: 41922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor AddIdentifierRef(Name.getAsIdentifierInfo(), Record); 41932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 41942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 41952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 41962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::ObjCOneArgSelector: 41972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 419890cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff AddSelectorRef(Name.getObjCSelector(), Record); 41992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 42002cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 42012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXConstructorName: 42022cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXDestructorName: 42032cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXConversionFunctionName: 42042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor AddTypeRef(Name.getCXXNameType(), Record); 42052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 42062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 42072cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXOperatorName: 42082cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor Record.push_back(Name.getCXXOverloadedOperator()); 42092cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 42102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 42113e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 42123e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); 42133e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt break; 42143e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 42152cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor case DeclarationName::CXXUsingDirective: 42162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor // No extra data to emit 42172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor break; 42182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 42192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 42206ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 42214045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidisvoid ASTWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, 422289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis DeclarationName Name, RecordDataImpl &Record) { 42234045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis switch (Name.getNameKind()) { 42244045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXConstructorName: 42254045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXDestructorName: 42264045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXConversionFunctionName: 42274045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddTypeSourceInfo(DNLoc.NamedType.TInfo, Record); 42284045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 42294045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 42304045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXOperatorName: 42314045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation( 42324045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.BeginOpNameLoc), 42334045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record); 42344045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation( 42354045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc), 42364045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record); 42374045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 42384045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 42394045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXLiteralOperatorName: 42404045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation( 42414045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis SourceLocation::getFromRawEncoding(DNLoc.CXXLiteralOperatorName.OpNameLoc), 42424045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record); 42434045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 42444045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 42454045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::Identifier: 42464045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::ObjCZeroArgSelector: 42474045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::ObjCOneArgSelector: 42484045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::ObjCMultiArgSelector: 42494045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis case DeclarationName::CXXUsingDirective: 42504045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis break; 42514045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis } 42524045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis} 42534045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 42544045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidisvoid ASTWriter::AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 425589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 42564045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddDeclarationName(NameInfo.getName(), Record); 42574045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddSourceLocation(NameInfo.getLoc(), Record); 42584045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName(), Record); 42594045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis} 42604045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 42614045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidisvoid ASTWriter::AddQualifierInfo(const QualifierInfo &Info, 426289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 4263c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor AddNestedNameSpecifierLoc(Info.QualifierLoc, Record); 42644045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis Record.push_back(Info.NumTemplParamLists); 42654045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) 42664045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis AddTemplateParameterList(Info.TemplParamLists[i], Record); 42674045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis} 42684045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 4269a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddNestedNameSpecifier(NestedNameSpecifier *NNS, 427089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 42716ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // Nested name specifiers usually aren't too long. I think that 8 would 4272fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner // typically accommodate the vast majority. 42735f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<NestedNameSpecifier *, 8> NestedNames; 42746ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 42756ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // Push each of the NNS's onto a stack for serialization in reverse order. 42766ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner while (NNS) { 42776ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NestedNames.push_back(NNS); 42786ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NNS = NNS->getPrefix(); 42796ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner } 42806ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 42816ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner Record.push_back(NestedNames.size()); 42826ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner while(!NestedNames.empty()) { 42836ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NNS = NestedNames.pop_back_val(); 42846ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); 42856ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner Record.push_back(Kind); 42866ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner switch (Kind) { 42876ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::Identifier: 42886ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddIdentifierRef(NNS->getAsIdentifier(), Record); 42896ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 42906ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 42916ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::Namespace: 42926ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddDeclRef(NNS->getAsNamespace(), Record); 42936ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 42946ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 429514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor case NestedNameSpecifier::NamespaceAlias: 429614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor AddDeclRef(NNS->getAsNamespaceAlias(), Record); 429714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor break; 429814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 42996ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::TypeSpec: 43006ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::TypeSpecWithTemplate: 43016ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner AddTypeRef(QualType(NNS->getAsType(), 0), Record); 43026ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); 43036ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 43046ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 43056ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner case NestedNameSpecifier::Global: 43066ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner // Don't need to write an associated value. 43076ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner break; 43086ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner } 43096ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner } 43106ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner} 431190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 4312dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregorvoid ASTWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 4313dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor RecordDataImpl &Record) { 4314dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor // Nested name specifiers usually aren't too long. I think that 8 would 4315fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner // typically accommodate the vast majority. 43165f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<NestedNameSpecifierLoc , 8> NestedNames; 4317dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 4318dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor // Push each of the nested-name-specifiers's onto a stack for 4319dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor // serialization in reverse order. 4320dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor while (NNS) { 4321dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor NestedNames.push_back(NNS); 4322dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor NNS = NNS.getPrefix(); 4323dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor } 4324dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 4325dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor Record.push_back(NestedNames.size()); 4326dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor while(!NestedNames.empty()) { 4327dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor NNS = NestedNames.pop_back_val(); 4328dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor NestedNameSpecifier::SpecifierKind Kind 4329dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor = NNS.getNestedNameSpecifier()->getKind(); 4330dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor Record.push_back(Kind); 4331dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor switch (Kind) { 4332dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::Identifier: 4333dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier(), Record); 4334dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceRange(NNS.getLocalSourceRange(), Record); 4335dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 4336dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 4337dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::Namespace: 4338dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace(), Record); 4339dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceRange(NNS.getLocalSourceRange(), Record); 4340dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 4341dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 4342dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::NamespaceAlias: 4343dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(), Record); 4344dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceRange(NNS.getLocalSourceRange(), Record); 4345dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 4346dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 4347dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::TypeSpec: 4348dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 4349dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor Record.push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); 4350dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddTypeLoc(NNS.getTypeLoc(), Record); 4351dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); 4352dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 4353dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 4354dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor case NestedNameSpecifier::Global: 4355dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor AddSourceLocation(NNS.getLocalSourceRange().getEnd(), Record); 4356dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor break; 4357dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor } 4358dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor } 4359dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor} 4360dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor 436189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddTemplateName(TemplateName Name, RecordDataImpl &Record) { 436220249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer TemplateName::NameKind Kind = Name.getKind(); 436390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(Kind); 436490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis switch (Kind) { 436590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::Template: 436690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(Name.getAsTemplateDecl(), Record); 436790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 436890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 436990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::OverloadedTemplate: { 437090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis OverloadedTemplateStorage *OvT = Name.getAsOverloadedTemplate(); 437190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(OvT->size()); 437290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis for (OverloadedTemplateStorage::iterator I = OvT->begin(), E = OvT->end(); 437390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis I != E; ++I) 437490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(*I, Record); 437590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 437690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 437720249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 437890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::QualifiedTemplate: { 437990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis QualifiedTemplateName *QualT = Name.getAsQualifiedTemplateName(); 438090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddNestedNameSpecifier(QualT->getQualifier(), Record); 438190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(QualT->hasTemplateKeyword()); 438290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(QualT->getTemplateDecl(), Record); 438390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 438490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 438520249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer 438690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateName::DependentTemplate: { 438790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis DependentTemplateName *DepT = Name.getAsDependentTemplateName(); 438890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddNestedNameSpecifier(DepT->getQualifier(), Record); 438990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(DepT->isIdentifier()); 439090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis if (DepT->isIdentifier()) 439190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddIdentifierRef(DepT->getIdentifier(), Record); 439290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis else 439390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(DepT->getOperator()); 439490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 439590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 4396146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 4397146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParm: { 4398146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 4399146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParm(); 4400146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall AddDeclRef(subst->getParameter(), Record); 4401146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall AddTemplateName(subst->getReplacement(), Record); 4402146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall break; 4403146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 44041aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 44051aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor case TemplateName::SubstTemplateTemplateParmPack: { 44061aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPackStorage *SubstPack 44071aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack(); 44081aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor AddDeclRef(SubstPack->getParameterPack(), Record); 44091aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor AddTemplateArgument(SubstPack->getArgumentPack(), Record); 44101aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor break; 44111aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 441290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 441390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 441490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 441520249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencervoid ASTWriter::AddTemplateArgument(const TemplateArgument &Arg, 441689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 441790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(Arg.getKind()); 441890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis switch (Arg.getKind()) { 441990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Null: 442090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 442190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Type: 442290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddTypeRef(Arg.getAsType(), Record); 442390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 442490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Declaration: 442590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddDeclRef(Arg.getAsDecl(), Record); 4426d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman Record.push_back(Arg.isDeclForReferenceParam()); 4427d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman break; 4428d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman case TemplateArgument::NullPtr: 4429d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman AddTypeRef(Arg.getNullPtrType(), Record); 443090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 443190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Integral: 4432855243789cb44799c03f4c7216d3d6308805f549Benjamin Kramer AddAPSInt(Arg.getAsIntegral(), Record); 443390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddTypeRef(Arg.getIntegralType(), Record); 443490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 443590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Template: 44362be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); 44372be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor break; 4438a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 4439a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor AddTemplateName(Arg.getAsTemplateOrTemplatePattern(), Record); 44402be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor if (llvm::Optional<unsigned> NumExpansions = Arg.getNumTemplateExpansions()) 44412be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor Record.push_back(*NumExpansions + 1); 44422be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor else 44432be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor Record.push_back(0); 444490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 444590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Expression: 444690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddStmt(Arg.getAsExpr()); 444790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 444890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis case TemplateArgument::Pack: 444990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis Record.push_back(Arg.pack_size()); 445090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis for (TemplateArgument::pack_iterator I=Arg.pack_begin(), E=Arg.pack_end(); 445190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis I != E; ++I) 445290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis AddTemplateArgument(*I, Record); 445390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis break; 445490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis } 445590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis} 4456dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis 4457dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidisvoid 4458a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian RedlASTWriter::AddTemplateParameterList(const TemplateParameterList *TemplateParams, 445989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 4460dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis assert(TemplateParams && "No TemplateParams!"); 4461dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddSourceLocation(TemplateParams->getTemplateLoc(), Record); 4462dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddSourceLocation(TemplateParams->getLAngleLoc(), Record); 4463dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddSourceLocation(TemplateParams->getRAngleLoc(), Record); 4464dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis Record.push_back(TemplateParams->size()); 4465dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis for (TemplateParameterList::const_iterator 4466dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis P = TemplateParams->begin(), PEnd = TemplateParams->end(); 4467dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis P != PEnd; ++P) 4468dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddDeclRef(*P, Record); 4469dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis} 4470dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis 4471dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis/// \brief Emit a template argument list. 4472dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidisvoid 4473a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian RedlASTWriter::AddTemplateArgumentList(const TemplateArgumentList *TemplateArgs, 447489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 4475dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis assert(TemplateArgs && "No TemplateArgs!"); 4476910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Record.push_back(TemplateArgs->size()); 4477910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor for (int i=0, e = TemplateArgs->size(); i != e; ++i) 4478dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis AddTemplateArgument(TemplateArgs->get(i), Record); 4479dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis} 448037ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis 448137ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis 448237ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidisvoid 44832a82ca255b0f99f6201a75ed52b91fc024f6e9cfArgyrios KyrtzidisASTWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record) { 448437ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis Record.push_back(Set.size()); 44852a82ca255b0f99f6201a75ed52b91fc024f6e9cfArgyrios Kyrtzidis for (ASTUnresolvedSet::const_iterator 448637ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis I = Set.begin(), E = Set.end(); I != E; ++I) { 448737ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis AddDeclRef(I.getDecl(), Record); 448837ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis Record.push_back(I.getAccess()); 448937ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis } 449037ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis} 44910745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis 4492a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base, 449389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis RecordDataImpl &Record) { 44940745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis Record.push_back(Base.isVirtual()); 44950745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis Record.push_back(Base.isBaseOfClass()); 44960745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis Record.push_back(Base.getAccessSpecifierAsWritten()); 4497f677ea3cc9598d9952ad7ffab5fb322ba4c5be31Sebastian Redl Record.push_back(Base.getInheritConstructors()); 44985606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky AddTypeSourceInfo(Base.getTypeSourceInfo(), Record); 44990745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis AddSourceRange(Base.getSourceRange(), Record); 4500f90b27ad077c3339b62befc892382845339f9490Douglas Gregor AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() 4501f90b27ad077c3339b62befc892382845339f9490Douglas Gregor : SourceLocation(), 4502f90b27ad077c3339b62befc892382845339f9490Douglas Gregor Record); 45030745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis} 450430c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl 45057c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregorvoid ASTWriter::FlushCXXBaseSpecifiers() { 45067c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor RecordData Record; 45077c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor for (unsigned I = 0, N = CXXBaseSpecifiersToWrite.size(); I != N; ++I) { 45087c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.clear(); 45097c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 45107c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor // Record the offset of this base-specifier set. 4511e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor unsigned Index = CXXBaseSpecifiersToWrite[I].ID - 1; 45127c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Index == CXXBaseSpecifiersOffsets.size()) 45137c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets.push_back(Stream.GetCurrentBitNo()); 45147c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor else { 45157c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Index > CXXBaseSpecifiersOffsets.size()) 45167c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets.resize(Index + 1); 45177c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersOffsets[Index] = Stream.GetCurrentBitNo(); 45187c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor } 45197c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 45207c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor const CXXBaseSpecifier *B = CXXBaseSpecifiersToWrite[I].Bases, 45217c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor *BEnd = CXXBaseSpecifiersToWrite[I].BasesEnd; 45227c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record.push_back(BEnd - B); 45237c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor for (; B != BEnd; ++B) 45247c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor AddCXXBaseSpecifier(*B, Record); 45257c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Stream.EmitRecord(serialization::DECL_CXX_BASE_SPECIFIERS, Record); 4526acec34bda4a765fd05ed10e5aa83bc93dac072c1Douglas Gregor 4527acec34bda4a765fd05ed10e5aa83bc93dac072c1Douglas Gregor // Flush any expressions that were written as part of the base specifiers. 4528acec34bda4a765fd05ed10e5aa83bc93dac072c1Douglas Gregor FlushStmts(); 45297c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor } 45307c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 45317c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor CXXBaseSpecifiersToWrite.clear(); 45327c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor} 45337c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 4534cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntvoid ASTWriter::AddCXXCtorInitializers( 4535cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt const CXXCtorInitializer * const *CtorInitializers, 4536cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt unsigned NumCtorInitializers, 4537cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt RecordDataImpl &Record) { 4538cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt Record.push_back(NumCtorInitializers); 4539cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt for (unsigned i=0; i != NumCtorInitializers; ++i) { 4540cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt const CXXCtorInitializer *Init = CtorInitializers[i]; 45418e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis 45428e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis if (Init->isBaseInitializer()) { 4543156b640c67300f2b70eb11102aa393a610798cc6Sean Hunt Record.push_back(CTOR_INITIALIZER_BASE); 454476852c218a207ef43583515cb835b6e855353a0fDouglas Gregor AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); 45458e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->isBaseVirtual()); 4546156b640c67300f2b70eb11102aa393a610798cc6Sean Hunt } else if (Init->isDelegatingInitializer()) { 4547156b640c67300f2b70eb11102aa393a610798cc6Sean Hunt Record.push_back(CTOR_INITIALIZER_DELEGATING); 454876852c218a207ef43583515cb835b6e855353a0fDouglas Gregor AddTypeSourceInfo(Init->getTypeSourceInfo(), Record); 4549156b640c67300f2b70eb11102aa393a610798cc6Sean Hunt } else if (Init->isMemberInitializer()){ 4550156b640c67300f2b70eb11102aa393a610798cc6Sean Hunt Record.push_back(CTOR_INITIALIZER_MEMBER); 4551156b640c67300f2b70eb11102aa393a610798cc6Sean Hunt AddDeclRef(Init->getMember(), Record); 45528e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } else { 4553156b640c67300f2b70eb11102aa393a610798cc6Sean Hunt Record.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); 4554156b640c67300f2b70eb11102aa393a610798cc6Sean Hunt AddDeclRef(Init->getIndirectMember(), Record); 45558e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } 455600eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet 45578e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddSourceLocation(Init->getMemberLocation(), Record); 45588e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddStmt(Init->getInit()); 45598e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddSourceLocation(Init->getLParenLoc(), Record); 45608e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddSourceLocation(Init->getRParenLoc(), Record); 45618e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->isWritten()); 45628e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis if (Init->isWritten()) { 45638e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->getSourceOrder()); 45648e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } else { 45658e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis Record.push_back(Init->getNumArrayIndices()); 45668e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis for (unsigned i=0, e=Init->getNumArrayIndices(); i != e; ++i) 45678e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis AddDeclRef(Init->getArrayIndex(i), Record); 45688e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } 45698e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis } 45708e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis} 45718e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis 457289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisvoid ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Record) { 457389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis assert(D->DefinitionData); 457489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData; 45759d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor Record.push_back(Data.IsLambda); 457689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredConstructor); 457789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredCopyConstructor); 457858e9797d001b34d03de6178eb91e9846fb90b79aDouglas Gregor Record.push_back(Data.UserDeclaredMoveConstructor); 457989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredCopyAssignment); 458058e9797d001b34d03de6178eb91e9846fb90b79aDouglas Gregor Record.push_back(Data.UserDeclaredMoveAssignment); 458189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.UserDeclaredDestructor); 458289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Aggregate); 458389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.PlainOldData); 458489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Empty); 458589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Polymorphic); 458689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.Abstract); 4587ec997dc66627957bcdcd3db7906a68c1e14a279cChandler Carruth Record.push_back(Data.IsStandardLayout); 4588a8225449421e8c1e996a7c48300521028946482aChandler Carruth Record.push_back(Data.HasNoNonEmptyBases); 4589a8225449421e8c1e996a7c48300521028946482aChandler Carruth Record.push_back(Data.HasPrivateFields); 4590a8225449421e8c1e996a7c48300521028946482aChandler Carruth Record.push_back(Data.HasProtectedFields); 4591a8225449421e8c1e996a7c48300521028946482aChandler Carruth Record.push_back(Data.HasPublicFields); 45922bb110125e0e5adb7c1c65d12adfa34151ca1c47Douglas Gregor Record.push_back(Data.HasMutableFields); 4593dfefb840e36f069286ef6cf178ef339c90f4603dRichard Smith Record.push_back(Data.HasOnlyCMembers); 4594d079abfb5eefaf7da232e39a6564f561402cf4feRichard Smith Record.push_back(Data.HasInClassInitializer); 4595023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt Record.push_back(Data.HasTrivialDefaultConstructor); 45966b8bc0707f26aa6acfdd80a59b9a3850cafbe387Richard Smith Record.push_back(Data.HasConstexprNonCopyMoveConstructor); 4597dfefb840e36f069286ef6cf178ef339c90f4603dRichard Smith Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr); 4598dfefb840e36f069286ef6cf178ef339c90f4603dRichard Smith Record.push_back(Data.HasConstexprDefaultConstructor); 459989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialCopyConstructor); 46004d6e5a22d9481bb83b82d911727540096d171c0bChandler Carruth Record.push_back(Data.HasTrivialMoveConstructor); 460189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialCopyAssignment); 46024d6e5a22d9481bb83b82d911727540096d171c0bChandler Carruth Record.push_back(Data.HasTrivialMoveAssignment); 460389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.HasTrivialDestructor); 4604dfefb840e36f069286ef6cf178ef339c90f4603dRichard Smith Record.push_back(Data.HasIrrelevantDestructor); 46059b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth Record.push_back(Data.HasNonLiteralTypeFieldsOrBases); 460689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.ComputedVisibleConversions); 4607cdee3fee8ca4df7fb9179f29cc3ba96ac4fd0f95Sean Hunt Record.push_back(Data.UserProvidedDefaultConstructor); 460889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredDefaultConstructor); 460989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredCopyConstructor); 461058e9797d001b34d03de6178eb91e9846fb90b79aDouglas Gregor Record.push_back(Data.DeclaredMoveConstructor); 461189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredCopyAssignment); 461258e9797d001b34d03de6178eb91e9846fb90b79aDouglas Gregor Record.push_back(Data.DeclaredMoveAssignment); 461389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.DeclaredDestructor); 461414c3633a0b6a06dd61c0cd239925174fc5728fffSebastian Redl Record.push_back(Data.FailedImplicitMoveConstructor); 461514c3633a0b6a06dd61c0cd239925174fc5728fffSebastian Redl Record.push_back(Data.FailedImplicitMoveAssignment); 4616dfefb840e36f069286ef6cf178ef339c90f4603dRichard Smith // IsLambda bit is already saved. 461789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis 461889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.NumBases); 46197c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Data.NumBases > 0) 46207c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor AddCXXBaseSpecifiersRef(Data.getBases(), Data.getBases() + Data.NumBases, 46217c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record); 46227c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 462389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis // FIXME: Make VBases lazily computed when needed to avoid storing them. 462489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis Record.push_back(Data.NumVBases); 46257c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor if (Data.NumVBases > 0) 46267c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor AddCXXBaseSpecifiersRef(Data.getVBases(), Data.getVBases() + Data.NumVBases, 46277c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor Record); 462889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis 462989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis AddUnresolvedSet(Data.Conversions, Record); 463089eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis AddUnresolvedSet(Data.VisibleConversions, Record); 463189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis // Data.Definition is the owning decl, no need to write it. 463289eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis AddDeclRef(Data.FirstFriend, Record); 46339d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor 46349d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor // Add lambda-specific data. 46359d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor if (Data.IsLambda) { 46369d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor CXXRecordDecl::LambdaDefinitionData &Lambda = D->getLambdaData(); 4637f4b7de1cef3007cc0479775638198287384d9af1Douglas Gregor Record.push_back(Lambda.Dependent); 46389d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor Record.push_back(Lambda.NumCaptures); 46399d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor Record.push_back(Lambda.NumExplicitCaptures); 46409e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor Record.push_back(Lambda.ManglingNumber); 4641ccc1b5eebc6ca8a904c58c0468b9a71483b7c7cfDouglas Gregor AddDeclRef(Lambda.ContextDecl, Record); 46428da8a660128180a31479216111ff9b19b11c95b4Eli Friedman AddTypeSourceInfo(Lambda.MethodTyInfo, Record); 46439d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { 46449d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor LambdaExpr::Capture &Capture = Lambda.Captures[I]; 46459d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor AddSourceLocation(Capture.getLocation(), Record); 46469d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor Record.push_back(Capture.isImplicit()); 46479d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor Record.push_back(Capture.getCaptureKind()); // FIXME: stable! 46489d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor VarDecl *Var = Capture.capturesVariable()? Capture.getCapturedVar() : 0; 46499d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor AddDeclRef(Var, Record); 46509d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor AddSourceLocation(Capture.isPackExpansion()? Capture.getEllipsisLoc() 46519d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor : SourceLocation(), 46529d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor Record); 46539d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor } 46549d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor } 465589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis} 465689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis 46577b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisvoid ASTWriter::ReaderInitialized(ASTReader *Reader) { 4658ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl assert(Reader && "Cannot remove chain"); 465910bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor assert((!Chain || Chain == Reader) && "Cannot replace chain"); 4660ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl assert(FirstDeclID == NextDeclID && 4661ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl FirstTypeID == NextTypeID && 4662ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl FirstIdentID == NextIdentID && 4663a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor FirstMacroID == NextMacroID && 466426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor FirstSubmoduleID == NextSubmoduleID && 4665e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl FirstSelectorID == NextSelectorID && 4666ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl "Setting chain after writing has started."); 4667f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor 4668ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl Chain = Reader; 46697b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 467010bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); 467110bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); 467210bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); 4673a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); 467426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); 467510bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); 46767b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextDeclID = FirstDeclID; 46777b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextTypeID = FirstTypeID; 46787b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextIdentID = FirstIdentID; 4679a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor NextMacroID = FirstMacroID; 46807b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis NextSelectorID = FirstSelectorID; 468126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor NextSubmoduleID = FirstSubmoduleID; 4682ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl} 4683ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl 46848538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { 4685f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl IdentifierIDs[II] = ID; 4686f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl} 4687f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl 4688a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregorvoid ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { 4689a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor MacroIDs[MI] = ID; 4690a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor} 4691a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 4692c8e5d51f51e46c6f7717761537c6609ef9daf57cArgyrios Kyrtzidisvoid ASTWriter::TypeRead(TypeIdx Idx, QualType T) { 469397475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // Always take the highest-numbered type index. This copes with an interesting 469497475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // case for chained AST writing where we schedule writing the type and then, 469520249a1af2e462dcafdd6a350f1c7967b264ff25Michael J. Spencer // later, deserialize the type from another AST. In this case, we want to 469697475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // keep the higher-numbered entry so that we can properly write it out to 469797475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor // the AST file. 469897475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor TypeIdx &StoredIdx = TypeIdxs[T]; 469997475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor if (Idx.getIndex() >= StoredIdx.getIndex()) 470097475834207bf5abb5b58534f783c9b71d4b9df1Douglas Gregor StoredIdx = Idx; 470130c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl} 470230c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl 47038538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlvoid ASTWriter::SelectorRead(SelectorID ID, Selector S) { 47045d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl SelectorIDs[S] = ID; 47055d05007b7a7883159154e3f65f338a2542d53913Sebastian Redl} 470677424bc3794f569816dba52e423b57486a98e5baDouglas Gregor 4707e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidisvoid ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, 470877424bc3794f569816dba52e423b57486a98e5baDouglas Gregor MacroDefinition *MD) { 4709e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); 471077424bc3794f569816dba52e423b57486a98e5baDouglas Gregor MacroDefinitions[MD] = ID; 471177424bc3794f569816dba52e423b57486a98e5baDouglas Gregor} 4712565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis 4713a015cab273705d1198d13e8389c2f4775f539a8bDouglas Gregorvoid ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { 4714a015cab273705d1198d13e8389c2f4775f539a8bDouglas Gregor assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); 4715a015cab273705d1198d13e8389c2f4775f539a8bDouglas Gregor SubmoduleIDs[Mod] = ID; 4716a015cab273705d1198d13e8389c2f4775f539a8bDouglas Gregor} 4717a015cab273705d1198d13e8389c2f4775f539a8bDouglas Gregor 4718a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregorvoid ASTWriter::UndefinedMacro(MacroInfo *MI) { 4719a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor MacroUpdates[MI].UndefLoc = MI->getUndefLoc(); 4720a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor} 4721a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 4722565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidisvoid ASTWriter::CompletedTagDefinition(const TagDecl *D) { 47235e1cdac63c3d9c9b32fa41fa0b2d242a58a20d49John McCall assert(D->isCompleteDefinition()); 472461c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor assert(!WritingAST && "Already writing the AST!"); 4725565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { 4726565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // We are interested when a PCH decl is modified. 4727919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (RD->isFromASTFile()) { 4728565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // A forward reference was mutated into a definition. Rewrite it. 4729565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // FIXME: This happens during template instantiation, should we 4730565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis // have created a new definition decl instead ? 4731d3d0755a4220d3fa6c125eb3f8ce29fc1424eac3Argyrios Kyrtzidis RewriteDecl(RD); 4732565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 4733565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis } 4734565bf30bf5607b9740d288d8d9c45cf38ea75298Argyrios Kyrtzidis} 4735a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 4736100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidisvoid ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { 473761c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor assert(!WritingAST && "Already writing the AST!"); 473861c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor 4739100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis // TU and namespaces are handled elsewhere. 4740100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) 4741100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis return; 4742100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis 4743919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!(!D->isFromASTFile() && cast<Decl>(DC)->isFromASTFile())) 4744100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis return; // Not a source decl added to a DeclContext from PCH. 4745100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis 4746100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis AddUpdatedDeclContext(DC); 47477518b3784ed2176aad8dcabe0685c6e02c5f1043Argyrios Kyrtzidis UpdatingVisibleDecls.push_back(D); 4748100050bf643bcfe2d06bdcef491e387171249260Argyrios Kyrtzidis} 4749b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis 4750b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidisvoid ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { 475161c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor assert(!WritingAST && "Already writing the AST!"); 4752b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis assert(D->isImplicit()); 4753919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!(!D->isFromASTFile() && RD->isFromASTFile())) 4754b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis return; // Not a source member added to a class from PCH. 4755b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis if (!isa<CXXMethodDecl>(D)) 4756b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis return; // We are interested in lazily declared implicit methods. 4757b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis 4758b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis // A decl coming from PCH was modified. 47595e1cdac63c3d9c9b32fa41fa0b2d242a58a20d49John McCall assert(RD->isCompleteDefinition()); 4760b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis UpdateRecord &Record = DeclUpdates[RD]; 4761b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis Record.push_back(UPD_CXX_ADDED_IMPLICIT_MEMBER); 476261c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor Record.push_back(reinterpret_cast<uint64_t>(D)); 4763b6cc0e1a789c3f33e3f4b1ee768e679a9beab941Argyrios Kyrtzidis} 4764bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis 4765bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidisvoid ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, 4766bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis const ClassTemplateSpecializationDecl *D) { 47670f04f69acd0a86ff78961933c13fe5aeda94e1b6Argyrios Kyrtzidis // The specializations set is kept in the canonical template. 476861c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor assert(!WritingAST && "Already writing the AST!"); 47690f04f69acd0a86ff78961933c13fe5aeda94e1b6Argyrios Kyrtzidis TD = TD->getCanonicalDecl(); 4770919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!(!D->isFromASTFile() && TD->isFromASTFile())) 4771bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis return; // Not a source specialization added to a template from PCH. 4772bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis 4773bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis UpdateRecord &Record = DeclUpdates[TD]; 4774bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); 477561c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor Record.push_back(reinterpret_cast<uint64_t>(D)); 4776bef1a7b9c175d37e4a727e6ce68bd05232fa6970Argyrios Kyrtzidis} 477789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 47785bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redlvoid ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, 47795bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl const FunctionDecl *D) { 47805bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl // The specializations set is kept in the canonical template. 478161c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor assert(!WritingAST && "Already writing the AST!"); 47825bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl TD = TD->getCanonicalDecl(); 4783919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!(!D->isFromASTFile() && TD->isFromASTFile())) 47845bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl return; // Not a source specialization added to a template from PCH. 47855bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl 47865bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl UpdateRecord &Record = DeclUpdates[TD]; 47875bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION); 478861c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor Record.push_back(reinterpret_cast<uint64_t>(D)); 47895bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl} 47905bbcdbf36f8cf79d99703ef20848c55960065e43Sebastian Redl 479158a2cd8c0d52e710cbcc57a67eac7b51b0b831c4Sebastian Redlvoid ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { 479261c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor assert(!WritingAST && "Already writing the AST!"); 4793919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!D->isFromASTFile()) 479458a2cd8c0d52e710cbcc57a67eac7b51b0b831c4Sebastian Redl return; // Declaration not imported from PCH. 479558a2cd8c0d52e710cbcc57a67eac7b51b0b831c4Sebastian Redl 479658a2cd8c0d52e710cbcc57a67eac7b51b0b831c4Sebastian Redl // Implicit decl from a PCH was defined. 479758a2cd8c0d52e710cbcc57a67eac7b51b0b831c4Sebastian Redl // FIXME: Should implicit definition be a separate FunctionDecl? 479858a2cd8c0d52e710cbcc57a67eac7b51b0b831c4Sebastian Redl RewriteDecl(D); 479958a2cd8c0d52e710cbcc57a67eac7b51b0b831c4Sebastian Redl} 480058a2cd8c0d52e710cbcc57a67eac7b51b0b831c4Sebastian Redl 4801f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redlvoid ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) { 480261c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor assert(!WritingAST && "Already writing the AST!"); 4803919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!D->isFromASTFile()) 4804f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl return; 4805f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl 4806f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl // Since the actual instantiation is delayed, this really means that we need 4807f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl // to update the instantiation location. 4808f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl UpdateRecord &Record = DeclUpdates[D]; 4809f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl Record.push_back(UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER); 4810f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl AddSourceLocation( 4811f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl D->getMemberSpecializationInfo()->getPointOfInstantiation(), Record); 4812f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl} 4813f79a71908d6f28cb2bc0c081d9a801ed14d61d82Sebastian Redl 4814e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidisvoid ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, 4815e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis const ObjCInterfaceDecl *IFD) { 481661c5e340c26971d195bd27232e7f2e71be24bb52Douglas Gregor assert(!WritingAST && "Already writing the AST!"); 4817919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor if (!IFD->isFromASTFile()) 4818e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis return; // Declaration not imported from PCH. 4819cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor 4820cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor assert(IFD->getDefinition() && "Category on a class without a definition?"); 4821cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor ObjCClassesWithCategories.insert( 4822cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); 4823e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis} 4824ad834d534e9a5db3d3baa09593775f83ceaff1f2Argyrios Kyrtzidis 48251a43415b28e60e0e421ef60e254126acec7ab462Argyrios Kyrtzidis 4826c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidisvoid ASTWriter::AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop, 4827c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis const ObjCPropertyDecl *OrigProp, 4828c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis const ObjCCategoryDecl *ClassExt) { 4829c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis const ObjCInterfaceDecl *D = ClassExt->getClassInterface(); 4830c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis if (!D) 4831c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis return; 4832c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis 4833c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis assert(!WritingAST && "Already writing the AST!"); 4834c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis if (!D->isFromASTFile()) 4835c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis return; // Declaration not imported from PCH. 4836c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis 4837c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis RewriteDecl(D); 4838c80553efdc269dabd4ed0c3210555f45729ab5ddArgyrios Kyrtzidis} 4839