2010-08-19 07:56:31 +08:00
|
|
|
//===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
|
2009-04-27 14:16:06 +08:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-08-19 07:56:37 +08:00
|
|
|
#include "clang/Serialization/ASTWriter.h"
|
2011-04-25 00:28:13 +08:00
|
|
|
#include "ASTCommon.h"
|
2009-04-27 14:16:06 +08:00
|
|
|
#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"
|
2010-10-21 00:22:56 +08:00
|
|
|
#include "clang/AST/DeclContextInternals.h"
|
2011-10-29 06:54:21 +08:00
|
|
|
#include "clang/Basic/SourceManager.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;
|
2011-04-25 00:28:13 +08:00
|
|
|
using namespace serialization;
|
2009-04-27 14:16:06 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Declaration serialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-06-30 06:47:00 +08:00
|
|
|
namespace clang {
|
2010-08-19 07:56:27 +08:00
|
|
|
class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
|
2009-04-27 14:16:06 +08:00
|
|
|
|
2010-08-19 07:56:21 +08:00
|
|
|
ASTWriter &Writer;
|
2009-04-27 14:16:06 +08:00
|
|
|
ASTContext &Context;
|
2010-10-25 01:26:27 +08:00
|
|
|
typedef ASTWriter::RecordData RecordData;
|
|
|
|
RecordData &Record;
|
2009-04-27 14:16:06 +08:00
|
|
|
|
|
|
|
public:
|
2010-08-19 07:57:32 +08:00
|
|
|
serialization::DeclCode Code;
|
2009-04-27 15:35:58 +08:00
|
|
|
unsigned AbbrevToUse;
|
2009-04-27 14:16:06 +08:00
|
|
|
|
2010-10-25 01:26:27 +08:00
|
|
|
ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, RecordData &Record)
|
2009-04-27 15:35:58 +08:00
|
|
|
: Writer(Writer), Context(Context), Record(Record) {
|
|
|
|
}
|
2010-10-25 01:26:27 +08:00
|
|
|
|
2010-07-02 23:58:43 +08:00
|
|
|
void Visit(Decl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
|
|
|
|
void VisitDecl(Decl *D);
|
|
|
|
void VisitTranslationUnitDecl(TranslationUnitDecl *D);
|
|
|
|
void VisitNamedDecl(NamedDecl *D);
|
2011-02-17 15:39:24 +08:00
|
|
|
void VisitLabelDecl(LabelDecl *LD);
|
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);
|
2011-12-19 22:40:25 +08:00
|
|
|
void VisitTypedefNameDecl(TypedefNameDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitTypedefDecl(TypedefDecl *D);
|
2011-04-15 22:24:37 +08:00
|
|
|
void VisitTypeAliasDecl(TypeAliasDecl *D);
|
2010-06-30 16:49:30 +08:00
|
|
|
void VisitUnresolvedUsingTypenameDecl(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);
|
2011-08-28 04:50:59 +08:00
|
|
|
void VisitClassScopeFunctionSpecializationDecl(
|
|
|
|
ClassScopeFunctionSpecializationDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
void VisitValueDecl(ValueDecl *D);
|
|
|
|
void VisitEnumConstantDecl(EnumConstantDecl *D);
|
2010-06-30 16:49:30 +08:00
|
|
|
void VisitUnresolvedUsingValueDecl(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);
|
2010-11-21 14:08:52 +08:00
|
|
|
void VisitIndirectFieldDecl(IndirectFieldDecl *D);
|
2009-04-27 14:16:06 +08:00
|
|
|
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);
|
2010-07-30 00:11:51 +08:00
|
|
|
void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitClassTemplateDecl(ClassTemplateDecl *D);
|
2010-06-22 17:55:07 +08:00
|
|
|
void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
|
2010-05-08 05:43:38 +08:00
|
|
|
void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
|
2011-05-06 05:57:07 +08:00
|
|
|
void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *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);
|
2011-12-03 07:23:56 +08:00
|
|
|
void VisitImportDecl(ImportDecl *D);
|
2010-06-05 13:09:32 +08:00
|
|
|
void VisitAccessSpecDecl(AccessSpecDecl *D);
|
2010-06-30 06:47:00 +08:00
|
|
|
void VisitFriendDecl(FriendDecl *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-08-04 01:30:10 +08:00
|
|
|
template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
|
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-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::Visit(Decl *D) {
|
|
|
|
DeclVisitor<ASTDeclWriter>::Visit(D);
|
2010-07-02 23:58:43 +08:00
|
|
|
|
2011-06-04 07:11:16 +08:00
|
|
|
// Source locations require array (variable-length) abbreviations. The
|
|
|
|
// abbreviation infrastructure requires that arrays are encoded last, so
|
|
|
|
// we handle it here in the case of those classes derived from DeclaratorDecl
|
|
|
|
if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)){
|
|
|
|
Writer.AddTypeSourceInfo(DD->getTypeSourceInfo(), Record);
|
|
|
|
}
|
|
|
|
|
2010-07-02 23:58:43 +08:00
|
|
|
// Handle FunctionDecl's body here and write it after all other Stmts/Exprs
|
|
|
|
// have been written. We want it last because we will not read it back when
|
2010-08-19 07:56:27 +08:00
|
|
|
// retrieving it from the AST, we'll just lazily set the offset.
|
2010-07-02 23:58:43 +08:00
|
|
|
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
2011-05-07 04:44:56 +08:00
|
|
|
Record.push_back(FD->doesThisDeclarationHaveABody());
|
|
|
|
if (FD->doesThisDeclarationHaveABody())
|
2010-07-02 23:58:43 +08:00
|
|
|
Writer.AddStmt(FD->getBody());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitDecl(Decl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record);
|
|
|
|
Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record);
|
|
|
|
Record.push_back(D->isInvalidDecl());
|
|
|
|
Record.push_back(D->hasAttrs());
|
2010-10-19 03:20:11 +08:00
|
|
|
if (D->hasAttrs())
|
|
|
|
Writer.WriteAttributes(D->getAttrs(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->isImplicit());
|
2010-06-18 07:14:26 +08:00
|
|
|
Record.push_back(D->isUsed(false));
|
2011-04-20 03:51:10 +08:00
|
|
|
Record.push_back(D->isReferenced());
|
2011-11-24 04:27:36 +08:00
|
|
|
Record.push_back(D->TopLevelDeclInObjCContainer);
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->getAccess());
|
2011-09-09 10:06:17 +08:00
|
|
|
Record.push_back(D->ModulePrivate);
|
2011-12-01 10:07:58 +08:00
|
|
|
Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation()));
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
|
2011-08-12 08:15:20 +08:00
|
|
|
llvm_unreachable("Translation units aren't directly serialized");
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddDeclarationName(D->getDeclName(), Record);
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitNamedDecl(D);
|
2011-03-06 23:48:19 +08:00
|
|
|
Writer.AddSourceLocation(D->getLocStart(), Record);
|
2010-07-02 19:55:01 +08:00
|
|
|
Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2011-12-19 22:40:25 +08:00
|
|
|
void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
|
Completely re-implement (de-)serialization of declaration
chains. The previous implementation relied heavily on the declaration
chain being stored as a (circular) linked list on disk, as it is in
memory. However, when deserializing from multiple modules, the
different chains could get mixed up, leading to broken declaration chains.
The new solution keeps track of the first and last declarations in the
chain for each module file. When we load a declaration, we search all
of the module files for redeclarations of that declaration, then
splice together all of the lists into a coherent whole (along with any
redeclarations that were actually parsed).
As a drive-by fix, (de-)serialize the redeclaration chains of
TypedefNameDecls, which had somehow gotten missed previously. Add a
test of this serialization.
This new scheme creates a redeclaration table that is fairly large in
the PCH file (on the order of 400k for Cocoa.h's 12MB PCH file). The
table is mmap'd in and searched via a binary search, but it's still
quite large. A future tweak will eliminate entries for declarations
that have no redeclarations anywhere, and should
drastically reduce the size of this table.
llvm-svn: 146841
2011-12-18 07:38:30 +08:00
|
|
|
VisitRedeclarable(D);
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitTypeDecl(D);
|
2011-12-19 22:40:25 +08:00
|
|
|
Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
|
|
|
|
}
|
2011-06-04 07:11:16 +08:00
|
|
|
|
2011-12-19 22:40:25 +08:00
|
|
|
void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
|
|
|
|
VisitTypedefNameDecl(D);
|
2011-06-04 07:11:16 +08:00
|
|
|
if (!D->hasAttrs() &&
|
|
|
|
!D->isImplicit() &&
|
|
|
|
!D->isUsed(false) &&
|
2011-12-19 23:27:36 +08:00
|
|
|
D->RedeclLink.getPointer() == D &&
|
2011-06-04 07:11:16 +08:00
|
|
|
!D->isInvalidDecl() &&
|
|
|
|
!D->isReferenced() &&
|
2011-11-24 05:11:23 +08:00
|
|
|
!D->isTopLevelDeclInObjCContainer() &&
|
2011-06-04 07:11:16 +08:00
|
|
|
D->getAccess() == AS_none &&
|
2011-09-09 10:06:17 +08:00
|
|
|
!D->isModulePrivate() &&
|
2011-06-04 07:11:16 +08:00
|
|
|
D->getDeclName().getNameKind() == DeclarationName::Identifier)
|
|
|
|
AbbrevToUse = Writer.getDeclTypedefAbbrev();
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_TYPEDEF;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2011-04-15 22:24:37 +08:00
|
|
|
void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
|
2011-12-19 22:40:25 +08:00
|
|
|
VisitTypedefNameDecl(D);
|
2011-04-15 22:24:37 +08:00
|
|
|
Code = serialization::DECL_TYPEALIAS;
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
|
2010-08-04 01:30:10 +08:00
|
|
|
VisitRedeclarable(D);
|
2011-10-27 01:53:41 +08:00
|
|
|
VisitTypeDecl(D);
|
2010-09-09 03:31:22 +08:00
|
|
|
Record.push_back(D->getIdentifierNamespace());
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
|
2011-10-07 14:10:15 +08:00
|
|
|
Record.push_back(D->isCompleteDefinition());
|
2010-02-13 01:40:34 +08:00
|
|
|
Record.push_back(D->isEmbeddedInDeclarator());
|
2011-10-01 06:11:31 +08:00
|
|
|
Record.push_back(D->isFreeStanding());
|
2009-07-14 11:18:02 +08:00
|
|
|
Writer.AddSourceLocation(D->getRBraceLoc(), Record);
|
2010-10-16 02:21:24 +08:00
|
|
|
Record.push_back(D->hasExtInfo());
|
|
|
|
if (D->hasExtInfo())
|
|
|
|
Writer.AddQualifierInfo(*D->getExtInfo(), Record);
|
|
|
|
else
|
2011-04-15 22:24:37 +08:00
|
|
|
Writer.AddDeclRef(D->getTypedefNameForAnonDecl(), Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitTagDecl(D);
|
2010-10-09 07:50:27 +08:00
|
|
|
Writer.AddTypeSourceInfo(D->getIntegerTypeSourceInfo(), Record);
|
|
|
|
if (!D->getIntegerTypeSourceInfo())
|
|
|
|
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());
|
2010-10-09 07:50:27 +08:00
|
|
|
Record.push_back(D->isScoped());
|
2010-12-04 02:54:17 +08:00
|
|
|
Record.push_back(D->isScopedUsingClassTag());
|
2010-10-09 07:50:27 +08:00
|
|
|
Record.push_back(D->isFixed());
|
2010-07-06 23:36:48 +08:00
|
|
|
Writer.AddDeclRef(D->getInstantiatedFromMemberEnum(), Record);
|
2011-06-04 07:11:16 +08:00
|
|
|
|
|
|
|
if (!D->hasAttrs() &&
|
|
|
|
!D->isImplicit() &&
|
|
|
|
!D->isUsed(false) &&
|
|
|
|
!D->hasExtInfo() &&
|
2011-12-19 23:27:36 +08:00
|
|
|
D->RedeclLink.getPointer() == D &&
|
2011-06-04 07:11:16 +08:00
|
|
|
!D->isInvalidDecl() &&
|
|
|
|
!D->isReferenced() &&
|
2011-11-24 05:11:23 +08:00
|
|
|
!D->isTopLevelDeclInObjCContainer() &&
|
2011-06-04 07:11:16 +08:00
|
|
|
D->getAccess() == AS_none &&
|
2011-09-09 10:06:17 +08:00
|
|
|
!D->isModulePrivate() &&
|
2011-06-04 07:11:16 +08:00
|
|
|
!CXXRecordDecl::classofKind(D->getKind()) &&
|
|
|
|
!D->getIntegerTypeSourceInfo() &&
|
|
|
|
D->getDeclName().getNameKind() == DeclarationName::Identifier)
|
|
|
|
AbbrevToUse = Writer.getDeclEnumAbbrev();
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_ENUM;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
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());
|
2011-06-03 10:27:19 +08:00
|
|
|
|
|
|
|
if (!D->hasAttrs() &&
|
|
|
|
!D->isImplicit() &&
|
|
|
|
!D->isUsed(false) &&
|
|
|
|
!D->hasExtInfo() &&
|
2011-12-19 23:27:36 +08:00
|
|
|
D->RedeclLink.getPointer() == D &&
|
2011-06-03 10:27:19 +08:00
|
|
|
!D->isInvalidDecl() &&
|
|
|
|
!D->isReferenced() &&
|
2011-11-24 05:11:23 +08:00
|
|
|
!D->isTopLevelDeclInObjCContainer() &&
|
2011-06-03 10:27:19 +08:00
|
|
|
D->getAccess() == AS_none &&
|
2011-09-09 10:06:17 +08:00
|
|
|
!D->isModulePrivate() &&
|
2011-06-03 10:27:19 +08:00
|
|
|
!CXXRecordDecl::classofKind(D->getKind()) &&
|
|
|
|
D->getDeclName().getNameKind() == DeclarationName::Identifier)
|
|
|
|
AbbrevToUse = Writer.getDeclRecordAbbrev();
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_RECORD;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddTypeRef(D->getType(), Record);
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitValueDecl(D);
|
|
|
|
Record.push_back(D->getInitExpr()? 1 : 0);
|
|
|
|
if (D->getInitExpr())
|
|
|
|
Writer.AddStmt(D->getInitExpr());
|
|
|
|
Writer.AddAPSInt(D->getInitVal(), Record);
|
2011-06-03 10:27:19 +08:00
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_ENUM_CONSTANT;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
2009-08-19 09:28:35 +08:00
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitValueDecl(D);
|
2011-03-08 16:55:46 +08:00
|
|
|
Writer.AddSourceLocation(D->getInnerLocStart(), Record);
|
2010-10-16 02:21:24 +08:00
|
|
|
Record.push_back(D->hasExtInfo());
|
|
|
|
if (D->hasExtInfo())
|
|
|
|
Writer.AddQualifierInfo(*D->getExtInfo(), Record);
|
2009-08-19 09:28:35 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
|
2010-09-09 03:31:22 +08:00
|
|
|
VisitRedeclarable(D);
|
2011-10-27 01:53:41 +08:00
|
|
|
VisitDeclaratorDecl(D);
|
2010-05-08 05:43:38 +08:00
|
|
|
|
2010-10-16 02:21:24 +08:00
|
|
|
Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
|
2010-07-05 18:38:01 +08:00
|
|
|
Record.push_back(D->getIdentifierNamespace());
|
2010-06-22 17:55:07 +08:00
|
|
|
Record.push_back(D->getTemplatedKind());
|
|
|
|
switch (D->getTemplatedKind()) {
|
2011-09-23 13:06:16 +08:00
|
|
|
default: llvm_unreachable("Unhandled TemplatedKind!");
|
2010-06-22 17:55:07 +08:00
|
|
|
case FunctionDecl::TK_NonTemplate:
|
|
|
|
break;
|
|
|
|
case FunctionDecl::TK_FunctionTemplate:
|
|
|
|
Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record);
|
|
|
|
break;
|
|
|
|
case FunctionDecl::TK_MemberSpecialization: {
|
|
|
|
MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
|
|
|
|
Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
|
|
|
|
Record.push_back(MemberInfo->getTemplateSpecializationKind());
|
|
|
|
Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FunctionDecl::TK_FunctionTemplateSpecialization: {
|
|
|
|
FunctionTemplateSpecializationInfo *
|
|
|
|
FTSInfo = D->getTemplateSpecializationInfo();
|
2010-09-09 19:28:23 +08:00
|
|
|
Writer.AddDeclRef(FTSInfo->getTemplate(), Record);
|
2010-06-22 17:55:07 +08:00
|
|
|
Record.push_back(FTSInfo->getTemplateSpecializationKind());
|
|
|
|
|
|
|
|
// Template arguments.
|
2010-06-23 21:48:30 +08:00
|
|
|
Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record);
|
2010-06-22 17:55:07 +08:00
|
|
|
|
|
|
|
// Template args as written.
|
2010-07-02 19:55:40 +08:00
|
|
|
Record.push_back(FTSInfo->TemplateArgumentsAsWritten != 0);
|
2010-06-22 17:55:07 +08:00
|
|
|
if (FTSInfo->TemplateArgumentsAsWritten) {
|
2011-09-23 04:07:09 +08:00
|
|
|
Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
|
|
|
|
for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
|
|
|
|
i!=e; ++i)
|
2010-06-22 17:55:07 +08:00
|
|
|
Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i],
|
|
|
|
Record);
|
2011-09-23 04:07:09 +08:00
|
|
|
Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc,
|
2010-06-22 17:55:07 +08:00
|
|
|
Record);
|
2011-09-23 04:07:09 +08:00
|
|
|
Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc,
|
2010-06-22 17:55:07 +08:00
|
|
|
Record);
|
|
|
|
}
|
2010-07-05 18:37:55 +08:00
|
|
|
|
|
|
|
Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record);
|
2010-09-13 19:45:48 +08:00
|
|
|
|
|
|
|
if (D->isCanonicalDecl()) {
|
|
|
|
// Write the template that contains the specializations set. We will
|
|
|
|
// add a FunctionTemplateSpecializationInfo to it when reading.
|
|
|
|
Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record);
|
|
|
|
}
|
2010-06-26 00:24:51 +08:00
|
|
|
break;
|
2010-06-22 17:55:07 +08:00
|
|
|
}
|
|
|
|
case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
|
|
|
|
DependentFunctionTemplateSpecializationInfo *
|
|
|
|
DFTSInfo = D->getDependentSpecializationInfo();
|
|
|
|
|
|
|
|
// Templates.
|
|
|
|
Record.push_back(DFTSInfo->getNumTemplates());
|
|
|
|
for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
|
|
|
|
Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record);
|
|
|
|
|
|
|
|
// Templates args.
|
|
|
|
Record.push_back(DFTSInfo->getNumTemplateArgs());
|
|
|
|
for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
|
|
|
|
Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record);
|
2010-07-05 18:37:55 +08:00
|
|
|
Writer.AddSourceLocation(DFTSInfo->getLAngleLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(DFTSInfo->getRAngleLoc(), Record);
|
2010-06-26 00:24:51 +08:00
|
|
|
break;
|
2010-06-22 17:55:07 +08:00
|
|
|
}
|
|
|
|
}
|
2010-05-08 05:43:38 +08:00
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
// FunctionDecl's body is handled last at ASTWriterDecl::Visit,
|
2010-07-02 23:58:43 +08:00
|
|
|
// after everything else is written.
|
2010-07-02 19:55:40 +08:00
|
|
|
|
|
|
|
Record.push_back(D->getStorageClass()); // FIXME: stable encoding
|
|
|
|
Record.push_back(D->getStorageClassAsWritten());
|
2010-12-10 00:59:22 +08:00
|
|
|
Record.push_back(D->IsInline);
|
2010-07-02 19:55:40 +08:00
|
|
|
Record.push_back(D->isInlineSpecified());
|
|
|
|
Record.push_back(D->isVirtualAsWritten());
|
|
|
|
Record.push_back(D->isPure());
|
|
|
|
Record.push_back(D->hasInheritedPrototype());
|
|
|
|
Record.push_back(D->hasWrittenPrototype());
|
2011-05-07 04:44:56 +08:00
|
|
|
Record.push_back(D->isDeletedAsWritten());
|
2010-07-02 19:55:40 +08:00
|
|
|
Record.push_back(D->isTrivial());
|
2011-05-13 06:46:29 +08:00
|
|
|
Record.push_back(D->isDefaulted());
|
|
|
|
Record.push_back(D->isExplicitlyDefaulted());
|
2010-07-02 19:55:40 +08:00
|
|
|
Record.push_back(D->hasImplicitReturnZero());
|
2011-08-16 05:04:07 +08:00
|
|
|
Record.push_back(D->isConstexpr());
|
2010-07-02 19:55:40 +08:00
|
|
|
Writer.AddSourceLocation(D->getLocEnd(), 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);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_FUNCTION;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
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.
|
2010-08-09 18:54:37 +08:00
|
|
|
bool HasBodyStuff = D->getBody() != 0 ||
|
|
|
|
D->getSelfDecl() != 0 || D->getCmdDecl() != 0;
|
|
|
|
Record.push_back(HasBodyStuff);
|
|
|
|
if (HasBodyStuff) {
|
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());
|
2010-07-23 02:24:20 +08:00
|
|
|
Record.push_back(D->isDefined());
|
2011-10-15 01:41:52 +08:00
|
|
|
|
|
|
|
Record.push_back(D->IsRedeclaration);
|
|
|
|
Record.push_back(D->HasRedeclaration);
|
|
|
|
if (D->HasRedeclaration) {
|
|
|
|
assert(Context.getObjCMethodRedeclaration(D));
|
|
|
|
Writer.AddDeclRef(Context.getObjCMethodRedeclaration(D), Record);
|
|
|
|
}
|
|
|
|
|
2009-04-27 14:16:06 +08:00
|
|
|
// 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());
|
2011-06-11 09:09:30 +08:00
|
|
|
Record.push_back(D->hasRelatedResultType());
|
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);
|
2011-10-03 14:37:04 +08:00
|
|
|
|
|
|
|
Record.push_back(D->SelLocsKind);
|
|
|
|
unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
|
|
|
|
SourceLocation *SelLocs = D->getStoredSelLocs();
|
|
|
|
Record.push_back(NumStoredSelLocs);
|
|
|
|
for (unsigned i = 0; i != NumStoredSelLocs; ++i)
|
|
|
|
Writer.AddSourceLocation(SelLocs[i], Record);
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_METHOD;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitNamedDecl(D);
|
2011-10-04 12:48:02 +08:00
|
|
|
Writer.AddSourceLocation(D->getAtStartLoc(), Record);
|
2010-05-08 05:43:38 +08:00
|
|
|
Writer.AddSourceRange(D->getAtEndRange(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
// Abstract class (no need to define a stable serialization::DECL code).
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
|
2011-12-16 02:03:09 +08:00
|
|
|
VisitRedeclarable(D);
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitObjCContainerDecl(D);
|
|
|
|
Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
|
2010-09-01 09:21:15 +08:00
|
|
|
|
2011-12-15 13:27:12 +08:00
|
|
|
ObjCInterfaceDecl *Def = D->getDefinition();
|
|
|
|
Writer.AddDeclRef(Def, Record);
|
|
|
|
|
|
|
|
if (D == Def) {
|
|
|
|
// Write the DefinitionData
|
|
|
|
ObjCInterfaceDecl::DefinitionData &Data = D->data();
|
|
|
|
|
|
|
|
Writer.AddDeclRef(D->getSuperClass(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
|
2011-12-16 06:34:59 +08:00
|
|
|
Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record);
|
|
|
|
|
2011-12-15 13:27:12 +08:00
|
|
|
// Write out the protocols that are directly referenced by the @interface.
|
|
|
|
Record.push_back(Data.ReferencedProtocols.size());
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator P = D->protocol_begin(),
|
|
|
|
PEnd = D->protocol_end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
Writer.AddDeclRef(*P, Record);
|
|
|
|
for (ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin(),
|
2010-01-16 23:02:53 +08:00
|
|
|
PLEnd = D->protocol_loc_end();
|
2011-12-15 13:27:12 +08:00
|
|
|
PL != PLEnd; ++PL)
|
|
|
|
Writer.AddSourceLocation(*PL, Record);
|
|
|
|
|
|
|
|
// Write out the protocols that are transitively referenced.
|
|
|
|
Record.push_back(Data.AllReferencedProtocols.size());
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator
|
|
|
|
P = Data.AllReferencedProtocols.begin(),
|
|
|
|
PEnd = Data.AllReferencedProtocols.end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
Writer.AddDeclRef(*P, Record);
|
|
|
|
|
|
|
|
// Write out the ivars.
|
|
|
|
Record.push_back(D->ivar_size());
|
|
|
|
for (ObjCInterfaceDecl::ivar_iterator I = D->ivar_begin(),
|
|
|
|
IEnd = D->ivar_end(); I != IEnd; ++I)
|
|
|
|
Writer.AddDeclRef(*I, Record);
|
|
|
|
|
|
|
|
Writer.AddDeclRef(D->getCategoryList(), Record);
|
|
|
|
}
|
2010-09-01 09:21:15 +08:00
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_INTERFACE;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitFieldDecl(D);
|
|
|
|
// FIXME: stable encoding for @public/@private/@protected/@package
|
2009-09-09 23:08:12 +08:00
|
|
|
Record.push_back(D->getAccessControl());
|
2010-07-18 02:35:47 +08:00
|
|
|
Record.push_back(D->getSynthesize());
|
2011-06-04 07:11:16 +08:00
|
|
|
|
|
|
|
if (!D->hasAttrs() &&
|
|
|
|
!D->isImplicit() &&
|
|
|
|
!D->isUsed(false) &&
|
|
|
|
!D->isInvalidDecl() &&
|
|
|
|
!D->isReferenced() &&
|
2011-09-09 10:06:17 +08:00
|
|
|
!D->isModulePrivate() &&
|
2011-06-04 07:11:16 +08:00
|
|
|
!D->getBitWidth() &&
|
|
|
|
!D->hasExtInfo() &&
|
|
|
|
D->getDeclName())
|
|
|
|
AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_IVAR;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitObjCContainerDecl(D);
|
2011-10-18 03:48:06 +08:00
|
|
|
Record.push_back(D->isInitiallyForwardDecl());
|
2009-04-27 14:16:06 +08:00
|
|
|
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);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_PROTOCOL;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitFieldDecl(D);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCClassDecl(ObjCClassDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitDecl(D);
|
2011-12-15 01:12:03 +08:00
|
|
|
Writer.AddDeclRef(D->Interface, Record);
|
|
|
|
Writer.AddSourceLocation(D->InterfaceLoc, Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_CLASS;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
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);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_FORWARD_PROTOCOL;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
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-08-24 02:51:39 +08:00
|
|
|
Record.push_back(D->hasSynthBitfield());
|
2010-01-17 00:38:58 +08:00
|
|
|
Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_CATEGORY;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddDeclRef(D->getClassInterface(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
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());
|
2010-06-23 07:20:40 +08:00
|
|
|
Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
|
2009-04-27 14:16:06 +08:00
|
|
|
// 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);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_PROPERTY;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::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);
|
2010-08-19 07:57:32 +08:00
|
|
|
// Abstract class (no need to define a stable serialization::DECL code).
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitObjCImplDecl(D);
|
|
|
|
Writer.AddIdentifierRef(D->getIdentifier(), Record);
|
2011-12-09 08:31:40 +08:00
|
|
|
Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_CATEGORY_IMPL;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitObjCImplDecl(D);
|
|
|
|
Writer.AddDeclRef(D->getSuperClass(), Record);
|
2011-01-09 04:30:50 +08:00
|
|
|
Writer.AddCXXCtorInitializers(D->IvarInitializers, D->NumIvarInitializers,
|
|
|
|
Record);
|
2010-08-24 02:51:39 +08:00
|
|
|
Record.push_back(D->hasSynthBitfield());
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_IMPLEMENTATION;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getLocStart(), Record);
|
|
|
|
Writer.AddDeclRef(D->getPropertyDecl(), Record);
|
|
|
|
Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
|
2010-11-17 09:03:52 +08:00
|
|
|
Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record);
|
2010-08-09 18:54:37 +08:00
|
|
|
Writer.AddStmt(D->getGetterCXXConstructor());
|
|
|
|
Writer.AddStmt(D->getSetterCXXAssignment());
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_OBJC_PROPERTY_IMPL;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::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());
|
2011-06-12 01:19:42 +08:00
|
|
|
Record.push_back(D->getBitWidth()? 1 : D->hasInClassInitializer() ? 2 : 0);
|
2009-04-27 14:16:06 +08:00
|
|
|
if (D->getBitWidth())
|
|
|
|
Writer.AddStmt(D->getBitWidth());
|
2011-06-12 01:19:42 +08:00
|
|
|
else if (D->hasInClassInitializer())
|
|
|
|
Writer.AddStmt(D->getInClassInitializer());
|
2010-07-05 05:44:35 +08:00
|
|
|
if (!D->getDeclName())
|
|
|
|
Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record);
|
2011-06-04 07:11:16 +08:00
|
|
|
|
|
|
|
if (!D->hasAttrs() &&
|
|
|
|
!D->isImplicit() &&
|
|
|
|
!D->isUsed(false) &&
|
|
|
|
!D->isInvalidDecl() &&
|
|
|
|
!D->isReferenced() &&
|
2011-11-24 05:11:23 +08:00
|
|
|
!D->isTopLevelDeclInObjCContainer() &&
|
2011-09-09 10:06:17 +08:00
|
|
|
!D->isModulePrivate() &&
|
2011-06-04 07:11:16 +08:00
|
|
|
!D->getBitWidth() &&
|
2011-06-12 01:19:42 +08:00
|
|
|
!D->hasInClassInitializer() &&
|
2011-06-04 07:11:16 +08:00
|
|
|
!D->hasExtInfo() &&
|
|
|
|
!ObjCIvarDecl::classofKind(D->getKind()) &&
|
|
|
|
!ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
|
|
|
|
D->getDeclName())
|
|
|
|
AbbrevToUse = Writer.getDeclFieldAbbrev();
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_FIELD;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-11-21 14:08:52 +08:00
|
|
|
void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
|
|
|
|
VisitValueDecl(D);
|
|
|
|
Record.push_back(D->getChainingSize());
|
|
|
|
|
|
|
|
for (IndirectFieldDecl::chain_iterator
|
|
|
|
P = D->chain_begin(),
|
|
|
|
PEnd = D->chain_end(); P != PEnd; ++P)
|
|
|
|
Writer.AddDeclRef(*P, Record);
|
|
|
|
Code = serialization::DECL_INDIRECTFIELD;
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
|
2010-09-09 03:31:22 +08:00
|
|
|
VisitRedeclarable(D);
|
2011-10-27 01:53:41 +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());
|
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());
|
2011-04-15 06:09:26 +08:00
|
|
|
Record.push_back(D->isCXXForRangeDecl());
|
2011-06-17 14:42:21 +08:00
|
|
|
Record.push_back(D->isARCPseudoStrong());
|
2011-12-19 14:19:21 +08:00
|
|
|
if (D->getInit()) {
|
|
|
|
Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
|
2009-04-27 14:16:06 +08:00
|
|
|
Writer.AddStmt(D->getInit());
|
2011-12-19 14:19:21 +08:00
|
|
|
} else {
|
|
|
|
Record.push_back(0);
|
|
|
|
}
|
2010-07-05 05:44:00 +08:00
|
|
|
|
|
|
|
MemberSpecializationInfo *SpecInfo
|
|
|
|
= D->isStaticDataMember() ? D->getMemberSpecializationInfo() : 0;
|
|
|
|
Record.push_back(SpecInfo != 0);
|
|
|
|
if (SpecInfo) {
|
|
|
|
Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record);
|
|
|
|
Record.push_back(SpecInfo->getTemplateSpecializationKind());
|
|
|
|
Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record);
|
|
|
|
}
|
|
|
|
|
2011-06-04 07:11:16 +08:00
|
|
|
if (!D->hasAttrs() &&
|
|
|
|
!D->isImplicit() &&
|
|
|
|
!D->isUsed(false) &&
|
|
|
|
!D->isInvalidDecl() &&
|
|
|
|
!D->isReferenced() &&
|
2011-11-24 05:11:23 +08:00
|
|
|
!D->isTopLevelDeclInObjCContainer() &&
|
2011-06-04 07:11:16 +08:00
|
|
|
D->getAccess() == AS_none &&
|
2011-09-09 10:06:17 +08:00
|
|
|
!D->isModulePrivate() &&
|
2011-06-04 07:11:16 +08:00
|
|
|
D->getDeclName().getNameKind() == DeclarationName::Identifier &&
|
|
|
|
!D->hasExtInfo() &&
|
2011-12-19 23:27:36 +08:00
|
|
|
D->RedeclLink.getPointer() == D &&
|
2011-06-04 07:11:16 +08:00
|
|
|
!D->hasCXXDirectInitializer() &&
|
|
|
|
D->getInit() == 0 &&
|
2011-06-17 14:42:21 +08:00
|
|
|
!isa<ParmVarDecl>(D) &&
|
2011-06-04 07:11:16 +08:00
|
|
|
!SpecInfo)
|
|
|
|
AbbrevToUse = Writer.getDeclVarAbbrev();
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_VAR;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitVarDecl(D);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_IMPLICIT_PARAM;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitVarDecl(D);
|
2011-05-02 08:30:12 +08:00
|
|
|
Record.push_back(D->isObjCMethodParameter());
|
2011-05-02 06:35:37 +08:00
|
|
|
Record.push_back(D->getFunctionScopeDepth());
|
|
|
|
Record.push_back(D->getFunctionScopeIndex());
|
2009-04-27 14:16:06 +08:00
|
|
|
Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
|
2011-03-09 12:22:44 +08:00
|
|
|
Record.push_back(D->isKNRPromoted());
|
2010-03-13 02:31:32 +08:00
|
|
|
Record.push_back(D->hasInheritedDefaultArg());
|
2010-07-05 05:44:07 +08:00
|
|
|
Record.push_back(D->hasUninstantiatedDefaultArg());
|
|
|
|
if (D->hasUninstantiatedDefaultArg())
|
|
|
|
Writer.AddStmt(D->getUninstantiatedDefaultArg());
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_PARM_VAR;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-06-17 14:42:21 +08:00
|
|
|
assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
|
|
|
|
|
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.
|
2011-06-04 07:11:16 +08:00
|
|
|
if (!D->hasAttrs() &&
|
|
|
|
!D->hasExtInfo() &&
|
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 &&
|
2011-09-09 10:06:17 +08:00
|
|
|
!D->isModulePrivate() &&
|
2009-04-27 15:35:58 +08:00
|
|
|
D->getStorageClass() == 0 &&
|
|
|
|
!D->hasCXXDirectInitializer() && // Can params have this ever?
|
2011-05-02 08:30:12 +08:00
|
|
|
D->getFunctionScopeDepth() == 0 &&
|
2010-03-13 02:31:32 +08:00
|
|
|
D->getObjCDeclQualifier() == 0 &&
|
2011-03-09 12:22:44 +08:00
|
|
|
!D->isKNRPromoted() &&
|
2010-05-09 14:40:08 +08:00
|
|
|
!D->hasInheritedDefaultArg() &&
|
2010-07-05 05:44:07 +08:00
|
|
|
D->getInit() == 0 &&
|
|
|
|
!D->hasUninstantiatedDefaultArg()) // No default expr.
|
2011-06-04 07:11:16 +08:00
|
|
|
AbbrevToUse = Writer.getDeclParmVarAbbrev();
|
2009-04-27 15:35:58 +08:00
|
|
|
|
|
|
|
// 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");
|
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");
|
2010-07-05 05:44:00 +08:00
|
|
|
assert(!D->isStaticDataMember() &&
|
|
|
|
"PARM_VAR_DECL can't be static data member");
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddStmt(D->getAsmString());
|
2011-03-03 22:20:18 +08:00
|
|
|
Writer.AddSourceLocation(D->getRParenLoc(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_FILE_SCOPE_ASM;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
|
2009-04-27 14:16:06 +08:00
|
|
|
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);
|
2011-02-02 21:00:07 +08:00
|
|
|
Record.push_back(D->capturesCXXThis());
|
2011-02-07 18:33:21 +08:00
|
|
|
Record.push_back(D->getNumCaptures());
|
2011-02-02 21:00:07 +08:00
|
|
|
for (BlockDecl::capture_iterator
|
2011-02-07 18:33:21 +08:00
|
|
|
i = D->capture_begin(), e = D->capture_end(); i != e; ++i) {
|
|
|
|
const BlockDecl::Capture &capture = *i;
|
|
|
|
Writer.AddDeclRef(capture.getVariable(), Record);
|
|
|
|
|
|
|
|
unsigned flags = 0;
|
|
|
|
if (capture.isByRef()) flags |= 1;
|
|
|
|
if (capture.isNested()) flags |= 2;
|
|
|
|
if (capture.hasCopyExpr()) flags |= 4;
|
|
|
|
Record.push_back(flags);
|
|
|
|
|
|
|
|
if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr());
|
|
|
|
}
|
2011-02-02 21:00:07 +08:00
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_BLOCK;
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitDecl(D);
|
|
|
|
Record.push_back(D->getLanguage());
|
2011-03-09 00:41:52 +08:00
|
|
|
Writer.AddSourceLocation(D->getExternLoc(), Record);
|
2011-03-03 22:52:38 +08:00
|
|
|
Writer.AddSourceLocation(D->getRBraceLoc(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_LINKAGE_SPEC;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2011-02-17 15:39:24 +08:00
|
|
|
void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
|
|
|
|
VisitNamedDecl(D);
|
2011-03-06 02:21:20 +08:00
|
|
|
Writer.AddSourceLocation(D->getLocStart(), Record);
|
2011-02-17 15:39:24 +08:00
|
|
|
Code = serialization::DECL_LABEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitNamedDecl(D);
|
2010-10-06 04:41:58 +08:00
|
|
|
Record.push_back(D->isInline());
|
2011-03-08 20:38:20 +08:00
|
|
|
Writer.AddSourceLocation(D->getLocStart(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getRBraceLoc(), Record);
|
2010-05-08 05:43:38 +08:00
|
|
|
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);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_NAMESPACE;
|
2010-08-06 05:22:19 +08:00
|
|
|
|
|
|
|
if (Writer.hasChain() && !D->isOriginalNamespace() &&
|
2011-09-10 07:01:35 +08:00
|
|
|
D->getOriginalNamespace()->isFromASTFile()) {
|
2010-10-21 00:22:56 +08:00
|
|
|
NamespaceDecl *NS = D->getOriginalNamespace();
|
2010-10-28 15:38:51 +08:00
|
|
|
Writer.AddUpdatedDeclContext(NS);
|
2010-10-21 00:22:56 +08:00
|
|
|
|
|
|
|
// Make sure all visible decls are written. They will be recorded later.
|
|
|
|
NS->lookup(DeclarationName());
|
|
|
|
StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(NS->getLookupPtr());
|
|
|
|
if (Map) {
|
|
|
|
for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
DeclContext::lookup_result Result = D->second.getLookupResult();
|
|
|
|
while (Result.first != Result.second) {
|
|
|
|
Writer.GetDeclRef(*Result.first);
|
|
|
|
++Result.first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-06 05:22:19 +08:00
|
|
|
}
|
2011-04-25 00:28:13 +08:00
|
|
|
|
2011-04-25 00:28:21 +08:00
|
|
|
if (Writer.hasChain() && D->isAnonymousNamespace() && !D->getNextNamespace()){
|
|
|
|
// This is a most recent reopening of the anonymous namespace. If its parent
|
|
|
|
// is in a previous PCH (or is the TU), mark that parent for update, because
|
|
|
|
// the original namespace always points to the latest re-opening of its
|
|
|
|
// anonymous namespace.
|
|
|
|
Decl *Parent = cast<Decl>(
|
|
|
|
D->getParent()->getRedeclContext()->getPrimaryContext());
|
2011-09-10 07:01:35 +08:00
|
|
|
if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
|
2011-04-25 00:28:13 +08:00
|
|
|
ASTWriter::UpdateRecord &Record = Writer.DeclUpdates[Parent];
|
|
|
|
Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE);
|
|
|
|
Writer.AddDeclRef(D, Record);
|
|
|
|
}
|
|
|
|
}
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitNamedDecl(D);
|
2010-09-01 08:08:19 +08:00
|
|
|
Writer.AddSourceLocation(D->getNamespaceLoc(), Record);
|
2010-05-08 05:43:38 +08:00
|
|
|
Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
|
2011-02-26 01:08:07 +08:00
|
|
|
Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
|
2010-05-08 05:43:38 +08:00
|
|
|
Writer.AddDeclRef(D->getNamespace(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_NAMESPACE_ALIAS;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getUsingLocation(), Record);
|
2011-02-25 08:36:19 +08:00
|
|
|
Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
|
2010-10-16 02:21:24 +08:00
|
|
|
Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
|
2010-11-10 13:40:41 +08:00
|
|
|
Writer.AddDeclRef(D->FirstUsingShadow, Record);
|
2010-05-08 05:43:38 +08:00
|
|
|
Record.push_back(D->isTypeName());
|
2010-07-05 05:44:35 +08:00
|
|
|
Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_USING;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitNamedDecl(D);
|
|
|
|
Writer.AddDeclRef(D->getTargetDecl(), Record);
|
2010-11-10 13:40:41 +08:00
|
|
|
Writer.AddDeclRef(D->UsingOrNextShadow, Record);
|
2010-07-05 05:44:35 +08:00
|
|
|
Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_USING_SHADOW;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitNamedDecl(D);
|
2010-09-01 11:07:18 +08:00
|
|
|
Writer.AddSourceLocation(D->getUsingLoc(), Record);
|
2010-05-08 05:43:38 +08:00
|
|
|
Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record);
|
2011-02-26 00:33:46 +08:00
|
|
|
Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
|
2010-05-08 05:43:38 +08:00
|
|
|
Writer.AddDeclRef(D->getNominatedNamespace(), Record);
|
|
|
|
Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_USING_DIRECTIVE;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitValueDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getUsingLoc(), Record);
|
2011-02-25 08:36:19 +08:00
|
|
|
Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
|
2010-10-16 02:21:24 +08:00
|
|
|
Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_UNRESOLVED_USING_VALUE;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
|
2010-05-08 05:43:38 +08:00
|
|
|
UnresolvedUsingTypenameDecl *D) {
|
|
|
|
VisitTypeDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getTypenameLoc(), Record);
|
2011-02-25 08:36:19 +08:00
|
|
|
Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitRecordDecl(D);
|
2010-06-20 03:28:53 +08:00
|
|
|
|
2010-10-25 01:26:31 +08:00
|
|
|
CXXRecordDecl *DefinitionDecl = 0;
|
|
|
|
if (D->DefinitionData)
|
|
|
|
DefinitionDecl = D->DefinitionData->Definition;
|
|
|
|
Writer.AddDeclRef(DefinitionDecl, Record);
|
2010-10-25 01:26:40 +08:00
|
|
|
if (D == DefinitionDecl)
|
|
|
|
Writer.AddCXXDefinitionData(D, Record);
|
2010-07-02 19:55:32 +08:00
|
|
|
|
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-10-15 04:14:38 +08:00
|
|
|
// Store the key function to avoid deserializing every method so we can
|
|
|
|
// compute it.
|
2011-10-07 14:10:15 +08:00
|
|
|
if (D->IsCompleteDefinition)
|
2010-10-15 04:14:38 +08:00
|
|
|
Writer.AddDeclRef(Context.getKeyFunction(D), Record);
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_CXX_RECORD;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitFunctionDecl(D);
|
2010-07-05 05:44:35 +08:00
|
|
|
Record.push_back(D->size_overridden_methods());
|
|
|
|
for (CXXMethodDecl::method_iterator
|
|
|
|
I = D->begin_overridden_methods(), E = D->end_overridden_methods();
|
|
|
|
I != E; ++I)
|
|
|
|
Writer.AddDeclRef(*I, Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_CXX_METHOD;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitCXXMethodDecl(D);
|
2010-07-02 23:58:43 +08:00
|
|
|
|
|
|
|
Record.push_back(D->IsExplicitSpecified);
|
|
|
|
Record.push_back(D->ImplicitlyDefined);
|
2011-01-09 04:30:50 +08:00
|
|
|
Writer.AddCXXCtorInitializers(D->CtorInitializers, D->NumCtorInitializers,
|
|
|
|
Record);
|
2010-07-02 23:58:43 +08:00
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_CXX_CONSTRUCTOR;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitCXXMethodDecl(D);
|
2010-07-02 23:58:43 +08:00
|
|
|
|
|
|
|
Record.push_back(D->ImplicitlyDefined);
|
|
|
|
Writer.AddDeclRef(D->OperatorDelete, Record);
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_CXX_DESTRUCTOR;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
|
2010-05-08 05:43:38 +08:00
|
|
|
VisitCXXMethodDecl(D);
|
2010-07-02 23:58:43 +08:00
|
|
|
Record.push_back(D->IsExplicitSpecified);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_CXX_CONVERSION;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2011-12-03 07:23:56 +08:00
|
|
|
void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
|
|
|
|
VisitDecl(D);
|
|
|
|
ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
|
|
|
|
Record.push_back(!IdentifierLocs.empty());
|
|
|
|
if (IdentifierLocs.empty()) {
|
|
|
|
Writer.AddSourceLocation(D->getLocEnd(), Record);
|
|
|
|
Record.push_back(1);
|
|
|
|
} else {
|
|
|
|
for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
|
|
|
|
Writer.AddSourceLocation(IdentifierLocs[I], Record);
|
|
|
|
Record.push_back(IdentifierLocs.size());
|
|
|
|
}
|
|
|
|
// Note: the number of source locations must always be the last element in
|
|
|
|
// the record.
|
|
|
|
Code = serialization::DECL_IMPORT;
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
|
2010-06-05 13:09:32 +08:00
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddSourceLocation(D->getColonLoc(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_ACCESS_SPEC;
|
2010-06-05 13:09:32 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
|
2010-07-05 18:38:01 +08:00
|
|
|
VisitDecl(D);
|
2010-06-30 06:47:00 +08:00
|
|
|
Record.push_back(D->Friend.is<TypeSourceInfo*>());
|
|
|
|
if (D->Friend.is<TypeSourceInfo*>())
|
|
|
|
Writer.AddTypeSourceInfo(D->Friend.get<TypeSourceInfo*>(), Record);
|
|
|
|
else
|
|
|
|
Writer.AddDeclRef(D->Friend.get<NamedDecl*>(), Record);
|
2010-10-28 04:23:41 +08:00
|
|
|
Writer.AddDeclRef(D->getNextFriend(), Record);
|
2010-10-16 14:59:13 +08:00
|
|
|
Record.push_back(D->UnsupportedFriend);
|
2010-06-30 06:47:00 +08:00
|
|
|
Writer.AddSourceLocation(D->FriendLoc, Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_FRIEND;
|
2010-06-30 06:47:00 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
|
2010-07-23 00:04:10 +08:00
|
|
|
VisitDecl(D);
|
|
|
|
Record.push_back(D->getNumTemplateParameters());
|
|
|
|
for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
|
|
|
|
Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record);
|
|
|
|
Record.push_back(D->getFriendDecl() != 0);
|
|
|
|
if (D->getFriendDecl())
|
|
|
|
Writer.AddDeclRef(D->getFriendDecl(), Record);
|
|
|
|
else
|
|
|
|
Writer.AddTypeSourceInfo(D->getFriendType(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getFriendLoc(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_FRIEND_TEMPLATE;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
|
2010-06-20 03:28:53 +08:00
|
|
|
VisitNamedDecl(D);
|
|
|
|
|
|
|
|
Writer.AddDeclRef(D->getTemplatedDecl(), Record);
|
2010-06-23 21:48:30 +08:00
|
|
|
Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
|
2010-09-09 03:31:22 +08:00
|
|
|
// Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
|
|
|
|
// getCommonPtr() can be used while this is still initializing.
|
2010-06-20 03:28:53 +08:00
|
|
|
|
|
|
|
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
|
2011-02-12 15:50:47 +08:00
|
|
|
if (D->getPreviousDeclaration())
|
|
|
|
Writer.AddDeclRef(D->getFirstDeclaration(), Record);
|
|
|
|
|
2010-06-20 03:28:53 +08:00
|
|
|
if (D->getPreviousDeclaration() == 0) {
|
2010-07-30 00:11:51 +08:00
|
|
|
// This TemplateDecl owns the CommonPtr; write it.
|
2010-07-10 05:11:43 +08:00
|
|
|
assert(D->isCanonicalDecl());
|
2010-06-20 03:28:53 +08:00
|
|
|
|
2010-07-30 00:11:51 +08:00
|
|
|
Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record);
|
|
|
|
if (D->getInstantiatedFromMemberTemplate())
|
|
|
|
Record.push_back(D->isMemberSpecialization());
|
2010-07-30 00:12:01 +08:00
|
|
|
|
|
|
|
Writer.AddDeclRef(D->getCommonPtr()->Latest, Record);
|
2010-08-04 01:30:10 +08:00
|
|
|
} else {
|
|
|
|
RedeclarableTemplateDecl *First = D->getFirstDeclaration();
|
|
|
|
assert(First != D);
|
|
|
|
// If this is a most recent redeclaration that is pointed to by a first decl
|
|
|
|
// in a chained PCH, keep track of the association with the map so we can
|
2010-08-19 07:56:27 +08:00
|
|
|
// update the first decl during AST reading.
|
2010-08-04 01:30:10 +08:00
|
|
|
if (First->getMostRecentDeclaration() == D &&
|
2011-09-10 07:07:59 +08:00
|
|
|
First->isFromASTFile() && !D->isFromASTFile()) {
|
2010-08-04 01:30:10 +08:00
|
|
|
assert(Writer.FirstLatestDecls.find(First)==Writer.FirstLatestDecls.end()
|
|
|
|
&& "The latest is already set");
|
|
|
|
Writer.FirstLatestDecls[First] = D;
|
|
|
|
}
|
2010-07-30 00:11:51 +08:00
|
|
|
}
|
2010-09-09 03:31:22 +08:00
|
|
|
|
|
|
|
VisitTemplateDecl(D);
|
|
|
|
Record.push_back(D->getIdentifierNamespace());
|
2010-07-30 00:11:51 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
|
2010-07-30 00:11:51 +08:00
|
|
|
VisitRedeclarableTemplateDecl(D);
|
|
|
|
|
|
|
|
if (D->getPreviousDeclaration() == 0) {
|
2010-06-20 03:28:53 +08:00
|
|
|
typedef llvm::FoldingSet<ClassTemplateSpecializationDecl> CTSDSetTy;
|
|
|
|
CTSDSetTy &CTSDSet = D->getSpecializations();
|
|
|
|
Record.push_back(CTSDSet.size());
|
2010-07-02 19:55:37 +08:00
|
|
|
for (CTSDSetTy::iterator I=CTSDSet.begin(), E = CTSDSet.end(); I!=E; ++I) {
|
2010-07-20 21:59:40 +08:00
|
|
|
assert(I->isCanonicalDecl() && "Expected only canonical decls in set");
|
2010-07-10 05:11:43 +08:00
|
|
|
Writer.AddDeclRef(&*I, Record);
|
2010-07-02 19:55:37 +08:00
|
|
|
}
|
2010-06-20 03:28:53 +08:00
|
|
|
|
|
|
|
typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> CTPSDSetTy;
|
|
|
|
CTPSDSetTy &CTPSDSet = D->getPartialSpecializations();
|
|
|
|
Record.push_back(CTPSDSet.size());
|
2010-07-02 19:55:37 +08:00
|
|
|
for (CTPSDSetTy::iterator I=CTPSDSet.begin(), E=CTPSDSet.end(); I!=E; ++I) {
|
2010-07-20 21:59:40 +08:00
|
|
|
assert(I->isCanonicalDecl() && "Expected only canonical decls in set");
|
2010-07-10 05:11:43 +08:00
|
|
|
Writer.AddDeclRef(&*I, Record);
|
2010-07-02 19:55:37 +08:00
|
|
|
}
|
2010-06-20 03:28:53 +08:00
|
|
|
|
|
|
|
// InjectedClassNameType is computed, no need to write it.
|
|
|
|
}
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_CLASS_TEMPLATE;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
|
2010-05-08 05:43:38 +08:00
|
|
|
ClassTemplateSpecializationDecl *D) {
|
2010-06-23 21:48:30 +08:00
|
|
|
VisitCXXRecordDecl(D);
|
|
|
|
|
|
|
|
llvm::PointerUnion<ClassTemplateDecl *,
|
|
|
|
ClassTemplatePartialSpecializationDecl *> InstFrom
|
|
|
|
= D->getSpecializedTemplateOrPartial();
|
2011-08-18 05:35:28 +08:00
|
|
|
if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
|
2010-08-25 06:50:24 +08:00
|
|
|
Writer.AddDeclRef(InstFromD, Record);
|
2010-06-23 21:48:30 +08:00
|
|
|
} else {
|
2011-08-18 05:35:28 +08:00
|
|
|
Writer.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>(),
|
|
|
|
Record);
|
2010-06-23 21:48:30 +08:00
|
|
|
Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Explicit info.
|
|
|
|
Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
|
|
|
|
if (D->getTypeAsWritten()) {
|
|
|
|
Writer.AddSourceLocation(D->getExternLoc(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
|
|
|
|
Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
|
|
|
|
Record.push_back(D->getSpecializationKind());
|
|
|
|
|
2010-07-20 21:59:40 +08:00
|
|
|
if (D->isCanonicalDecl()) {
|
|
|
|
// When reading, we'll add it to the folding set of the following template.
|
2010-07-10 05:11:43 +08:00
|
|
|
Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
|
2010-05-08 05:43:38 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *D) {
|
2010-06-23 21:48:30 +08:00
|
|
|
VisitClassTemplateSpecializationDecl(D);
|
|
|
|
|
|
|
|
Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
|
|
|
|
|
|
|
|
Record.push_back(D->getNumTemplateArgsAsWritten());
|
|
|
|
for (int i = 0, e = D->getNumTemplateArgsAsWritten(); i != e; ++i)
|
|
|
|
Writer.AddTemplateArgumentLoc(D->getTemplateArgsAsWritten()[i], Record);
|
|
|
|
|
|
|
|
Record.push_back(D->getSequenceNumber());
|
|
|
|
|
|
|
|
// These are read/set from/to the first declaration.
|
|
|
|
if (D->getPreviousDeclaration() == 0) {
|
|
|
|
Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
|
|
|
|
Record.push_back(D->isMemberSpecialization());
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2011-08-28 04:50:59 +08:00
|
|
|
void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
|
|
|
|
ClassScopeFunctionSpecializationDecl *D) {
|
2011-08-17 09:06:54 +08:00
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddDeclRef(D->getSpecialization(), Record);
|
|
|
|
Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
|
2010-07-30 00:11:51 +08:00
|
|
|
VisitRedeclarableTemplateDecl(D);
|
2010-06-22 17:55:07 +08:00
|
|
|
|
|
|
|
if (D->getPreviousDeclaration() == 0) {
|
|
|
|
// This FunctionTemplateDecl owns the CommonPtr; write it.
|
|
|
|
|
2010-07-06 23:37:09 +08:00
|
|
|
// Write the function specialization declarations.
|
|
|
|
Record.push_back(D->getSpecializations().size());
|
|
|
|
for (llvm::FoldingSet<FunctionTemplateSpecializationInfo>::iterator
|
|
|
|
I = D->getSpecializations().begin(),
|
2010-07-20 21:59:58 +08:00
|
|
|
E = D->getSpecializations().end() ; I != E; ++I) {
|
|
|
|
assert(I->Function->isCanonicalDecl() &&
|
|
|
|
"Expected only canonical decls in set");
|
2010-07-06 23:37:09 +08:00
|
|
|
Writer.AddDeclRef(I->Function, Record);
|
2010-07-20 21:59:58 +08:00
|
|
|
}
|
2010-06-22 17:55:07 +08:00
|
|
|
}
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_FUNCTION_TEMPLATE;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
|
2010-06-20 03:28:53 +08:00
|
|
|
VisitTypeDecl(D);
|
|
|
|
|
|
|
|
Record.push_back(D->wasDeclaredWithTypename());
|
|
|
|
Record.push_back(D->defaultArgumentWasInherited());
|
|
|
|
Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record);
|
|
|
|
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_TEMPLATE_TYPE_PARM;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
|
2011-01-20 04:10:05 +08:00
|
|
|
// For an expanded parameter pack, record the number of expansion types here
|
|
|
|
// so that it's easier for
|
|
|
|
if (D->isExpandedParameterPack())
|
|
|
|
Record.push_back(D->getNumExpansionTypes());
|
|
|
|
|
2011-02-09 09:13:10 +08:00
|
|
|
VisitDeclaratorDecl(D);
|
2010-06-26 00:25:09 +08:00
|
|
|
// TemplateParmPosition.
|
|
|
|
Record.push_back(D->getDepth());
|
|
|
|
Record.push_back(D->getPosition());
|
2011-01-20 04:10:05 +08:00
|
|
|
|
|
|
|
if (D->isExpandedParameterPack()) {
|
|
|
|
for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
|
|
|
|
Writer.AddTypeRef(D->getExpansionType(I), Record);
|
|
|
|
Writer.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I), Record);
|
|
|
|
}
|
|
|
|
|
|
|
|
Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
|
|
|
|
} else {
|
|
|
|
// Rest of NonTypeTemplateParmDecl.
|
|
|
|
Record.push_back(D->isParameterPack());
|
|
|
|
Record.push_back(D->getDefaultArgument() != 0);
|
|
|
|
if (D->getDefaultArgument()) {
|
|
|
|
Writer.AddStmt(D->getDefaultArgument());
|
|
|
|
Record.push_back(D->defaultArgumentWasInherited());
|
|
|
|
}
|
|
|
|
Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
|
2010-06-26 00:25:09 +08:00
|
|
|
}
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
|
2010-07-09 01:12:57 +08:00
|
|
|
VisitTemplateDecl(D);
|
|
|
|
// TemplateParmPosition.
|
|
|
|
Record.push_back(D->getDepth());
|
|
|
|
Record.push_back(D->getPosition());
|
|
|
|
// Rest of TemplateTemplateParmDecl.
|
|
|
|
Writer.AddTemplateArgumentLoc(D->getDefaultArgument(), Record);
|
|
|
|
Record.push_back(D->defaultArgumentWasInherited());
|
2011-01-05 23:48:55 +08:00
|
|
|
Record.push_back(D->isParameterPack());
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
2011-05-06 05:57:07 +08:00
|
|
|
void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
|
|
|
|
VisitRedeclarableTemplateDecl(D);
|
|
|
|
Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
|
2010-07-23 01:28:12 +08:00
|
|
|
VisitDecl(D);
|
|
|
|
Writer.AddStmt(D->getAssertExpr());
|
|
|
|
Writer.AddStmt(D->getMessage());
|
2011-03-09 00:41:52 +08:00
|
|
|
Writer.AddSourceLocation(D->getRParenLoc(), Record);
|
2010-08-19 07:57:32 +08:00
|
|
|
Code = serialization::DECL_STATIC_ASSERT;
|
2010-05-08 05:43:38 +08:00
|
|
|
}
|
|
|
|
|
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.
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::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);
|
|
|
|
}
|
|
|
|
|
2010-08-04 01:30:10 +08:00
|
|
|
template <typename T>
|
2010-08-19 07:56:27 +08:00
|
|
|
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
|
2011-12-19 23:27:36 +08:00
|
|
|
enum { OnlyDeclaration = 0, FirstInFile, PointsToPrevious };
|
|
|
|
if (D->RedeclLink.getPointer() == D) {
|
|
|
|
// This is the only declaration.
|
|
|
|
Record.push_back(OnlyDeclaration);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-04 01:30:10 +08:00
|
|
|
T *First = D->getFirstDeclaration();
|
Completely re-implement (de-)serialization of declaration
chains. The previous implementation relied heavily on the declaration
chain being stored as a (circular) linked list on disk, as it is in
memory. However, when deserializing from multiple modules, the
different chains could get mixed up, leading to broken declaration chains.
The new solution keeps track of the first and last declarations in the
chain for each module file. When we load a declaration, we search all
of the module files for redeclarations of that declaration, then
splice together all of the lists into a coherent whole (along with any
redeclarations that were actually parsed).
As a drive-by fix, (de-)serialize the redeclaration chains of
TypedefNameDecls, which had somehow gotten missed previously. Add a
test of this serialization.
This new scheme creates a redeclaration table that is fairly large in
the PCH file (on the order of 400k for Cocoa.h's 12MB PCH file). The
table is mmap'd in and searched via a binary search, but it's still
quite large. A future tweak will eliminate entries for declarations
that have no redeclarations anywhere, and should
drastically reduce the size of this table.
llvm-svn: 146841
2011-12-18 07:38:30 +08:00
|
|
|
if (!D->getPreviousDeclaration() ||
|
|
|
|
D->getPreviousDeclaration()->isFromASTFile()) {
|
|
|
|
Record.push_back(FirstInFile);
|
|
|
|
Writer.AddDeclRef(First, Record);
|
|
|
|
|
|
|
|
// Capture the set of redeclarations in this file.
|
|
|
|
LocalRedeclarationsInfo LocalInfo = {
|
|
|
|
Writer.GetDeclRef(First),
|
|
|
|
Writer.GetDeclRef(static_cast<T*>(D)),
|
|
|
|
Writer.GetDeclRef(D->getMostRecentDeclaration())
|
|
|
|
};
|
|
|
|
Writer.LocalRedeclarations.push_back(LocalInfo);
|
|
|
|
} else {
|
|
|
|
Record.push_back(PointsToPrevious);
|
|
|
|
Writer.AddDeclRef(First, Record);
|
|
|
|
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
|
2010-08-04 01:30:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-04-27 14:16:06 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-08-19 07:56:21 +08:00
|
|
|
// ASTWriter Implementation
|
2009-04-27 14:16:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-08-19 07:56:21 +08:00
|
|
|
void ASTWriter::WriteDeclsBlockAbbrevs() {
|
2009-04-27 15:35:58 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2011-06-03 10:27:19 +08:00
|
|
|
BitCodeAbbrev *Abv;
|
|
|
|
|
2011-06-04 07:11:16 +08:00
|
|
|
// Abbreviation for DECL_FIELD
|
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
|
2011-06-03 10:27:19 +08:00
|
|
|
// Decl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl (!?)
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isUsed
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
|
2011-11-24 04:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
|
2011-09-09 10:06:17 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
2011-12-01 10:07:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
2011-06-04 07:11:16 +08:00
|
|
|
// NamedDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
|
|
|
// ValueDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
|
|
|
|
// DeclaratorDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
|
|
|
|
// FieldDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
|
|
|
|
// Type Source Info
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
|
|
|
|
DeclFieldAbbrev = Stream.EmitAbbrev(Abv);
|
|
|
|
|
|
|
|
// Abbreviation for DECL_OBJC_IVAR
|
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
|
|
|
|
// Decl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl (!?)
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isUsed
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
|
2011-11-24 04:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
|
2011-09-09 10:06:17 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
2011-12-01 10:07:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
2011-06-03 10:27:19 +08:00
|
|
|
// NamedDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
|
|
|
// ValueDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
|
2011-06-04 07:11:16 +08:00
|
|
|
// DeclaratorDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
|
|
|
|
// FieldDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
|
|
|
|
// ObjC Ivar
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
|
|
|
|
// Type Source Info
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
|
|
|
|
DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abv);
|
|
|
|
|
|
|
|
// Abbreviation for DECL_ENUM
|
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
|
2011-10-27 01:53:41 +08:00
|
|
|
// Redeclarable
|
2011-12-19 23:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
|
2011-06-04 07:11:16 +08:00
|
|
|
// Decl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl (!?)
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isUsed
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
|
2011-11-24 04:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
2011-09-09 10:06:17 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
2011-12-01 10:07:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
2011-06-04 07:11:16 +08:00
|
|
|
// NamedDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
|
|
|
// TypeDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
|
|
|
|
// TagDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
|
2011-10-07 14:10:15 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
|
2011-10-01 06:11:31 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypedefNameAnonDecl
|
|
|
|
// EnumDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
|
|
|
|
// DC
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
|
|
|
|
DeclEnumAbbrev = Stream.EmitAbbrev(Abv);
|
2011-06-03 10:27:19 +08:00
|
|
|
|
|
|
|
// Abbreviation for DECL_RECORD
|
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
|
2011-10-27 01:53:41 +08:00
|
|
|
// Redeclarable
|
2011-12-19 23:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
|
2011-06-03 10:27:19 +08:00
|
|
|
// Decl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl (!?)
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isUsed
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
|
2011-11-24 04:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
2011-06-03 10:27:19 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
2011-09-09 10:06:17 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
2011-12-01 10:07:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
2011-06-03 10:27:19 +08:00
|
|
|
// NamedDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
|
|
|
// TypeDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
|
|
|
|
// TagDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
|
2011-10-07 14:10:15 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
|
2011-06-03 10:27:19 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
|
2011-10-01 06:11:31 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
|
2011-06-03 10:27:19 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypedefNameAnonDecl
|
|
|
|
// RecordDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
|
|
|
|
// DC
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
|
|
|
|
DeclRecordAbbrev = Stream.EmitAbbrev(Abv);
|
|
|
|
|
|
|
|
// Abbreviation for DECL_PARM_VAR
|
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
|
2011-10-27 01:53:41 +08:00
|
|
|
// Redeclarable
|
2011-12-19 23:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
|
2009-04-27 15:35:58 +08:00
|
|
|
// Decl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
|
|
|
|
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
|
2011-04-20 03:51:10 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
|
2011-11-24 04:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
2009-04-27 15:35:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
2011-09-09 10:06:17 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
2011-12-01 10:07:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
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
|
2011-03-08 16:55:46 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
|
2010-10-16 02:21:24 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
|
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
|
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
|
2011-04-15 06:09:26 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isCXXForRangeDecl
|
2011-06-17 14:42:21 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isARCPseudoStrong
|
2009-04-27 15:35:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasInit
|
2010-07-05 05:44:00 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
|
2009-04-27 15:35:58 +08:00
|
|
|
// ParmVarDecl
|
2011-05-02 08:30:12 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
|
2011-05-02 06:35:37 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
|
2009-04-27 15:35:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
|
2011-03-09 12:22:44 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
|
2010-03-13 02:31:32 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
|
2010-07-05 05:44:07 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
|
2011-06-04 07:11:16 +08:00
|
|
|
// Type Source Info
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
|
|
|
|
DeclParmVarAbbrev = Stream.EmitAbbrev(Abv);
|
2010-07-27 08:17:23 +08:00
|
|
|
|
2011-06-07 00:22:39 +08:00
|
|
|
// Abbreviation for DECL_TYPEDEF
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
|
Completely re-implement (de-)serialization of declaration
chains. The previous implementation relied heavily on the declaration
chain being stored as a (circular) linked list on disk, as it is in
memory. However, when deserializing from multiple modules, the
different chains could get mixed up, leading to broken declaration chains.
The new solution keeps track of the first and last declarations in the
chain for each module file. When we load a declaration, we search all
of the module files for redeclarations of that declaration, then
splice together all of the lists into a coherent whole (along with any
redeclarations that were actually parsed).
As a drive-by fix, (de-)serialize the redeclaration chains of
TypedefNameDecls, which had somehow gotten missed previously. Add a
test of this serialization.
This new scheme creates a redeclaration table that is fairly large in
the PCH file (on the order of 400k for Cocoa.h's 12MB PCH file). The
table is mmap'd in and searched via a binary search, but it's still
quite large. A future tweak will eliminate entries for declarations
that have no redeclarations anywhere, and should
drastically reduce the size of this table.
llvm-svn: 146841
2011-12-18 07:38:30 +08:00
|
|
|
// Redeclarable
|
2011-12-19 23:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
|
2011-06-04 07:11:16 +08:00
|
|
|
// Decl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl (!?)
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isUsed
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
|
2011-11-24 04:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
2011-09-09 10:06:17 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
2011-12-01 10:07:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
2011-06-04 07:11:16 +08:00
|
|
|
// NamedDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
|
|
|
// TypeDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
|
|
|
|
// TypedefDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
|
|
|
|
DeclTypedefAbbrev = Stream.EmitAbbrev(Abv);
|
|
|
|
|
2011-06-07 00:22:39 +08:00
|
|
|
// Abbreviation for DECL_VAR
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
|
2011-10-27 01:53:41 +08:00
|
|
|
// Redeclarable
|
2011-12-19 23:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
|
2011-06-04 07:11:16 +08:00
|
|
|
// Decl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl (!?)
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isUsed
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
|
2011-11-24 04:27:36 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
2011-09-09 10:06:17 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
2011-12-01 10:07:58 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
2011-06-04 07:11:16 +08:00
|
|
|
// NamedDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
|
|
|
// ValueDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
|
|
|
|
// DeclaratorDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
|
|
|
|
Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
|
|
|
|
// VarDecl
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClassAsWritten
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isThreadSpecified
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
|
2011-06-17 14:42:21 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
|
2011-06-04 07:11:16 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasInit
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasMemberSpecInfo
|
|
|
|
// Type Source Info
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
|
|
|
|
DeclVarAbbrev = Stream.EmitAbbrev(Abv);
|
|
|
|
|
2011-06-07 00:22:39 +08:00
|
|
|
// Abbreviation for EXPR_DECL_REF
|
2011-06-03 10:27:19 +08:00
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
|
|
|
|
//Stmt
|
|
|
|
//Expr
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
|
2011-07-01 09:22:09 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
|
2011-06-03 10:27:19 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
|
|
|
|
//DeclRefExpr
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
|
2011-10-05 15:56:41 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
|
2011-06-03 10:27:19 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
|
|
|
|
DeclRefExprAbbrev = Stream.EmitAbbrev(Abv);
|
|
|
|
|
|
|
|
// Abbreviation for EXPR_INTEGER_LITERAL
|
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
|
|
|
|
//Stmt
|
|
|
|
//Expr
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
|
2011-07-01 09:22:09 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
|
2011-06-03 10:27:19 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
|
|
|
|
//Integer Literal
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
|
|
|
|
Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
|
|
|
|
IntegerLiteralAbbrev = Stream.EmitAbbrev(Abv);
|
|
|
|
|
|
|
|
// Abbreviation for EXPR_CHARACTER_LITERAL
|
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
|
|
|
|
//Stmt
|
|
|
|
//Expr
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
|
2011-07-01 09:22:09 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
|
2011-06-03 10:27:19 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
|
2011-06-04 05:46:44 +08:00
|
|
|
//Character Literal
|
2011-06-03 10:27:19 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //IsWide
|
|
|
|
CharacterLiteralAbbrev = Stream.EmitAbbrev(Abv);
|
|
|
|
|
2010-07-27 08:17:23 +08:00
|
|
|
Abv = new BitCodeAbbrev();
|
2010-08-19 07:57:32 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
|
2010-07-27 08:17:23 +08:00
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
|
|
|
|
DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abv);
|
2010-08-21 00:04:35 +08:00
|
|
|
|
|
|
|
Abv = new BitCodeAbbrev();
|
|
|
|
Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
|
|
|
|
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
|
|
|
|
DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abv);
|
2009-04-27 15:35:58 +08:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
///
|
2010-08-19 07:56:27 +08:00
|
|
|
/// Such decls will always be deserialized from the AST file, so we would like
|
2009-09-17 11:06:51 +08:00
|
|
|
/// 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.
|
|
|
|
static bool isRequiredDecl(const Decl *D, ASTContext &Context) {
|
2011-09-14 05:35:00 +08:00
|
|
|
// An ObjCMethodDecl is never considered as "required" because its
|
|
|
|
// implementation container always is.
|
|
|
|
|
2010-08-09 18:54:20 +08:00
|
|
|
// File scoped assembly or obj-c implementation must be seen.
|
2011-09-10 08:22:34 +08:00
|
|
|
if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
|
2009-09-17 11:06:51 +08:00
|
|
|
return true;
|
|
|
|
|
2010-07-30 04:08:05 +08:00
|
|
|
return Context.DeclMustBeEmitted(D);
|
2009-09-17 11:06:51 +08:00
|
|
|
}
|
|
|
|
|
2010-08-19 07:56:21 +08:00
|
|
|
void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
|
2010-10-28 17:29:32 +08:00
|
|
|
// Switch case IDs are per Decl.
|
|
|
|
ClearSwitchCaseIDs();
|
|
|
|
|
2009-04-27 14:16:06 +08:00
|
|
|
RecordData Record;
|
2010-08-19 07:56:27 +08:00
|
|
|
ASTDeclWriter W(*this, Context, Record);
|
2009-04-27 14:16:06 +08:00
|
|
|
|
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
|
2010-08-19 07:57:32 +08:00
|
|
|
serialization::DeclID &IDR = DeclIDs[D];
|
2010-08-13 08:28:03 +08:00
|
|
|
if (IDR == 0)
|
|
|
|
IDR = NextDeclID++;
|
2010-08-19 07:57:32 +08:00
|
|
|
serialization::DeclID ID = IDR;
|
2010-08-13 08:28:03 +08:00
|
|
|
|
|
|
|
if (ID < FirstDeclID) {
|
|
|
|
// We're replacing a decl in a previous file.
|
2011-10-31 15:20:15 +08:00
|
|
|
ReplacedDecls.push_back(ReplacedDeclInfo(ID, Stream.GetCurrentBitNo(),
|
|
|
|
D->getLocation()));
|
2010-08-13 08:28:03 +08:00
|
|
|
} else {
|
|
|
|
unsigned Index = ID - FirstDeclID;
|
|
|
|
|
|
|
|
// Record the offset for this declaration
|
2011-10-29 06:54:21 +08:00
|
|
|
SourceLocation Loc = D->getLocation();
|
2010-08-13 08:28:03 +08:00
|
|
|
if (DeclOffsets.size() == Index)
|
2011-10-29 06:54:21 +08:00
|
|
|
DeclOffsets.push_back(DeclOffset(Loc, Stream.GetCurrentBitNo()));
|
2010-08-13 08:28:03 +08:00
|
|
|
else if (DeclOffsets.size() < Index) {
|
|
|
|
DeclOffsets.resize(Index+1);
|
2011-10-29 06:54:21 +08:00
|
|
|
DeclOffsets[Index].setLocation(Loc);
|
2011-10-28 02:47:35 +08:00
|
|
|
DeclOffsets[Index].BitOffset = Stream.GetCurrentBitNo();
|
2010-08-13 08:28:03 +08:00
|
|
|
}
|
2011-10-29 06:54:21 +08:00
|
|
|
|
|
|
|
SourceManager &SM = Context.getSourceManager();
|
2011-10-29 07:57:43 +08:00
|
|
|
if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
|
|
|
|
associateDeclWithFile(D, ID);
|
2009-10-17 08:13:19 +08:00
|
|
|
}
|
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();
|
2010-08-19 07:57:32 +08:00
|
|
|
W.Code = (serialization::DeclCode)0;
|
2009-10-17 08:13:19 +08:00
|
|
|
W.AbbrevToUse = 0;
|
|
|
|
W.Visit(D);
|
|
|
|
if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset);
|
|
|
|
|
2009-12-03 17:13:36 +08:00
|
|
|
if (!W.Code)
|
2011-07-23 18:55:15 +08:00
|
|
|
llvm::report_fatal_error(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
|
|
|
// Flush any expressions that were written as part of this declaration.
|
|
|
|
FlushStmts();
|
2010-10-30 06:39:52 +08:00
|
|
|
|
|
|
|
// Flush C++ base specifiers, if there are any.
|
|
|
|
FlushCXXBaseSpecifiers();
|
|
|
|
|
2009-10-17 08:13:19 +08:00
|
|
|
// Note "external" declarations so that we can add them to a record in the
|
2010-08-19 07:56:27 +08:00
|
|
|
// AST file later.
|
2009-10-17 08:13:19 +08:00
|
|
|
//
|
|
|
|
// FIXME: This should be renamed, the predicate is much more complicated.
|
|
|
|
if (isRequiredDecl(D, Context))
|
2010-08-13 08:28:03 +08:00
|
|
|
ExternalDefinitions.push_back(ID);
|
2009-04-27 14:16:06 +08:00
|
|
|
}
|