summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization/ASTWriterDecl.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-04-06 17:06:00 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-04-06 17:06:00 +0000
commit290d8019162faeac878f7f58f2f3643833b97fb0 (patch)
treeedf43e550e01b7844d071a0da0d5cbadb63707b0 /clang/lib/Serialization/ASTWriterDecl.cpp
parent4812c91f56252bb0a72234abf12a2fe5ffe515e8 (diff)
downloadbcm5719-llvm-290d8019162faeac878f7f58f2f3643833b97fb0.tar.gz
bcm5719-llvm-290d8019162faeac878f7f58f2f3643833b97fb0.zip
Re-commit r265518 ("[modules] Continue factoring encoding of AST records out of
ASTWriter."), reverted in r265526, with a fix for an iterator invalidation bug (thanks, MSan!). llvm-svn: 265564
Diffstat (limited to 'clang/lib/Serialization/ASTWriterDecl.cpp')
-rw-r--r--clang/lib/Serialization/ASTWriterDecl.cpp64
1 files changed, 28 insertions, 36 deletions
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 4c0fa1a201d..3182e2b6f28 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -171,17 +171,6 @@ namespace clang {
Record.AddSourceLocation(typeParams->getRAngleLoc());
}
- void AddFunctionDefinition(const FunctionDecl *FD) {
- assert(FD->doesThisDeclarationHaveABody());
- if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
- Record.push_back(CD->NumCtorInitializers);
- if (CD->NumCtorInitializers)
- Record.AddCXXCtorInitializersRef(
- llvm::makeArrayRef(CD->init_begin(), CD->init_end()));
- }
- Writer.AddStmt(FD->getBody());
- }
-
/// Add to the record the first declaration from each module file that
/// provides a declaration of D. The intent is to provide a sufficient
/// set such that reloading this set will load all current redeclarations.
@@ -293,7 +282,7 @@ void ASTDeclWriter::Visit(Decl *D) {
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Record.push_back(FD->doesThisDeclarationHaveABody());
if (FD->doesThisDeclarationHaveABody())
- AddFunctionDefinition(FD);
+ Record.AddFunctionDefinition(FD);
}
}
@@ -508,7 +497,7 @@ void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
VisitValueDecl(D);
Record.push_back(D->getInitExpr()? 1 : 0);
if (D->getInitExpr())
- Writer.AddStmt(D->getInitExpr());
+ Record.AddStmt(D->getInitExpr());
Record.AddAPSInt(D->getInitVal());
Code = serialization::DECL_ENUM_CONSTANT;
@@ -629,7 +618,7 @@ void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Record.push_back(HasBodyStuff);
if (HasBodyStuff) {
- Writer.AddStmt(D->getBody());
+ Record.AddStmt(D->getBody());
Record.AddDeclRef(D->getSelfDecl());
Record.AddDeclRef(D->getCmdDecl());
}
@@ -846,8 +835,8 @@ void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Record.AddDeclRef(D->getPropertyDecl());
Record.AddDeclRef(D->getPropertyIvarDecl());
Record.AddSourceLocation(D->getPropertyIvarDeclLoc());
- Writer.AddStmt(D->getGetterCXXConstructor());
- Writer.AddStmt(D->getSetterCXXAssignment());
+ Record.AddStmt(D->getGetterCXXConstructor());
+ Record.AddStmt(D->getSetterCXXAssignment());
Code = serialization::DECL_OBJC_PROPERTY_IMPL;
}
@@ -863,7 +852,7 @@ void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
QualType(static_cast<Type *>(D->InitStorage.getPointer()), 0));
} else {
Record.push_back(D->InitStorage.getInt() + 1);
- Writer.AddStmt(static_cast<Expr *>(D->InitStorage.getPointer()));
+ Record.AddStmt(static_cast<Expr *>(D->InitStorage.getPointer()));
}
if (!D->getDeclName())
Record.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D));
@@ -922,7 +911,7 @@ void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
if (D->getInit()) {
Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
- Writer.AddStmt(D->getInit());
+ Record.AddStmt(D->getInit());
} else {
Record.push_back(0);
}
@@ -984,7 +973,7 @@ void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Record.push_back(D->hasInheritedDefaultArg());
Record.push_back(D->hasUninstantiatedDefaultArg());
if (D->hasUninstantiatedDefaultArg())
- Writer.AddStmt(D->getUninstantiatedDefaultArg());
+ Record.AddStmt(D->getUninstantiatedDefaultArg());
Code = serialization::DECL_PARM_VAR;
assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
@@ -1023,7 +1012,7 @@ void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
VisitDecl(D);
- Writer.AddStmt(D->getAsmString());
+ Record.AddStmt(D->getAsmString());
Record.AddSourceLocation(D->getRParenLoc());
Code = serialization::DECL_FILE_SCOPE_ASM;
}
@@ -1035,7 +1024,7 @@ void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
VisitDecl(D);
- Writer.AddStmt(D->getBody());
+ Record.AddStmt(D->getBody());
Record.AddTypeSourceInfo(D->getSignatureAsWritten());
Record.push_back(D->param_size());
for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
@@ -1055,7 +1044,7 @@ void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
if (capture.hasCopyExpr()) flags |= 4;
Record.push_back(flags);
- if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr());
+ if (capture.hasCopyExpr()) Record.AddStmt(capture.getCopyExpr());
}
Code = serialization::DECL_BLOCK;
@@ -1505,7 +1494,7 @@ void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
!D->defaultArgumentWasInherited();
Record.push_back(OwnsDefaultArg);
if (OwnsDefaultArg)
- Writer.AddStmt(D->getDefaultArgument());
+ Record.AddStmt(D->getDefaultArgument());
Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
}
}
@@ -1546,9 +1535,9 @@ void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
VisitDecl(D);
- Writer.AddStmt(D->getAssertExpr());
+ Record.AddStmt(D->getAssertExpr());
Record.push_back(D->isFailed());
- Writer.AddStmt(D->getMessage());
+ Record.AddStmt(D->getMessage());
Record.AddSourceLocation(D->getRParenLoc());
Code = serialization::DECL_STATIC_ASSERT;
}
@@ -1661,15 +1650,15 @@ void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
Record.push_back(D->varlist_size());
VisitDecl(D);
for (auto *I : D->varlists())
- Writer.AddStmt(I);
+ Record.AddStmt(I);
Code = serialization::DECL_OMP_THREADPRIVATE;
}
void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
VisitValueDecl(D);
Record.AddSourceLocation(D->getLocStart());
- Writer.AddStmt(D->getCombiner());
- Writer.AddStmt(D->getInitializer());
+ Record.AddStmt(D->getCombiner());
+ Record.AddStmt(D->getInitializer());
Record.AddDeclRef(D->getPrevDeclInScope());
Code = serialization::DECL_OMP_DECLARE_REDUCTION;
}
@@ -2149,9 +2138,6 @@ static bool isRequiredDecl(const Decl *D, ASTContext &Context,
}
void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
- // Switch case IDs are per Decl.
- ClearSwitchCaseIDs();
-
// Determine the ID for this declaration.
serialization::DeclID ID;
assert(!D->isFromASTFile() && "should not be emitting imported decl");
@@ -2210,10 +2196,16 @@ void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
EagerlyDeserializedDecls.push_back(ID);
}
-void ASTWriter::AddFunctionDefinition(const FunctionDecl *FD,
- RecordDataImpl &Record) {
- ClearSwitchCaseIDs();
+void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
+ // Switch case IDs are per function body.
+ Writer->ClearSwitchCaseIDs();
- ASTDeclWriter W(*this, FD->getASTContext(), Record);
- W.AddFunctionDefinition(FD);
+ assert(FD->doesThisDeclarationHaveABody());
+ if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
+ Record->push_back(CD->getNumCtorInitializers());
+ if (CD->getNumCtorInitializers())
+ AddCXXCtorInitializersRef(
+ llvm::makeArrayRef(CD->init_begin(), CD->init_end()));
+ }
+ AddStmt(FD->getBody());
}
OpenPOWER on IntegriCloud