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"
162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/ASTContext.h"
172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/Decl.h"
182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/DeclContextInternals.h"
1989eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis#include "clang/AST/DeclFriend.h"
20651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "clang/AST/DeclLookups.h"
2155fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/DeclTemplate.h"
220b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor#include "clang/AST/Expr.h"
237a1fad38256eb4c5129359be85ba1ea1678eb5c9John McCall#include "clang/AST/ExprCXX.h"
242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/Type.h"
25a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#include "clang/AST/TypeLocVisitor.h"
266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "clang/Basic/DiagnosticOptions.h"
2714f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "clang/Basic/FileManager.h"
2810e286aa8d39fb51a21412850265d9dae74613eeChris Lattner#include "clang/Basic/FileSystemStatCache.h"
2914f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "clang/Basic/SourceManager.h"
30bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor#include "clang/Basic/SourceManagerInternals.h"
312bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor#include "clang/Basic/TargetInfo.h"
3257016dda61498294120b1a881d9e6606337b29d9Douglas Gregor#include "clang/Basic/TargetOptions.h"
33ab41e63821dc60ad144d0684df8d79a9eef86b75Douglas Gregor#include "clang/Basic/Version.h"
340a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor#include "clang/Basic/VersionTuple.h"
3555fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Lex/HeaderSearch.h"
3655fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Lex/HeaderSearchOptions.h"
3755fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Lex/MacroInfo.h"
3855fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Lex/PreprocessingRecord.h"
3955fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Lex/Preprocessor.h"
4055fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Lex/PreprocessorOptions.h"
4155fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Sema/IdentifierResolver.h"
4255fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Sema/Sema.h"
4355fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Serialization/ASTReader.h"
4417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APFloat.h"
4517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APInt.h"
46ed3802e5da6e7d41975b1cb3d7ae3a3b9e855d10Argyrios Kyrtzidis#include "llvm/ADT/Hashing.h"
472596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar#include "llvm/ADT/StringExtras.h"
482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/Bitcode/BitstreamWriter.h"
49651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "llvm/Support/EndianStream.h"
50fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer#include "llvm/Support/FileSystem.h"
5114f79002e58556798e86168c63e48d533287eda5Douglas Gregor#include "llvm/Support/MemoryBuffer.h"
526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "llvm/Support/OnDiskHashTable.h"
5303013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/Path.h"
54f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor#include <algorithm>
553c304bd9ec2b4611572d4cbae9e1727bbecb5dc9Chris Lattner#include <cstdio>
56cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor#include <string.h>
57f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor#include <utility>
582cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorusing namespace clang;
598538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redlusing namespace clang::serialization;
602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
61ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redltemplate <typename T, typename Allocator>
625f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnerstatic StringRef data(const std::vector<T, Allocator> &v) {
635f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  if (v.empty()) return StringRef();
645f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  return StringRef(reinterpret_cast<const char*>(&v[0]),
656e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer                         sizeof(T) * v.size());
66ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl}
676e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer
686e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramertemplate <typename T>
695f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnerstatic StringRef data(const SmallVectorImpl<T> &v) {
705f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner  return StringRef(reinterpret_cast<const char*>(v.data()),
716e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer                         sizeof(T) * v.size());
72ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl}
73ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl
742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===//
752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// Type serialization
762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===//
7712b1c7615d4f9a2edc544be499f895f16ac100edChris Lattner
782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace {
793397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  class ASTTypeWriter {
80a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl    ASTWriter &Writer;
8189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis    ASTWriter::RecordDataImpl &Record;
822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  public:
842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    /// \brief Type code that corresponds to the record generated.
858538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl    TypeCode Code;
862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
8789eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis    ASTTypeWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record)
888538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      : Writer(Writer), Record(Record), Code(TYPE_EXT_QUAL) { }
892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    void VisitArrayType(const ArrayType *T);
912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    void VisitFunctionType(const FunctionType *T);
922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    void VisitTagType(const TagType *T);
932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T);
952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#define ABSTRACT_TYPE(Class, Base)
962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/TypeNodes.def"
972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  };
982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1003397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) {
101b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  llvm_unreachable("Built-in types are never serialized");
1022cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1032cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1043397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitComplexType(const ComplexType *T) {
1052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Writer.AddTypeRef(T->getElementType(), Record);
1068538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_COMPLEX;
1072cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1082cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1093397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitPointerType(const PointerType *T) {
1102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Writer.AddTypeRef(T->getPointeeType(), Record);
1118538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_POINTER;
1122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
11412df246d6dea2ee1f92c186f922f1afcf499647aReid Klecknervoid ASTTypeWriter::VisitDecayedType(const DecayedType *T) {
11512df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner  Writer.AddTypeRef(T->getOriginalType(), Record);
11612df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner  Code = TYPE_DECAYED;
11712df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner}
11812df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner
119651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid ASTTypeWriter::VisitAdjustedType(const AdjustedType *T) {
120651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Writer.AddTypeRef(T->getOriginalType(), Record);
121651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Writer.AddTypeRef(T->getAdjustedType(), Record);
122651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Code = TYPE_ADJUSTED;
123651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines}
124651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
1253397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) {
1261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Writer.AddTypeRef(T->getPointeeType(), Record);
1278538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_BLOCK_POINTER;
1282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1303397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) {
131df1550fc59b51681d37225934fe4e3acac321621Richard Smith  Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record);
132df1550fc59b51681d37225934fe4e3acac321621Richard Smith  Record.push_back(T->isSpelledAsLValue());
1338538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_LVALUE_REFERENCE;
1342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1363397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) {
137df1550fc59b51681d37225934fe4e3acac321621Richard Smith  Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record);
1388538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_RVALUE_REFERENCE;
1392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1413397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitMemberPointerType(const MemberPointerType *T) {
1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Writer.AddTypeRef(T->getPointeeType(), Record);
1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Writer.AddTypeRef(QualType(T->getClass(), 0), Record);
1448538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_MEMBER_POINTER;
1452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1473397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitArrayType(const ArrayType *T) {
1482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Writer.AddTypeRef(T->getElementType(), Record);
1492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Record.push_back(T->getSizeModifier()); // FIXME: stable values
1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values
1512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1533397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) {
1542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  VisitArrayType(T);
1552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Writer.AddAPInt(T->getSize(), Record);
1568538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_CONSTANT_ARRAY;
1572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1582cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1593397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  VisitArrayType(T);
1618538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_INCOMPLETE_ARRAY;
1622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1643397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitVariableArrayType(const VariableArrayType *T) {
1652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  VisitArrayType(T);
1667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  Writer.AddSourceLocation(T->getLBracketLoc(), Record);
1677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  Writer.AddSourceLocation(T->getRBracketLoc(), Record);
168c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor  Writer.AddStmt(T->getSizeExpr());
1698538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_VARIABLE_ARRAY;
1702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1723397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitVectorType(const VectorType *T) {
1732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Writer.AddTypeRef(T->getElementType(), Record);
1742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Record.push_back(T->getNumElements());
175e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  Record.push_back(T->getVectorKind());
1768538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_VECTOR;
1772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1793397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitExtVectorType(const ExtVectorType *T) {
1802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  VisitVectorType(T);
1818538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_EXT_VECTOR;
1822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1843397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionType(const FunctionType *T) {
185651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Writer.AddTypeRef(T->getReturnType(), Record);
186264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  FunctionType::ExtInfo C = T->getExtInfo();
187264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  Record.push_back(C.getNoReturn());
188a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman  Record.push_back(C.getHasRegParm());
189425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  Record.push_back(C.getRegParm());
190ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  // FIXME: need to stabilize encoding of calling convention...
191264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  Record.push_back(C.getCC());
192f85e193739c953358c865005855253af4f68a497John McCall  Record.push_back(C.getProducesResult());
1932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1953397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  VisitFunctionType(T);
1978538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_FUNCTION_NO_PROTO;
1982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
1992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
200651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstatic void addExceptionSpec(ASTWriter &Writer, const FunctionProtoType *T,
201651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                             ASTWriter::RecordDataImpl &Record) {
20260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  Record.push_back(T->getExceptionSpecType());
20360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  if (T->getExceptionSpecType() == EST_Dynamic) {
20460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    Record.push_back(T->getNumExceptions());
20560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I)
20660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      Writer.AddTypeRef(T->getExceptionType(I), Record);
20760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  } else if (T->getExceptionSpecType() == EST_ComputedNoexcept) {
20860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    Writer.AddStmt(T->getNoexceptExpr());
2097bb698aa054de4c0e0aa23973b2c62dac9611262Richard Smith  } else if (T->getExceptionSpecType() == EST_Uninstantiated) {
2107bb698aa054de4c0e0aa23973b2c62dac9611262Richard Smith    Writer.AddDeclRef(T->getExceptionSpecDecl(), Record);
2117bb698aa054de4c0e0aa23973b2c62dac9611262Richard Smith    Writer.AddDeclRef(T->getExceptionSpecTemplate(), Record);
212b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith  } else if (T->getExceptionSpecType() == EST_Unevaluated) {
213b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith    Writer.AddDeclRef(T->getExceptionSpecDecl(), Record);
21460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
215651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines}
216651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
217651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid ASTTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) {
218651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  VisitFunctionType(T);
219651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Record.push_back(T->getNumParams());
220651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  for (unsigned I = 0, N = T->getNumParams(); I != N; ++I)
221651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    Writer.AddTypeRef(T->getParamType(I), Record);
222651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Record.push_back(T->isVariadic());
223651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Record.push_back(T->hasTrailingReturn());
224651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Record.push_back(T->getTypeQuals());
225651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  Record.push_back(static_cast<unsigned>(T->getRefQualifier()));
226651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  addExceptionSpec(Writer, T, Record);
2278538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_FUNCTION_PROTO;
2282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
2292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2303397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
231ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  Writer.AddDeclRef(T->getDecl(), Record);
2328538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_UNRESOLVED_USING;
233ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
234ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2353397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypedefType(const TypedefType *T) {
2362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Writer.AddDeclRef(T->getDecl(), Record);
2379763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis  assert(!T->isCanonicalUnqualified() && "Invalid typedef ?");
2389763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis  Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record);
2398538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_TYPEDEF;
2402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
2412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2423397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) {
243c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor  Writer.AddStmt(T->getUnderlyingExpr());
2448538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_TYPEOF_EXPR;
2452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
2462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2473397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTypeOfType(const TypeOfType *T) {
2482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Writer.AddTypeRef(T->getUnderlyingType(), Record);
2498538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_TYPEOF;
2502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
2512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2523397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitDecltypeType(const DecltypeType *T) {
253f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregor  Writer.AddTypeRef(T->getUnderlyingType(), Record);
254395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Writer.AddStmt(T->getUnderlyingExpr());
2558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_DECLTYPE;
256395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}
257395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson
258ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntvoid ASTTypeWriter::VisitUnaryTransformType(const UnaryTransformType *T) {
259ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  Writer.AddTypeRef(T->getBaseType(), Record);
260ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  Writer.AddTypeRef(T->getUnderlyingType(), Record);
261ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  Record.push_back(T->getUTTKind());
262ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  Code = TYPE_UNARY_TRANSFORM;
263ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
264ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
26534b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid ASTTypeWriter::VisitAutoType(const AutoType *T) {
26634b41d939a1328f484511c6002ba2456db879a29Richard Smith  Writer.AddTypeRef(T->getDeducedType(), Record);
267a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith  Record.push_back(T->isDecltypeAuto());
268dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith  if (T->getDeducedType().isNull())
269dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith    Record.push_back(T->isDependentType());
27034b41d939a1328f484511c6002ba2456db879a29Richard Smith  Code = TYPE_AUTO;
27134b41d939a1328f484511c6002ba2456db879a29Richard Smith}
27234b41d939a1328f484511c6002ba2456db879a29Richard Smith
2733397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitTagType(const TagType *T) {
274be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis  Record.push_back(T->isDependentType());
27556ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor  Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record);
2761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  assert(!T->isBeingDefined() &&
2772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor         "Cannot serialize in the middle of a type definition");
2782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
2792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2803397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitRecordType(const RecordType *T) {
2812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  VisitTagType(T);
2828538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_RECORD;
2832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
2842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2853397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitEnumType(const EnumType *T) {
2862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  VisitTagType(T);
2878538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_ENUM;
2882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
2892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid ASTTypeWriter::VisitAttributedType(const AttributedType *T) {
2919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Writer.AddTypeRef(T->getModifiedType(), Record);
2929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Writer.AddTypeRef(T->getEquivalentType(), Record);
2939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Record.push_back(T->getAttrKind());
2949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Code = TYPE_ATTRIBUTED;
2959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
2969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
2971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid
2983397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitSubstTemplateTypeParmType(
29949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                                        const SubstTemplateTypeParmType *T) {
30049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record);
30149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  Writer.AddTypeRef(T->getReplacementType(), Record);
3028538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_SUBST_TEMPLATE_TYPE_PARM;
30349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
30449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
30549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallvoid
306c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorASTTypeWriter::VisitSubstTemplateTypeParmPackType(
307c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                      const SubstTemplateTypeParmPackType *T) {
308c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record);
309c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  Writer.AddTemplateArgument(T->getArgumentPack(), Record);
310c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  Code = TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK;
311c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}
312c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
313c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid
3143397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitTemplateSpecializationType(
3152cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor                                       const TemplateSpecializationType *T) {
316be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis  Record.push_back(T->isDependentType());
31790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  Writer.AddTemplateName(T->getTemplateName(), Record);
31890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  Record.push_back(T->getNumArgs());
31990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end();
32090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis         ArgI != ArgE; ++ArgI)
32190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis    Writer.AddTemplateArgument(*ArgI, Record);
3223e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  Writer.AddTypeRef(T->isTypeAlias() ? T->getAliasedType() :
3233e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                    T->isCanonicalUnqualified() ? QualType()
3249763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis                                                : T->getCanonicalTypeInternal(),
3259763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis                    Record);
3268538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_TEMPLATE_SPECIALIZATION;
32790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis}
32890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis
32990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid
3303397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
331ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis  VisitArrayType(T);
332ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis  Writer.AddStmt(T->getSizeExpr());
333ae8b17f1d5d303af53db5a4f4a375ea6b9356566Argyrios Kyrtzidis  Writer.AddSourceRange(T->getBracketsRange(), Record);
3348538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_DEPENDENT_SIZED_ARRAY;
33590b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis}
33690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis
33790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid
3383397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentSizedExtVectorType(
33990b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis                                        const DependentSizedExtVectorType *T) {
34090b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  // FIXME: Serialize this type (C++ only)
341b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  llvm_unreachable("Cannot serialize dependent sized extended vector types");
34290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis}
34390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis
34490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid
3453397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
34690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  Record.push_back(T->getDepth());
34790b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  Record.push_back(T->getIndex());
34890b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis  Record.push_back(T->isParameterPack());
3494fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  Writer.AddDeclRef(T->getDecl(), Record);
3508538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_TEMPLATE_TYPE_PARM;
35190b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis}
35290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis
35390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid
3543397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentNameType(const DependentNameType *T) {
3558dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  Record.push_back(T->getKeyword());
3568dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  Writer.AddNestedNameSpecifier(T->getQualifier(), Record);
3578dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  Writer.AddIdentifierRef(T->getIdentifier(), Record);
358f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis  Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType()
359f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis                                                : T->getCanonicalTypeInternal(),
360f48d45e3e36c132bdee3373beec4e8b19ae3f9c4Argyrios Kyrtzidis                    Record);
3618538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_DEPENDENT_NAME;
36290b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis}
36390b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis
36490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidisvoid
3653397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitDependentTemplateSpecializationType(
36690b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis                                const DependentTemplateSpecializationType *T) {
3673acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis  Record.push_back(T->getKeyword());
3683acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis  Writer.AddNestedNameSpecifier(T->getQualifier(), Record);
3693acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis  Writer.AddIdentifierRef(T->getIdentifier(), Record);
3703acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis  Record.push_back(T->getNumArgs());
3713acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis  for (DependentTemplateSpecializationType::iterator
3723acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis         I = T->begin(), E = T->end(); I != E; ++I)
3733acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis    Writer.AddTemplateArgument(*I, Record);
3748538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION;
3752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
3762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
3777536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorvoid ASTTypeWriter::VisitPackExpansionType(const PackExpansionType *T) {
3787536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  Writer.AddTypeRef(T->getPattern(), Record);
379dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie  if (Optional<unsigned> NumExpansions = T->getNumExpansions())
380cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    Record.push_back(*NumExpansions + 1);
381cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  else
382cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    Record.push_back(0);
3837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  Code = TYPE_PACK_EXPANSION;
3847536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}
3857536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
386075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaravoid ASTTypeWriter::VisitParenType(const ParenType *T) {
387075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  Writer.AddTypeRef(T->getInnerType(), Record);
388075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  Code = TYPE_PAREN;
389075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
390075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
3913397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) {
392465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  Record.push_back(T->getKeyword());
3933acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis  Writer.AddNestedNameSpecifier(T->getQualifier(), Record);
3943acad62a239448bef0f5848b2a0d5f7dfefd3d14Argyrios Kyrtzidis  Writer.AddTypeRef(T->getNamedType(), Record);
3958538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_ELABORATED;
3962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
3972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
3983397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
399a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor  Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record);
40031f17ecbef57b5679c017c375db330546b7b5145John McCall  Writer.AddTypeRef(T->getInjectedSpecializationType(), Record);
4018538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_INJECTED_CLASS_NAME;
4023cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
4033cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
4043397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
40556ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor  Writer.AddDeclRef(T->getDecl()->getCanonicalDecl(), Record);
4068538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_OBJC_INTERFACE;
407c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
408c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4093397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlvoid ASTTypeWriter::VisitObjCObjectType(const ObjCObjectType *T) {
410c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Writer.AddTypeRef(T->getBaseType(), Record);
4112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  Record.push_back(T->getNumProtocols());
412651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  for (const auto *I : T->quals())
413651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    Writer.AddDeclRef(I, Record);
4148538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_OBJC_OBJECT;
4152cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
4162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
417d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffvoid
4183397c5570369f19b2d6c52e898f708d75ceede1fSebastian RedlASTTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Writer.AddTypeRef(T->getPointeeType(), Record);
4208538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Code = TYPE_OBJC_OBJECT_POINTER;
4212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
4222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
423b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanvoid
424b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanASTTypeWriter::VisitAtomicType(const AtomicType *T) {
425b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  Writer.AddTypeRef(T->getValueType(), Record);
426b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  Code = TYPE_ATOMIC;
427b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}
428b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
429a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallnamespace {
430a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
431a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallclass TypeLocWriter : public TypeLocVisitor<TypeLocWriter> {
432a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  ASTWriter &Writer;
43389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis  ASTWriter::RecordDataImpl &Record;
434a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
435a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCallpublic:
43689eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis  TypeLocWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record)
437a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall    : Writer(Writer), Record(Record) { }
438a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
43951bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
440a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#define TYPELOC(CLASS, PARENT) \
44151bd803fbdade51d674598ed45da3d54190a656cJohn McCall    void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
442a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall#include "clang/AST/TypeLocNodes.def"
443a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
44451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  void VisitArrayTypeLoc(ArrayTypeLoc TyLoc);
44551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc);
446a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall};
447a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
448a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
449a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
45051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
45151bd803fbdade51d674598ed45da3d54190a656cJohn McCall  // nothing to do
45251bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
45351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
454ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  Writer.AddSourceLocation(TL.getBuiltinLoc(), Record);
455ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (TL.needsExtraLocalData()) {
456ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    Record.push_back(TL.getWrittenTypeSpec());
457ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    Record.push_back(TL.getWrittenSignSpec());
458ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    Record.push_back(TL.getWrittenWidthSpec());
459ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    Record.push_back(TL.hasModeAttr());
460ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
46151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
46251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) {
46351bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
46451bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
46551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) {
46651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getStarLoc(), Record);
46751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
46812df246d6dea2ee1f92c186f922f1afcf499647aReid Klecknervoid TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
46912df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner  // nothing to do
47012df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner}
471651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
472651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  // nothing to do
473651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines}
47451bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
47551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getCaretLoc(), Record);
47651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
47751bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
47851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getAmpLoc(), Record);
47951bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
48051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
48151bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record);
48251bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
48351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
48451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getStarLoc(), Record);
485b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  Writer.AddTypeSourceInfo(TL.getClassTInfo(), Record);
48651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
48751bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) {
48851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getLBracketLoc(), Record);
48951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getRBracketLoc(), Record);
49051bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Record.push_back(TL.getSizeExpr() ? 1 : 0);
49151bd803fbdade51d674598ed45da3d54190a656cJohn McCall  if (TL.getSizeExpr())
49251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    Writer.AddStmt(TL.getSizeExpr());
49351bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
49451bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
49551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  VisitArrayTypeLoc(TL);
49651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
49751bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
49851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  VisitArrayTypeLoc(TL);
49951bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
50051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
50151bd803fbdade51d674598ed45da3d54190a656cJohn McCall  VisitArrayTypeLoc(TL);
50251bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
50351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDependentSizedArrayTypeLoc(
50451bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                            DependentSizedArrayTypeLoc TL) {
50551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  VisitArrayTypeLoc(TL);
50651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
50751bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDependentSizedExtVectorTypeLoc(
50851bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                        DependentSizedExtVectorTypeLoc TL) {
50951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
51051bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
51151bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) {
51251bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
51351bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
51451bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
51551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
51651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
51751bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) {
518796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  Writer.AddSourceLocation(TL.getLocalRangeBegin(), Record);
51959c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara  Writer.AddSourceLocation(TL.getLParenLoc(), Record);
52059c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara  Writer.AddSourceLocation(TL.getRParenLoc(), Record);
521796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  Writer.AddSourceLocation(TL.getLocalRangeEnd(), Record);
522651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i)
523651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    Writer.AddDeclRef(TL.getParam(i), Record);
52451bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
52551bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
52651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  VisitFunctionTypeLoc(TL);
52751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
52851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
52951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  VisitFunctionTypeLoc(TL);
53051bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
531ed97649e9574b9d854fa4d6109c9333ae0993554John McCallvoid TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
532ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
533ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
53451bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
53551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
53651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
53751bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
538cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  Writer.AddSourceLocation(TL.getTypeofLoc(), Record);
539cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  Writer.AddSourceLocation(TL.getLParenLoc(), Record);
540cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  Writer.AddSourceLocation(TL.getRParenLoc(), Record);
54151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
54251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
543cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  Writer.AddSourceLocation(TL.getTypeofLoc(), Record);
544cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  Writer.AddSourceLocation(TL.getLParenLoc(), Record);
545cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  Writer.AddSourceLocation(TL.getRParenLoc(), Record);
546cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record);
54751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}
54851bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
54951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
550a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
551ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntvoid TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
552ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  Writer.AddSourceLocation(TL.getKWLoc(), Record);
553ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  Writer.AddSourceLocation(TL.getLParenLoc(), Record);
554ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  Writer.AddSourceLocation(TL.getRParenLoc(), Record);
555ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record);
556ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
55734b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) {
55834b41d939a1328f484511c6002ba2456db879a29Richard Smith  Writer.AddSourceLocation(TL.getNameLoc(), Record);
55934b41d939a1328f484511c6002ba2456db879a29Richard Smith}
56051bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) {
56151bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
562a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
56351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) {
56451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
565a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
5669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallvoid TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
5679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Writer.AddSourceLocation(TL.getAttrNameLoc(), Record);
5689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrOperand()) {
5699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    SourceRange range = TL.getAttrOperandParensRange();
5709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Writer.AddSourceLocation(range.getBegin(), Record);
5719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Writer.AddSourceLocation(range.getEnd(), Record);
5729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
5739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrExprOperand()) {
5749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Expr *operand = TL.getAttrExprOperand();
5759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Record.push_back(operand ? 1 : 0);
5769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (operand) Writer.AddStmt(operand);
5779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  } else if (TL.hasAttrEnumOperand()) {
5789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Writer.AddSourceLocation(TL.getAttrEnumOperandLoc(), Record);
5799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
5809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
58151bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
58251bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
583a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
58449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallvoid TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc(
58549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                                            SubstTemplateTypeParmTypeLoc TL) {
58649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
58749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
588c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc(
589c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          SubstTemplateTypeParmPackTypeLoc TL) {
590c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  Writer.AddSourceLocation(TL.getNameLoc(), Record);
591c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}
59251bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitTemplateSpecializationTypeLoc(
59351bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                           TemplateSpecializationTypeLoc TL) {
59455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara  Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record);
595833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record);
596833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  Writer.AddSourceLocation(TL.getLAngleLoc(), Record);
597833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  Writer.AddSourceLocation(TL.getRAngleLoc(), Record);
598833ca991c1bfc967f0995974ca86f66ba1f666b5John 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);
601a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
602075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaravoid TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) {
603075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  Writer.AddSourceLocation(TL.getLParenLoc(), Record);
604075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  Writer.AddSourceLocation(TL.getRParenLoc(), Record);
605075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
606465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaravoid TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
60738a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara  Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record);
6089e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record);
609a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
6103cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallvoid TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
6113cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
6123cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
6134714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregorvoid TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
61438a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara  Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record);
6152494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record);
61651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
617a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
61833500955d731c73717af52088b7fc0e7a85681e7John McCallvoid TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc(
61933500955d731c73717af52088b7fc0e7a85681e7John McCall       DependentTemplateSpecializationTypeLoc TL) {
62055d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara  Writer.AddSourceLocation(TL.getElaboratedKeywordLoc(), Record);
62194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  Writer.AddNestedNameSpecifierLoc(TL.getQualifierLoc(), Record);
62266581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara  Writer.AddSourceLocation(TL.getTemplateKeywordLoc(), Record);
62355d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara  Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record);
62433500955d731c73717af52088b7fc0e7a85681e7John McCall  Writer.AddSourceLocation(TL.getLAngleLoc(), Record);
62533500955d731c73717af52088b7fc0e7a85681e7John McCall  Writer.AddSourceLocation(TL.getRAngleLoc(), Record);
62633500955d731c73717af52088b7fc0e7a85681e7John McCall  for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
62744f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis    Writer.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(),
62844f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis                                      TL.getArgLoc(I).getLocInfo(), Record);
62933500955d731c73717af52088b7fc0e7a85681e7John McCall}
6307536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorvoid TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) {
6317536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  Writer.AddSourceLocation(TL.getEllipsisLoc(), Record);
6327536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}
63351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
63451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getNameLoc(), Record);
635c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
636c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
637c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Record.push_back(TL.hasBaseTypeAsWritten());
63854e14c4db764c0636160d26c5bbf491637c83a76John McCall  Writer.AddSourceLocation(TL.getLAngleLoc(), Record);
63954e14c4db764c0636160d26c5bbf491637c83a76John McCall  Writer.AddSourceLocation(TL.getRAngleLoc(), Record);
64054e14c4db764c0636160d26c5bbf491637c83a76John McCall  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
64154e14c4db764c0636160d26c5bbf491637c83a76John McCall    Writer.AddSourceLocation(TL.getProtocolLoc(i), Record);
642a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
64351bd803fbdade51d674598ed45da3d54190a656cJohn McCallvoid TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
64451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  Writer.AddSourceLocation(TL.getStarLoc(), Record);
645a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall}
646b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanvoid TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
647b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  Writer.AddSourceLocation(TL.getKWLoc(), Record);
648b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  Writer.AddSourceLocation(TL.getLParenLoc(), Record);
649b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  Writer.AddSourceLocation(TL.getRParenLoc(), Record);
650b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}
651a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
6524dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner//===----------------------------------------------------------------------===//
653a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl// ASTWriter Implementation
6542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===//
6552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
656b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattnerstatic void EmitBlockID(unsigned ID, const char *Name,
657b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner                        llvm::BitstreamWriter &Stream,
65889eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis                        ASTWriter::RecordDataImpl &Record) {
659b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Record.clear();
660b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Record.push_back(ID);
661b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
662b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner
663b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  // Emit the block name if present.
6646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  if (!Name || Name[0] == 0)
6656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return;
666b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Record.clear();
667b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  while (*Name)
668b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner    Record.push_back(*Name++);
669b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record);
670b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner}
671b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner
672b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattnerstatic void EmitRecordID(unsigned ID, const char *Name,
673b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner                         llvm::BitstreamWriter &Stream,
67489eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis                         ASTWriter::RecordDataImpl &Record) {
675b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Record.clear();
676b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Record.push_back(ID);
677b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  while (*Name)
678b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner    Record.push_back(*Name++);
679b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
6800558df2da807646e65d4fa290f4e92114af1a746Chris Lattner}
6810558df2da807646e65d4fa290f4e92114af1a746Chris Lattner
6820558df2da807646e65d4fa290f4e92114af1a746Chris Lattnerstatic void AddStmtsExprs(llvm::BitstreamWriter &Stream,
68389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis                          ASTWriter::RecordDataImpl &Record) {
6848538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define RECORD(X) EmitRecordID(X, #X, Stream, Record)
6850558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_STOP);
6860558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_NULL_PTR);
6870558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_NULL);
6880558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_COMPOUND);
6890558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_CASE);
6900558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_DEFAULT);
6910558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_LABEL);
692534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  RECORD(STMT_ATTRIBUTED);
6930558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_IF);
6940558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_SWITCH);
6950558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_WHILE);
6960558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_DO);
6970558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_FOR);
6980558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_GOTO);
6990558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_INDIRECT_GOTO);
7000558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_CONTINUE);
7010558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_BREAK);
7020558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_RETURN);
7030558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_DECL);
704df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  RECORD(STMT_GCCASM);
705cd518a0ebc7c0a6aa41d717c360462540ef80a76Chad Rosier  RECORD(STMT_MSASM);
7060558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_PREDEFINED);
7070558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_DECL_REF);
7080558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_INTEGER_LITERAL);
7090558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_FLOATING_LITERAL);
7100558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_IMAGINARY_LITERAL);
7110558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_STRING_LITERAL);
7120558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_CHARACTER_LITERAL);
7130558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_PAREN);
7140558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_UNARY_OPERATOR);
7150558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_SIZEOF_ALIGN_OF);
7160558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_ARRAY_SUBSCRIPT);
7170558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_CALL);
7180558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_MEMBER);
7190558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_BINARY_OPERATOR);
7200558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR);
7210558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_CONDITIONAL_OPERATOR);
7220558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_IMPLICIT_CAST);
7230558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_CSTYLE_CAST);
7240558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_COMPOUND_LITERAL);
7250558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_EXT_VECTOR_ELEMENT);
7260558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_INIT_LIST);
7270558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_DESIGNATED_INIT);
7280558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_IMPLICIT_VALUE_INIT);
7290558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_VA_ARG);
7300558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_ADDR_LABEL);
7310558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_STMT);
7320558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_CHOOSE);
7330558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_GNU_NULL);
7340558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_SHUFFLE_VECTOR);
7350558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_BLOCK);
736f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  RECORD(EXPR_GENERIC_SELECTION);
7370558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_OBJC_STRING_LITERAL);
738eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  RECORD(EXPR_OBJC_BOXED_EXPRESSION);
739ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  RECORD(EXPR_OBJC_ARRAY_LITERAL);
740ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  RECORD(EXPR_OBJC_DICTIONARY_LITERAL);
7410558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_OBJC_ENCODE);
7420558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_OBJC_SELECTOR_EXPR);
7430558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_OBJC_PROTOCOL_EXPR);
7440558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_OBJC_IVAR_REF_EXPR);
7450558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_OBJC_PROPERTY_REF_EXPR);
7460558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_OBJC_KVC_REF_EXPR);
7470558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(EXPR_OBJC_MESSAGE_EXPR);
7480558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_OBJC_FOR_COLLECTION);
7490558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_OBJC_CATCH);
7500558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_OBJC_FINALLY);
7510558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_OBJC_AT_TRY);
7520558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_OBJC_AT_SYNCHRONIZED);
7530558df2da807646e65d4fa290f4e92114af1a746Chris Lattner  RECORD(STMT_OBJC_AT_THROW);
754ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  RECORD(EXPR_OBJC_BOOL_LITERAL);
755eb7f96141f754150a92433286fa385910a22f494Sam Weinig  RECORD(EXPR_CXX_OPERATOR_CALL);
756eb7f96141f754150a92433286fa385910a22f494Sam Weinig  RECORD(EXPR_CXX_CONSTRUCT);
757eb7f96141f754150a92433286fa385910a22f494Sam Weinig  RECORD(EXPR_CXX_STATIC_CAST);
758eb7f96141f754150a92433286fa385910a22f494Sam Weinig  RECORD(EXPR_CXX_DYNAMIC_CAST);
759eb7f96141f754150a92433286fa385910a22f494Sam Weinig  RECORD(EXPR_CXX_REINTERPRET_CAST);
760eb7f96141f754150a92433286fa385910a22f494Sam Weinig  RECORD(EXPR_CXX_CONST_CAST);
761eb7f96141f754150a92433286fa385910a22f494Sam Weinig  RECORD(EXPR_CXX_FUNCTIONAL_CAST);
7629fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  RECORD(EXPR_USER_DEFINED_LITERAL);
7637c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  RECORD(EXPR_CXX_STD_INITIALIZER_LIST);
764eb7f96141f754150a92433286fa385910a22f494Sam Weinig  RECORD(EXPR_CXX_BOOL_LITERAL);
765eb7f96141f754150a92433286fa385910a22f494Sam Weinig  RECORD(EXPR_CXX_NULL_PTR_LITERAL);
766b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_TYPEID_EXPR);
767b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_TYPEID_TYPE);
768b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_UUIDOF_EXPR);
769b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_UUIDOF_TYPE);
770b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_THIS);
771b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_THROW);
772b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_DEFAULT_ARG);
773b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_BIND_TEMPORARY);
774b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_SCALAR_VALUE_INIT);
775b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_NEW);
776b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_DELETE);
777b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR);
778b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_EXPR_WITH_CLEANUPS);
779b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER);
780b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF);
781b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT);
782b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_UNRESOLVED_MEMBER);
783b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_UNRESOLVED_LOOKUP);
784b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_CXX_NOEXCEPT);
785b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_OPAQUE_VALUE);
786b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_PACK_EXPANSION);
787b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_SIZEOF_PACK);
788b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK);
789e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  RECORD(EXPR_CUDA_KERNEL_CALL);
7900558df2da807646e65d4fa290f4e92114af1a746Chris Lattner#undef RECORD
791b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner}
7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
793a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redlvoid ASTWriter::WriteBlockInfoBlock() {
794b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RecordData Record;
795b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3);
7961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7978538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record)
7988538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl#define RECORD(X) EmitRecordID(X, #X, Stream, Record)
7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8007ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  // Control Block.
8017ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  BLOCK(CONTROL_BLOCK);
8027ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  RECORD(METADATA);
8036bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  RECORD(MODULE_NAME);
8046bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  RECORD(MODULE_MAP_FILE);
8057ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  RECORD(IMPORTS);
8067ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  RECORD(LANGUAGE_OPTIONS);
8077ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  RECORD(TARGET_OPTIONS);
80839c497b6d5e99acecbe03ee173249ee21933e855Douglas Gregor  RECORD(ORIGINAL_FILE);
8097ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  RECORD(ORIGINAL_PCH_DIR);
810992d91742129c1f77563df0b3d0a40b36fd13e3eArgyrios Kyrtzidis  RECORD(ORIGINAL_FILE_ID);
811a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor  RECORD(INPUT_FILE_OFFSETS);
8125f3d8224af99ad0d9107601c0c31b74693371cc1Douglas Gregor  RECORD(DIAGNOSTIC_OPTIONS);
8131b2c3c0884e917ae5d59edde7d93b2af33c6a1b6Douglas Gregor  RECORD(FILE_SYSTEM_OPTIONS);
814bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor  RECORD(HEADER_SEARCH_OPTIONS);
815a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor  RECORD(PREPROCESSOR_OPTIONS);
816a71a7d8a1ce4474e7bdb680658fb58b6caf391d3Douglas Gregor
817c337fefd7317714d365a2acf4f1d2939bbcf8e3bDouglas Gregor  BLOCK(INPUT_FILES_BLOCK);
818c337fefd7317714d365a2acf4f1d2939bbcf8e3bDouglas Gregor  RECORD(INPUT_FILE);
819c337fefd7317714d365a2acf4f1d2939bbcf8e3bDouglas Gregor
8207ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  // AST Top-Level Block.
8217ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  BLOCK(AST_BLOCK);
822b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_OFFSET);
823b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(DECL_OFFSET);
824b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(IDENTIFIER_OFFSET);
825b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(IDENTIFIER_TABLE);
826651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  RECORD(EAGERLY_DESERIALIZED_DECLS);
827b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(SPECIAL_TYPES);
828b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(STATISTICS);
829b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TENTATIVE_DEFINITIONS);
83049b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis  RECORD(UNUSED_FILESCOPED_DECLS);
8315ea6ef490547917426d5e2ed14c9f36521bbeacfRichard Smith  RECORD(LOCALLY_SCOPED_EXTERN_C_DECLS);
832b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(SELECTOR_OFFSETS);
833b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(METHOD_POOL);
834b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(PP_COUNTER_VALUE);
8357f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  RECORD(SOURCE_LOCATION_OFFSETS);
8367f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  RECORD(SOURCE_LOCATION_PRELOADS);
837b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor  RECORD(EXT_VECTOR_DECLS);
838e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  RECORD(PPD_ENTITIES_OFFSETS);
839320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian  RECORD(REFERENCED_SELECTOR_POOL);
840b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TU_UPDATE_LEXICAL);
8412171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor  RECORD(LOCAL_REDECLARATIONS_MAP);
842b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(SEMA_DECL_REFS);
843b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(WEAK_UNDECLARED_IDENTIFIERS);
844b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(PENDING_IMPLICIT_INSTANTIATIONS);
845b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_REPLACEMENTS);
846b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(UPDATE_VISIBLE);
847b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_UPDATE_OFFSETS);
848b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_UPDATES);
849b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(CXX_BASE_SPECIFIER_OFFSETS);
850b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DIAG_PRAGMA_MAPPINGS);
85184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  RECORD(CUDA_SPECIAL_DECL_REFS);
852cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  RECORD(HEADER_SEARCH_TABLE);
85384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  RECORD(FP_PRAGMA_OPTIONS);
85484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  RECORD(OPENCL_EXTENSIONS);
855ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt  RECORD(DELEGATING_CTORS);
856d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  RECORD(KNOWN_NAMESPACES);
857cd0655b17249c4c4908ca91462657f62285017e6Nick Lewycky  RECORD(UNDEFINED_BUT_USED);
858837593fec8389eea3143920d7f2180b079b609e8Douglas Gregor  RECORD(MODULE_OFFSET_MAP);
859837593fec8389eea3143920d7f2180b079b609e8Douglas Gregor  RECORD(SOURCE_MANAGER_LINE_TABLE);
860cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  RECORD(OBJC_CATEGORIES_MAP);
861a126651270acf17c434f60f86a3ab3687f87813aDouglas Gregor  RECORD(FILE_SORTED_DECLS);
862a126651270acf17c434f60f86a3ab3687f87813aDouglas Gregor  RECORD(IMPORTED_MODULES);
8632171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor  RECORD(MERGED_DECLARATIONS);
8642171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor  RECORD(LOCAL_REDECLARATIONS);
865cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  RECORD(OBJC_CATEGORIES);
866a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  RECORD(MACRO_OFFSET);
8679317ab94bb68122ba6fc728eb73c1308fb913cd1Argyrios Kyrtzidis  RECORD(MACRO_TABLE);
868ac32d9044b9c1e7492cef929a322d23ce899d276Richard Smith  RECORD(LATE_PARSED_TEMPLATE);
8696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  RECORD(OPTIMIZE_PRAGMA_OPTIONS);
8702171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor
871b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  // SourceManager Block.
8722f4efd10c805cb779618c1a22a35eb07b5043c4eChris Lattner  BLOCK(SOURCE_MANAGER_BLOCK);
873b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(SM_SLOC_FILE_ENTRY);
874b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(SM_SLOC_BUFFER_ENTRY);
875b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(SM_SLOC_BUFFER_BLOB);
876f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth  RECORD(SM_SLOC_EXPANSION_ENTRY);
8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
878b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  // Preprocessor Block.
8792f4efd10c805cb779618c1a22a35eb07b5043c4eChris Lattner  BLOCK(PREPROCESSOR_BLOCK);
880b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(PP_MACRO_OBJECT_LIKE);
881b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(PP_MACRO_FUNCTION_LIKE);
882b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(PP_TOKEN);
883b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor
88461d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor  // Decls and Types block.
88561d60ee6aa0a5ded0ddcf48679673b37506a1895Douglas Gregor  BLOCK(DECLTYPES_BLOCK);
886b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_EXT_QUAL);
887b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_COMPLEX);
888b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_POINTER);
889b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_BLOCK_POINTER);
890b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_LVALUE_REFERENCE);
891b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_RVALUE_REFERENCE);
892b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_MEMBER_POINTER);
893b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_CONSTANT_ARRAY);
894b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_INCOMPLETE_ARRAY);
895b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_VARIABLE_ARRAY);
896b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_VECTOR);
897b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_EXT_VECTOR);
898b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_FUNCTION_PROTO);
899b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_FUNCTION_NO_PROTO);
900b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_TYPEDEF);
901b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_TYPEOF_EXPR);
902b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_TYPEOF);
903b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_RECORD);
904b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_ENUM);
905b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(TYPE_OBJC_INTERFACE);
906a53d2cbe37e4be0d95b9d3e09f74eafae31fc940John McCall  RECORD(TYPE_OBJC_OBJECT);
907d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  RECORD(TYPE_OBJC_OBJECT_POINTER);
908b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_DECLTYPE);
909b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_ELABORATED);
910b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM);
911b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_UNRESOLVED_USING);
912b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_INJECTED_CLASS_NAME);
913b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_OBJC_OBJECT);
914b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_TEMPLATE_TYPE_PARM);
915b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_TEMPLATE_SPECIALIZATION);
916b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_DEPENDENT_NAME);
917b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION);
918b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_DEPENDENT_SIZED_ARRAY);
919b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_PAREN);
920b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_PACK_EXPANSION);
921b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_ATTRIBUTED);
922b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK);
923b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  RECORD(TYPE_ATOMIC);
9240ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_TYPEDEF);
9250ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_ENUM);
9260ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_RECORD);
9270ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_ENUM_CONSTANT);
9280ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_FUNCTION);
9290ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_METHOD);
9300ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_INTERFACE);
9310ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_PROTOCOL);
9320ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_IVAR);
9330ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_AT_DEFS_FIELD);
9340ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_CATEGORY);
9350ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_CATEGORY_IMPL);
9360ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_IMPLEMENTATION);
9370ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_COMPATIBLE_ALIAS);
9380ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_PROPERTY);
9390ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_OBJC_PROPERTY_IMPL);
940b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(DECL_FIELD);
94176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  RECORD(DECL_MS_PROPERTY);
942b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(DECL_VAR);
9430ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_IMPLICIT_PARAM);
944b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  RECORD(DECL_PARM_VAR);
9450ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_FILE_SCOPE_ASM);
9460ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_BLOCK);
9470ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_CONTEXT_LEXICAL);
9480ff8cda4442cff571aba1be91dd16f64a0bf16aaChris Lattner  RECORD(DECL_CONTEXT_VISIBLE);
949b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_NAMESPACE);
950b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_NAMESPACE_ALIAS);
951b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_USING);
952b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_USING_SHADOW);
953b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_USING_DIRECTIVE);
954b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_UNRESOLVED_USING_VALUE);
955b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_UNRESOLVED_USING_TYPENAME);
956b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_LINKAGE_SPEC);
957b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_CXX_RECORD);
958b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_CXX_METHOD);
959b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_CXX_CONSTRUCTOR);
960b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_CXX_DESTRUCTOR);
961b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_CXX_CONVERSION);
962b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_ACCESS_SPEC);
963b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_FRIEND);
964b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_FRIEND_TEMPLATE);
965b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_CLASS_TEMPLATE);
966b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION);
967b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION);
968ef4579cda09b73e3d4d98af48201da25adc29326Larisse Voufo  RECORD(DECL_VAR_TEMPLATE);
969ef4579cda09b73e3d4d98af48201da25adc29326Larisse Voufo  RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION);
970ef4579cda09b73e3d4d98af48201da25adc29326Larisse Voufo  RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION);
971b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_FUNCTION_TEMPLATE);
972b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_TEMPLATE_TYPE_PARM);
973b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_NON_TYPE_TEMPLATE_PARM);
974b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_TEMPLATE_TEMPLATE_PARM);
975b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_STATIC_ASSERT);
976b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_CXX_BASE_SPECIFIERS);
977b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_INDIRECTFIELD);
978b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor  RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK);
979b6c2b3f658df5525b9c0af606b64d304e7416c2fDouglas Gregor
980a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor  // Statements and Exprs can occur in the Decls and Types block.
981a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor  AddStmtsExprs(Stream, Record);
982a72d8c4556fbdfca2c9e101722812861fcbdde12Douglas Gregor
9834800a5c79023271408af49797e09be32aca93232Douglas Gregor  BLOCK(PREPROCESSOR_DETAIL_BLOCK);
984f70d12dbd49fcc25f1dfc0127217112ae76bcb8fChandler Carruth  RECORD(PPD_MACRO_EXPANSION);
9854800a5c79023271408af49797e09be32aca93232Douglas Gregor  RECORD(PPD_MACRO_DEFINITION);
9864800a5c79023271408af49797e09be32aca93232Douglas Gregor  RECORD(PPD_INCLUSION_DIRECTIVE);
9874800a5c79023271408af49797e09be32aca93232Douglas Gregor
988b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner#undef RECORD
989b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner#undef BLOCK
990b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner  Stream.ExitBlock();
991b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner}
992b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner
993e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \brief Adjusts the given filename to only write out the portion of the
994e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// filename that is not part of the system root directory.
9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
996e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \param Filename the file name to adjust.
997e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor///
998e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and
999e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// the returned filename will be adjusted by this system root.
1000e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor///
1001e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// \returns either the original filename (if it needs no adjustment) or the
1002e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor/// adjusted filename (which points into the @p Filename parameter).
10031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpstatic const char *
1004832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas GregoradjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) {
1005e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  assert(Filename && "No file name to adjust?");
10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1007832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor  if (isysroot.empty())
1008e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor    return Filename;
10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1010e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  // Verify that the filename and the system root have the same prefix.
1011e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  unsigned Pos = 0;
1012832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor  for (; Filename[Pos] && Pos < isysroot.size(); ++Pos)
1013e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor    if (Filename[Pos] != isysroot[Pos])
1014e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor      return Filename; // Prefixes don't match.
10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1016e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  // We hit the end of the filename before we hit the end of the system root.
1017e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  if (!Filename[Pos])
1018e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor    return Filename;
10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1020e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  // If the file name has a '/' at the current position, skip over the '/'.
1021e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  // We distinguish sysroot-based includes from absolute includes by the
1022e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  // absence of '/' at the beginning of sysroot-based includes.
1023e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  if (Filename[Pos] == '/')
1024e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor    ++Pos;
10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1026e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  return Filename + Pos;
1027e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor}
1028b145b1e9de866e79fb386e4a074dc0b41853acf3Chris Lattner
10291d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor/// \brief Write the control block.
1030bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregorvoid ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
1031bbf38319edd4eddc55ec273934e990d7e84991deDouglas Gregor                                  StringRef isysroot,
10321d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor                                  const std::string &OutputFile) {
10332bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor  using namespace llvm;
10347ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  Stream.EnterSubblock(CONTROL_BLOCK_ID, 5);
10357ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  RecordData Record;
10361d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor
1037e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  // Metadata
10387ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  BitCodeAbbrev *MetadataAbbrev = new BitCodeAbbrev();
10397ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA));
10407ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major
10417ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor
10427ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj.
10437ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min.
10447ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable
10457ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors
10467ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag
10477ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  unsigned MetadataAbbrevCode = Stream.EmitAbbrev(MetadataAbbrev);
10487ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  Record.push_back(METADATA);
10498538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Record.push_back(VERSION_MAJOR);
10508538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Record.push_back(VERSION_MINOR);
1051e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  Record.push_back(CLANG_VERSION_MAJOR);
1052e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  Record.push_back(CLANG_VERSION_MINOR);
1053832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor  Record.push_back(!isysroot.empty());
1054bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  Record.push_back(ASTHasCompilerErrors);
10557ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor  Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record,
10567ae467f02b0f2ba3897ee03e0d011433789b5434Douglas Gregor                            getClangFullRepositoryVersion());
1057e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor
10586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  // Module name
10596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  if (WritingModule) {
10606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
10616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME));
10626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
10636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev);
10646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    RecordData Record;
10656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Record.push_back(MODULE_NAME);
10666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name);
10676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  }
10686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
10696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  // Module map file
10706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  if (WritingModule) {
10716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
10726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Abbrev->Add(BitCodeAbbrevOp(MODULE_MAP_FILE));
10736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Filename
10746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev);
10756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
10766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    assert(WritingModule->ModuleMap && "missing module map");
10776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    SmallString<128> ModuleMap(WritingModule->ModuleMap->getName());
10786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    llvm::sys::fs::make_absolute(ModuleMap);
10796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    RecordData Record;
10806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Record.push_back(MODULE_MAP_FILE);
10816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    Stream.EmitRecordWithBlob(AbbrevCode, Record, ModuleMap.str());
10826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  }
10836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
10841d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor  // Imports
1085e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor  if (Chain) {
1086e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor    serialization::ModuleManager &Mgr = Chain->getModuleManager();
1087e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor    Record.clear();
108810bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor
108910bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor    for (ModuleManager::ModuleIterator M = Mgr.begin(), MEnd = Mgr.end();
109010bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor         M != MEnd; ++M) {
109110bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor      // Skip modules that weren't directly imported.
109210bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor      if (!(*M)->isDirectlyImported())
109310bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor        continue;
109410bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor
109510bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor      Record.push_back((unsigned)(*M)->Kind); // FIXME: Stable encoding
1096958bcaf3d4e0c1ae46de3e84e7c2a7638c3c5286Argyrios Kyrtzidis      AddSourceLocation((*M)->ImportLoc, Record);
1097677e15ffee2ecc9c1c8f46fd77cab4b5afb59640Douglas Gregor      Record.push_back((*M)->File->getSize());
1098677e15ffee2ecc9c1c8f46fd77cab4b5afb59640Douglas Gregor      Record.push_back((*M)->File->getModificationTime());
109910bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor      const std::string &FileName = (*M)->FileName;
110010bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor      Record.push_back(FileName.size());
110110bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor      Record.append(FileName.begin(), FileName.end());
110210bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor    }
1103e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor    Stream.EmitRecord(IMPORTS, Record);
1104e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor  }
11051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11061d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor  // Language options.
11071d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor  Record.clear();
11081d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor  const LangOptions &LangOpts = Context.getLangOpts();
11091d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor#define LANGOPT(Name, Bits, Default, Description) \
11101d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor  Record.push_back(LangOpts.Name);
11111d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
11121d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor  Record.push_back(static_cast<unsigned>(LangOpts.get##Name()));
11131d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor#include "clang/Basic/LangOptions.def"
11144f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz#define SANITIZER(NAME, ID) Record.push_back(LangOpts.Sanitize.ID);
11154f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz#include "clang/Basic/Sanitizers.def"
11161d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor
11171d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor  Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind());
11181d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor  AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record);
1119