//===--- PCHWriter.h - Precompiled Headers Writer ---------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the PCHWriter class, which writes a precompiled header.
//
//===----------------------------------------------------------------------===//
#include "clang/Frontend/PCHWriter.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclContextInternals.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/Type.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/SourceManagerInternals.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MemoryBuffer.h"
#include <cstdio>
using namespace clang;
//===----------------------------------------------------------------------===//
// Type serialization
//===----------------------------------------------------------------------===//
namespace {
class VISIBILITY_HIDDEN PCHTypeWriter {
PCHWriter &Writer;
PCHWriter::RecordData &Record;
public:
/// \brief Type code that corresponds to the record generated.
pch::TypeCode Code;
PCHTypeWriter(PCHWriter &Writer, PCHWriter::RecordData &Record)
: Writer(Writer), Record(Record) { }
void VisitArrayType(const ArrayType *T);
void VisitFunctionType(const FunctionType *T);
void VisitTagType(const TagType *T);
#define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T);
#define ABSTRACT_TYPE(Class, Base)
#define DEPENDENT_TYPE(Class, Base)
#include "clang/AST/TypeNodes.def"
};
}
void PCHTypeWriter::VisitExtQualType(const ExtQualType *T) {
Writer.AddTypeRef(QualType(T->getBaseType(), 0), Record);
Record.push_back(T->getObjCGCAttr()); // FIXME: use stable values
Record.push_back(T->getAddressSpace());
Code = pch::TYPE_EXT_QUAL;
}
void PCHTypeWriter::VisitBuiltinType(const BuiltinType *T) {
assert(false && "Built-in types are never serialized");
}
void PCHTypeWriter::VisitFixedWidthIntType(const FixedWidthIntType *T) {
Record.push_back(T->getWidth());
Record.push_back(T->isSigned());
Code = pch::TYPE_FIXED_WIDTH_INT;
}
void PCHTypeWriter::VisitComplexType(const ComplexType *T) {
Writer.AddTypeRef(T->getElementType(), Record);
Code = pch::TYPE_COMPLEX;
}
void PCHTypeWriter::VisitPointerType(const PointerType *T) {
Writer.AddTypeRef(T->getPointeeType(), Record);
Code = pch::TYPE_POINTER;
}
void PCHTypeWriter::VisitBlockPointerType(const BlockPointerType *T) {
Writer.AddTypeRef(T->getPointeeType(), Record);
Code = pch::TYPE_BLOCK_POINTER;
}
void PCHTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) {
Writer.AddTypeRef(T->getPointeeType(), Record);
Code = pch::TYPE_LVALUE_REFERENCE;
}
void PCHTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) {
Writer.AddTypeRef(T->getPointeeType(), Record);
Code = pch::TYPE_RVALUE_REFERENCE;
}
void PCHTypeWriter::VisitMemberPointerType(const MemberPointerType *T) {
Writer.AddTypeRef(T->getPointeeType(), Record);
Writer.AddTypeRef(QualType(T->getClass(), 0), Record);
Code = pch::TYPE_MEMBER_POINTER;
}
void PCHTypeWriter::VisitArrayType(const ArrayType *T) {
Writer.AddTypeRef(T->getElementType(), Record);
Record.push_back(T->getSizeModifier()); // FIXME: stable values
Record.push_back(T->getIndexTypeQualifier()); // FIXME: stable values
}
void PCHTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) {
VisitArrayType(T);
Writer.AddAPInt(T->getSize(), Record);
Code = pch::TYPE_CONSTANT_ARRAY;
}
void PCHTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
VisitArrayType(T);
Code = pch::TYPE_INCOMPLETE_ARRAY;
}
void PCHTypeWriter::VisitVariableArrayType(const VariableArrayType *T) {
VisitArrayType(T);
// FIXME: Serialize array size expression.
assert(false && "Cannot serialize variable-length arrays");
Code = pch::TYPE_VARIABLE_ARRAY;
}
void PCHTypeWriter::VisitVectorType(const VectorType *T) {
Writer.AddTypeRef(T