2009-04-27 14:16:06 +08:00
|
|
|
//===--- PCHWriterDecl.cpp - Declaration Serialization --------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements serialization for Declarations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Frontend/PCHWriter.h"
|
|
|
|
#include "clang/AST/DeclVisitor.h"
|
2010-05-08 05:43:38 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2009-04-27 14:16:06 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2009-12-03 17:13:36 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2009-04-27 14:16:06 +08:00
|
|
|
#include "llvm/Bitcode/BitstreamWriter.h"
|
2009-12-03 17:13:36 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-04-27 14:16:06 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Declaration serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class PCHDeclWriter : public DeclVisitor<PCHDeclWriter, void> {
|
|
|
|
|
|
|
|
PCHWriter &Writer;
|
|
|
|
ASTContext &Context;
|
|
|
|
PCHWriter::RecordData &Record;
|
|
|
|
|
|
|
|
public:
|
|
|
|
pch::DeclCode Code;
|
2009-04-27 15:35:58 +08:00
|
|
|
unsigned AbbrevToUse;
|
2009-04-27 14:16:06 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
PCHDeclWriter(PCHWriter &Writer, ASTContext &Context,
|
|
|
|
PCHWriter::RecordData &Record)
|
2009-04-27 15:35:58 +08:00
|
|
|
: Writer(Writer), Context(Context), Record(Record) {
|
|
|
|
}
|
2009-04-27 14:16:06 +08:00
|
|
|
|
|
|
|
void VisitDecl(Decl *D);
|
|
|
|
void VisitTranslationUnitDecl(TranslationUnitDecl *D);
|
|
|
|
void VisitNamedDecl(NamedDecl *D);
|
2010-02-22 02:22:14 +08:00
|
|
|
void VisitNamespaceDecl(NamespaceDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
|
|
|
|
void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitTypeDecl(TypeDecl *D);
|
|
|
|
void VisitTypedefDecl(TypedefDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitUnresolvedUsingTypename(UnresolvedUsingTypenameDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitTagDecl(TagDecl *D);
|
|
|
|
void VisitEnumDecl(EnumDecl *D);
|
|
|
|
void VisitRecordDecl(RecordDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitCXXRecordDecl(CXXRecordDecl *D);
|
|
|
|
void VisitClassTemplateSpecializationDecl(
|
|
|
|
ClassTemplateSpecializationDecl *D);
|
|
|
|
void VisitClassTemplatePartialSpecializationDecl(
|
|
|
|
ClassTemplatePartialSpecializationDecl *D);
|
|
|
|
void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitValueDecl(ValueDecl *D);
|
|
|
|
void VisitEnumConstantDecl(EnumConstantDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D);
|
2009-08-19 09:28:35 +08:00
|
|
|
void VisitDeclaratorDecl(DeclaratorDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitFunctionDecl(FunctionDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitCXXMethodDecl(CXXMethodDecl *D);
|
|
|
|
void VisitCXXConstructorDecl(CXXConstructorDecl *D);
|
|
|
|
void VisitCXXDestructorDecl(CXXDestructorDecl *D);
|
|
|
|
void VisitCXXConversionDecl(CXXConversionDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitFieldDecl(FieldDecl *D);
|
|
|
|
void VisitVarDecl(VarDecl *D);
|
|
|
|
void VisitImplicitParamDecl(ImplicitParamDecl *D);
|
|
|
|
void VisitParmVarDecl(ParmVarDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
|
|
|
|
void VisitTemplateDecl(TemplateDecl *D);
|
|
|
|
void VisitClassTemplateDecl(ClassTemplateDecl *D);
|
|
|
|
void visitFunctionTemplateDecl(FunctionTemplateDecl *D);
|
|
|
|
void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
|
2010-06-20 22:40:59 +08:00
|
|
|
void VisitUsingDecl(UsingDecl *D);
|
|
|
|
void VisitUsingShadowDecl(UsingShadowDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitLinkageSpecDecl(LinkageSpecDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
|
2010-06-05 13:09:32 +08:00
|
|
|
void VisitAccessSpecDecl(AccessSpecDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitFriendTemplateDecl(FriendTemplateDecl *D);
|
|
|
|
void VisitStaticAssertDecl(StaticAssertDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitBlockDecl(BlockDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
|
2009-04-27 14:16:06 +08:00
|
|
|
uint64_t VisibleOffset);
|
2010-05-08 05:43:38 +08:00
|
|
|
|
|
|
|
|
2010-05-30 15:21:58 +08:00
|
|
|
// FIXME: Put in the same order is DeclNodes.td?
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitObjCMethodDecl(ObjCMethodDecl *D);
|
|
|
|
void VisitObjCContainerDecl(ObjCContainerDecl *D);
|
|
|
|
void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
|
|
|
|
void VisitObjCIvarDecl(ObjCIvarDecl *D);
|
|
|
|
void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
|
|
|
|
void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
|
|
|
|
void VisitObjCClassDecl(ObjCClassDecl *D);
|
|
|
|
void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
|
|
|
|
void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
|
|
|
|
void VisitObjCImplDecl(ObjCImplDecl *D);
|
|
|
|
void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
|
|
|
|
void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
|
|
|
|
void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
|
|
|
|
void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
|
|
|
|
void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
|
2010-06-04 03:28:45 +08:00
|
|
|
|
|
|
|
void WriteCXXBaseSpecifier(const CXXBaseSpecifier *Base);
|
2009-04-27 14:16:06 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitDecl(Decl *D) {
|
|
|
|
Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record);
|
|
|
|
Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record);
|
|
|
|
Writer.AddSourceLocation(D->getLocation(), Record);
|
|
|
|
Record.push_back(D->isInvalidDecl());
|
|
|
|
Record.push_back(D->hasAttrs());
|
|
|
|
Record.push_back(D->isImplicit());
|
2010-06-18 07:14:26 +08:00
|
|
|
Record.push_back(D->isUsed(false));
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->getAccess());
|
2009-10-17 04:01:17 +08:00
|
|
|
Record.push_back(D->getPCHLevel());
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
|
|
|
|
VisitDecl(D);
|
2010-05-08 05:43:38 +08:00
|
|
|
Writer.AddDeclRef(D->getAnonymousNamespace(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_TRANSLATION_UNIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitNamedDecl(NamedDecl *D) {
|
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddDeclarationName(D->getDeclName(), Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitTypeDecl(TypeDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
2010-06-20 03:29:21 +08:00
|
|
|
if (isa<CXXRecordDecl>(D)) {
|
|
|
|
// FIXME: Hack. To read a templated CXXRecordDecl from PCH, we need an
|
|
|
|
// initialized CXXRecordDecl before creating an InjectedClassNameType.
|
|
|
|
// Delay emitting/reading CXXRecordDecl's TypeForDecl until when we handle
|
|
|
|
// CXXRecordDecl emitting/initialization.
|
|
|
|
Writer.AddTypeRef(QualType(), Record);
|
|
|
|
} else
|
|
|
|
Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
|
|
|
|
VisitTypeDecl(D);
|
2009-12-07 10:54:59 +08:00
|
|
|
Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_TYPEDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitTagDecl(TagDecl *D) {
|
|
|
|
VisitTypeDecl(D);
|
2009-07-30 07:36:44 +08:00
|
|
|
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
|
|
|
|
Record.push_back(D->isDefinition());
|
2010-02-13 01:40:34 +08:00
|
|
|
Record.push_back(D->isEmbeddedInDeclarator());
|
2009-07-14 11:18:02 +08:00
|
|
|
Writer.AddSourceLocation(D->getRBraceLoc(), Record);
|
2009-07-21 22:46:17 +08:00
|
|
|
Writer.AddSourceLocation(D->getTagKeywordLoc(), Record);
|
2010-03-15 18:12:16 +08:00
|
|
|
// FIXME: maybe write optional qualifier and its range.
|
|
|
|
Writer.AddDeclRef(D->getTypedefForAnonDecl(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitEnumDecl(EnumDecl *D) {
|
|
|
|
VisitTagDecl(D);
|
|
|
|
Writer.AddTypeRef(D->getIntegerType(), Record);
|
2009-12-09 17:09:27 +08:00
|
|
|
Writer.AddTypeRef(D->getPromotionType(), Record);
|
2010-05-06 16:49:23 +08:00
|
|
|
Record.push_back(D->getNumPositiveBits());
|
|
|
|
Record.push_back(D->getNumNegativeBits());
|
2009-05-28 01:20:35 +08:00
|
|
|
// FIXME: C++ InstantiatedFrom
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_ENUM;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitRecordDecl(RecordDecl *D) {
|
|
|
|
VisitTagDecl(D);
|
|
|
|
Record.push_back(D->hasFlexibleArrayMember());
|
|
|
|
Record.push_back(D->isAnonymousStructOrUnion());
|
2009-07-09 00:37:44 +08:00
|
|
|
Record.push_back(D->hasObjectMember());
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_RECORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitValueDecl(ValueDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddTypeRef(D->getType(), Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
|
|
|
|
VisitValueDecl(D);
|
|
|
|
Record.push_back(D->getInitExpr()? 1 : 0);
|
|
|
|
if (D->getInitExpr())
|
|
|
|
Writer.AddStmt(D->getInitExpr());
|
|
|
|
Writer.AddAPSInt(D->getInitVal(), Record);
|
|
|
|
Code = pch::DECL_ENUM_CONSTANT;
|
|
|
|
}
|
2009-08-19 09:28:35 +08:00
|
|
|
|
|
|
|
void PCHDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitValueDecl(D);
|
2009-12-07 10:54:59 +08:00
|
|
|
Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
|
2010-03-15 18:12:16 +08:00
|
|
|
// FIXME: write optional qualifier and its range.
|
2009-08-19 09:28:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
|
|
|
|
VisitDeclaratorDecl(D);
|
2010-05-08 05:43:38 +08:00
|
|
|
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->isThisDeclarationADefinition());
|
|
|
|
if (D->isThisDeclarationADefinition())
|
2009-06-30 10:35:26 +08:00
|
|
|
Writer.AddStmt(D->getBody());
|
2010-05-08 05:43:38 +08:00
|
|
|
|
2009-04-27 14:16:06 +08:00
|
|
|
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
|
|
|
|
Record.push_back(D->getStorageClass()); // FIXME: stable encoding
|
2010-04-20 06:54:31 +08:00
|
|
|
Record.push_back(D->getStorageClassAsWritten());
|
2009-10-28 05:01:01 +08:00
|
|
|
Record.push_back(D->isInlineSpecified());
|
2009-05-15 06:15:41 +08:00
|
|
|
Record.push_back(D->isVirtualAsWritten());
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->isPure());
|
2009-05-15 05:46:00 +08:00
|
|
|
Record.push_back(D->hasInheritedPrototype());
|
|
|
|
Record.push_back(D->hasWrittenPrototype());
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->isDeleted());
|
2009-09-22 13:38:14 +08:00
|
|
|
Record.push_back(D->isTrivial());
|
|
|
|
Record.push_back(D->isCopyAssignment());
|
|
|
|
Record.push_back(D->hasImplicitReturnZero());
|
2010-05-08 05:43:38 +08:00
|
|
|
// FIXME: C++ TemplateOrInstantiation???
|
2009-06-20 16:09:34 +08:00
|
|
|
Writer.AddSourceLocation(D->getLocEnd(), Record);
|
2010-05-08 05:43:38 +08:00
|
|
|
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->param_size());
|
|
|
|
for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
Writer.AddDeclRef(*P, Record);
|
|
|
|
Code = pch::DECL_FUNCTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
|
|
|
// FIXME: convert to LazyStmtPtr?
|
2009-09-09 23:08:12 +08:00
|
|
|
// Unlike C/C++, method bodies will never be in header files.
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->getBody() != 0);
|
|
|
|
if (D->getBody() != 0) {
|
2009-06-30 10:35:26 +08:00
|
|
|
Writer.AddStmt(D->getBody());
|
2009-04-27 14:16:06 +08:00
|
|
|
Writer.AddDeclRef(D->getSelfDecl(), Record);
|
|
|
|
Writer.AddDeclRef(D->getCmdDecl(), Record);
|
|
|
|
}
|
|
|
|
Record.push_back(D->isInstanceMethod());
|
|
|
|
Record.push_back(D->isVariadic());
|
|
|
|
Record.push_back(D->isSynthesized());
|
|
|
|
// FIXME: stable encoding for @required/@optional
|
2009-09-09 23:08:12 +08:00
|
|
|
Record.push_back(D->getImplementationControl());
|
2009-04-27 14:16:06 +08:00
|
|
|
// FIXME: stable encoding for in/out/inout/bycopy/byref/oneway
|
2009-09-09 23:08:12 +08:00
|
|
|
Record.push_back(D->getObjCDeclQualifier());
|
2010-04-09 05:29:11 +08:00
|
|
|
Record.push_back(D->getNumSelectorArgs());
|
2009-04-27 14:16:06 +08:00
|
|
|
Writer.AddTypeRef(D->getResultType(), Record);
|
2010-03-08 22:59:44 +08:00
|
|
|
Writer.AddTypeSourceInfo(D->getResultTypeSourceInfo(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Writer.AddSourceLocation(D->getLocEnd(), Record);
|
|
|
|
Record.push_back(D->param_size());
|
2009-09-09 23:08:12 +08:00
|
|
|
for (ObjCMethodDecl::param_iterator P = D->param_begin(),
|
2009-04-27 14:16:06 +08:00
|
|
|
PEnd = D->param_end(); P != PEnd; ++P)
|
|
|
|
Writer.AddDeclRef(*P, Record);
|
|
|
|
Code = pch::DECL_OBJC_METHOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
2010-05-08 05:43:38 +08:00
|
|
|
Writer.AddSourceRange(D->getAtEndRange(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
// Abstract class (no need to define a stable pch::DECL code).
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
|
|
|
|
VisitObjCContainerDecl(D);
|
|
|
|
Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
|
|
|
|
Writer.AddDeclRef(D->getSuperClass(), Record);
|
|
|
|
Record.push_back(D->protocol_size());
|
2009-09-09 23:08:12 +08:00
|
|
|
for (ObjCInterfaceDecl::protocol_iterator P = D->protocol_begin(),
|
2009-04-27 14:16:06 +08:00
|
|
|
PEnd = D->protocol_end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
Writer.AddDeclRef(*P, Record);
|
2010-01-16 23:02:53 +08:00
|
|
|
for (ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin(),
|
|
|
|
PLEnd = D->protocol_loc_end();
|
|
|
|
PL != PLEnd; ++PL)
|
|
|
|
Writer.AddSourceLocation(*PL, Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->ivar_size());
|
2009-09-09 23:08:12 +08:00
|
|
|
for (ObjCInterfaceDecl::ivar_iterator I = D->ivar_begin(),
|
2009-04-27 14:16:06 +08:00
|
|
|
IEnd = D->ivar_end(); I != IEnd; ++I)
|
|
|
|
Writer.AddDeclRef(*I, Record);
|
|
|
|
Writer.AddDeclRef(D->getCategoryList(), Record);
|
|
|
|
Record.push_back(D->isForwardDecl());
|
|
|
|
Record.push_back(D->isImplicitInterfaceDecl());
|
|
|
|
Writer.AddSourceLocation(D->getClassLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getLocEnd(), Record);
|
|
|
|
Code = pch::DECL_OBJC_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
|
|
|
|
VisitFieldDecl(D);
|
|
|
|
// FIXME: stable encoding for @public/@private/@protected/@package
|
2009-09-09 23:08:12 +08:00
|
|
|
Record.push_back(D->getAccessControl());
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_OBJC_IVAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
|
|
|
|
VisitObjCContainerDecl(D);
|
|
|
|
Record.push_back(D->isForwardDecl());
|
|
|
|
Writer.AddSourceLocation(D->getLocEnd(), Record);
|
|
|
|
Record.push_back(D->protocol_size());
|
2009-09-09 23:08:12 +08:00
|
|
|
for (ObjCProtocolDecl::protocol_iterator
|
2009-04-27 14:16:06 +08:00
|
|
|
I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I)
|
|
|
|
Writer.AddDeclRef(*I, Record);
|
2010-01-16 23:02:53 +08:00
|
|
|
for (ObjCProtocolDecl::protocol_loc_iterator PL = D->protocol_loc_begin(),
|
|
|
|
PLEnd = D->protocol_loc_end();
|
|
|
|
PL != PLEnd; ++PL)
|
|
|
|
Writer.AddSourceLocation(*PL, Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_OBJC_PROTOCOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
|
|
|
|
VisitFieldDecl(D);
|
|
|
|
Code = pch::DECL_OBJC_AT_DEFS_FIELD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCClassDecl(ObjCClassDecl *D) {
|
|
|
|
VisitDecl(D);
|
|
|
|
Record.push_back(D->size());
|
|
|
|
for (ObjCClassDecl::iterator I = D->begin(), IEnd = D->end(); I != IEnd; ++I)
|
2009-11-18 08:28:11 +08:00
|
|
|
Writer.AddDeclRef(I->getInterface(), Record);
|
|
|
|
for (ObjCClassDecl::iterator I = D->begin(), IEnd = D->end(); I != IEnd; ++I)
|
|
|
|
Writer.AddSourceLocation(I->getLocation(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_OBJC_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
|
|
|
|
VisitDecl(D);
|
|
|
|
Record.push_back(D->protocol_size());
|
2010-01-16 23:02:53 +08:00
|
|
|
for (ObjCForwardProtocolDecl::protocol_iterator
|
2009-04-27 14:16:06 +08:00
|
|
|
I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I)
|
|
|
|
Writer.AddDeclRef(*I, Record);
|
2010-01-16 23:02:53 +08:00
|
|
|
for (ObjCForwardProtocolDecl::protocol_loc_iterator
|
|
|
|
PL = D->protocol_loc_begin(), PLEnd = D->protocol_loc_end();
|
|
|
|
PL != PLEnd; ++PL)
|
|
|
|
Writer.AddSourceLocation(*PL, Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_OBJC_FORWARD_PROTOCOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
|
|
|
|
VisitObjCContainerDecl(D);
|
|
|
|
Writer.AddDeclRef(D->getClassInterface(), Record);
|
|
|
|
Record.push_back(D->protocol_size());
|
2010-01-16 23:02:53 +08:00
|
|
|
for (ObjCCategoryDecl::protocol_iterator
|
2009-04-27 14:16:06 +08:00
|
|
|
I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I)
|
|
|
|
Writer.AddDeclRef(*I, Record);
|
2010-01-16 23:02:53 +08:00
|
|
|
for (ObjCCategoryDecl::protocol_loc_iterator
|
|
|
|
PL = D->protocol_loc_begin(), PLEnd = D->protocol_loc_end();
|
|
|
|
PL != PLEnd; ++PL)
|
|
|
|
Writer.AddSourceLocation(*PL, Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Writer.AddDeclRef(D->getNextClassCategory(), Record);
|
2010-01-17 00:38:58 +08:00
|
|
|
Writer.AddSourceLocation(D->getAtLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_OBJC_CATEGORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddDeclRef(D->getClassInterface(), Record);
|
|
|
|
Code = pch::DECL_OBJC_COMPATIBLE_ALIAS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
2010-01-22 01:36:00 +08:00
|
|
|
Writer.AddSourceLocation(D->getAtLoc(), Record);
|
2010-06-05 04:50:08 +08:00
|
|
|
Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
// FIXME: stable encoding
|
|
|
|
Record.push_back((unsigned)D->getPropertyAttributes());
|
|
|
|
// FIXME: stable encoding
|
|
|
|
Record.push_back((unsigned)D->getPropertyImplementation());
|
|
|
|
Writer.AddDeclarationName(D->getGetterName(), Record);
|
|
|
|
Writer.AddDeclarationName(D->getSetterName(), Record);
|
|
|
|
Writer.AddDeclRef(D->getGetterMethodDecl(), Record);
|
|
|
|
Writer.AddDeclRef(D->getSetterMethodDecl(), Record);
|
|
|
|
Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
|
|
|
|
Code = pch::DECL_OBJC_PROPERTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
|
2009-07-28 03:04:32 +08:00
|
|
|
VisitObjCContainerDecl(D);
|
2009-04-27 14:16:06 +08:00
|
|
|
Writer.AddDeclRef(D->getClassInterface(), Record);
|
|
|
|
// Abstract class (no need to define a stable pch::DECL code).
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
|
|
|
|
VisitObjCImplDecl(D);
|
|
|
|
Writer.AddIdentifierRef(D->getIdentifier(), Record);
|
|
|
|
Code = pch::DECL_OBJC_CATEGORY_IMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
|
|
|
|
VisitObjCImplDecl(D);
|
|
|
|
Writer.AddDeclRef(D->getSuperClass(), Record);
|
2010-04-29 00:11:27 +08:00
|
|
|
// FIXME add writing of IvarInitializers and NumIvarInitializers.
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_OBJC_IMPLEMENTATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
|
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getLocStart(), Record);
|
|
|
|
Writer.AddDeclRef(D->getPropertyDecl(), Record);
|
|
|
|
Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
|
2010-05-06 05:52:17 +08:00
|
|
|
// FIXME. write GetterCXXConstructor and SetterCXXAssignment.
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_OBJC_PROPERTY_IMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitFieldDecl(FieldDecl *D) {
|
2009-08-19 09:28:35 +08:00
|
|
|
VisitDeclaratorDecl(D);
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->isMutable());
|
|
|
|
Record.push_back(D->getBitWidth()? 1 : 0);
|
|
|
|
if (D->getBitWidth())
|
|
|
|
Writer.AddStmt(D->getBitWidth());
|
|
|
|
Code = pch::DECL_FIELD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitVarDecl(VarDecl *D) {
|
2009-08-19 09:28:35 +08:00
|
|
|
VisitDeclaratorDecl(D);
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->getStorageClass()); // FIXME: stable encoding
|
2010-04-20 06:54:31 +08:00
|
|
|
Record.push_back(D->getStorageClassAsWritten());
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->isThreadSpecified());
|
|
|
|
Record.push_back(D->hasCXXDirectInitializer());
|
|
|
|
Record.push_back(D->isDeclaredInCondition());
|
2010-05-04 02:51:14 +08:00
|
|
|
Record.push_back(D->isExceptionVariable());
|
2010-05-15 14:01:05 +08:00
|
|
|
Record.push_back(D->isNRVOVariable());
|
2009-04-27 14:16:06 +08:00
|
|
|
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
|
2010-05-09 14:40:08 +08:00
|
|
|
Record.push_back(D->getInit() ? 1 : 0);
|
2009-04-27 14:16:06 +08:00
|
|
|
if (D->getInit())
|
|
|
|
Writer.AddStmt(D->getInit());
|
|
|
|
Code = pch::DECL_VAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
|
|
|
|
VisitVarDecl(D);
|
|
|
|
Code = pch::DECL_IMPLICIT_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
|
|
|
|
VisitVarDecl(D);
|
|
|
|
Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
|
2010-03-13 02:31:32 +08:00
|
|
|
Record.push_back(D->hasInheritedDefaultArg());
|
2009-04-27 14:16:06 +08:00
|
|
|
Code = pch::DECL_PARM_VAR;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 15:35:58 +08:00
|
|
|
// If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
|
|
|
|
// we dynamically check for the properties that we optimize for, but don't
|
|
|
|
// know are true of all PARM_VAR_DECLs.
|
2009-12-07 10:54:59 +08:00
|
|
|
if (!D->getTypeSourceInfo() &&
|
2009-08-19 09:28:35 +08:00
|
|
|
!D->hasAttrs() &&
|
2009-04-27 15:35:58 +08:00
|
|
|
!D->isImplicit() &&
|
2010-06-18 07:14:26 +08:00
|
|
|
!D->isUsed(false) &&
|
2009-04-27 15:35:58 +08:00
|
|
|
D->getAccess() == AS_none &&
|
2009-10-17 04:01:17 +08:00
|
|
|
D->getPCHLevel() == 0 &&
|
2009-04-27 15:35:58 +08:00
|
|
|
D->getStorageClass() == 0 &&
|
|
|
|
!D->hasCXXDirectInitializer() && // Can params have this ever?
|
2010-03-13 02:31:32 +08:00
|
|
|
D->getObjCDeclQualifier() == 0 &&
|
2010-05-09 14:40:08 +08:00
|
|
|
!D->hasInheritedDefaultArg() &&
|
|
|
|
D->getInit() == 0) // No default expr.
|
2009-04-27 15:35:58 +08:00
|
|
|
AbbrevToUse = Writer.getParmVarDeclAbbrev();
|
|
|
|
|
|
|
|
// Check things we know are true of *every* PARM_VAR_DECL, which is more than
|
|
|
|
// just us assuming it.
|
|
|
|
assert(!D->isInvalidDecl() && "Shouldn't emit invalid decls");
|
|
|
|
assert(!D->isThreadSpecified() && "PARM_VAR_DECL can't be __thread");
|
|
|
|
assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
|
|
|
|
assert(!D->isDeclaredInCondition() && "PARM_VAR_DECL can't be in condition");
|
2010-05-04 02:51:14 +08:00
|
|
|
assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
|
2009-04-27 15:35:58 +08:00
|
|
|
assert(D->getPreviousDeclaration() == 0 && "PARM_VAR_DECL can't be redecl");
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
|
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddStmt(D->getAsmString());
|
|
|
|
Code = pch::DECL_FILE_SCOPE_ASM;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitBlockDecl(BlockDecl *D) {
|
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddStmt(D->getBody());
|
2010-06-04 19:21:44 +08:00
|
|
|
Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->param_size());
|
|
|
|
for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
Writer.AddDeclRef(*P, Record);
|
|
|
|
Code = pch::DECL_BLOCK;
|
|
|
|
}
|
|
|
|
|
2010-05-08 05:43:38 +08:00
|
|
|
void PCHDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
|
|
|
|
VisitDecl(D);
|
|
|
|
// FIXME: It might be nice to serialize the brace locations for this
|
|
|
|
// declaration, which don't seem to be readily available in the AST.
|
|
|
|
Record.push_back(D->getLanguage());
|
|
|
|
Record.push_back(D->hasBraces());
|
|
|
|
Code = pch::DECL_LINKAGE_SPEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getLBracLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getRBracLoc(), Record);
|
|
|
|
Writer.AddDeclRef(D->getNextNamespace(), Record);
|
|
|
|
|
|
|
|
// Only write one reference--original or anonymous
|
|
|
|
Record.push_back(D->isOriginalNamespace());
|
|
|
|
if (D->isOriginalNamespace())
|
|
|
|
Writer.AddDeclRef(D->getAnonymousNamespace(), Record);
|
|
|
|
else
|
|
|
|
Writer.AddDeclRef(D->getOriginalNamespace(), Record);
|
|
|
|
Code = pch::DECL_NAMESPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getAliasLoc(), Record);
|
|
|
|
Writer.AddSourceRange(D->getQualifierRange(), Record);
|
|
|
|
Writer.AddNestedNameSpecifier(D->getQualifier(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
|
|
|
|
Writer.AddDeclRef(D->getNamespace(), Record);
|
|
|
|
Code = pch::DECL_NAMESPACE_ALIAS;
|
|
|
|
}
|
|
|
|
|
2010-06-20 22:40:59 +08:00
|
|
|
void PCHDeclWriter::VisitUsingDecl(UsingDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddSourceRange(D->getNestedNameRange(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getUsingLocation(), Record);
|
|
|
|
Writer.AddNestedNameSpecifier(D->getTargetNestedNameDecl(), Record);
|
|
|
|
Record.push_back(D->getNumShadowDecls());
|
|
|
|
for (UsingDecl::shadow_iterator P = D->shadow_begin(),
|
|
|
|
PEnd = D->shadow_end(); P != PEnd; ++P)
|
|
|
|
Writer.AddDeclRef(*P, Record);
|
|
|
|
Record.push_back(D->isTypeName());
|
|
|
|
Code = pch::DECL_USING;
|
|
|
|
}
|
|
|
|
|
2010-06-20 22:40:59 +08:00
|
|
|
void PCHDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddDeclRef(D->getTargetDecl(), Record);
|
|
|
|
Writer.AddDeclRef(D->getUsingDecl(), Record);
|
|
|
|
Code = pch::DECL_USING_SHADOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record);
|
|
|
|
Writer.AddSourceRange(D->getQualifierRange(), Record);
|
|
|
|
Writer.AddNestedNameSpecifier(D->getQualifier(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getIdentLocation(), Record);
|
|
|
|
Writer.AddDeclRef(D->getNominatedNamespace(), Record);
|
|
|
|
Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record);
|
|
|
|
Code = pch::DECL_USING_DIRECTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D) {
|
|
|
|
VisitValueDecl(D);
|
|
|
|
Writer.AddSourceRange(D->getTargetNestedNameRange(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getUsingLoc(), Record);
|
|
|
|
Writer.AddNestedNameSpecifier(D->getTargetNestedNameSpecifier(), Record);
|
|
|
|
Code = pch::DECL_UNRESOLVED_USING_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitUnresolvedUsingTypename(
|
|
|
|
UnresolvedUsingTypenameDecl *D) {
|
|
|
|
VisitTypeDecl(D);
|
|
|
|
Writer.AddSourceRange(D->getTargetNestedNameRange(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getUsingLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getTypenameLoc(), Record);
|
|
|
|
Writer.AddNestedNameSpecifier(D->getTargetNestedNameSpecifier(), Record);
|
|
|
|
Code = pch::DECL_UNRESOLVED_USING_TYPENAME;
|
|
|
|
}
|
|
|
|
|
2010-06-04 03:28:45 +08:00
|
|
|
void PCHDeclWriter::WriteCXXBaseSpecifier(const CXXBaseSpecifier *Base) {
|
|
|
|
Record.push_back(Base->isVirtual());
|
|
|
|
Record.push_back(Base->isBaseOfClass());
|
|
|
|
Record.push_back(Base->getAccessSpecifierAsWritten());
|
|
|
|
Writer.AddTypeRef(Base->getType(), Record);
|
|
|
|
Writer.AddSourceRange(Base->getSourceRange(), Record);
|
|
|
|
}
|
|
|
|
|
2010-05-08 05:43:38 +08:00
|
|
|
void PCHDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
|
|
|
|
// assert(false && "cannot write CXXRecordDecl");
|
|
|
|
VisitRecordDecl(D);
|
2010-06-20 03:28:53 +08:00
|
|
|
|
|
|
|
enum {
|
|
|
|
CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
|
|
|
|
};
|
|
|
|
if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
|
|
|
|
Record.push_back(CXXRecTemplate);
|
|
|
|
Writer.AddDeclRef(TemplD, Record);
|
|
|
|
} else if (MemberSpecializationInfo *MSInfo
|
|
|
|
= D->getMemberSpecializationInfo()) {
|
|
|
|
Record.push_back(CXXRecMemberSpecialization);
|
|
|
|
Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record);
|
|
|
|
Record.push_back(MSInfo->getTemplateSpecializationKind());
|
|
|
|
Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record);
|
|
|
|
} else {
|
|
|
|
Record.push_back(CXXRecNotTemplate);
|
|
|
|
}
|
|
|
|
|
2010-06-20 03:29:21 +08:00
|
|
|
// FIXME: Hack. See PCHDeclWriter::VisitTypeDecl.
|
|
|
|
Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
|
|
|
|
|
2010-06-04 03:28:45 +08:00
|
|
|
if (D->isDefinition()) {
|
|
|
|
unsigned NumBases = D->getNumBases();
|
|
|
|
Record.push_back(NumBases);
|
|
|
|
for (CXXRecordDecl::base_class_iterator I = D->bases_begin(),
|
|
|
|
E = D->bases_end(); I != E; ++I)
|
|
|
|
WriteCXXBaseSpecifier(&*I);
|
|
|
|
}
|
2010-05-08 05:43:38 +08:00
|
|
|
Code = pch::DECL_CXX_RECORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
|
|
|
|
// assert(false && "cannot write CXXMethodDecl");
|
|
|
|
VisitFunctionDecl(D);
|
|
|
|
Code = pch::DECL_CXX_METHOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
|
|
|
|
// assert(false && "cannot write CXXConstructorDecl");
|
|
|
|
VisitCXXMethodDecl(D);
|
|
|
|
Code = pch::DECL_CXX_CONSTRUCTOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
|
|
|
|
// assert(false && "cannot write CXXDestructorDecl");
|
|
|
|
VisitCXXMethodDecl(D);
|
|
|
|
Code = pch::DECL_CXX_DESTRUCTOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
|
|
|
|
// assert(false && "cannot write CXXConversionDecl");
|
|
|
|
VisitCXXMethodDecl(D);
|
|
|
|
Code = pch::DECL_CXX_CONVERSION;
|
|
|
|
}
|
|
|
|
|
2010-06-05 13:09:32 +08:00
|
|
|
void PCHDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
|
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getColonLoc(), Record);
|
|
|
|
Code = pch::DECL_ACCESS_SPEC;
|
|
|
|
}
|
|
|
|
|
2010-05-08 05:43:38 +08:00
|
|
|
void PCHDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
|
|
|
|
assert(false && "cannot write FriendTemplateDecl");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
|
2010-06-20 03:28:53 +08:00
|
|
|
VisitNamedDecl(D);
|
|
|
|
|
|
|
|
Writer.AddDeclRef(D->getTemplatedDecl(), Record);
|
|
|
|
{
|
|
|
|
// TemplateParams.
|
|
|
|
TemplateParameterList *TPL = D->getTemplateParameters();
|
|
|
|
assert(TPL && "No TemplateParameters!");
|
|
|
|
Writer.AddSourceLocation(TPL->getTemplateLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(TPL->getLAngleLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(TPL->getRAngleLoc(), Record);
|
|
|
|
Record.push_back(TPL->size());
|
|
|
|
for (TemplateParameterList::iterator P = TPL->begin(), PEnd = TPL->end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
Writer.AddDeclRef(*P, Record);
|
|
|
|
}
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
|
2010-06-20 03:28:53 +08:00
|
|
|
VisitTemplateDecl(D);
|
|
|
|
|
|
|
|
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
|
|
|
|
if (D->getPreviousDeclaration() == 0) {
|
|
|
|
// This ClassTemplateDecl owns the CommonPtr; write it.
|
|
|
|
|
|
|
|
typedef llvm::FoldingSet<ClassTemplateSpecializationDecl> CTSDSetTy;
|
|
|
|
CTSDSetTy &CTSDSet = D->getSpecializations();
|
|
|
|
Record.push_back(CTSDSet.size());
|
|
|
|
for (CTSDSetTy::iterator I=CTSDSet.begin(), E = CTSDSet.end(); I!=E; ++I)
|
|
|
|
Writer.AddDeclRef(&*I, Record);
|
|
|
|
|
|
|
|
typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> CTPSDSetTy;
|
|
|
|
CTPSDSetTy &CTPSDSet = D->getPartialSpecializations();
|
|
|
|
Record.push_back(CTPSDSet.size());
|
|
|
|
for (CTPSDSetTy::iterator I=CTPSDSet.begin(), E = CTPSDSet.end(); I!=E; ++I)
|
|
|
|
Writer.AddDeclRef(&*I, Record);
|
|
|
|
|
|
|
|
// InjectedClassNameType is computed, no need to write it.
|
|
|
|
|
|
|
|
Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record);
|
|
|
|
if (D->getInstantiatedFromMemberTemplate())
|
|
|
|
Record.push_back(D->isMemberSpecialization());
|
|
|
|
}
|
|
|
|
Code = pch::DECL_CLASS_TEMPLATE;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitClassTemplateSpecializationDecl(
|
|
|
|
ClassTemplateSpecializationDecl *D) {
|
|
|
|
assert(false && "cannot write ClassTemplateSpecializationDecl");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitClassTemplatePartialSpecializationDecl(
|
|
|
|
ClassTemplatePartialSpecializationDecl *D) {
|
|
|
|
assert(false && "cannot write ClassTemplatePartialSpecializationDecl");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::visitFunctionTemplateDecl(FunctionTemplateDecl *D) {
|
|
|
|
assert(false && "cannot write FunctionTemplateDecl");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
|
2010-06-20 03:28:53 +08:00
|
|
|
VisitTypeDecl(D);
|
|
|
|
|
|
|
|
Record.push_back(D->wasDeclaredWithTypename());
|
|
|
|
Record.push_back(D->isParameterPack());
|
|
|
|
Record.push_back(D->defaultArgumentWasInherited());
|
|
|
|
Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record);
|
|
|
|
|
|
|
|
Code = pch::DECL_TEMPLATE_TYPE_PARM;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
|
|
|
|
assert(false && "cannot write NonTypeTemplateParmDecl");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
|
|
|
|
assert(false && "cannot write TemplateTemplateParmDecl");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCHDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
|
|
|
|
assert(false && "cannot write StaticAssertDecl");
|
|
|
|
}
|
|
|
|
|
2009-04-27 14:16:06 +08:00
|
|
|
/// \brief Emit the DeclContext part of a declaration context decl.
|
|
|
|
///
|
|
|
|
/// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL
|
|
|
|
/// block for this declaration context is stored. May be 0 to indicate
|
|
|
|
/// that there are no declarations stored within this context.
|
|
|
|
///
|
|
|
|
/// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE
|
|
|
|
/// block for this declaration context is stored. May be 0 to indicate
|
|
|
|
/// that there are no declarations visible from this context. Note
|
|
|
|
/// that this value will not be emitted for non-primary declaration
|
|
|
|
/// contexts.
|
2009-09-09 23:08:12 +08:00
|
|
|
void PCHDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
|
2009-04-27 14:16:06 +08:00
|
|
|
uint64_t VisibleOffset) {
|
|
|
|
Record.push_back(LexicalOffset);
|
|
|
|
Record.push_back(VisibleOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PCHWriter Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-27 15:35:58 +08:00
|
|
|
void PCHWriter::WriteDeclsBlockAbbrevs() {
|
|
|
|
using namespace llvm;
|
|
|
|
// Abbreviation for DECL_PARM_VAR.
|
|
|
|
BitCodeAbbrev *Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(pch::DECL_PARM_VAR));
|
|
|
|
|
|
|
|
// Decl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl (!?)
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
|
2009-06-20 07:52:42 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isUsed
|
2009-04-27 15:35:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
2009-10-17 04:01:17 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // PCH level
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 15:35:58 +08:00
|
|
|
// NamedDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
|
|
|
// ValueDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
|
2009-08-19 09:28:35 +08:00
|
|
|
// DeclaratorDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(pch::PREDEF_TYPE_NULL_ID)); // InfoType
|
2009-04-27 15:35:58 +08:00
|
|
|
// VarDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // StorageClass
|
2010-04-20 06:54:31 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // StorageClassAsWritten
|
2009-04-27 15:35:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isThreadSpecified
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isDeclaredInCondition
|
2010-05-04 02:51:14 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isExceptionVariable
|
2010-05-15 14:01:05 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isNRVOVariable
|
2009-04-27 15:35:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // PrevDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasInit
|
|
|
|
// ParmVarDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
|
2010-03-13 02:31:32 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-27 15:35:58 +08:00
|
|
|
ParmVarDeclAbbrev = Stream.EmitAbbrev(Abv);
|
|
|
|
}
|
|
|
|
|
2009-09-17 11:06:51 +08:00
|
|
|
/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
|
|
|
|
/// consumers of the AST.
|
|
|
|
///
|
|
|
|
/// Such decls will always be deserialized from the PCH file, so we would like
|
|
|
|
/// this to be as restrictive as possible. Currently the predicate is driven by
|
|
|
|
/// code generation requirements, if other clients have a different notion of
|
|
|
|
/// what is "required" then we may have to consider an alternate scheme where
|
|
|
|
/// clients can iterate over the top-level decls and get information on them,
|
|
|
|
/// without necessary deserializing them. We could explicitly require such
|
|
|
|
/// clients to use a separate API call to "realize" the decl. This should be
|
|
|
|
/// relatively painless since they would presumably only do it for top-level
|
|
|
|
/// decls.
|
|
|
|
//
|
|
|
|
// FIXME: This predicate is essentially IRgen's predicate to determine whether a
|
|
|
|
// declaration can be deferred. Merge them somehow.
|
|
|
|
static bool isRequiredDecl(const Decl *D, ASTContext &Context) {
|
|
|
|
// File scoped assembly must be seen.
|
|
|
|
if (isa<FileScopeAsmDecl>(D))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Otherwise if this isn't a function or a file scoped variable it doesn't
|
|
|
|
// need to be seen.
|
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
|
|
|
if (!VD->isFileVarDecl())
|
|
|
|
return false;
|
|
|
|
} else if (!isa<FunctionDecl>(D))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Aliases and used decls must be seen.
|
|
|
|
if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
// Forward declarations don't need to be seen.
|
|
|
|
if (!FD->isThisDeclarationADefinition())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Constructors and destructors must be seen.
|
|
|
|
if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Otherwise, this is required unless it is static.
|
|
|
|
//
|
|
|
|
// FIXME: Inlines.
|
|
|
|
return FD->getStorageClass() != FunctionDecl::Static;
|
|
|
|
} else {
|
|
|
|
const VarDecl *VD = cast<VarDecl>(D);
|
|
|
|
|
|
|
|
// In C++, this doesn't need to be seen if it is marked "extern".
|
|
|
|
if (Context.getLangOptions().CPlusPlus && !VD->getInit() &&
|
|
|
|
(VD->getStorageClass() == VarDecl::Extern ||
|
|
|
|
VD->isExternC()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// In C, this doesn't need to be seen unless it is a definition.
|
|
|
|
if (!Context.getLangOptions().CPlusPlus && !VD->getInit())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Otherwise, this is required unless it is static.
|
|
|
|
return VD->getStorageClass() != VarDecl::Static;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
void PCHWriter::WriteDecl(ASTContext &Context, Decl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
RecordData Record;
|
|
|
|
PCHDeclWriter W(*this, Context, Record);
|
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
// If this declaration is also a DeclContext, write blocks for the
|
|
|
|
// declarations that lexically stored inside its context and those
|
|
|
|
// declarations that are visible from its context. These blocks
|
|
|
|
// are written before the declaration itself so that we can put
|
|
|
|
// their offsets into the record for the declaration.
|
|
|
|
uint64_t LexicalOffset = 0;
|
|
|
|
uint64_t VisibleOffset = 0;
|
|
|
|
DeclContext *DC = dyn_cast<DeclContext>(D);
|
|
|
|
if (DC) {
|
|
|
|
LexicalOffset = WriteDeclContextLexicalBlock(Context, DC);
|
|
|
|
VisibleOffset = WriteDeclContextVisibleBlock(Context, DC);
|
|
|
|
}
|
2009-04-27 14:16:06 +08:00
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
// Determine the ID for this declaration
|
|
|
|
pch::DeclID &ID = DeclIDs[D];
|
|
|
|
if (ID == 0)
|
|
|
|
ID = DeclIDs.size();
|
2009-04-27 14:16:06 +08:00
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
unsigned Index = ID - 1;
|
2009-04-27 14:16:06 +08:00
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
// Record the offset for this declaration
|
|
|
|
if (DeclOffsets.size() == Index)
|
|
|
|
DeclOffsets.push_back(Stream.GetCurrentBitNo());
|
|
|
|
else if (DeclOffsets.size() < Index) {
|
|
|
|
DeclOffsets.resize(Index+1);
|
|
|
|
DeclOffsets[Index] = Stream.GetCurrentBitNo();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
// Build and emit a record for this declaration
|
|
|
|
Record.clear();
|
|
|
|
W.Code = (pch::DeclCode)0;
|
|
|
|
W.AbbrevToUse = 0;
|
|
|
|
W.Visit(D);
|
|
|
|
if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset);
|
|
|
|
|
2009-12-03 17:13:36 +08:00
|
|
|
if (!W.Code)
|
2010-04-08 06:58:06 +08:00
|
|
|
llvm::report_fatal_error(llvm::StringRef("unexpected declaration kind '") +
|
2009-12-03 17:13:36 +08:00
|
|
|
D->getDeclKindName() + "'");
|
2009-10-17 08:13:19 +08:00
|
|
|
Stream.EmitRecord(W.Code, Record, W.AbbrevToUse);
|
2009-04-27 14:16:06 +08:00
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
// If the declaration had any attributes, write them now.
|
|
|
|
if (D->hasAttrs())
|
|
|
|
WriteAttributeRecord(D->getAttrs());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
// Flush any expressions that were written as part of this declaration.
|
|
|
|
FlushStmts();
|
2009-04-27 14:16:06 +08:00
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
// Note "external" declarations so that we can add them to a record in the
|
|
|
|
// PCH file later.
|
|
|
|
//
|
|
|
|
// FIXME: This should be renamed, the predicate is much more complicated.
|
|
|
|
if (isRequiredDecl(D, Context))
|
|
|
|
ExternalDefinitions.push_back(Index + 1);
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|