2009-04-10 06:27:44 +08:00
|
|
|
//===--- 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"
|
2009-04-20 23:53:59 +08:00
|
|
|
#include "../Sema/Sema.h" // FIXME: move header into include/clang/Sema
|
2009-09-09 23:08:12 +08:00
|
|
|
#include "../Sema/IdentifierResolver.h" // FIXME: move header
|
2009-04-10 06:27:44 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
#include "clang/AST/DeclContextInternals.h"
|
2009-04-15 05:18:50 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2009-04-10 06:27:44 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2009-10-17 05:56:05 +08:00
|
|
|
#include "clang/AST/TypeLocVisitor.h"
|
2009-04-11 02:00:12 +08:00
|
|
|
#include "clang/Lex/MacroInfo.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2009-04-25 04:03:17 +08:00
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
2009-04-10 11:52:48 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
2009-04-21 04:36:09 +08:00
|
|
|
#include "clang/Basic/OnDiskHashTable.h"
|
2009-04-10 11:52:48 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2009-04-14 00:31:14 +08:00
|
|
|
#include "clang/Basic/SourceManagerInternals.h"
|
2009-04-11 05:16:55 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2009-04-28 06:23:34 +08:00
|
|
|
#include "clang/Basic/Version.h"
|
2009-04-15 05:55:33 +08:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
|
|
|
#include "llvm/ADT/APInt.h"
|
2009-10-18 07:52:28 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2009-04-10 06:27:44 +08:00
|
|
|
#include "llvm/Bitcode/BitstreamWriter.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2009-04-10 11:52:48 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2009-05-12 09:31:05 +08:00
|
|
|
#include "llvm/System/Path.h"
|
2009-04-12 02:40:46 +08:00
|
|
|
#include <cstdio>
|
2009-04-10 06:27:44 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-04-27 14:16:06 +08:00
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
namespace {
|
|
|
|
class VISIBILITY_HIDDEN PCHTypeWriter {
|
|
|
|
PCHWriter &Writer;
|
|
|
|
PCHWriter::RecordData &Record;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// \brief Type code that corresponds to the record generated.
|
|
|
|
pch::TypeCode Code;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
PCHTypeWriter(PCHWriter &Writer, PCHWriter::RecordData &Record)
|
2009-04-28 02:38:38 +08:00
|
|
|
: Writer(Writer), Record(Record), Code(pch::TYPE_EXT_QUAL) { }
|
2009-04-10 06:27:44 +08:00
|
|
|
|
|
|
|
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::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) {
|
2009-09-09 23:08:12 +08:00
|
|
|
Writer.AddTypeRef(T->getPointeeType(), Record);
|
2009-04-10 06:27:44 +08:00
|
|
|
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) {
|
2009-09-09 23:08:12 +08:00
|
|
|
Writer.AddTypeRef(T->getPointeeType(), Record);
|
|
|
|
Writer.AddTypeRef(QualType(T->getClass(), 0), Record);
|
2009-04-10 06:27:44 +08:00
|
|
|
Code = pch::TYPE_MEMBER_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitArrayType(const ArrayType *T) {
|
|
|
|
Writer.AddTypeRef(T->getElementType(), Record);
|
|
|
|
Record.push_back(T->getSizeModifier()); // FIXME: stable values
|
2009-09-25 03:53:00 +08:00
|
|
|
Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2009-07-06 23:59:29 +08:00
|
|
|
Writer.AddSourceLocation(T->getLBracketLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(T->getRBracketLoc(), Record);
|
2009-04-17 06:23:12 +08:00
|
|
|
Writer.AddStmt(T->getSizeExpr());
|
2009-04-10 06:27:44 +08:00
|
|
|
Code = pch::TYPE_VARIABLE_ARRAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitVectorType(const VectorType *T) {
|
|
|
|
Writer.AddTypeRef(T->getElementType(), Record);
|
|
|
|
Record.push_back(T->getNumElements());
|
|
|
|
Code = pch::TYPE_VECTOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitExtVectorType(const ExtVectorType *T) {
|
|
|
|
VisitVectorType(T);
|
|
|
|
Code = pch::TYPE_EXT_VECTOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitFunctionType(const FunctionType *T) {
|
|
|
|
Writer.AddTypeRef(T->getResultType(), Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
|
|
|
|
VisitFunctionType(T);
|
|
|
|
Code = pch::TYPE_FUNCTION_NO_PROTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) {
|
|
|
|
VisitFunctionType(T);
|
|
|
|
Record.push_back(T->getNumArgs());
|
|
|
|
for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I)
|
|
|
|
Writer.AddTypeRef(T->getArgType(I), Record);
|
|
|
|
Record.push_back(T->isVariadic());
|
|
|
|
Record.push_back(T->getTypeQuals());
|
2009-05-28 06:11:52 +08:00
|
|
|
Record.push_back(T->hasExceptionSpec());
|
|
|
|
Record.push_back(T->hasAnyExceptionSpec());
|
|
|
|
Record.push_back(T->getNumExceptions());
|
|
|
|
for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I)
|
|
|
|
Writer.AddTypeRef(T->getExceptionType(I), Record);
|
2009-04-10 06:27:44 +08:00
|
|
|
Code = pch::TYPE_FUNCTION_PROTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitTypedefType(const TypedefType *T) {
|
|
|
|
Writer.AddDeclRef(T->getDecl(), Record);
|
|
|
|
Code = pch::TYPE_TYPEDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) {
|
2009-04-17 06:23:12 +08:00
|
|
|
Writer.AddStmt(T->getUnderlyingExpr());
|
2009-04-10 06:27:44 +08:00
|
|
|
Code = pch::TYPE_TYPEOF_EXPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitTypeOfType(const TypeOfType *T) {
|
|
|
|
Writer.AddTypeRef(T->getUnderlyingType(), Record);
|
|
|
|
Code = pch::TYPE_TYPEOF;
|
|
|
|
}
|
|
|
|
|
2009-06-25 03:06:50 +08:00
|
|
|
void PCHTypeWriter::VisitDecltypeType(const DecltypeType *T) {
|
|
|
|
Writer.AddStmt(T->getUnderlyingExpr());
|
|
|
|
Code = pch::TYPE_DECLTYPE;
|
|
|
|
}
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
void PCHTypeWriter::VisitTagType(const TagType *T) {
|
|
|
|
Writer.AddDeclRef(T->getDecl(), Record);
|
2009-09-09 23:08:12 +08:00
|
|
|
assert(!T->isBeingDefined() &&
|
2009-04-10 06:27:44 +08:00
|
|
|
"Cannot serialize in the middle of a type definition");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitRecordType(const RecordType *T) {
|
|
|
|
VisitTagType(T);
|
|
|
|
Code = pch::TYPE_RECORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitEnumType(const EnumType *T) {
|
|
|
|
VisitTagType(T);
|
|
|
|
Code = pch::TYPE_ENUM;
|
|
|
|
}
|
|
|
|
|
2009-09-05 08:15:47 +08:00
|
|
|
void PCHTypeWriter::VisitElaboratedType(const ElaboratedType *T) {
|
|
|
|
Writer.AddTypeRef(T->getUnderlyingType(), Record);
|
|
|
|
Record.push_back(T->getTagKind());
|
|
|
|
Code = pch::TYPE_ELABORATED;
|
|
|
|
}
|
|
|
|
|
2009-10-18 17:09:24 +08:00
|
|
|
void
|
|
|
|
PCHTypeWriter::VisitSubstTemplateTypeParmType(
|
|
|
|
const SubstTemplateTypeParmType *T) {
|
|
|
|
Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record);
|
|
|
|
Writer.AddTypeRef(T->getReplacementType(), Record);
|
|
|
|
Code = pch::TYPE_SUBST_TEMPLATE_TYPE_PARM;
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void
|
2009-04-10 06:27:44 +08:00
|
|
|
PCHTypeWriter::VisitTemplateSpecializationType(
|
|
|
|
const TemplateSpecializationType *T) {
|
2009-04-16 02:43:11 +08:00
|
|
|
// FIXME: Serialize this type (C++ only)
|
2009-04-10 06:27:44 +08:00
|
|
|
assert(false && "Cannot serialize template specialization types");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitQualifiedNameType(const QualifiedNameType *T) {
|
2009-04-16 02:43:11 +08:00
|
|
|
// FIXME: Serialize this type (C++ only)
|
2009-04-10 06:27:44 +08:00
|
|
|
assert(false && "Cannot serialize qualified name types");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
|
|
|
|
Writer.AddDeclRef(T->getDecl(), Record);
|
|
|
|
Record.push_back(T->getNumProtocols());
|
2009-05-28 00:21:00 +08:00
|
|
|
for (ObjCInterfaceType::qual_iterator I = T->qual_begin(),
|
|
|
|
E = T->qual_end(); I != E; ++I)
|
|
|
|
Writer.AddDeclRef(*I, Record);
|
2009-07-18 23:33:26 +08:00
|
|
|
Code = pch::TYPE_OBJC_INTERFACE;
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
2009-06-18 06:40:22 +08:00
|
|
|
void
|
|
|
|
PCHTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
|
2009-09-09 23:08:12 +08:00
|
|
|
Writer.AddTypeRef(T->getPointeeType(), Record);
|
2009-04-10 06:27:44 +08:00
|
|
|
Record.push_back(T->getNumProtocols());
|
2009-06-18 06:40:22 +08:00
|
|
|
for (ObjCInterfaceType::qual_iterator I = T->qual_begin(),
|
2009-05-28 00:21:00 +08:00
|
|
|
E = T->qual_end(); I != E; ++I)
|
|
|
|
Writer.AddDeclRef(*I, Record);
|
2009-06-18 06:40:22 +08:00
|
|
|
Code = pch::TYPE_OBJC_OBJECT_POINTER;
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
2009-10-17 05:56:05 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> {
|
|
|
|
PCHWriter &Writer;
|
|
|
|
PCHWriter::RecordData &Record;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TypeLocWriter(PCHWriter &Writer, PCHWriter::RecordData &Record)
|
|
|
|
: Writer(Writer), Record(Record) { }
|
|
|
|
|
2009-10-18 09:05:36 +08:00
|
|
|
#define ABSTRACT_TYPELOC(CLASS, PARENT)
|
2009-10-17 05:56:05 +08:00
|
|
|
#define TYPELOC(CLASS, PARENT) \
|
2009-10-18 09:05:36 +08:00
|
|
|
void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
|
2009-10-17 05:56:05 +08:00
|
|
|
#include "clang/AST/TypeLocNodes.def"
|
|
|
|
|
2009-10-18 09:05:36 +08:00
|
|
|
void VisitArrayTypeLoc(ArrayTypeLoc TyLoc);
|
|
|
|
void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc);
|
2009-10-17 05:56:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitFixedWidthIntTypeLoc(FixedWidthIntTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getStarLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getCaretLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getAmpLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getStarLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getLBracketLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(TL.getRBracketLoc(), Record);
|
|
|
|
Record.push_back(TL.getSizeExpr() ? 1 : 0);
|
|
|
|
if (TL.getSizeExpr())
|
|
|
|
Writer.AddStmt(TL.getSizeExpr());
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
|
|
|
|
VisitArrayTypeLoc(TL);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
|
|
|
|
VisitArrayTypeLoc(TL);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
|
|
|
|
VisitArrayTypeLoc(TL);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitDependentSizedArrayTypeLoc(
|
|
|
|
DependentSizedArrayTypeLoc TL) {
|
|
|
|
VisitArrayTypeLoc(TL);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc(
|
|
|
|
DependentSizedExtVectorTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getLParenLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(TL.getRParenLoc(), Record);
|
|
|
|
for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
|
|
|
|
Writer.AddDeclRef(TL.getArg(i), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
|
|
|
|
VisitFunctionTypeLoc(TL);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
|
|
|
|
VisitFunctionTypeLoc(TL);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
|
|
|
void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
2009-10-18 17:09:24 +08:00
|
|
|
void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc(
|
|
|
|
SubstTemplateTypeParmTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
|
|
|
}
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitTemplateSpecializationTypeLoc(
|
|
|
|
TemplateSpecializationTypeLoc TL) {
|
2009-10-29 16:12:44 +08:00
|
|
|
Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(TL.getLAngleLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(TL.getRAngleLoc(), Record);
|
|
|
|
for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
|
|
|
|
Writer.AddTemplateArgumentLoc(TL.getArgLoc(i), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitQualifiedNameTypeLoc(QualifiedNameTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitTypenameTypeLoc(TypenameTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getNameLoc(), Record);
|
2009-10-23 06:37:11 +08:00
|
|
|
Writer.AddSourceLocation(TL.getLAngleLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(TL.getRAngleLoc(), Record);
|
|
|
|
for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
|
|
|
|
Writer.AddSourceLocation(TL.getProtocolLoc(i), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
2009-10-18 09:05:36 +08:00
|
|
|
void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
|
|
|
|
Writer.AddSourceLocation(TL.getStarLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(TL.getLAngleLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(TL.getRAngleLoc(), Record);
|
2009-10-23 06:37:11 +08:00
|
|
|
Record.push_back(TL.hasBaseTypeAsWritten());
|
|
|
|
Record.push_back(TL.hasProtocolsAsWritten());
|
|
|
|
if (TL.hasProtocolsAsWritten())
|
|
|
|
for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
|
|
|
|
Writer.AddSourceLocation(TL.getProtocolLoc(i), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
}
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PCHWriter Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-27 06:26:21 +08:00
|
|
|
static void EmitBlockID(unsigned ID, const char *Name,
|
|
|
|
llvm::BitstreamWriter &Stream,
|
|
|
|
PCHWriter::RecordData &Record) {
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(ID);
|
|
|
|
Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
|
|
|
|
|
|
|
|
// Emit the block name if present.
|
|
|
|
if (Name == 0 || Name[0] == 0) return;
|
|
|
|
Record.clear();
|
|
|
|
while (*Name)
|
|
|
|
Record.push_back(*Name++);
|
|
|
|
Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EmitRecordID(unsigned ID, const char *Name,
|
|
|
|
llvm::BitstreamWriter &Stream,
|
|
|
|
PCHWriter::RecordData &Record) {
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(ID);
|
|
|
|
while (*Name)
|
|
|
|
Record.push_back(*Name++);
|
|
|
|
Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
|
2009-04-27 08:49:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void AddStmtsExprs(llvm::BitstreamWriter &Stream,
|
|
|
|
PCHWriter::RecordData &Record) {
|
|
|
|
#define RECORD(X) EmitRecordID(pch::X, #X, Stream, Record)
|
|
|
|
RECORD(STMT_STOP);
|
|
|
|
RECORD(STMT_NULL_PTR);
|
|
|
|
RECORD(STMT_NULL);
|
|
|
|
RECORD(STMT_COMPOUND);
|
|
|
|
RECORD(STMT_CASE);
|
|
|
|
RECORD(STMT_DEFAULT);
|
|
|
|
RECORD(STMT_LABEL);
|
|
|
|
RECORD(STMT_IF);
|
|
|
|
RECORD(STMT_SWITCH);
|
|
|
|
RECORD(STMT_WHILE);
|
|
|
|
RECORD(STMT_DO);
|
|
|
|
RECORD(STMT_FOR);
|
|
|
|
RECORD(STMT_GOTO);
|
|
|
|
RECORD(STMT_INDIRECT_GOTO);
|
|
|
|
RECORD(STMT_CONTINUE);
|
|
|
|
RECORD(STMT_BREAK);
|
|
|
|
RECORD(STMT_RETURN);
|
|
|
|
RECORD(STMT_DECL);
|
|
|
|
RECORD(STMT_ASM);
|
|
|
|
RECORD(EXPR_PREDEFINED);
|
|
|
|
RECORD(EXPR_DECL_REF);
|
|
|
|
RECORD(EXPR_INTEGER_LITERAL);
|
|
|
|
RECORD(EXPR_FLOATING_LITERAL);
|
|
|
|
RECORD(EXPR_IMAGINARY_LITERAL);
|
|
|
|
RECORD(EXPR_STRING_LITERAL);
|
|
|
|
RECORD(EXPR_CHARACTER_LITERAL);
|
|
|
|
RECORD(EXPR_PAREN);
|
|
|
|
RECORD(EXPR_UNARY_OPERATOR);
|
|
|
|
RECORD(EXPR_SIZEOF_ALIGN_OF);
|
|
|
|
RECORD(EXPR_ARRAY_SUBSCRIPT);
|
|
|
|
RECORD(EXPR_CALL);
|
|
|
|
RECORD(EXPR_MEMBER);
|
|
|
|
RECORD(EXPR_BINARY_OPERATOR);
|
|
|
|
RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR);
|
|
|
|
RECORD(EXPR_CONDITIONAL_OPERATOR);
|
|
|
|
RECORD(EXPR_IMPLICIT_CAST);
|
|
|
|
RECORD(EXPR_CSTYLE_CAST);
|
|
|
|
RECORD(EXPR_COMPOUND_LITERAL);
|
|
|
|
RECORD(EXPR_EXT_VECTOR_ELEMENT);
|
|
|
|
RECORD(EXPR_INIT_LIST);
|
|
|
|
RECORD(EXPR_DESIGNATED_INIT);
|
|
|
|
RECORD(EXPR_IMPLICIT_VALUE_INIT);
|
|
|
|
RECORD(EXPR_VA_ARG);
|
|
|
|
RECORD(EXPR_ADDR_LABEL);
|
|
|
|
RECORD(EXPR_STMT);
|
|
|
|
RECORD(EXPR_TYPES_COMPATIBLE);
|
|
|
|
RECORD(EXPR_CHOOSE);
|
|
|
|
RECORD(EXPR_GNU_NULL);
|
|
|
|
RECORD(EXPR_SHUFFLE_VECTOR);
|
|
|
|
RECORD(EXPR_BLOCK);
|
|
|
|
RECORD(EXPR_BLOCK_DECL_REF);
|
|
|
|
RECORD(EXPR_OBJC_STRING_LITERAL);
|
|
|
|
RECORD(EXPR_OBJC_ENCODE);
|
|
|
|
RECORD(EXPR_OBJC_SELECTOR_EXPR);
|
|
|
|
RECORD(EXPR_OBJC_PROTOCOL_EXPR);
|
|
|
|
RECORD(EXPR_OBJC_IVAR_REF_EXPR);
|
|
|
|
RECORD(EXPR_OBJC_PROPERTY_REF_EXPR);
|
|
|
|
RECORD(EXPR_OBJC_KVC_REF_EXPR);
|
|
|
|
RECORD(EXPR_OBJC_MESSAGE_EXPR);
|
|
|
|
RECORD(EXPR_OBJC_SUPER_EXPR);
|
|
|
|
RECORD(STMT_OBJC_FOR_COLLECTION);
|
|
|
|
RECORD(STMT_OBJC_CATCH);
|
|
|
|
RECORD(STMT_OBJC_FINALLY);
|
|
|
|
RECORD(STMT_OBJC_AT_TRY);
|
|
|
|
RECORD(STMT_OBJC_AT_SYNCHRONIZED);
|
|
|
|
RECORD(STMT_OBJC_AT_THROW);
|
|
|
|
#undef RECORD
|
2009-04-27 06:26:21 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 06:26:21 +08:00
|
|
|
void PCHWriter::WriteBlockInfoBlock() {
|
|
|
|
RecordData Record;
|
|
|
|
Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 08:40:25 +08:00
|
|
|
#define BLOCK(X) EmitBlockID(pch::X ## _ID, #X, Stream, Record)
|
2009-04-27 06:26:21 +08:00
|
|
|
#define RECORD(X) EmitRecordID(pch::X, #X, Stream, Record)
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 06:26:21 +08:00
|
|
|
// PCH Top-Level Block.
|
2009-04-27 08:40:25 +08:00
|
|
|
BLOCK(PCH_BLOCK);
|
2009-06-03 17:23:28 +08:00
|
|
|
RECORD(ORIGINAL_FILE_NAME);
|
2009-04-27 06:26:21 +08:00
|
|
|
RECORD(TYPE_OFFSET);
|
|
|
|
RECORD(DECL_OFFSET);
|
|
|
|
RECORD(LANGUAGE_OPTIONS);
|
2009-04-28 06:23:34 +08:00
|
|
|
RECORD(METADATA);
|
2009-04-27 06:26:21 +08:00
|
|
|
RECORD(IDENTIFIER_OFFSET);
|
|
|
|
RECORD(IDENTIFIER_TABLE);
|
|
|
|
RECORD(EXTERNAL_DEFINITIONS);
|
|
|
|
RECORD(SPECIAL_TYPES);
|
|
|
|
RECORD(STATISTICS);
|
|
|
|
RECORD(TENTATIVE_DEFINITIONS);
|
|
|
|
RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS);
|
|
|
|
RECORD(SELECTOR_OFFSETS);
|
|
|
|
RECORD(METHOD_POOL);
|
|
|
|
RECORD(PP_COUNTER_VALUE);
|
2009-04-27 14:38:32 +08:00
|
|
|
RECORD(SOURCE_LOCATION_OFFSETS);
|
|
|
|
RECORD(SOURCE_LOCATION_PRELOADS);
|
2009-04-28 02:38:38 +08:00
|
|
|
RECORD(STAT_CACHE);
|
2009-04-28 04:06:05 +08:00
|
|
|
RECORD(EXT_VECTOR_DECLS);
|
Add support for retrieving the Doxygen comment associated with a given
declaration in the AST.
The new ASTContext::getCommentForDecl function searches for a comment
that is attached to the given declaration, and returns that comment,
which may be composed of several comment blocks.
Comments are always available in an AST. However, to avoid harming
performance, we don't actually parse the comments. Rather, we keep the
source ranges of all of the comments within a large, sorted vector,
then lazily extract comments via a binary search in that vector only
when needed (which never occurs in a "normal" compile).
Comments are written to a precompiled header/AST file as a blob of
source ranges. That blob is only lazily loaded when one requests a
comment for a declaration (this never occurs in a "normal" compile).
The indexer testbed now supports comment extraction. When the
-point-at location points to a declaration with a Doxygen-style
comment, the indexer testbed prints the associated comment
block(s). See test/Index/comments.c for an example.
Some notes:
- We don't actually attempt to parse the comment blocks themselves,
beyond identifying them as Doxygen comment blocks to associate them
with a declaration.
- We won't find comment blocks that aren't adjacent to the
declaration, because we start our search based on the location of
the declaration.
- We don't go through the necessary hops to find, for example,
whether some redeclaration of a declaration has comments when our
current declaration does not. Similarly, we don't attempt to
associate a \param Foo marker in a function body comment with the
parameter named Foo (although that is certainly possible).
- Verification of my "no performance impact" claims is still "to be
done".
llvm-svn: 74704
2009-07-03 01:08:52 +08:00
|
|
|
RECORD(COMMENT_RANGES);
|
2009-10-06 05:07:28 +08:00
|
|
|
RECORD(SVN_BRANCH_REVISION);
|
|
|
|
|
2009-04-27 06:26:21 +08:00
|
|
|
// SourceManager Block.
|
2009-04-27 08:40:25 +08:00
|
|
|
BLOCK(SOURCE_MANAGER_BLOCK);
|
2009-04-27 06:26:21 +08:00
|
|
|
RECORD(SM_SLOC_FILE_ENTRY);
|
|
|
|
RECORD(SM_SLOC_BUFFER_ENTRY);
|
|
|
|
RECORD(SM_SLOC_BUFFER_BLOB);
|
|
|
|
RECORD(SM_SLOC_INSTANTIATION_ENTRY);
|
|
|
|
RECORD(SM_LINE_TABLE);
|
|
|
|
RECORD(SM_HEADER_FILE_INFO);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 06:26:21 +08:00
|
|
|
// Preprocessor Block.
|
2009-04-27 08:40:25 +08:00
|
|
|
BLOCK(PREPROCESSOR_BLOCK);
|
2009-04-27 06:26:21 +08:00
|
|
|
RECORD(PP_MACRO_OBJECT_LIKE);
|
|
|
|
RECORD(PP_MACRO_FUNCTION_LIKE);
|
|
|
|
RECORD(PP_TOKEN);
|
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
// Decls and Types block.
|
|
|
|
BLOCK(DECLTYPES_BLOCK);
|
2009-04-27 06:26:21 +08:00
|
|
|
RECORD(TYPE_EXT_QUAL);
|
|
|
|
RECORD(TYPE_FIXED_WIDTH_INT);
|
|
|
|
RECORD(TYPE_COMPLEX);
|
|
|
|
RECORD(TYPE_POINTER);
|
|
|
|
RECORD(TYPE_BLOCK_POINTER);
|
|
|
|
RECORD(TYPE_LVALUE_REFERENCE);
|
|
|
|
RECORD(TYPE_RVALUE_REFERENCE);
|
|
|
|
RECORD(TYPE_MEMBER_POINTER);
|
|
|
|
RECORD(TYPE_CONSTANT_ARRAY);
|
|
|
|
RECORD(TYPE_INCOMPLETE_ARRAY);
|
|
|
|
RECORD(TYPE_VARIABLE_ARRAY);
|
|
|
|
RECORD(TYPE_VECTOR);
|
|
|
|
RECORD(TYPE_EXT_VECTOR);
|
|
|
|
RECORD(TYPE_FUNCTION_PROTO);
|
|
|
|
RECORD(TYPE_FUNCTION_NO_PROTO);
|
|
|
|
RECORD(TYPE_TYPEDEF);
|
|
|
|
RECORD(TYPE_TYPEOF_EXPR);
|
|
|
|
RECORD(TYPE_TYPEOF);
|
|
|
|
RECORD(TYPE_RECORD);
|
|
|
|
RECORD(TYPE_ENUM);
|
|
|
|
RECORD(TYPE_OBJC_INTERFACE);
|
2009-06-18 06:40:22 +08:00
|
|
|
RECORD(TYPE_OBJC_OBJECT_POINTER);
|
2009-04-27 06:32:16 +08:00
|
|
|
RECORD(DECL_ATTR);
|
|
|
|
RECORD(DECL_TRANSLATION_UNIT);
|
|
|
|
RECORD(DECL_TYPEDEF);
|
|
|
|
RECORD(DECL_ENUM);
|
|
|
|
RECORD(DECL_RECORD);
|
|
|
|
RECORD(DECL_ENUM_CONSTANT);
|
|
|
|
RECORD(DECL_FUNCTION);
|
|
|
|
RECORD(DECL_OBJC_METHOD);
|
|
|
|
RECORD(DECL_OBJC_INTERFACE);
|
|
|
|
RECORD(DECL_OBJC_PROTOCOL);
|
|
|
|
RECORD(DECL_OBJC_IVAR);
|
|
|
|
RECORD(DECL_OBJC_AT_DEFS_FIELD);
|
|
|
|
RECORD(DECL_OBJC_CLASS);
|
|
|
|
RECORD(DECL_OBJC_FORWARD_PROTOCOL);
|
|
|
|
RECORD(DECL_OBJC_CATEGORY);
|
|
|
|
RECORD(DECL_OBJC_CATEGORY_IMPL);
|
|
|
|
RECORD(DECL_OBJC_IMPLEMENTATION);
|
|
|
|
RECORD(DECL_OBJC_COMPATIBLE_ALIAS);
|
|
|
|
RECORD(DECL_OBJC_PROPERTY);
|
|
|
|
RECORD(DECL_OBJC_PROPERTY_IMPL);
|
2009-04-27 06:26:21 +08:00
|
|
|
RECORD(DECL_FIELD);
|
|
|
|
RECORD(DECL_VAR);
|
2009-04-27 06:32:16 +08:00
|
|
|
RECORD(DECL_IMPLICIT_PARAM);
|
2009-04-27 06:26:21 +08:00
|
|
|
RECORD(DECL_PARM_VAR);
|
2009-04-27 06:32:16 +08:00
|
|
|
RECORD(DECL_FILE_SCOPE_ASM);
|
|
|
|
RECORD(DECL_BLOCK);
|
|
|
|
RECORD(DECL_CONTEXT_LEXICAL);
|
|
|
|
RECORD(DECL_CONTEXT_VISIBLE);
|
2009-10-17 08:13:19 +08:00
|
|
|
// Statements and Exprs can occur in the Decls and Types block.
|
2009-04-27 08:49:53 +08:00
|
|
|
AddStmtsExprs(Stream, Record);
|
2009-04-27 06:26:21 +08:00
|
|
|
#undef RECORD
|
|
|
|
#undef BLOCK
|
|
|
|
Stream.ExitBlock();
|
|
|
|
}
|
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
/// \brief Adjusts the given filename to only write out the portion of the
|
|
|
|
/// filename that is not part of the system root directory.
|
2009-09-09 23:08:12 +08:00
|
|
|
///
|
2009-07-07 08:12:59 +08:00
|
|
|
/// \param Filename the file name to adjust.
|
|
|
|
///
|
|
|
|
/// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and
|
|
|
|
/// the returned filename will be adjusted by this system root.
|
|
|
|
///
|
|
|
|
/// \returns either the original filename (if it needs no adjustment) or the
|
|
|
|
/// adjusted filename (which points into the @p Filename parameter).
|
2009-09-09 23:08:12 +08:00
|
|
|
static const char *
|
2009-07-07 08:12:59 +08:00
|
|
|
adjustFilenameForRelocatablePCH(const char *Filename, const char *isysroot) {
|
|
|
|
assert(Filename && "No file name to adjust?");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
if (!isysroot)
|
|
|
|
return Filename;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
// Verify that the filename and the system root have the same prefix.
|
|
|
|
unsigned Pos = 0;
|
|
|
|
for (; Filename[Pos] && isysroot[Pos]; ++Pos)
|
|
|
|
if (Filename[Pos] != isysroot[Pos])
|
|
|
|
return Filename; // Prefixes don't match.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
// We hit the end of the filename before we hit the end of the system root.
|
|
|
|
if (!Filename[Pos])
|
|
|
|
return Filename;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
// If the file name has a '/' at the current position, skip over the '/'.
|
|
|
|
// We distinguish sysroot-based includes from absolute includes by the
|
|
|
|
// absence of '/' at the beginning of sysroot-based includes.
|
|
|
|
if (Filename[Pos] == '/')
|
|
|
|
++Pos;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
return Filename + Pos;
|
|
|
|
}
|
2009-04-27 06:26:21 +08:00
|
|
|
|
2009-04-28 06:23:34 +08:00
|
|
|
/// \brief Write the PCH metadata (e.g., i686-apple-darwin9).
|
2009-07-07 08:12:59 +08:00
|
|
|
void PCHWriter::WriteMetadata(ASTContext &Context, const char *isysroot) {
|
2009-04-11 05:16:55 +08:00
|
|
|
using namespace llvm;
|
2009-05-12 09:31:05 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
// Metadata
|
|
|
|
const TargetInfo &Target = Context.Target;
|
|
|
|
BitCodeAbbrev *MetaAbbrev = new BitCodeAbbrev();
|
|
|
|
MetaAbbrev->Add(BitCodeAbbrevOp(pch::METADATA));
|
|
|
|
MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // PCH major
|
|
|
|
MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // PCH minor
|
|
|
|
MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major
|
|
|
|
MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor
|
|
|
|
MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable
|
|
|
|
MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Target triple
|
|
|
|
unsigned MetaAbbrevCode = Stream.EmitAbbrev(MetaAbbrev);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(pch::METADATA);
|
|
|
|
Record.push_back(pch::VERSION_MAJOR);
|
|
|
|
Record.push_back(pch::VERSION_MINOR);
|
|
|
|
Record.push_back(CLANG_VERSION_MAJOR);
|
|
|
|
Record.push_back(CLANG_VERSION_MINOR);
|
|
|
|
Record.push_back(isysroot != 0);
|
2009-08-24 17:10:05 +08:00
|
|
|
const std::string &TripleStr = Target.getTriple().getTriple();
|
2009-08-24 17:31:37 +08:00
|
|
|
Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, TripleStr);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-12 09:31:05 +08:00
|
|
|
// Original file name
|
|
|
|
SourceManager &SM = Context.getSourceManager();
|
|
|
|
if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
|
|
|
|
BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev();
|
|
|
|
FileAbbrev->Add(BitCodeAbbrevOp(pch::ORIGINAL_FILE_NAME));
|
|
|
|
FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
|
|
|
|
unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev);
|
|
|
|
|
|
|
|
llvm::sys::Path MainFilePath(MainFile->getName());
|
|
|
|
std::string MainFileName;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-12 09:31:05 +08:00
|
|
|
if (!MainFilePath.isAbsolute()) {
|
|
|
|
llvm::sys::Path P = llvm::sys::Path::GetCurrentDirectory();
|
2009-08-24 06:45:33 +08:00
|
|
|
P.appendComponent(MainFilePath.str());
|
|
|
|
MainFileName = P.str();
|
2009-05-12 09:31:05 +08:00
|
|
|
} else {
|
2009-08-24 06:45:33 +08:00
|
|
|
MainFileName = MainFilePath.str();
|
2009-05-12 09:31:05 +08:00
|
|
|
}
|
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
const char *MainFileNameStr = MainFileName.c_str();
|
2009-09-09 23:08:12 +08:00
|
|
|
MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr,
|
2009-07-07 08:12:59 +08:00
|
|
|
isysroot);
|
2009-05-12 09:31:05 +08:00
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(pch::ORIGINAL_FILE_NAME);
|
2009-08-24 17:31:37 +08:00
|
|
|
Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr);
|
2009-05-12 09:31:05 +08:00
|
|
|
}
|
2009-10-06 05:07:28 +08:00
|
|
|
|
|
|
|
// Subversion branch/version information.
|
|
|
|
BitCodeAbbrev *SvnAbbrev = new BitCodeAbbrev();
|
|
|
|
SvnAbbrev->Add(BitCodeAbbrevOp(pch::SVN_BRANCH_REVISION));
|
|
|
|
SvnAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // SVN revision
|
|
|
|
SvnAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag
|
|
|
|
unsigned SvnAbbrevCode = Stream.EmitAbbrev(SvnAbbrev);
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(pch::SVN_BRANCH_REVISION);
|
|
|
|
Record.push_back(getClangSubversionRevision());
|
|
|
|
Stream.EmitRecordWithBlob(SvnAbbrevCode, Record, getClangSubversionPath());
|
2009-04-11 05:16:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Write the LangOptions structure.
|
2009-04-11 04:39:37 +08:00
|
|
|
void PCHWriter::WriteLanguageOptions(const LangOptions &LangOpts) {
|
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(LangOpts.Trigraphs);
|
|
|
|
Record.push_back(LangOpts.BCPLComment); // BCPL-style '//' comments.
|
|
|
|
Record.push_back(LangOpts.DollarIdents); // '$' allowed in identifiers.
|
|
|
|
Record.push_back(LangOpts.AsmPreprocessor); // Preprocessor in asm mode.
|
|
|
|
Record.push_back(LangOpts.GNUMode); // True in gnu99 mode false in c99 mode (etc)
|
|
|
|
Record.push_back(LangOpts.ImplicitInt); // C89 implicit 'int'.
|
|
|
|
Record.push_back(LangOpts.Digraphs); // C94, C99 and C++
|
|
|
|
Record.push_back(LangOpts.HexFloats); // C99 Hexadecimal float constants.
|
|
|
|
Record.push_back(LangOpts.C99); // C99 Support
|
|
|
|
Record.push_back(LangOpts.Microsoft); // Microsoft extensions.
|
|
|
|
Record.push_back(LangOpts.CPlusPlus); // C++ Support
|
|
|
|
Record.push_back(LangOpts.CPlusPlus0x); // C++0x Support
|
|
|
|
Record.push_back(LangOpts.CXXOperatorNames); // Treat C++ operator names as keywords.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-11 04:39:37 +08:00
|
|
|
Record.push_back(LangOpts.ObjC1); // Objective-C 1 support enabled.
|
|
|
|
Record.push_back(LangOpts.ObjC2); // Objective-C 2 support enabled.
|
|
|
|
Record.push_back(LangOpts.ObjCNonFragileABI); // Objective-C modern abi enabled
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-11 04:39:37 +08:00
|
|
|
Record.push_back(LangOpts.PascalStrings); // Allow Pascal strings
|
|
|
|
Record.push_back(LangOpts.WritableStrings); // Allow writable strings
|
|
|
|
Record.push_back(LangOpts.LaxVectorConversions);
|
2009-06-26 07:01:11 +08:00
|
|
|
Record.push_back(LangOpts.AltiVec);
|
2009-04-11 04:39:37 +08:00
|
|
|
Record.push_back(LangOpts.Exceptions); // Support exception handling.
|
|
|
|
|
|
|
|
Record.push_back(LangOpts.NeXTRuntime); // Use NeXT runtime.
|
|
|
|
Record.push_back(LangOpts.Freestanding); // Freestanding implementation
|
|
|
|
Record.push_back(LangOpts.NoBuiltin); // Do not use builtin functions (-fno-builtin)
|
|
|
|
|
2009-04-27 15:35:58 +08:00
|
|
|
// Whether static initializers are protected by locks.
|
|
|
|
Record.push_back(LangOpts.ThreadsafeStatics);
|
2009-09-03 22:36:33 +08:00
|
|
|
Record.push_back(LangOpts.POSIXThreads);
|
2009-04-11 04:39:37 +08:00
|
|
|
Record.push_back(LangOpts.Blocks); // block extension to C
|
|
|
|
Record.push_back(LangOpts.EmitAllDecls); // Emit all declarations, even if
|
|
|
|
// they are unused.
|
|
|
|
Record.push_back(LangOpts.MathErrno); // Math functions must respect errno
|
|
|
|
// (modulo the platform support).
|
|
|
|
|
|
|
|
Record.push_back(LangOpts.OverflowChecking); // Extension to call a handler function when
|
|
|
|
// signed integer arithmetic overflows.
|
|
|
|
|
|
|
|
Record.push_back(LangOpts.HeinousExtensions); // Extensions that we really don't like and
|
|
|
|
// may be ripped out at any time.
|
|
|
|
|
|
|
|
Record.push_back(LangOpts.Optimize); // Whether __OPTIMIZE__ should be defined.
|
2009-09-09 23:08:12 +08:00
|
|
|
Record.push_back(LangOpts.OptimizeSize); // Whether __OPTIMIZE_SIZE__ should be
|
2009-04-11 04:39:37 +08:00
|
|
|
// defined.
|
|
|
|
Record.push_back(LangOpts.Static); // Should __STATIC__ be defined (as
|
|
|
|
// opposed to __DYNAMIC__).
|
|
|
|
Record.push_back(LangOpts.PICLevel); // The value for __PIC__, if non-zero.
|
|
|
|
|
|
|
|
Record.push_back(LangOpts.GNUInline); // Should GNU inline semantics be
|
|
|
|
// used (instead of C99 semantics).
|
|
|
|
Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined.
|
2009-05-14 03:49:53 +08:00
|
|
|
Record.push_back(LangOpts.AccessControl); // Whether C++ access control should
|
|
|
|
// be enabled.
|
2009-06-05 15:05:05 +08:00
|
|
|
Record.push_back(LangOpts.CharIsSigned); // Whether char is a signed or
|
|
|
|
// unsigned type
|
2009-11-06 04:14:16 +08:00
|
|
|
Record.push_back(LangOpts.ShortWChar); // force wchar_t to be unsigned short
|
2009-04-11 04:39:37 +08:00
|
|
|
Record.push_back(LangOpts.getGCMode());
|
|
|
|
Record.push_back(LangOpts.getVisibilityMode());
|
2009-09-21 12:16:19 +08:00
|
|
|
Record.push_back(LangOpts.getStackProtectorMode());
|
2009-04-11 04:39:37 +08:00
|
|
|
Record.push_back(LangOpts.InstantiationDepth);
|
2009-06-26 07:01:11 +08:00
|
|
|
Record.push_back(LangOpts.OpenCL);
|
2009-08-23 06:30:33 +08:00
|
|
|
Record.push_back(LangOpts.ElideConstructors);
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecord(pch::LANGUAGE_OPTIONS, Record);
|
2009-04-11 04:39:37 +08:00
|
|
|
}
|
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// stat cache Serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// Trait used for the on-disk hash table of stat cache results.
|
|
|
|
class VISIBILITY_HIDDEN PCHStatCacheTrait {
|
|
|
|
public:
|
|
|
|
typedef const char * key_type;
|
|
|
|
typedef key_type key_type_ref;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
typedef std::pair<int, struct stat> data_type;
|
|
|
|
typedef const data_type& data_type_ref;
|
|
|
|
|
|
|
|
static unsigned ComputeHash(const char *path) {
|
2009-10-18 07:52:28 +08:00
|
|
|
return llvm::HashString(path);
|
2009-04-28 02:38:38 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
std::pair<unsigned,unsigned>
|
2009-04-28 02:38:38 +08:00
|
|
|
EmitKeyDataLength(llvm::raw_ostream& Out, const char *path,
|
|
|
|
data_type_ref Data) {
|
|
|
|
unsigned StrLen = strlen(path);
|
|
|
|
clang::io::Emit16(Out, StrLen);
|
|
|
|
unsigned DataLen = 1; // result value
|
|
|
|
if (Data.first == 0)
|
|
|
|
DataLen += 4 + 4 + 2 + 8 + 8;
|
|
|
|
clang::io::Emit8(Out, DataLen);
|
|
|
|
return std::make_pair(StrLen + 1, DataLen);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
void EmitKey(llvm::raw_ostream& Out, const char *path, unsigned KeyLen) {
|
|
|
|
Out.write(path, KeyLen);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
void EmitData(llvm::raw_ostream& Out, key_type_ref,
|
|
|
|
data_type_ref Data, unsigned DataLen) {
|
|
|
|
using namespace clang::io;
|
|
|
|
uint64_t Start = Out.tell(); (void)Start;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
// Result of stat()
|
|
|
|
Emit8(Out, Data.first? 1 : 0);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
if (Data.first == 0) {
|
|
|
|
Emit32(Out, (uint32_t) Data.second.st_ino);
|
|
|
|
Emit32(Out, (uint32_t) Data.second.st_dev);
|
|
|
|
Emit16(Out, (uint16_t) Data.second.st_mode);
|
|
|
|
Emit64(Out, (uint64_t) Data.second.st_mtime);
|
|
|
|
Emit64(Out, (uint64_t) Data.second.st_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(Out.tell() - Start == DataLen && "Wrong data length");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
/// \brief Write the stat() system call cache to the PCH file.
|
2009-07-07 08:12:59 +08:00
|
|
|
void PCHWriter::WriteStatCache(MemorizeStatCalls &StatCalls,
|
|
|
|
const char *isysroot) {
|
2009-04-28 02:38:38 +08:00
|
|
|
// Build the on-disk hash table containing information about every
|
|
|
|
// stat() call.
|
|
|
|
OnDiskChainedHashTableGenerator<PCHStatCacheTrait> Generator;
|
|
|
|
unsigned NumStatEntries = 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
for (MemorizeStatCalls::iterator Stat = StatCalls.begin(),
|
2009-04-28 02:38:38 +08:00
|
|
|
StatEnd = StatCalls.end();
|
2009-07-07 08:12:59 +08:00
|
|
|
Stat != StatEnd; ++Stat, ++NumStatEntries) {
|
|
|
|
const char *Filename = Stat->first();
|
|
|
|
Filename = adjustFilenameForRelocatablePCH(Filename, isysroot);
|
|
|
|
Generator.insert(Filename, Stat->second);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
// Create the on-disk hash table in a buffer.
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::SmallString<4096> StatCacheData;
|
2009-04-28 02:38:38 +08:00
|
|
|
uint32_t BucketOffset;
|
|
|
|
{
|
|
|
|
llvm::raw_svector_ostream Out(StatCacheData);
|
|
|
|
// Make sure that no bucket is at offset 0
|
|
|
|
clang::io::Emit32(Out, 0);
|
|
|
|
BucketOffset = Generator.Emit(Out);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a blob abbreviation
|
|
|
|
using namespace llvm;
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::STAT_CACHE));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
|
|
|
|
unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev);
|
|
|
|
|
|
|
|
// Write the stat cache
|
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(pch::STAT_CACHE);
|
|
|
|
Record.push_back(BucketOffset);
|
|
|
|
Record.push_back(NumStatEntries);
|
2009-08-24 17:31:37 +08:00
|
|
|
Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str());
|
2009-04-28 02:38:38 +08:00
|
|
|
}
|
|
|
|
|
2009-04-10 11:52:48 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Source Manager Serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// \brief Create an abbreviation for the SLocEntry that refers to a
|
|
|
|
/// file.
|
2009-04-17 06:23:12 +08:00
|
|
|
static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) {
|
2009-04-10 11:52:48 +08:00
|
|
|
using namespace llvm;
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_FILE_ENTRY));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
|
2009-04-17 06:23:12 +08:00
|
|
|
return Stream.EmitAbbrev(Abbrev);
|
2009-04-10 11:52:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Create an abbreviation for the SLocEntry that refers to a
|
|
|
|
/// buffer.
|
2009-04-17 06:23:12 +08:00
|
|
|
static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) {
|
2009-04-10 11:52:48 +08:00
|
|
|
using namespace llvm;
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_BUFFER_ENTRY));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob
|
2009-04-17 06:23:12 +08:00
|
|
|
return Stream.EmitAbbrev(Abbrev);
|
2009-04-10 11:52:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Create an abbreviation for the SLocEntry that refers to a
|
|
|
|
/// buffer's blob.
|
2009-04-17 06:23:12 +08:00
|
|
|
static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) {
|
2009-04-10 11:52:48 +08:00
|
|
|
using namespace llvm;
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_BUFFER_BLOB));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob
|
2009-04-17 06:23:12 +08:00
|
|
|
return Stream.EmitAbbrev(Abbrev);
|
2009-04-10 11:52:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Create an abbreviation for the SLocEntry that refers to an
|
|
|
|
/// buffer.
|
2009-04-17 06:23:12 +08:00
|
|
|
static unsigned CreateSLocInstantiationAbbrev(llvm::BitstreamWriter &Stream) {
|
2009-04-10 11:52:48 +08:00
|
|
|
using namespace llvm;
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_INSTANTIATION_ENTRY));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location
|
2009-04-16 02:05:10 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length
|
2009-04-17 06:23:12 +08:00
|
|
|
return Stream.EmitAbbrev(Abbrev);
|
2009-04-10 11:52:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Writes the block containing the serialized form of the
|
|
|
|
/// source manager.
|
|
|
|
///
|
|
|
|
/// TODO: We should probably use an on-disk hash table (stored in a
|
|
|
|
/// blob), indexed based on the file name, so that we only create
|
|
|
|
/// entries for files that we actually need. In the common case (no
|
|
|
|
/// errors), we probably won't have to create file entries for any of
|
|
|
|
/// the files in the AST.
|
2009-04-26 08:07:37 +08:00
|
|
|
void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
|
2009-07-07 08:12:59 +08:00
|
|
|
const Preprocessor &PP,
|
|
|
|
const char *isysroot) {
|
2009-04-27 14:38:32 +08:00
|
|
|
RecordData Record;
|
|
|
|
|
2009-04-11 01:16:57 +08:00
|
|
|
// Enter the source manager block.
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EnterSubblock(pch::SOURCE_MANAGER_BLOCK_ID, 3);
|
2009-04-10 11:52:48 +08:00
|
|
|
|
|
|
|
// Abbreviations for the various kinds of source-location entries.
|
2009-04-28 03:03:22 +08:00
|
|
|
unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream);
|
|
|
|
unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream);
|
|
|
|
unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream);
|
|
|
|
unsigned SLocInstantiationAbbrv = CreateSLocInstantiationAbbrev(Stream);
|
2009-04-27 14:38:32 +08:00
|
|
|
|
|
|
|
// Write the line table.
|
|
|
|
if (SourceMgr.hasLineTable()) {
|
|
|
|
LineTableInfo &LineTable = SourceMgr.getLineTable();
|
|
|
|
|
|
|
|
// Emit the file names
|
|
|
|
Record.push_back(LineTable.getNumFilenames());
|
|
|
|
for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) {
|
|
|
|
// Emit the file name
|
|
|
|
const char *Filename = LineTable.getFilename(I);
|
2009-07-07 08:12:59 +08:00
|
|
|
Filename = adjustFilenameForRelocatablePCH(Filename, isysroot);
|
2009-04-27 14:38:32 +08:00
|
|
|
unsigned FilenameLen = Filename? strlen(Filename) : 0;
|
|
|
|
Record.push_back(FilenameLen);
|
|
|
|
if (FilenameLen)
|
|
|
|
Record.insert(Record.end(), Filename, Filename + FilenameLen);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:38:32 +08:00
|
|
|
// Emit the line entries
|
|
|
|
for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end();
|
|
|
|
L != LEnd; ++L) {
|
|
|
|
// Emit the file ID
|
|
|
|
Record.push_back(L->first);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:38:32 +08:00
|
|
|
// Emit the line entries
|
|
|
|
Record.push_back(L->second.size());
|
2009-09-09 23:08:12 +08:00
|
|
|
for (std::vector<LineEntry>::iterator LE = L->second.begin(),
|
2009-04-27 14:38:32 +08:00
|
|
|
LEEnd = L->second.end();
|
|
|
|
LE != LEEnd; ++LE) {
|
|
|
|
Record.push_back(LE->FileOffset);
|
|
|
|
Record.push_back(LE->LineNo);
|
|
|
|
Record.push_back(LE->FilenameID);
|
|
|
|
Record.push_back((unsigned)LE->FileKind);
|
|
|
|
Record.push_back(LE->IncludeOffset);
|
|
|
|
}
|
|
|
|
}
|
2009-05-22 16:38:27 +08:00
|
|
|
Stream.EmitRecord(pch::SM_LINE_TABLE, Record);
|
2009-04-27 14:38:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write out entries for all of the header files we know about.
|
2009-09-09 23:08:12 +08:00
|
|
|
HeaderSearch &HS = PP.getHeaderSearchInfo();
|
2009-04-27 14:38:32 +08:00
|
|
|
Record.clear();
|
2009-09-09 23:08:12 +08:00
|
|
|
for (HeaderSearch::header_file_iterator I = HS.header_file_begin(),
|
2009-04-27 14:38:32 +08:00
|
|
|
E = HS.header_file_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
Record.push_back(I->isImport);
|
|
|
|
Record.push_back(I->DirInfo);
|
|
|
|
Record.push_back(I->NumIncludes);
|
|
|
|
AddIdentifierRef(I->ControllingMacro, Record);
|
|
|
|
Stream.EmitRecord(pch::SM_HEADER_FILE_INFO, Record);
|
|
|
|
Record.clear();
|
|
|
|
}
|
2009-04-10 11:52:48 +08:00
|
|
|
|
|
|
|
// Write out the source location entry table. We skip the first
|
|
|
|
// entry, which is always the same dummy entry.
|
2009-04-28 03:01:47 +08:00
|
|
|
std::vector<uint32_t> SLocEntryOffsets;
|
2009-04-27 14:38:32 +08:00
|
|
|
RecordData PreloadSLocs;
|
|
|
|
SLocEntryOffsets.reserve(SourceMgr.sloc_entry_size() - 1);
|
2009-10-17 06:46:09 +08:00
|
|
|
for (unsigned I = 1, N = SourceMgr.sloc_entry_size(); I != N; ++I) {
|
|
|
|
// Get this source location entry.
|
|
|
|
const SrcMgr::SLocEntry *SLoc = &SourceMgr.getSLocEntry(I);
|
|
|
|
|
2009-04-27 14:38:32 +08:00
|
|
|
// Record the offset of this source-location entry.
|
|
|
|
SLocEntryOffsets.push_back(Stream.GetCurrentBitNo());
|
|
|
|
|
2009-04-10 11:52:48 +08:00
|
|
|
// Figure out which record code to use.
|
|
|
|
unsigned Code;
|
|
|
|
if (SLoc->isFile()) {
|
|
|
|
if (SLoc->getFile().getContentCache()->Entry)
|
|
|
|
Code = pch::SM_SLOC_FILE_ENTRY;
|
|
|
|
else
|
|
|
|
Code = pch::SM_SLOC_BUFFER_ENTRY;
|
|
|
|
} else
|
|
|
|
Code = pch::SM_SLOC_INSTANTIATION_ENTRY;
|
2009-04-27 14:38:32 +08:00
|
|
|
Record.clear();
|
2009-04-10 11:52:48 +08:00
|
|
|
Record.push_back(Code);
|
|
|
|
|
|
|
|
Record.push_back(SLoc->getOffset());
|
|
|
|
if (SLoc->isFile()) {
|
|
|
|
const SrcMgr::FileInfo &File = SLoc->getFile();
|
|
|
|
Record.push_back(File.getIncludeLoc().getRawEncoding());
|
|
|
|
Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding
|
2009-04-14 00:31:14 +08:00
|
|
|
Record.push_back(File.hasLineDirectives());
|
2009-04-10 11:52:48 +08:00
|
|
|
|
|
|
|
const SrcMgr::ContentCache *Content = File.getContentCache();
|
|
|
|
if (Content->Entry) {
|
|
|
|
// The source location entry is a file. The blob associated
|
|
|
|
// with this entry is the file name.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
// Turn the file name into an absolute path, if it isn't already.
|
|
|
|
const char *Filename = Content->Entry->getName();
|
|
|
|
llvm::sys::Path FilePath(Filename, strlen(Filename));
|
|
|
|
std::string FilenameStr;
|
|
|
|
if (!FilePath.isAbsolute()) {
|
|
|
|
llvm::sys::Path P = llvm::sys::Path::GetCurrentDirectory();
|
2009-08-24 06:45:33 +08:00
|
|
|
P.appendComponent(FilePath.str());
|
|
|
|
FilenameStr = P.str();
|
2009-07-07 08:12:59 +08:00
|
|
|
Filename = FilenameStr.c_str();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
Filename = adjustFilenameForRelocatablePCH(Filename, isysroot);
|
2009-08-24 17:31:37 +08:00
|
|
|
Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename);
|
2009-04-27 14:38:32 +08:00
|
|
|
|
|
|
|
// FIXME: For now, preload all file source locations, so that
|
|
|
|
// we get the appropriate File entries in the reader. This is
|
|
|
|
// a temporary measure.
|
|
|
|
PreloadSLocs.push_back(SLocEntryOffsets.size());
|
2009-04-10 11:52:48 +08:00
|
|
|
} else {
|
|
|
|
// The source location entry is a buffer. The blob associated
|
|
|
|
// with this entry contains the contents of the buffer.
|
|
|
|
|
|
|
|
// We add one to the size so that we capture the trailing NULL
|
|
|
|
// that is required by llvm::MemoryBuffer::getMemBuffer (on
|
|
|
|
// the reader side).
|
|
|
|
const llvm::MemoryBuffer *Buffer = Content->getBuffer();
|
|
|
|
const char *Name = Buffer->getBufferIdentifier();
|
2009-08-24 17:31:37 +08:00
|
|
|
Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record,
|
|
|
|
llvm::StringRef(Name, strlen(Name) + 1));
|
2009-04-10 11:52:48 +08:00
|
|
|
Record.clear();
|
|
|
|
Record.push_back(pch::SM_SLOC_BUFFER_BLOB);
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record,
|
2009-08-24 17:31:37 +08:00
|
|
|
llvm::StringRef(Buffer->getBufferStart(),
|
|
|
|
Buffer->getBufferSize() + 1));
|
2009-04-27 14:38:32 +08:00
|
|
|
|
|
|
|
if (strcmp(Name, "<built-in>") == 0)
|
|
|
|
PreloadSLocs.push_back(SLocEntryOffsets.size());
|
2009-04-10 11:52:48 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The source location entry is an instantiation.
|
|
|
|
const SrcMgr::InstantiationInfo &Inst = SLoc->getInstantiation();
|
|
|
|
Record.push_back(Inst.getSpellingLoc().getRawEncoding());
|
|
|
|
Record.push_back(Inst.getInstantiationLocStart().getRawEncoding());
|
|
|
|
Record.push_back(Inst.getInstantiationLocEnd().getRawEncoding());
|
|
|
|
|
2009-04-16 02:05:10 +08:00
|
|
|
// Compute the token length for this macro expansion.
|
|
|
|
unsigned NextOffset = SourceMgr.getNextOffset();
|
2009-10-17 06:46:09 +08:00
|
|
|
if (I + 1 != N)
|
|
|
|
NextOffset = SourceMgr.getSLocEntry(I + 1).getOffset();
|
2009-04-16 02:05:10 +08:00
|
|
|
Record.push_back(NextOffset - SLoc->getOffset() - 1);
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecordWithAbbrev(SLocInstantiationAbbrv, Record);
|
2009-04-10 11:52:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-27 14:38:32 +08:00
|
|
|
Stream.ExitBlock();
|
2009-04-14 00:31:14 +08:00
|
|
|
|
2009-04-27 14:38:32 +08:00
|
|
|
if (SLocEntryOffsets.empty())
|
|
|
|
return;
|
2009-04-26 08:07:37 +08:00
|
|
|
|
2009-04-27 14:38:32 +08:00
|
|
|
// Write the source-location offsets table into the PCH block. This
|
|
|
|
// table is used for lazily loading source-location information.
|
|
|
|
using namespace llvm;
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::SOURCE_LOCATION_OFFSETS));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // next offset
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets
|
|
|
|
unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 14:38:32 +08:00
|
|
|
Record.clear();
|
|
|
|
Record.push_back(pch::SOURCE_LOCATION_OFFSETS);
|
|
|
|
Record.push_back(SLocEntryOffsets.size());
|
|
|
|
Record.push_back(SourceMgr.getNextOffset());
|
|
|
|
Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
|
2009-09-09 23:08:12 +08:00
|
|
|
(const char *)&SLocEntryOffsets.front(),
|
2009-04-28 03:01:47 +08:00
|
|
|
SLocEntryOffsets.size()*sizeof(SLocEntryOffsets[0]));
|
2009-04-27 14:38:32 +08:00
|
|
|
|
|
|
|
// Write the source location entry preloads array, telling the PCH
|
|
|
|
// reader which source locations entries it should load eagerly.
|
|
|
|
Stream.EmitRecord(pch::SOURCE_LOCATION_PRELOADS, PreloadSLocs);
|
2009-04-10 11:52:48 +08:00
|
|
|
}
|
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Preprocessor Serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-11 01:15:23 +08:00
|
|
|
/// \brief Writes the block containing the serialized form of the
|
|
|
|
/// preprocessor.
|
|
|
|
///
|
2009-04-11 02:08:30 +08:00
|
|
|
void PCHWriter::WritePreprocessor(const Preprocessor &PP) {
|
2009-04-11 02:00:12 +08:00
|
|
|
RecordData Record;
|
|
|
|
|
2009-04-13 09:29:17 +08:00
|
|
|
// If the preprocessor __COUNTER__ value has been bumped, remember it.
|
|
|
|
if (PP.getCounterValue() != 0) {
|
|
|
|
Record.push_back(PP.getCounterValue());
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecord(pch::PP_COUNTER_VALUE, Record);
|
2009-04-13 09:29:17 +08:00
|
|
|
Record.clear();
|
2009-04-26 08:07:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enter the preprocessor block.
|
|
|
|
Stream.EnterSubblock(pch::PREPROCESSOR_BLOCK_ID, 2);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-26 08:07:37 +08:00
|
|
|
// If the PCH file contains __DATE__ or __TIME__ emit a warning about this.
|
|
|
|
// FIXME: use diagnostics subsystem for localization etc.
|
|
|
|
if (PP.SawDateOrTime())
|
|
|
|
fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-11 02:00:12 +08:00
|
|
|
// Loop over all the macro definitions that are live at the end of the file,
|
|
|
|
// emitting each to the PP section.
|
2009-10-18 01:25:45 +08:00
|
|
|
// FIXME: Make sure that this sees macros defined in included PCH files.
|
2009-04-11 02:00:12 +08:00
|
|
|
for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
|
|
|
|
I != E; ++I) {
|
2009-04-11 05:41:48 +08:00
|
|
|
// FIXME: This emits macros in hash table order, we should do it in a stable
|
|
|
|
// order so that output is reproducible.
|
2009-04-11 02:00:12 +08:00
|
|
|
MacroInfo *MI = I->second;
|
|
|
|
|
|
|
|
// Don't emit builtin macros like __LINE__ to the PCH file unless they have
|
|
|
|
// been redefined by the header (in which case they are not isBuiltinMacro).
|
|
|
|
if (MI->isBuiltinMacro())
|
|
|
|
continue;
|
|
|
|
|
2009-04-22 07:56:24 +08:00
|
|
|
// FIXME: Remove this identifier reference?
|
2009-04-12 05:15:38 +08:00
|
|
|
AddIdentifierRef(I->first, Record);
|
2009-04-22 07:56:24 +08:00
|
|
|
MacroOffsets[I->first] = Stream.GetCurrentBitNo();
|
2009-04-11 02:00:12 +08:00
|
|
|
Record.push_back(MI->getDefinitionLoc().getRawEncoding());
|
|
|
|
Record.push_back(MI->isUsed());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-11 02:00:12 +08:00
|
|
|
unsigned Code;
|
|
|
|
if (MI->isObjectLike()) {
|
|
|
|
Code = pch::PP_MACRO_OBJECT_LIKE;
|
|
|
|
} else {
|
|
|
|
Code = pch::PP_MACRO_FUNCTION_LIKE;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-11 02:00:12 +08:00
|
|
|
Record.push_back(MI->isC99Varargs());
|
|
|
|
Record.push_back(MI->isGNUVarargs());
|
|
|
|
Record.push_back(MI->getNumArgs());
|
|
|
|
for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end();
|
|
|
|
I != E; ++I)
|
2009-04-12 05:15:38 +08:00
|
|
|
AddIdentifierRef(*I, Record);
|
2009-04-11 02:00:12 +08:00
|
|
|
}
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecord(Code, Record);
|
2009-04-11 02:00:12 +08:00
|
|
|
Record.clear();
|
2009-04-11 01:16:57 +08:00
|
|
|
|
2009-04-11 02:08:30 +08:00
|
|
|
// Emit the tokens array.
|
|
|
|
for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) {
|
|
|
|
// Note that we know that the preprocessor does not have any annotation
|
|
|
|
// tokens in it because they are created by the parser, and thus can't be
|
|
|
|
// in a macro definition.
|
|
|
|
const Token &Tok = MI->getReplacementToken(TokNo);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-11 02:08:30 +08:00
|
|
|
Record.push_back(Tok.getLocation().getRawEncoding());
|
|
|
|
Record.push_back(Tok.getLength());
|
|
|
|
|
|
|
|
// FIXME: When reading literal tokens, reconstruct the literal pointer if
|
|
|
|
// it is needed.
|
2009-04-12 05:15:38 +08:00
|
|
|
AddIdentifierRef(Tok.getIdentifierInfo(), Record);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-11 02:08:30 +08:00
|
|
|
// FIXME: Should translate token kind to a stable encoding.
|
|
|
|
Record.push_back(Tok.getKind());
|
|
|
|
// FIXME: Should translate token flags to a stable encoding.
|
|
|
|
Record.push_back(Tok.getFlags());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecord(pch::PP_TOKEN, Record);
|
2009-04-11 02:08:30 +08:00
|
|
|
Record.clear();
|
|
|
|
}
|
2009-04-22 07:56:24 +08:00
|
|
|
++NumMacros;
|
2009-04-11 02:00:12 +08:00
|
|
|
}
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.ExitBlock();
|
2009-04-11 01:15:23 +08:00
|
|
|
}
|
|
|
|
|
Add support for retrieving the Doxygen comment associated with a given
declaration in the AST.
The new ASTContext::getCommentForDecl function searches for a comment
that is attached to the given declaration, and returns that comment,
which may be composed of several comment blocks.
Comments are always available in an AST. However, to avoid harming
performance, we don't actually parse the comments. Rather, we keep the
source ranges of all of the comments within a large, sorted vector,
then lazily extract comments via a binary search in that vector only
when needed (which never occurs in a "normal" compile).
Comments are written to a precompiled header/AST file as a blob of
source ranges. That blob is only lazily loaded when one requests a
comment for a declaration (this never occurs in a "normal" compile).
The indexer testbed now supports comment extraction. When the
-point-at location points to a declaration with a Doxygen-style
comment, the indexer testbed prints the associated comment
block(s). See test/Index/comments.c for an example.
Some notes:
- We don't actually attempt to parse the comment blocks themselves,
beyond identifying them as Doxygen comment blocks to associate them
with a declaration.
- We won't find comment blocks that aren't adjacent to the
declaration, because we start our search based on the location of
the declaration.
- We don't go through the necessary hops to find, for example,
whether some redeclaration of a declaration has comments when our
current declaration does not. Similarly, we don't attempt to
associate a \param Foo marker in a function body comment with the
parameter named Foo (although that is certainly possible).
- Verification of my "no performance impact" claims is still "to be
done".
llvm-svn: 74704
2009-07-03 01:08:52 +08:00
|
|
|
void PCHWriter::WriteComments(ASTContext &Context) {
|
|
|
|
using namespace llvm;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Add support for retrieving the Doxygen comment associated with a given
declaration in the AST.
The new ASTContext::getCommentForDecl function searches for a comment
that is attached to the given declaration, and returns that comment,
which may be composed of several comment blocks.
Comments are always available in an AST. However, to avoid harming
performance, we don't actually parse the comments. Rather, we keep the
source ranges of all of the comments within a large, sorted vector,
then lazily extract comments via a binary search in that vector only
when needed (which never occurs in a "normal" compile).
Comments are written to a precompiled header/AST file as a blob of
source ranges. That blob is only lazily loaded when one requests a
comment for a declaration (this never occurs in a "normal" compile).
The indexer testbed now supports comment extraction. When the
-point-at location points to a declaration with a Doxygen-style
comment, the indexer testbed prints the associated comment
block(s). See test/Index/comments.c for an example.
Some notes:
- We don't actually attempt to parse the comment blocks themselves,
beyond identifying them as Doxygen comment blocks to associate them
with a declaration.
- We won't find comment blocks that aren't adjacent to the
declaration, because we start our search based on the location of
the declaration.
- We don't go through the necessary hops to find, for example,
whether some redeclaration of a declaration has comments when our
current declaration does not. Similarly, we don't attempt to
associate a \param Foo marker in a function body comment with the
parameter named Foo (although that is certainly possible).
- Verification of my "no performance impact" claims is still "to be
done".
llvm-svn: 74704
2009-07-03 01:08:52 +08:00
|
|
|
if (Context.Comments.empty())
|
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Add support for retrieving the Doxygen comment associated with a given
declaration in the AST.
The new ASTContext::getCommentForDecl function searches for a comment
that is attached to the given declaration, and returns that comment,
which may be composed of several comment blocks.
Comments are always available in an AST. However, to avoid harming
performance, we don't actually parse the comments. Rather, we keep the
source ranges of all of the comments within a large, sorted vector,
then lazily extract comments via a binary search in that vector only
when needed (which never occurs in a "normal" compile).
Comments are written to a precompiled header/AST file as a blob of
source ranges. That blob is only lazily loaded when one requests a
comment for a declaration (this never occurs in a "normal" compile).
The indexer testbed now supports comment extraction. When the
-point-at location points to a declaration with a Doxygen-style
comment, the indexer testbed prints the associated comment
block(s). See test/Index/comments.c for an example.
Some notes:
- We don't actually attempt to parse the comment blocks themselves,
beyond identifying them as Doxygen comment blocks to associate them
with a declaration.
- We won't find comment blocks that aren't adjacent to the
declaration, because we start our search based on the location of
the declaration.
- We don't go through the necessary hops to find, for example,
whether some redeclaration of a declaration has comments when our
current declaration does not. Similarly, we don't attempt to
associate a \param Foo marker in a function body comment with the
parameter named Foo (although that is certainly possible).
- Verification of my "no performance impact" claims is still "to be
done".
llvm-svn: 74704
2009-07-03 01:08:52 +08:00
|
|
|
BitCodeAbbrev *CommentAbbrev = new BitCodeAbbrev();
|
|
|
|
CommentAbbrev->Add(BitCodeAbbrevOp(pch::COMMENT_RANGES));
|
|
|
|
CommentAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
|
|
|
|
unsigned CommentCode = Stream.EmitAbbrev(CommentAbbrev);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Add support for retrieving the Doxygen comment associated with a given
declaration in the AST.
The new ASTContext::getCommentForDecl function searches for a comment
that is attached to the given declaration, and returns that comment,
which may be composed of several comment blocks.
Comments are always available in an AST. However, to avoid harming
performance, we don't actually parse the comments. Rather, we keep the
source ranges of all of the comments within a large, sorted vector,
then lazily extract comments via a binary search in that vector only
when needed (which never occurs in a "normal" compile).
Comments are written to a precompiled header/AST file as a blob of
source ranges. That blob is only lazily loaded when one requests a
comment for a declaration (this never occurs in a "normal" compile).
The indexer testbed now supports comment extraction. When the
-point-at location points to a declaration with a Doxygen-style
comment, the indexer testbed prints the associated comment
block(s). See test/Index/comments.c for an example.
Some notes:
- We don't actually attempt to parse the comment blocks themselves,
beyond identifying them as Doxygen comment blocks to associate them
with a declaration.
- We won't find comment blocks that aren't adjacent to the
declaration, because we start our search based on the location of
the declaration.
- We don't go through the necessary hops to find, for example,
whether some redeclaration of a declaration has comments when our
current declaration does not. Similarly, we don't attempt to
associate a \param Foo marker in a function body comment with the
parameter named Foo (although that is certainly possible).
- Verification of my "no performance impact" claims is still "to be
done".
llvm-svn: 74704
2009-07-03 01:08:52 +08:00
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(pch::COMMENT_RANGES);
|
2009-09-09 23:08:12 +08:00
|
|
|
Stream.EmitRecordWithBlob(CommentCode, Record,
|
Add support for retrieving the Doxygen comment associated with a given
declaration in the AST.
The new ASTContext::getCommentForDecl function searches for a comment
that is attached to the given declaration, and returns that comment,
which may be composed of several comment blocks.
Comments are always available in an AST. However, to avoid harming
performance, we don't actually parse the comments. Rather, we keep the
source ranges of all of the comments within a large, sorted vector,
then lazily extract comments via a binary search in that vector only
when needed (which never occurs in a "normal" compile).
Comments are written to a precompiled header/AST file as a blob of
source ranges. That blob is only lazily loaded when one requests a
comment for a declaration (this never occurs in a "normal" compile).
The indexer testbed now supports comment extraction. When the
-point-at location points to a declaration with a Doxygen-style
comment, the indexer testbed prints the associated comment
block(s). See test/Index/comments.c for an example.
Some notes:
- We don't actually attempt to parse the comment blocks themselves,
beyond identifying them as Doxygen comment blocks to associate them
with a declaration.
- We won't find comment blocks that aren't adjacent to the
declaration, because we start our search based on the location of
the declaration.
- We don't go through the necessary hops to find, for example,
whether some redeclaration of a declaration has comments when our
current declaration does not. Similarly, we don't attempt to
associate a \param Foo marker in a function body comment with the
parameter named Foo (although that is certainly possible).
- Verification of my "no performance impact" claims is still "to be
done".
llvm-svn: 74704
2009-07-03 01:08:52 +08:00
|
|
|
(const char*)&Context.Comments[0],
|
|
|
|
Context.Comments.size() * sizeof(SourceRange));
|
|
|
|
}
|
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type Serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-04-11 01:15:23 +08:00
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
/// \brief Write the representation of a type to the PCH stream.
|
2009-09-25 03:53:00 +08:00
|
|
|
void PCHWriter::WriteType(QualType T) {
|
2009-04-11 01:25:41 +08:00
|
|
|
pch::TypeID &ID = TypeIDs[T];
|
2009-04-11 01:16:57 +08:00
|
|
|
if (ID == 0) // we haven't seen this type before.
|
2009-04-10 06:27:44 +08:00
|
|
|
ID = NextTypeID++;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
// Record the offset for this type.
|
|
|
|
if (TypeOffsets.size() == ID - pch::NUM_PREDEF_TYPE_IDS)
|
2009-04-17 06:23:12 +08:00
|
|
|
TypeOffsets.push_back(Stream.GetCurrentBitNo());
|
2009-04-10 06:27:44 +08:00
|
|
|
else if (TypeOffsets.size() < ID - pch::NUM_PREDEF_TYPE_IDS) {
|
|
|
|
TypeOffsets.resize(ID + 1 - pch::NUM_PREDEF_TYPE_IDS);
|
2009-04-17 06:23:12 +08:00
|
|
|
TypeOffsets[ID - pch::NUM_PREDEF_TYPE_IDS] = Stream.GetCurrentBitNo();
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RecordData Record;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
// Emit the type's representation.
|
|
|
|
PCHTypeWriter W(*this, Record);
|
2009-09-25 03:53:00 +08:00
|
|
|
|
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
llvm-svn: 88969
2009-11-17 05:35:15 +08:00
|
|
|
if (T.hasLocalNonFastQualifiers()) {
|
|
|
|
Qualifiers Qs = T.getLocalQualifiers();
|
|
|
|
AddTypeRef(T.getLocalUnqualifiedType(), Record);
|
2009-09-25 03:53:00 +08:00
|
|
|
Record.push_back(Qs.getAsOpaqueValue());
|
|
|
|
W.Code = pch::TYPE_EXT_QUAL;
|
|
|
|
} else {
|
|
|
|
switch (T->getTypeClass()) {
|
|
|
|
// For all of the concrete, non-dependent types, call the
|
|
|
|
// appropriate visitor function.
|
2009-04-10 06:27:44 +08:00
|
|
|
#define TYPE(Class, Base) \
|
2009-09-25 03:53:00 +08:00
|
|
|
case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break;
|
2009-04-10 06:27:44 +08:00
|
|
|
#define ABSTRACT_TYPE(Class, Base)
|
|
|
|
#define DEPENDENT_TYPE(Class, Base)
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
|
|
|
|
2009-09-25 03:53:00 +08:00
|
|
|
// For all of the dependent type nodes (which only occur in C++
|
|
|
|
// templates), produce an error.
|
2009-04-10 06:27:44 +08:00
|
|
|
#define TYPE(Class, Base)
|
|
|
|
#define DEPENDENT_TYPE(Class, Base) case Type::Class:
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
2009-09-25 03:53:00 +08:00
|
|
|
assert(false && "Cannot serialize dependent type nodes");
|
|
|
|
break;
|
|
|
|
}
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the serialized record.
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecord(W.Code, Record);
|
2009-04-15 05:18:50 +08:00
|
|
|
|
|
|
|
// Flush any expressions that were written as part of this type.
|
2009-04-17 06:23:12 +08:00
|
|
|
FlushStmts();
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Declaration Serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
/// \brief Write the block containing all of the declaration IDs
|
|
|
|
/// lexically declared within the given DeclContext.
|
|
|
|
///
|
|
|
|
/// \returns the offset of the DECL_CONTEXT_LEXICAL block within the
|
|
|
|
/// bistream, or 0 if no block was written.
|
2009-09-09 23:08:12 +08:00
|
|
|
uint64_t PCHWriter::WriteDeclContextLexicalBlock(ASTContext &Context,
|
2009-04-10 06:27:44 +08:00
|
|
|
DeclContext *DC) {
|
2009-06-30 10:36:12 +08:00
|
|
|
if (DC->decls_empty())
|
2009-04-10 06:27:44 +08:00
|
|
|
return 0;
|
|
|
|
|
2009-04-17 06:23:12 +08:00
|
|
|
uint64_t Offset = Stream.GetCurrentBitNo();
|
2009-04-10 06:27:44 +08:00
|
|
|
RecordData Record;
|
2009-06-30 10:36:12 +08:00
|
|
|
for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
|
|
|
|
D != DEnd; ++D)
|
2009-04-10 06:27:44 +08:00
|
|
|
AddDeclRef(*D, Record);
|
|
|
|
|
2009-04-23 06:34:57 +08:00
|
|
|
++NumLexicalDeclContexts;
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecord(pch::DECL_CONTEXT_LEXICAL, Record);
|
2009-04-10 06:27:44 +08:00
|
|
|
return Offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Write the block containing all of the declaration IDs
|
|
|
|
/// visible from the given DeclContext.
|
|
|
|
///
|
|
|
|
/// \returns the offset of the DECL_CONTEXT_VISIBLE block within the
|
|
|
|
/// bistream, or 0 if no block was written.
|
|
|
|
uint64_t PCHWriter::WriteDeclContextVisibleBlock(ASTContext &Context,
|
|
|
|
DeclContext *DC) {
|
|
|
|
if (DC->getPrimaryContext() != DC)
|
|
|
|
return 0;
|
|
|
|
|
2009-04-22 06:32:33 +08:00
|
|
|
// Since there is no name lookup into functions or methods, and we
|
|
|
|
// perform name lookup for the translation unit via the
|
|
|
|
// IdentifierInfo chains, don't bother to build a
|
|
|
|
// visible-declarations table for these entities.
|
|
|
|
if (DC->isFunctionOrMethod() || DC->isTranslationUnit())
|
2009-04-18 23:49:20 +08:00
|
|
|
return 0;
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
// Force the DeclContext to build a its name-lookup table.
|
2009-06-30 10:36:12 +08:00
|
|
|
DC->lookup(DeclarationName());
|
2009-04-10 06:27:44 +08:00
|
|
|
|
|
|
|
// Serialize the contents of the mapping used for lookup. Note that,
|
|
|
|
// although we have two very different code paths, the serialized
|
|
|
|
// representation is the same for both cases: a declaration name,
|
|
|
|
// followed by a size, followed by references to the visible
|
|
|
|
// declarations that have that name.
|
2009-04-17 06:23:12 +08:00
|
|
|
uint64_t Offset = Stream.GetCurrentBitNo();
|
2009-04-10 06:27:44 +08:00
|
|
|
RecordData Record;
|
|
|
|
StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr());
|
2009-04-14 05:20:57 +08:00
|
|
|
if (!Map)
|
|
|
|
return 0;
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
AddDeclarationName(D->first, Record);
|
|
|
|
DeclContext::lookup_result Result = D->second.getLookupResult(Context);
|
|
|
|
Record.push_back(Result.second - Result.first);
|
2009-09-09 23:08:12 +08:00
|
|
|
for (; Result.first != Result.second; ++Result.first)
|
2009-04-10 06:27:44 +08:00
|
|
|
AddDeclRef(*Result.first, Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Record.size() == 0)
|
|
|
|
return 0;
|
|
|
|
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecord(pch::DECL_CONTEXT_VISIBLE, Record);
|
2009-04-23 06:34:57 +08:00
|
|
|
++NumVisibleDeclContexts;
|
2009-04-10 06:27:44 +08:00
|
|
|
return Offset;
|
|
|
|
}
|
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Global Method Pool and Selector Serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-25 05:10:55 +08:00
|
|
|
namespace {
|
|
|
|
// Trait used for the on-disk hash table used in the method pool.
|
|
|
|
class VISIBILITY_HIDDEN PCHMethodPoolTrait {
|
|
|
|
PCHWriter &Writer;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef Selector key_type;
|
|
|
|
typedef key_type key_type_ref;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-25 05:10:55 +08:00
|
|
|
typedef std::pair<ObjCMethodList, ObjCMethodList> data_type;
|
|
|
|
typedef const data_type& data_type_ref;
|
|
|
|
|
|
|
|
explicit PCHMethodPoolTrait(PCHWriter &Writer) : Writer(Writer) { }
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-25 05:10:55 +08:00
|
|
|
static unsigned ComputeHash(Selector Sel) {
|
|
|
|
unsigned N = Sel.getNumArgs();
|
|
|
|
if (N == 0)
|
|
|
|
++N;
|
|
|
|
unsigned R = 5381;
|
|
|
|
for (unsigned I = 0; I != N; ++I)
|
|
|
|
if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I))
|
2009-10-18 07:52:28 +08:00
|
|
|
R = llvm::HashString(II->getName(), R);
|
2009-04-25 05:10:55 +08:00
|
|
|
return R;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
std::pair<unsigned,unsigned>
|
2009-04-25 05:10:55 +08:00
|
|
|
EmitKeyDataLength(llvm::raw_ostream& Out, Selector Sel,
|
|
|
|
data_type_ref Methods) {
|
|
|
|
unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4);
|
|
|
|
clang::io::Emit16(Out, KeyLen);
|
|
|
|
unsigned DataLen = 2 + 2; // 2 bytes for each of the method counts
|
2009-09-09 23:08:12 +08:00
|
|
|
for (const ObjCMethodList *Method = &Methods.first; Method;
|
2009-04-25 05:10:55 +08:00
|
|
|
Method = Method->Next)
|
|
|
|
if (Method->Method)
|
|
|
|
DataLen += 4;
|
2009-09-09 23:08:12 +08:00
|
|
|
for (const ObjCMethodList *Method = &Methods.second; Method;
|
2009-04-25 05:10:55 +08:00
|
|
|
Method = Method->Next)
|
|
|
|
if (Method->Method)
|
|
|
|
DataLen += 4;
|
|
|
|
clang::io::Emit16(Out, DataLen);
|
|
|
|
return std::make_pair(KeyLen, DataLen);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-26 01:48:32 +08:00
|
|
|
void EmitKey(llvm::raw_ostream& Out, Selector Sel, unsigned) {
|
2009-09-09 23:08:12 +08:00
|
|
|
uint64_t Start = Out.tell();
|
2009-04-26 01:48:32 +08:00
|
|
|
assert((Start >> 32) == 0 && "Selector key offset too large");
|
|
|
|
Writer.SetSelectorOffset(Sel, Start);
|
2009-04-25 05:10:55 +08:00
|
|
|
unsigned N = Sel.getNumArgs();
|
|
|
|
clang::io::Emit16(Out, N);
|
|
|
|
if (N == 0)
|
|
|
|
N = 1;
|
|
|
|
for (unsigned I = 0; I != N; ++I)
|
2009-09-09 23:08:12 +08:00
|
|
|
clang::io::Emit32(Out,
|
2009-04-25 05:10:55 +08:00
|
|
|
Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I)));
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-25 05:10:55 +08:00
|
|
|
void EmitData(llvm::raw_ostream& Out, key_type_ref,
|
2009-04-25 05:49:02 +08:00
|
|
|
data_type_ref Methods, unsigned DataLen) {
|
|
|
|
uint64_t Start = Out.tell(); (void)Start;
|
2009-04-25 05:10:55 +08:00
|
|
|
unsigned NumInstanceMethods = 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
for (const ObjCMethodList *Method = &Methods.first; Method;
|
2009-04-25 05:10:55 +08:00
|
|
|
Method = Method->Next)
|
|
|
|
if (Method->Method)
|
|
|
|
++NumInstanceMethods;
|
|
|
|
|
|
|
|
unsigned NumFactoryMethods = 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
for (const ObjCMethodList *Method = &Methods.second; Method;
|
2009-04-25 05:10:55 +08:00
|
|
|
Method = Method->Next)
|
|
|
|
if (Method->Method)
|
|
|
|
++NumFactoryMethods;
|
|
|
|
|
|
|
|
clang::io::Emit16(Out, NumInstanceMethods);
|
|
|
|
clang::io::Emit16(Out, NumFactoryMethods);
|
2009-09-09 23:08:12 +08:00
|
|
|
for (const ObjCMethodList *Method = &Methods.first; Method;
|
2009-04-25 05:10:55 +08:00
|
|
|
Method = Method->Next)
|
|
|
|
if (Method->Method)
|
|
|
|
clang::io::Emit32(Out, Writer.getDeclID(Method->Method));
|
2009-09-09 23:08:12 +08:00
|
|
|
for (const ObjCMethodList *Method = &Methods.second; Method;
|
2009-04-25 05:10:55 +08:00
|
|
|
Method = Method->Next)
|
|
|
|
if (Method->Method)
|
|
|
|
clang::io::Emit32(Out, Writer.getDeclID(Method->Method));
|
2009-04-25 05:49:02 +08:00
|
|
|
|
|
|
|
assert(Out.tell() - Start == DataLen && "Data length is wrong");
|
2009-04-25 05:10:55 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
/// \brief Write the method pool into the PCH file.
|
|
|
|
///
|
|
|
|
/// The method pool contains both instance and factory methods, stored
|
|
|
|
/// in an on-disk hash table indexed by the selector.
|
|
|
|
void PCHWriter::WriteMethodPool(Sema &SemaRef) {
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Create and write out the blob that contains the instance and
|
|
|
|
// factor method pools.
|
|
|
|
bool Empty = true;
|
|
|
|
{
|
|
|
|
OnDiskChainedHashTableGenerator<PCHMethodPoolTrait> Generator;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-25 05:10:55 +08:00
|
|
|
// Create the on-disk hash table representation. Start by
|
|
|
|
// iterating through the instance method pool.
|
|
|
|
PCHMethodPoolTrait::key_type Key;
|
2009-04-26 01:48:32 +08:00
|
|
|
unsigned NumSelectorsInMethodPool = 0;
|
2009-04-25 05:10:55 +08:00
|
|
|
for (llvm::DenseMap<Selector, ObjCMethodList>::iterator
|
2009-09-09 23:08:12 +08:00
|
|
|
Instance = SemaRef.InstanceMethodPool.begin(),
|
2009-04-25 05:10:55 +08:00
|
|
|
InstanceEnd = SemaRef.InstanceMethodPool.end();
|
|
|
|
Instance != InstanceEnd; ++Instance) {
|
|
|
|
// Check whether there is a factory method with the same
|
|
|
|
// selector.
|
|
|
|
llvm::DenseMap<Selector, ObjCMethodList>::iterator Factory
|
|
|
|
= SemaRef.FactoryMethodPool.find(Instance->first);
|
|
|
|
|
|
|
|
if (Factory == SemaRef.FactoryMethodPool.end())
|
|
|
|
Generator.insert(Instance->first,
|
2009-09-09 23:08:12 +08:00
|
|
|
std::make_pair(Instance->second,
|
2009-04-25 05:10:55 +08:00
|
|
|
ObjCMethodList()));
|
|
|
|
else
|
|
|
|
Generator.insert(Instance->first,
|
|
|
|
std::make_pair(Instance->second, Factory->second));
|
|
|
|
|
2009-04-26 01:48:32 +08:00
|
|
|
++NumSelectorsInMethodPool;
|
2009-04-25 05:10:55 +08:00
|
|
|
Empty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now iterate through the factory method pool, to pick up any
|
|
|
|
// selectors that weren't already in the instance method pool.
|
|
|
|
for (llvm::DenseMap<Selector, ObjCMethodList>::iterator
|
2009-09-09 23:08:12 +08:00
|
|
|
Factory = SemaRef.FactoryMethodPool.begin(),
|
2009-04-25 05:10:55 +08:00
|
|
|
FactoryEnd = SemaRef.FactoryMethodPool.end();
|
|
|
|
Factory != FactoryEnd; ++Factory) {
|
|
|
|
// Check whether there is an instance method with the same
|
|
|
|
// selector. If so, there is no work to do here.
|
|
|
|
llvm::DenseMap<Selector, ObjCMethodList>::iterator Instance
|
|
|
|
= SemaRef.InstanceMethodPool.find(Factory->first);
|
|
|
|
|
2009-04-26 01:48:32 +08:00
|
|
|
if (Instance == SemaRef.InstanceMethodPool.end()) {
|
2009-04-25 05:10:55 +08:00
|
|
|
Generator.insert(Factory->first,
|
|
|
|
std::make_pair(ObjCMethodList(), Factory->second));
|
2009-04-26 01:48:32 +08:00
|
|
|
++NumSelectorsInMethodPool;
|
|
|
|
}
|
2009-04-25 05:10:55 +08:00
|
|
|
|
|
|
|
Empty = false;
|
|
|
|
}
|
|
|
|
|
2009-04-26 01:48:32 +08:00
|
|
|
if (Empty && SelectorOffsets.empty())
|
2009-04-25 05:10:55 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Create the on-disk hash table in a buffer.
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::SmallString<4096> MethodPool;
|
2009-04-25 05:10:55 +08:00
|
|
|
uint32_t BucketOffset;
|
2009-04-26 01:48:32 +08:00
|
|
|
SelectorOffsets.resize(SelVector.size());
|
2009-04-25 05:10:55 +08:00
|
|
|
{
|
|
|
|
PCHMethodPoolTrait Trait(*this);
|
|
|
|
llvm::raw_svector_ostream Out(MethodPool);
|
|
|
|
// Make sure that no bucket is at offset 0
|
2009-04-25 05:49:02 +08:00
|
|
|
clang::io::Emit32(Out, 0);
|
2009-04-25 05:10:55 +08:00
|
|
|
BucketOffset = Generator.Emit(Out, Trait);
|
2009-04-26 01:48:32 +08:00
|
|
|
|
|
|
|
// For every selector that we have seen but which was not
|
|
|
|
// written into the hash table, write the selector itself and
|
|
|
|
// record it's offset.
|
|
|
|
for (unsigned I = 0, N = SelVector.size(); I != N; ++I)
|
|
|
|
if (SelectorOffsets[I] == 0)
|
|
|
|
Trait.EmitKey(Out, SelVector[I], 0);
|
2009-04-25 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a blob abbreviation
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::METHOD_POOL));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
|
2009-04-26 01:48:32 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
|
2009-04-25 05:10:55 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
|
|
|
|
unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev);
|
|
|
|
|
2009-04-26 01:48:32 +08:00
|
|
|
// Write the method pool
|
2009-04-25 05:10:55 +08:00
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(pch::METHOD_POOL);
|
|
|
|
Record.push_back(BucketOffset);
|
2009-04-26 01:48:32 +08:00
|
|
|
Record.push_back(NumSelectorsInMethodPool);
|
2009-08-24 17:31:37 +08:00
|
|
|
Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str());
|
2009-04-26 01:48:32 +08:00
|
|
|
|
|
|
|
// Create a blob abbreviation for the selector table offsets.
|
|
|
|
Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::SELECTOR_OFFSETS));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
|
|
|
|
unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
|
|
|
|
|
|
|
|
// Write the selector offsets table.
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(pch::SELECTOR_OFFSETS);
|
|
|
|
Record.push_back(SelectorOffsets.size());
|
|
|
|
Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record,
|
|
|
|
(const char *)&SelectorOffsets.front(),
|
|
|
|
SelectorOffsets.size() * 4);
|
2009-04-25 05:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Identifier Table Serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-21 04:36:09 +08:00
|
|
|
namespace {
|
|
|
|
class VISIBILITY_HIDDEN PCHIdentifierTableTrait {
|
|
|
|
PCHWriter &Writer;
|
2009-04-22 07:56:24 +08:00
|
|
|
Preprocessor &PP;
|
2009-04-21 04:36:09 +08:00
|
|
|
|
2009-04-29 05:18:29 +08:00
|
|
|
/// \brief Determines whether this is an "interesting" identifier
|
|
|
|
/// that needs a full IdentifierInfo structure written into the hash
|
|
|
|
/// table.
|
|
|
|
static bool isInterestingIdentifier(const IdentifierInfo *II) {
|
|
|
|
return II->isPoisoned() ||
|
|
|
|
II->isExtensionToken() ||
|
|
|
|
II->hasMacroDefinition() ||
|
|
|
|
II->getObjCOrBuiltinID() ||
|
|
|
|
II->getFETokenInfo<void>();
|
|
|
|
}
|
|
|
|
|
2009-04-21 04:36:09 +08:00
|
|
|
public:
|
|
|
|
typedef const IdentifierInfo* key_type;
|
|
|
|
typedef key_type key_type_ref;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-21 04:36:09 +08:00
|
|
|
typedef pch::IdentID data_type;
|
|
|
|
typedef data_type data_type_ref;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
PCHIdentifierTableTrait(PCHWriter &Writer, Preprocessor &PP)
|
2009-04-22 07:56:24 +08:00
|
|
|
: Writer(Writer), PP(PP) { }
|
2009-04-21 04:36:09 +08:00
|
|
|
|
|
|
|
static unsigned ComputeHash(const IdentifierInfo* II) {
|
2009-10-18 07:52:28 +08:00
|
|
|
return llvm::HashString(II->getName());
|
2009-04-21 04:36:09 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
std::pair<unsigned,unsigned>
|
|
|
|
EmitKeyDataLength(llvm::raw_ostream& Out, const IdentifierInfo* II,
|
2009-04-21 04:36:09 +08:00
|
|
|
pch::IdentID ID) {
|
2009-10-19 04:26:12 +08:00
|
|
|
unsigned KeyLen = II->getLength() + 1;
|
2009-04-29 05:18:29 +08:00
|
|
|
unsigned DataLen = 4; // 4 bytes for the persistent ID << 1
|
|
|
|
if (isInterestingIdentifier(II)) {
|
2009-04-29 05:32:13 +08:00
|
|
|
DataLen += 2; // 2 bytes for builtin ID, flags
|
2009-09-09 23:08:12 +08:00
|
|
|
if (II->hasMacroDefinition() &&
|
2009-04-29 05:18:29 +08:00
|
|
|
!PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro())
|
2009-04-29 05:32:13 +08:00
|
|
|
DataLen += 4;
|
2009-04-29 05:18:29 +08:00
|
|
|
for (IdentifierResolver::iterator D = IdentifierResolver::begin(II),
|
|
|
|
DEnd = IdentifierResolver::end();
|
|
|
|
D != DEnd; ++D)
|
|
|
|
DataLen += sizeof(pch::DeclID);
|
|
|
|
}
|
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header.
This patch changes the primary name lookup method for entities within
a precompiled header. Previously, we would load all of the names of
declarations at translation unit scope into a large DenseMap (inside
the TranslationUnitDecl's DeclContext), and then perform a special
"last resort" lookup into this DeclContext when we knew there was a
PCH file (see Sema::LookupName). Now, when we see an identifier named
for the first time, we load all of the declarations with that name
that are visible from the translation unit into the IdentifierInfo's
chain of declarations. Thus, the explicit "look into the translation
unit's DeclContext" code is gone, and Sema effectively uses the same
IdentifierInfo-based name lookup mechanism whether we are using a PCH
file or not.
This approach should help PCH scale with the size of the input program
rather than the size of the PCH file. The "Hello, World!" application
with Carbon.h as a PCH file now loads 20% of the identifiers in the
PCH file rather than 85% of the identifiers.
90% of the 20% of identifiers loaded are actually loaded when we
deserialize the preprocessor state. The next step is to make the
preprocessor load macros lazily, which should drastically reduce the
number of types, declarations, and identifiers loaded for "Hello,
World".
llvm-svn: 69737
2009-04-22 06:25:48 +08:00
|
|
|
clang::io::Emit16(Out, DataLen);
|
2009-04-29 04:01:51 +08:00
|
|
|
// We emit the key length after the data length so that every
|
|
|
|
// string is preceded by a 16-bit length. This matches the PTH
|
|
|
|
// format for storing identifiers.
|
2009-04-26 05:04:17 +08:00
|
|
|
clang::io::Emit16(Out, KeyLen);
|
2009-04-21 04:36:09 +08:00
|
|
|
return std::make_pair(KeyLen, DataLen);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
void EmitKey(llvm::raw_ostream& Out, const IdentifierInfo* II,
|
2009-04-21 04:36:09 +08:00
|
|
|
unsigned KeyLen) {
|
|
|
|
// Record the location of the key data. This is used when generating
|
|
|
|
// the mapping from persistent IDs to strings.
|
|
|
|
Writer.SetIdentifierOffset(II, Out.tell());
|
2009-10-19 04:26:12 +08:00
|
|
|
Out.write(II->getNameStart(), KeyLen);
|
2009-04-21 04:36:09 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
void EmitData(llvm::raw_ostream& Out, const IdentifierInfo* II,
|
2009-04-21 04:36:09 +08:00
|
|
|
pch::IdentID ID, unsigned) {
|
2009-04-29 05:18:29 +08:00
|
|
|
if (!isInterestingIdentifier(II)) {
|
|
|
|
clang::io::Emit32(Out, ID << 1);
|
|
|
|
return;
|
|
|
|
}
|
2009-04-29 05:32:13 +08:00
|
|
|
|
2009-04-29 05:18:29 +08:00
|
|
|
clang::io::Emit32(Out, (ID << 1) | 0x01);
|
2009-04-21 04:36:09 +08:00
|
|
|
uint32_t Bits = 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
bool hasMacroDefinition =
|
|
|
|
II->hasMacroDefinition() &&
|
2009-04-22 07:56:24 +08:00
|
|
|
!PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro();
|
2009-04-29 05:32:13 +08:00
|
|
|
Bits = (uint32_t)II->getObjCOrBuiltinID();
|
2009-04-23 02:49:13 +08:00
|
|
|
Bits = (Bits << 1) | hasMacroDefinition;
|
2009-04-21 04:36:09 +08:00
|
|
|
Bits = (Bits << 1) | II->isExtensionToken();
|
|
|
|
Bits = (Bits << 1) | II->isPoisoned();
|
|
|
|
Bits = (Bits << 1) | II->isCPlusPlusOperatorKeyword();
|
2009-04-29 05:32:13 +08:00
|
|
|
clang::io::Emit16(Out, Bits);
|
2009-04-21 04:36:09 +08:00
|
|
|
|
2009-04-22 07:56:24 +08:00
|
|
|
if (hasMacroDefinition)
|
2009-04-29 05:32:13 +08:00
|
|
|
clang::io::Emit32(Out, Writer.getMacroOffset(II));
|
2009-04-22 07:56:24 +08:00
|
|
|
|
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header.
This patch changes the primary name lookup method for entities within
a precompiled header. Previously, we would load all of the names of
declarations at translation unit scope into a large DenseMap (inside
the TranslationUnitDecl's DeclContext), and then perform a special
"last resort" lookup into this DeclContext when we knew there was a
PCH file (see Sema::LookupName). Now, when we see an identifier named
for the first time, we load all of the declarations with that name
that are visible from the translation unit into the IdentifierInfo's
chain of declarations. Thus, the explicit "look into the translation
unit's DeclContext" code is gone, and Sema effectively uses the same
IdentifierInfo-based name lookup mechanism whether we are using a PCH
file or not.
This approach should help PCH scale with the size of the input program
rather than the size of the PCH file. The "Hello, World!" application
with Carbon.h as a PCH file now loads 20% of the identifiers in the
PCH file rather than 85% of the identifiers.
90% of the 20% of identifiers loaded are actually loaded when we
deserialize the preprocessor state. The next step is to make the
preprocessor load macros lazily, which should drastically reduce the
number of types, declarations, and identifiers loaded for "Hello,
World".
llvm-svn: 69737
2009-04-22 06:25:48 +08:00
|
|
|
// Emit the declaration IDs in reverse order, because the
|
|
|
|
// IdentifierResolver provides the declarations as they would be
|
|
|
|
// visible (e.g., the function "stat" would come before the struct
|
|
|
|
// "stat"), but IdentifierResolver::AddDeclToIdentifierChain()
|
|
|
|
// adds declarations to the end of the list (so we need to see the
|
|
|
|
// struct "status" before the function "status").
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::SmallVector<Decl *, 16> Decls(IdentifierResolver::begin(II),
|
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header.
This patch changes the primary name lookup method for entities within
a precompiled header. Previously, we would load all of the names of
declarations at translation unit scope into a large DenseMap (inside
the TranslationUnitDecl's DeclContext), and then perform a special
"last resort" lookup into this DeclContext when we knew there was a
PCH file (see Sema::LookupName). Now, when we see an identifier named
for the first time, we load all of the declarations with that name
that are visible from the translation unit into the IdentifierInfo's
chain of declarations. Thus, the explicit "look into the translation
unit's DeclContext" code is gone, and Sema effectively uses the same
IdentifierInfo-based name lookup mechanism whether we are using a PCH
file or not.
This approach should help PCH scale with the size of the input program
rather than the size of the PCH file. The "Hello, World!" application
with Carbon.h as a PCH file now loads 20% of the identifiers in the
PCH file rather than 85% of the identifiers.
90% of the 20% of identifiers loaded are actually loaded when we
deserialize the preprocessor state. The next step is to make the
preprocessor load macros lazily, which should drastically reduce the
number of types, declarations, and identifiers loaded for "Hello,
World".
llvm-svn: 69737
2009-04-22 06:25:48 +08:00
|
|
|
IdentifierResolver::end());
|
|
|
|
for (llvm::SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(),
|
|
|
|
DEnd = Decls.rend();
|
2009-04-21 04:36:09 +08:00
|
|
|
D != DEnd; ++D)
|
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header.
This patch changes the primary name lookup method for entities within
a precompiled header. Previously, we would load all of the names of
declarations at translation unit scope into a large DenseMap (inside
the TranslationUnitDecl's DeclContext), and then perform a special
"last resort" lookup into this DeclContext when we knew there was a
PCH file (see Sema::LookupName). Now, when we see an identifier named
for the first time, we load all of the declarations with that name
that are visible from the translation unit into the IdentifierInfo's
chain of declarations. Thus, the explicit "look into the translation
unit's DeclContext" code is gone, and Sema effectively uses the same
IdentifierInfo-based name lookup mechanism whether we are using a PCH
file or not.
This approach should help PCH scale with the size of the input program
rather than the size of the PCH file. The "Hello, World!" application
with Carbon.h as a PCH file now loads 20% of the identifiers in the
PCH file rather than 85% of the identifiers.
90% of the 20% of identifiers loaded are actually loaded when we
deserialize the preprocessor state. The next step is to make the
preprocessor load macros lazily, which should drastically reduce the
number of types, declarations, and identifiers loaded for "Hello,
World".
llvm-svn: 69737
2009-04-22 06:25:48 +08:00
|
|
|
clang::io::Emit32(Out, Writer.getDeclID(*D));
|
2009-04-21 04:36:09 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2009-04-11 08:14:32 +08:00
|
|
|
/// \brief Write the identifier table into the PCH file.
|
|
|
|
///
|
|
|
|
/// The identifier table consists of a blob containing string data
|
|
|
|
/// (the actual identifiers themselves) and a separate "offsets" index
|
|
|
|
/// that maps identifier IDs to locations within the blob.
|
2009-04-22 07:56:24 +08:00
|
|
|
void PCHWriter::WriteIdentifierTable(Preprocessor &PP) {
|
2009-04-11 08:14:32 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Create and write out the blob that contains the identifier
|
|
|
|
// strings.
|
|
|
|
{
|
2009-04-21 04:36:09 +08:00
|
|
|
OnDiskChainedHashTableGenerator<PCHIdentifierTableTrait> Generator;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-29 04:33:11 +08:00
|
|
|
// Look for any identifiers that were named while processing the
|
|
|
|
// headers, but are otherwise not needed. We add these to the hash
|
|
|
|
// table to enable checking of the predefines buffer in the case
|
|
|
|
// where the user adds new macro definitions when building the PCH
|
|
|
|
// file.
|
|
|
|
for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(),
|
|
|
|
IDEnd = PP.getIdentifierTable().end();
|
|
|
|
ID != IDEnd; ++ID)
|
|
|
|
getIdentifierRef(ID->second);
|
|
|
|
|
2009-04-21 04:36:09 +08:00
|
|
|
// Create the on-disk hash table representation.
|
2009-04-29 04:33:11 +08:00
|
|
|
IdentifierOffsets.resize(IdentifierIDs.size());
|
2009-04-11 08:14:32 +08:00
|
|
|
for (llvm::DenseMap<const IdentifierInfo *, pch::IdentID>::iterator
|
|
|
|
ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end();
|
|
|
|
ID != IDEnd; ++ID) {
|
|
|
|
assert(ID->first && "NULL identifier in identifier table");
|
2009-04-29 04:01:51 +08:00
|
|
|
Generator.insert(ID->first, ID->second);
|
2009-04-21 04:36:09 +08:00
|
|
|
}
|
2009-04-11 08:14:32 +08:00
|
|
|
|
2009-04-21 04:36:09 +08:00
|
|
|
// Create the on-disk hash table in a buffer.
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::SmallString<4096> IdentifierTable;
|
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header.
This patch changes the primary name lookup method for entities within
a precompiled header. Previously, we would load all of the names of
declarations at translation unit scope into a large DenseMap (inside
the TranslationUnitDecl's DeclContext), and then perform a special
"last resort" lookup into this DeclContext when we knew there was a
PCH file (see Sema::LookupName). Now, when we see an identifier named
for the first time, we load all of the declarations with that name
that are visible from the translation unit into the IdentifierInfo's
chain of declarations. Thus, the explicit "look into the translation
unit's DeclContext" code is gone, and Sema effectively uses the same
IdentifierInfo-based name lookup mechanism whether we are using a PCH
file or not.
This approach should help PCH scale with the size of the input program
rather than the size of the PCH file. The "Hello, World!" application
with Carbon.h as a PCH file now loads 20% of the identifiers in the
PCH file rather than 85% of the identifiers.
90% of the 20% of identifiers loaded are actually loaded when we
deserialize the preprocessor state. The next step is to make the
preprocessor load macros lazily, which should drastically reduce the
number of types, declarations, and identifiers loaded for "Hello,
World".
llvm-svn: 69737
2009-04-22 06:25:48 +08:00
|
|
|
uint32_t BucketOffset;
|
2009-04-21 04:36:09 +08:00
|
|
|
{
|
2009-04-22 07:56:24 +08:00
|
|
|
PCHIdentifierTableTrait Trait(*this, PP);
|
2009-04-21 04:36:09 +08:00
|
|
|
llvm::raw_svector_ostream Out(IdentifierTable);
|
2009-04-25 05:10:55 +08:00
|
|
|
// Make sure that no bucket is at offset 0
|
2009-04-25 05:49:02 +08:00
|
|
|
clang::io::Emit32(Out, 0);
|
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header.
This patch changes the primary name lookup method for entities within
a precompiled header. Previously, we would load all of the names of
declarations at translation unit scope into a large DenseMap (inside
the TranslationUnitDecl's DeclContext), and then perform a special
"last resort" lookup into this DeclContext when we knew there was a
PCH file (see Sema::LookupName). Now, when we see an identifier named
for the first time, we load all of the declarations with that name
that are visible from the translation unit into the IdentifierInfo's
chain of declarations. Thus, the explicit "look into the translation
unit's DeclContext" code is gone, and Sema effectively uses the same
IdentifierInfo-based name lookup mechanism whether we are using a PCH
file or not.
This approach should help PCH scale with the size of the input program
rather than the size of the PCH file. The "Hello, World!" application
with Carbon.h as a PCH file now loads 20% of the identifiers in the
PCH file rather than 85% of the identifiers.
90% of the 20% of identifiers loaded are actually loaded when we
deserialize the preprocessor state. The next step is to make the
preprocessor load macros lazily, which should drastically reduce the
number of types, declarations, and identifiers loaded for "Hello,
World".
llvm-svn: 69737
2009-04-22 06:25:48 +08:00
|
|
|
BucketOffset = Generator.Emit(Out, Trait);
|
2009-04-11 08:14:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a blob abbreviation
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::IDENTIFIER_TABLE));
|
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header.
This patch changes the primary name lookup method for entities within
a precompiled header. Previously, we would load all of the names of
declarations at translation unit scope into a large DenseMap (inside
the TranslationUnitDecl's DeclContext), and then perform a special
"last resort" lookup into this DeclContext when we knew there was a
PCH file (see Sema::LookupName). Now, when we see an identifier named
for the first time, we load all of the declarations with that name
that are visible from the translation unit into the IdentifierInfo's
chain of declarations. Thus, the explicit "look into the translation
unit's DeclContext" code is gone, and Sema effectively uses the same
IdentifierInfo-based name lookup mechanism whether we are using a PCH
file or not.
This approach should help PCH scale with the size of the input program
rather than the size of the PCH file. The "Hello, World!" application
with Carbon.h as a PCH file now loads 20% of the identifiers in the
PCH file rather than 85% of the identifiers.
90% of the 20% of identifiers loaded are actually loaded when we
deserialize the preprocessor state. The next step is to make the
preprocessor load macros lazily, which should drastically reduce the
number of types, declarations, and identifiers loaded for "Hello,
World".
llvm-svn: 69737
2009-04-22 06:25:48 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
|
2009-04-21 04:36:09 +08:00
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
|
2009-04-17 06:23:12 +08:00
|
|
|
unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev);
|
2009-04-11 08:14:32 +08:00
|
|
|
|
|
|
|
// Write the identifier table
|
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(pch::IDENTIFIER_TABLE);
|
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header.
This patch changes the primary name lookup method for entities within
a precompiled header. Previously, we would load all of the names of
declarations at translation unit scope into a large DenseMap (inside
the TranslationUnitDecl's DeclContext), and then perform a special
"last resort" lookup into this DeclContext when we knew there was a
PCH file (see Sema::LookupName). Now, when we see an identifier named
for the first time, we load all of the declarations with that name
that are visible from the translation unit into the IdentifierInfo's
chain of declarations. Thus, the explicit "look into the translation
unit's DeclContext" code is gone, and Sema effectively uses the same
IdentifierInfo-based name lookup mechanism whether we are using a PCH
file or not.
This approach should help PCH scale with the size of the input program
rather than the size of the PCH file. The "Hello, World!" application
with Carbon.h as a PCH file now loads 20% of the identifiers in the
PCH file rather than 85% of the identifiers.
90% of the 20% of identifiers loaded are actually loaded when we
deserialize the preprocessor state. The next step is to make the
preprocessor load macros lazily, which should drastically reduce the
number of types, declarations, and identifiers loaded for "Hello,
World".
llvm-svn: 69737
2009-04-22 06:25:48 +08:00
|
|
|
Record.push_back(BucketOffset);
|
2009-08-24 17:31:37 +08:00
|
|
|
Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str());
|
2009-04-11 08:14:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write the offsets table for identifier IDs.
|
2009-04-26 03:10:14 +08:00
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::IDENTIFIER_OFFSET));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
|
|
|
|
unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
|
|
|
|
|
|
|
|
RecordData Record;
|
|
|
|
Record.push_back(pch::IDENTIFIER_OFFSET);
|
|
|
|
Record.push_back(IdentifierOffsets.size());
|
|
|
|
Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record,
|
|
|
|
(const char *)&IdentifierOffsets.front(),
|
|
|
|
IdentifierOffsets.size() * sizeof(uint32_t));
|
2009-04-11 08:14:32 +08:00
|
|
|
}
|
|
|
|
|
2009-04-28 02:38:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// General Serialization Routines
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-16 05:30:51 +08:00
|
|
|
/// \brief Write a record containing the given attributes.
|
|
|
|
void PCHWriter::WriteAttributeRecord(const Attr *Attr) {
|
|
|
|
RecordData Record;
|
|
|
|
for (; Attr; Attr = Attr->getNext()) {
|
|
|
|
Record.push_back(Attr->getKind()); // FIXME: stable encoding
|
|
|
|
Record.push_back(Attr->isInherited());
|
|
|
|
switch (Attr->getKind()) {
|
|
|
|
case Attr::Alias:
|
|
|
|
AddString(cast<AliasAttr>(Attr)->getAliasee(), Record);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::Aligned:
|
|
|
|
Record.push_back(cast<AlignedAttr>(Attr)->getAlignment());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::AlwaysInline:
|
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-16 05:30:51 +08:00
|
|
|
case Attr::AnalyzerNoReturn:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::Annotate:
|
|
|
|
AddString(cast<AnnotateAttr>(Attr)->getAnnotation(), Record);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::AsmLabel:
|
|
|
|
AddString(cast<AsmLabelAttr>(Attr)->getLabel(), Record);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::Blocks:
|
|
|
|
Record.push_back(cast<BlocksAttr>(Attr)->getType()); // FIXME: stable
|
|
|
|
break;
|
|
|
|
|
2009-11-10 02:38:53 +08:00
|
|
|
case Attr::CDecl:
|
|
|
|
break;
|
|
|
|
|
2009-04-16 05:30:51 +08:00
|
|
|
case Attr::Cleanup:
|
|
|
|
AddDeclRef(cast<CleanupAttr>(Attr)->getFunctionDecl(), Record);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::Const:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::Constructor:
|
|
|
|
Record.push_back(cast<ConstructorAttr>(Attr)->getPriority());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::DLLExport:
|
|
|
|
case Attr::DLLImport:
|
|
|
|
case Attr::Deprecated:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::Destructor:
|
|
|
|
Record.push_back(cast<DestructorAttr>(Attr)->getPriority());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::FastCall:
|
2009-11-21 16:43:09 +08:00
|
|
|
case Attr::Final:
|
2009-04-16 05:30:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::Format: {
|
|
|
|
const FormatAttr *Format = cast<FormatAttr>(Attr);
|
|
|
|
AddString(Format->getType(), Record);
|
|
|
|
Record.push_back(Format->getFormatIdx());
|
|
|
|
Record.push_back(Format->getFirstArg());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-21 01:41:43 +08:00
|
|
|
case Attr::FormatArg: {
|
|
|
|
const FormatArgAttr *Format = cast<FormatArgAttr>(Attr);
|
|
|
|
Record.push_back(Format->getFormatIdx());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-14 02:09:35 +08:00
|
|
|
case Attr::Sentinel : {
|
|
|
|
const SentinelAttr *Sentinel = cast<SentinelAttr>(Attr);
|
|
|
|
Record.push_back(Sentinel->getSentinel());
|
|
|
|
Record.push_back(Sentinel->getNullPos());
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-21 03:12:28 +08:00
|
|
|
case Attr::GNUInline:
|
2009-04-16 05:30:51 +08:00
|
|
|
case Attr::IBOutletKind:
|
2009-08-10 04:07:29 +08:00
|
|
|
case Attr::Malloc:
|
2009-08-27 06:31:08 +08:00
|
|
|
case Attr::NoDebug:
|
2009-04-16 05:30:51 +08:00
|
|
|
case Attr::NoReturn:
|
|
|
|
case Attr::NoThrow:
|
2009-08-27 06:31:08 +08:00
|
|
|
case Attr::NoInline:
|
2009-04-16 05:30:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::NonNull: {
|
|
|
|
const NonNullAttr *NonNull = cast<NonNullAttr>(Attr);
|
|
|
|
Record.push_back(NonNull->size());
|
|
|
|
Record.insert(Record.end(), NonNull->begin(), NonNull->end());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Attr::ObjCException:
|
|
|
|
case Attr::ObjCNSObject:
|
2009-05-09 10:44:38 +08:00
|
|
|
case Attr::CFReturnsRetained:
|
|
|
|
case Attr::NSReturnsRetained:
|
2009-04-16 05:30:51 +08:00
|
|
|
case Attr::Overloadable:
|
|
|
|
break;
|
|
|
|
|
2009-08-09 02:23:56 +08:00
|
|
|
case Attr::PragmaPack:
|
|
|
|
Record.push_back(cast<PragmaPackAttr>(Attr)->getAlignment());
|
2009-04-16 05:30:51 +08:00
|
|
|
break;
|
|
|
|
|
2009-08-09 02:23:56 +08:00
|
|
|
case Attr::Packed:
|
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-16 05:30:51 +08:00
|
|
|
case Attr::Pure:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::Regparm:
|
|
|
|
Record.push_back(cast<RegparmAttr>(Attr)->getNumParams());
|
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-26 14:32:41 +08:00
|
|
|
case Attr::ReqdWorkGroupSize:
|
|
|
|
Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getXDim());
|
|
|
|
Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getYDim());
|
|
|
|
Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getZDim());
|
|
|
|
break;
|
2009-04-16 05:30:51 +08:00
|
|
|
|
|
|
|
case Attr::Section:
|
|
|
|
AddString(cast<SectionAttr>(Attr)->getName(), Record);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::StdCall:
|
|
|
|
case Attr::TransparentUnion:
|
|
|
|
case Attr::Unavailable:
|
|
|
|
case Attr::Unused:
|
|
|
|
case Attr::Used:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::Visibility:
|
|
|
|
// FIXME: stable encoding
|
2009-09-09 23:08:12 +08:00
|
|
|
Record.push_back(cast<VisibilityAttr>(Attr)->getVisibility());
|
2009-04-16 05:30:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Attr::WarnUnusedResult:
|
|
|
|
case Attr::Weak:
|
|
|
|
case Attr::WeakImport:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecord(pch::DECL_ATTR, Record);
|
2009-04-16 05:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHWriter::AddString(const std::string &Str, RecordData &Record) {
|
|
|
|
Record.push_back(Str.size());
|
|
|
|
Record.insert(Record.end(), Str.begin(), Str.end());
|
|
|
|
}
|
|
|
|
|
2009-04-21 04:36:09 +08:00
|
|
|
/// \brief Note that the identifier II occurs at the given offset
|
|
|
|
/// within the identifier table.
|
|
|
|
void PCHWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) {
|
2009-04-26 03:10:14 +08:00
|
|
|
IdentifierOffsets[IdentifierIDs[II] - 1] = Offset;
|
2009-04-21 04:36:09 +08:00
|
|
|
}
|
|
|
|
|
2009-04-26 01:48:32 +08:00
|
|
|
/// \brief Note that the selector Sel occurs at the given offset
|
|
|
|
/// within the method pool/selector table.
|
|
|
|
void PCHWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) {
|
|
|
|
unsigned ID = SelectorIDs[Sel];
|
|
|
|
assert(ID && "Unknown selector");
|
|
|
|
SelectorOffsets[ID - 1] = Offset;
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream)
|
|
|
|
: Stream(Stream), NextTypeID(pch::NUM_PREDEF_TYPE_IDS),
|
2009-04-23 06:34:57 +08:00
|
|
|
NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0),
|
|
|
|
NumVisibleDeclContexts(0) { }
|
2009-04-10 06:27:44 +08:00
|
|
|
|
2009-07-07 08:12:59 +08:00
|
|
|
void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
|
|
|
|
const char *isysroot) {
|
2009-04-26 02:35:21 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-04-20 23:53:59 +08:00
|
|
|
ASTContext &Context = SemaRef.Context;
|
|
|
|
Preprocessor &PP = SemaRef.PP;
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
// Emit the file header.
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.Emit((unsigned)'C', 8);
|
|
|
|
Stream.Emit((unsigned)'P', 8);
|
|
|
|
Stream.Emit((unsigned)'C', 8);
|
|
|
|
Stream.Emit((unsigned)'H', 8);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 06:26:21 +08:00
|
|
|
WriteBlockInfoBlock();
|
2009-04-10 06:27:44 +08:00
|
|
|
|
|
|
|
// The translation unit is the first declaration we'll emit.
|
|
|
|
DeclIDs[Context.getTranslationUnitDecl()] = 1;
|
2009-10-17 08:13:19 +08:00
|
|
|
DeclTypesToEmit.push(Context.getTranslationUnitDecl());
|
2009-04-10 06:27:44 +08:00
|
|
|
|
2009-04-23 02:49:13 +08:00
|
|
|
// Make sure that we emit IdentifierInfos (and any attached
|
|
|
|
// declarations) for builtins.
|
|
|
|
{
|
|
|
|
IdentifierTable &Table = PP.getIdentifierTable();
|
|
|
|
llvm::SmallVector<const char *, 32> BuiltinNames;
|
|
|
|
Context.BuiltinInfo.GetBuiltinNames(BuiltinNames,
|
|
|
|
Context.getLangOptions().NoBuiltin);
|
|
|
|
for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I)
|
|
|
|
getIdentifierRef(&Table.get(BuiltinNames[I]));
|
|
|
|
}
|
|
|
|
|
2009-09-09 02:19:27 +08:00
|
|
|
// Build a record containing all of the tentative definitions in this file, in
|
|
|
|
// TentativeDefinitionList order. Generally, this record will be empty for
|
|
|
|
// headers.
|
2009-04-23 06:02:47 +08:00
|
|
|
RecordData TentativeDefinitions;
|
2009-09-09 02:19:27 +08:00
|
|
|
for (unsigned i = 0, e = SemaRef.TentativeDefinitionList.size(); i != e; ++i){
|
|
|
|
VarDecl *VD =
|
|
|
|
SemaRef.TentativeDefinitions.lookup(SemaRef.TentativeDefinitionList[i]);
|
|
|
|
if (VD) AddDeclRef(VD, TentativeDefinitions);
|
|
|
|
}
|
2009-04-23 06:02:47 +08:00
|
|
|
|
2009-04-23 06:18:58 +08:00
|
|
|
// Build a record containing all of the locally-scoped external
|
|
|
|
// declarations in this header file. Generally, this record will be
|
|
|
|
// empty.
|
|
|
|
RecordData LocallyScopedExternalDecls;
|
2009-09-09 02:19:27 +08:00
|
|
|
// FIXME: This is filling in the PCH file in densemap order which is
|
|
|
|
// nondeterminstic!
|
2009-09-09 23:08:12 +08:00
|
|
|
for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator
|
2009-04-23 06:18:58 +08:00
|
|
|
TD = SemaRef.LocallyScopedExternalDecls.begin(),
|
|
|
|
TDEnd = SemaRef.LocallyScopedExternalDecls.end();
|
|
|
|
TD != TDEnd; ++TD)
|
|
|
|
AddDeclRef(TD->second, LocallyScopedExternalDecls);
|
|
|
|
|
2009-04-28 04:06:05 +08:00
|
|
|
// Build a record containing all of the ext_vector declarations.
|
|
|
|
RecordData ExtVectorDecls;
|
|
|
|
for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I)
|
|
|
|
AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls);
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
// Write the remaining PCH contents.
|
2009-04-18 13:55:16 +08:00
|
|
|
RecordData Record;
|
2009-04-26 02:35:21 +08:00
|
|
|
Stream.EnterSubblock(pch::PCH_BLOCK_ID, 4);
|
2009-07-07 08:12:59 +08:00
|
|
|
WriteMetadata(Context, isysroot);
|
2009-04-11 04:39:37 +08:00
|
|
|
WriteLanguageOptions(Context.getLangOptions());
|
2009-07-07 08:12:59 +08:00
|
|
|
if (StatCalls && !isysroot)
|
|
|
|
WriteStatCache(*StatCalls, isysroot);
|
|
|
|
WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot);
|
2009-09-09 23:08:12 +08:00
|
|
|
WriteComments(Context);
|
2009-07-18 23:33:26 +08:00
|
|
|
// Write the record of special types.
|
|
|
|
Record.clear();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-18 23:33:26 +08:00
|
|
|
AddTypeRef(Context.getBuiltinVaListType(), Record);
|
|
|
|
AddTypeRef(Context.getObjCIdType(), Record);
|
|
|
|
AddTypeRef(Context.getObjCSelType(), Record);
|
|
|
|
AddTypeRef(Context.getObjCProtoType(), Record);
|
|
|
|
AddTypeRef(Context.getObjCClassType(), Record);
|
|
|
|
AddTypeRef(Context.getRawCFConstantStringType(), Record);
|
|
|
|
AddTypeRef(Context.getRawObjCFastEnumerationStateType(), Record);
|
|
|
|
AddTypeRef(Context.getFILEType(), Record);
|
2009-07-28 10:25:19 +08:00
|
|
|
AddTypeRef(Context.getjmp_bufType(), Record);
|
|
|
|
AddTypeRef(Context.getsigjmp_bufType(), Record);
|
2009-08-21 08:27:50 +08:00
|
|
|
AddTypeRef(Context.ObjCIdRedefinitionType, Record);
|
|
|
|
AddTypeRef(Context.ObjCClassRedefinitionType, Record);
|
2009-11-22 03:53:08 +08:00
|
|
|
#if 0
|
|
|
|
// FIXME. Accommodate for this in several PCH/Indexer tests
|
|
|
|
AddTypeRef(Context.ObjCSELRedefinitionType, Record);
|
|
|
|
#endif
|
2009-10-20 10:12:22 +08:00
|
|
|
AddTypeRef(Context.getRawBlockdescriptorType(), Record);
|
2009-10-22 08:49:09 +08:00
|
|
|
AddTypeRef(Context.getRawBlockdescriptorExtendedType(), Record);
|
2009-07-18 23:33:26 +08:00
|
|
|
Stream.EmitRecord(pch::SPECIAL_TYPES, Record);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-26 11:49:13 +08:00
|
|
|
// Keep writing types and declarations until all types and
|
|
|
|
// declarations have been written.
|
2009-10-17 08:13:19 +08:00
|
|
|
Stream.EnterSubblock(pch::DECLTYPES_BLOCK_ID, 3);
|
|
|
|
WriteDeclsBlockAbbrevs();
|
|
|
|
while (!DeclTypesToEmit.empty()) {
|
|
|
|
DeclOrType DOT = DeclTypesToEmit.front();
|
|
|
|
DeclTypesToEmit.pop();
|
|
|
|
if (DOT.isType())
|
|
|
|
WriteType(DOT.getType());
|
|
|
|
else
|
|
|
|
WriteDecl(Context, DOT.getDecl());
|
|
|
|
}
|
|
|
|
Stream.ExitBlock();
|
|
|
|
|
2009-10-18 01:25:45 +08:00
|
|
|
WritePreprocessor(PP);
|
2009-04-25 05:10:55 +08:00
|
|
|
WriteMethodPool(SemaRef);
|
2009-04-22 07:56:24 +08:00
|
|
|
WriteIdentifierTable(PP);
|
2009-04-26 02:35:21 +08:00
|
|
|
|
|
|
|
// Write the type offsets array
|
|
|
|
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::TYPE_OFFSET));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block
|
|
|
|
unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(pch::TYPE_OFFSET);
|
|
|
|
Record.push_back(TypeOffsets.size());
|
|
|
|
Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record,
|
2009-09-09 23:08:12 +08:00
|
|
|
(const char *)&TypeOffsets.front(),
|
2009-04-28 02:24:17 +08:00
|
|
|
TypeOffsets.size() * sizeof(TypeOffsets[0]));
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-26 02:35:21 +08:00
|
|
|
// Write the declaration offsets array
|
|
|
|
Abbrev = new BitCodeAbbrev();
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(pch::DECL_OFFSET));
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations
|
|
|
|
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block
|
|
|
|
unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
|
|
|
|
Record.clear();
|
|
|
|
Record.push_back(pch::DECL_OFFSET);
|
|
|
|
Record.push_back(DeclOffsets.size());
|
|
|
|
Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record,
|
2009-09-09 23:08:12 +08:00
|
|
|
(const char *)&DeclOffsets.front(),
|
2009-04-28 02:24:17 +08:00
|
|
|
DeclOffsets.size() * sizeof(DeclOffsets[0]));
|
2009-04-18 13:55:16 +08:00
|
|
|
|
2009-04-23 06:02:47 +08:00
|
|
|
// Write the record containing external, unnamed definitions.
|
2009-04-14 08:24:19 +08:00
|
|
|
if (!ExternalDefinitions.empty())
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.EmitRecord(pch::EXTERNAL_DEFINITIONS, ExternalDefinitions);
|
2009-04-23 06:02:47 +08:00
|
|
|
|
|
|
|
// Write the record containing tentative definitions.
|
|
|
|
if (!TentativeDefinitions.empty())
|
|
|
|
Stream.EmitRecord(pch::TENTATIVE_DEFINITIONS, TentativeDefinitions);
|
2009-04-23 06:18:58 +08:00
|
|
|
|
|
|
|
// Write the record containing locally-scoped external definitions.
|
|
|
|
if (!LocallyScopedExternalDecls.empty())
|
2009-09-09 23:08:12 +08:00
|
|
|
Stream.EmitRecord(pch::LOCALLY_SCOPED_EXTERNAL_DECLS,
|
2009-04-23 06:18:58 +08:00
|
|
|
LocallyScopedExternalDecls);
|
2009-04-28 04:06:05 +08:00
|
|
|
|
|
|
|
// Write the record containing ext_vector type names.
|
|
|
|
if (!ExtVectorDecls.empty())
|
|
|
|
Stream.EmitRecord(pch::EXT_VECTOR_DECLS, ExtVectorDecls);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-18 06:13:46 +08:00
|
|
|
// Some simple statistics
|
2009-04-18 13:55:16 +08:00
|
|
|
Record.clear();
|
2009-04-18 06:13:46 +08:00
|
|
|
Record.push_back(NumStatements);
|
2009-04-22 07:56:24 +08:00
|
|
|
Record.push_back(NumMacros);
|
2009-04-23 06:34:57 +08:00
|
|
|
Record.push_back(NumLexicalDeclContexts);
|
|
|
|
Record.push_back(NumVisibleDeclContexts);
|
2009-04-18 06:13:46 +08:00
|
|
|
Stream.EmitRecord(pch::STATISTICS, Record);
|
2009-04-17 06:23:12 +08:00
|
|
|
Stream.ExitBlock();
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHWriter::AddSourceLocation(SourceLocation Loc, RecordData &Record) {
|
|
|
|
Record.push_back(Loc.getRawEncoding());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHWriter::AddAPInt(const llvm::APInt &Value, RecordData &Record) {
|
|
|
|
Record.push_back(Value.getBitWidth());
|
|
|
|
unsigned N = Value.getNumWords();
|
|
|
|
const uint64_t* Words = Value.getRawData();
|
|
|
|
for (unsigned I = 0; I != N; ++I)
|
|
|
|
Record.push_back(Words[I]);
|
|
|
|
}
|
|
|
|
|
2009-04-14 02:14:40 +08:00
|
|
|
void PCHWriter::AddAPSInt(const llvm::APSInt &Value, RecordData &Record) {
|
|
|
|
Record.push_back(Value.isUnsigned());
|
|
|
|
AddAPInt(Value, Record);
|
|
|
|
}
|
|
|
|
|
2009-04-15 05:55:33 +08:00
|
|
|
void PCHWriter::AddAPFloat(const llvm::APFloat &Value, RecordData &Record) {
|
|
|
|
AddAPInt(Value.bitcastToAPInt(), Record);
|
|
|
|
}
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
void PCHWriter::AddIdentifierRef(const IdentifierInfo *II, RecordData &Record) {
|
2009-04-23 02:49:13 +08:00
|
|
|
Record.push_back(getIdentifierRef(II));
|
|
|
|
}
|
|
|
|
|
|
|
|
pch::IdentID PCHWriter::getIdentifierRef(const IdentifierInfo *II) {
|
|
|
|
if (II == 0)
|
|
|
|
return 0;
|
2009-04-11 08:14:32 +08:00
|
|
|
|
|
|
|
pch::IdentID &ID = IdentifierIDs[II];
|
|
|
|
if (ID == 0)
|
|
|
|
ID = IdentifierIDs.size();
|
2009-04-23 02:49:13 +08:00
|
|
|
return ID;
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
2009-04-23 18:39:46 +08:00
|
|
|
void PCHWriter::AddSelectorRef(const Selector SelRef, RecordData &Record) {
|
|
|
|
if (SelRef.getAsOpaquePtr() == 0) {
|
|
|
|
Record.push_back(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pch::SelectorID &SID = SelectorIDs[SelRef];
|
|
|
|
if (SID == 0) {
|
|
|
|
SID = SelectorIDs.size();
|
|
|
|
SelVector.push_back(SelRef);
|
|
|
|
}
|
|
|
|
Record.push_back(SID);
|
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:44 +08:00
|
|
|
void PCHWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg,
|
|
|
|
RecordData &Record) {
|
|
|
|
switch (Arg.getArgument().getKind()) {
|
|
|
|
case TemplateArgument::Expression:
|
|
|
|
AddStmt(Arg.getLocInfo().getAsExpr());
|
|
|
|
break;
|
|
|
|
case TemplateArgument::Type:
|
|
|
|
AddDeclaratorInfo(Arg.getLocInfo().getAsDeclaratorInfo(), Record);
|
|
|
|
break;
|
2009-11-11 09:00:40 +08:00
|
|
|
case TemplateArgument::Template:
|
|
|
|
Record.push_back(
|
|
|
|
Arg.getTemplateQualifierRange().getBegin().getRawEncoding());
|
|
|
|
Record.push_back(Arg.getTemplateQualifierRange().getEnd().getRawEncoding());
|
|
|
|
Record.push_back(Arg.getTemplateNameLoc().getRawEncoding());
|
|
|
|
break;
|
2009-10-29 16:12:44 +08:00
|
|
|
case TemplateArgument::Null:
|
|
|
|
case TemplateArgument::Integral:
|
|
|
|
case TemplateArgument::Declaration:
|
|
|
|
case TemplateArgument::Pack:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-17 05:56:05 +08:00
|
|
|
void PCHWriter::AddDeclaratorInfo(DeclaratorInfo *DInfo, RecordData &Record) {
|
|
|
|
if (DInfo == 0) {
|
|
|
|
AddTypeRef(QualType(), Record);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-18 09:05:36 +08:00
|
|
|
AddTypeRef(DInfo->getType(), Record);
|
2009-10-17 05:56:05 +08:00
|
|
|
TypeLocWriter TLW(*this, Record);
|
|
|
|
for (TypeLoc TL = DInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
|
|
|
|
TLW.Visit(TL);
|
|
|
|
}
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
void PCHWriter::AddTypeRef(QualType T, RecordData &Record) {
|
|
|
|
if (T.isNull()) {
|
|
|
|
Record.push_back(pch::PREDEF_TYPE_NULL_ID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
llvm-svn: 88969
2009-11-17 05:35:15 +08:00
|
|
|
unsigned FastQuals = T.getLocalFastQualifiers();
|
2009-09-25 03:53:00 +08:00
|
|
|
T.removeFastQualifiers();
|
|
|
|
|
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
llvm-svn: 88969
2009-11-17 05:35:15 +08:00
|
|
|
if (T.hasLocalNonFastQualifiers()) {
|
2009-09-25 03:53:00 +08:00
|
|
|
pch::TypeID &ID = TypeIDs[T];
|
|
|
|
if (ID == 0) {
|
|
|
|
// We haven't seen these qualifiers applied to this type before.
|
|
|
|
// Assign it a new ID. This is the only time we enqueue a
|
|
|
|
// qualified type, and it has no CV qualifiers.
|
|
|
|
ID = NextTypeID++;
|
2009-10-17 08:13:19 +08:00
|
|
|
DeclTypesToEmit.push(T);
|
2009-09-25 03:53:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encode the type qualifiers in the type reference.
|
|
|
|
Record.push_back((ID << Qualifiers::FastWidth) | FastQuals);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
llvm-svn: 88969
2009-11-17 05:35:15 +08:00
|
|
|
assert(!T.hasLocalQualifiers());
|
2009-09-25 03:53:00 +08:00
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr())) {
|
2009-04-11 07:10:45 +08:00
|
|
|
pch::TypeID ID = 0;
|
2009-04-10 06:27:44 +08:00
|
|
|
switch (BT->getKind()) {
|
|
|
|
case BuiltinType::Void: ID = pch::PREDEF_TYPE_VOID_ID; break;
|
|
|
|
case BuiltinType::Bool: ID = pch::PREDEF_TYPE_BOOL_ID; break;
|
|
|
|
case BuiltinType::Char_U: ID = pch::PREDEF_TYPE_CHAR_U_ID; break;
|
|
|
|
case BuiltinType::UChar: ID = pch::PREDEF_TYPE_UCHAR_ID; break;
|
|
|
|
case BuiltinType::UShort: ID = pch::PREDEF_TYPE_USHORT_ID; break;
|
|
|
|
case BuiltinType::UInt: ID = pch::PREDEF_TYPE_UINT_ID; break;
|
|
|
|
case BuiltinType::ULong: ID = pch::PREDEF_TYPE_ULONG_ID; break;
|
|
|
|
case BuiltinType::ULongLong: ID = pch::PREDEF_TYPE_ULONGLONG_ID; break;
|
2009-04-30 10:43:43 +08:00
|
|
|
case BuiltinType::UInt128: ID = pch::PREDEF_TYPE_UINT128_ID; break;
|
2009-04-10 06:27:44 +08:00
|
|
|
case BuiltinType::Char_S: ID = pch::PREDEF_TYPE_CHAR_S_ID; break;
|
|
|
|
case BuiltinType::SChar: ID = pch::PREDEF_TYPE_SCHAR_ID; break;
|
|
|
|
case BuiltinType::WChar: ID = pch::PREDEF_TYPE_WCHAR_ID; break;
|
|
|
|
case BuiltinType::Short: ID = pch::PREDEF_TYPE_SHORT_ID; break;
|
|
|
|
case BuiltinType::Int: ID = pch::PREDEF_TYPE_INT_ID; break;
|
|
|
|
case BuiltinType::Long: ID = pch::PREDEF_TYPE_LONG_ID; break;
|
|
|
|
case BuiltinType::LongLong: ID = pch::PREDEF_TYPE_LONGLONG_ID; break;
|
2009-04-30 10:43:43 +08:00
|
|
|
case BuiltinType::Int128: ID = pch::PREDEF_TYPE_INT128_ID; break;
|
2009-04-10 06:27:44 +08:00
|
|
|
case BuiltinType::Float: ID = pch::PREDEF_TYPE_FLOAT_ID; break;
|
|
|
|
case BuiltinType::Double: ID = pch::PREDEF_TYPE_DOUBLE_ID; break;
|
|
|
|
case BuiltinType::LongDouble: ID = pch::PREDEF_TYPE_LONGDOUBLE_ID; break;
|
2009-05-11 02:38:11 +08:00
|
|
|
case BuiltinType::NullPtr: ID = pch::PREDEF_TYPE_NULLPTR_ID; break;
|
2009-07-14 14:30:34 +08:00
|
|
|
case BuiltinType::Char16: ID = pch::PREDEF_TYPE_CHAR16_ID; break;
|
|
|
|
case BuiltinType::Char32: ID = pch::PREDEF_TYPE_CHAR32_ID; break;
|
2009-04-10 06:27:44 +08:00
|
|
|
case BuiltinType::Overload: ID = pch::PREDEF_TYPE_OVERLOAD_ID; break;
|
|
|
|
case BuiltinType::Dependent: ID = pch::PREDEF_TYPE_DEPENDENT_ID; break;
|
2009-07-16 02:40:39 +08:00
|
|
|
case BuiltinType::ObjCId: ID = pch::PREDEF_TYPE_OBJC_ID; break;
|
|
|
|
case BuiltinType::ObjCClass: ID = pch::PREDEF_TYPE_OBJC_CLASS; break;
|
2009-11-22 03:53:08 +08:00
|
|
|
case BuiltinType::ObjCSel: ID = pch::PREDEF_TYPE_OBJC_SEL; break;
|
2009-06-27 02:41:36 +08:00
|
|
|
case BuiltinType::UndeducedAuto:
|
|
|
|
assert(0 && "Should not see undeduced auto here");
|
|
|
|
break;
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
2009-09-25 03:53:00 +08:00
|
|
|
Record.push_back((ID << Qualifiers::FastWidth) | FastQuals);
|
2009-04-10 06:27:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-25 03:53:00 +08:00
|
|
|
pch::TypeID &ID = TypeIDs[T];
|
2009-04-26 11:49:13 +08:00
|
|
|
if (ID == 0) {
|
|
|
|
// We haven't seen this type before. Assign it a new ID and put it
|
2009-09-25 03:53:00 +08:00
|
|
|
// into the queue of types to emit.
|
2009-04-10 06:27:44 +08:00
|
|
|
ID = NextTypeID++;
|
2009-10-17 08:13:19 +08:00
|
|
|
DeclTypesToEmit.push(T);
|
2009-04-26 11:49:13 +08:00
|
|
|
}
|
2009-04-10 06:27:44 +08:00
|
|
|
|
|
|
|
// Encode the type qualifiers in the type reference.
|
2009-09-25 03:53:00 +08:00
|
|
|
Record.push_back((ID << Qualifiers::FastWidth) | FastQuals);
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHWriter::AddDeclRef(const Decl *D, RecordData &Record) {
|
|
|
|
if (D == 0) {
|
|
|
|
Record.push_back(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-11 01:25:41 +08:00
|
|
|
pch::DeclID &ID = DeclIDs[D];
|
2009-09-09 23:08:12 +08:00
|
|
|
if (ID == 0) {
|
2009-04-10 06:27:44 +08:00
|
|
|
// We haven't seen this declaration before. Give it a new ID and
|
|
|
|
// enqueue it in the list of declarations to emit.
|
|
|
|
ID = DeclIDs.size();
|
2009-10-17 08:13:19 +08:00
|
|
|
DeclTypesToEmit.push(const_cast<Decl *>(D));
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Record.push_back(ID);
|
|
|
|
}
|
|
|
|
|
2009-04-21 04:36:09 +08:00
|
|
|
pch::DeclID PCHWriter::getDeclID(const Decl *D) {
|
|
|
|
if (D == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!");
|
|
|
|
return DeclIDs[D];
|
|
|
|
}
|
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
void PCHWriter::AddDeclarationName(DeclarationName Name, RecordData &Record) {
|
2009-04-27 15:35:58 +08:00
|
|
|
// FIXME: Emit a stable enum for NameKind. 0 = Identifier etc.
|
2009-04-10 06:27:44 +08:00
|
|
|
Record.push_back(Name.getNameKind());
|
|
|
|
switch (Name.getNameKind()) {
|
|
|
|
case DeclarationName::Identifier:
|
|
|
|
AddIdentifierRef(Name.getAsIdentifierInfo(), Record);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
2009-04-23 18:39:46 +08:00
|
|
|
AddSelectorRef(Name.getObjCSelector(), Record);
|
2009-04-10 06:27:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
|
|
|
AddTypeRef(Name.getCXXNameType(), Record);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclarationName::CXXOperatorName:
|
|
|
|
Record.push_back(Name.getCXXOverloadedOperator());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclarationName::CXXUsingDirective:
|
|
|
|
// No extra data to emit
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-04-15 05:18:50 +08:00
|
|
|
|