From 6dfc1978ace21b4d528fd80040ef350bf4d45d5d Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 3 Dec 2009 18:44:40 +0000 Subject: [PATCH] A new helper function to set various bits in the class when a new virtual function is declared/instantiated. it is used in couple of places. llvm-svn: 90470 --- clang/include/clang/AST/DeclCXX.h | 4 ++++ clang/lib/AST/DeclCXX.cpp | 12 ++++++++++++ clang/lib/Sema/SemaDecl.cpp | 9 +-------- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 ++------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 81f85e81a00a..340096c9dc3c 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -533,6 +533,10 @@ public: /// [dcl.init.aggr]). void setAggregate(bool Agg) { Aggregate = Agg; } + /// setMethodAsVirtual - Make input method virtual and set the necesssary + /// special function bits and other bits accordingly. + void setMethodAsVirtual(FunctionDecl *Method); + /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class /// that is an aggregate that has no non-static non-POD data members, no /// reference data members, no user-defined copy assignment operator and no diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 89ea097a33c1..979723a19547 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -439,6 +439,18 @@ void CXXRecordDecl::addConversionFunction(FunctionTemplateDecl *ConvDecl) { Conversions.addDecl(ConvDecl); } + +void CXXRecordDecl::setMethodAsVirtual(FunctionDecl *Method) { + Method->setVirtualAsWritten(true); + setAggregate(false); + setPOD(false); + setEmpty(false); + setPolymorphic(true); + setHasTrivialConstructor(false); + setHasTrivialCopyConstructor(false); + setHasTrivialCopyAssignment(false); +} + CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) return cast(MSInfo->getInstantiatedFrom()); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ea5e47a9a341..e02849f5d59b 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2822,15 +2822,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, SourceRange(D.getDeclSpec().getVirtualSpecLoc())); } else { // Okay: Add virtual to the method. - cast(NewFD)->setVirtualAsWritten(true); CXXRecordDecl *CurClass = cast(DC); - CurClass->setAggregate(false); - CurClass->setPOD(false); - CurClass->setEmpty(false); - CurClass->setPolymorphic(true); - CurClass->setHasTrivialConstructor(false); - CurClass->setHasTrivialCopyConstructor(false); - CurClass->setHasTrivialCopyAssignment(false); + CurClass->setMethodAsVirtual(NewFD); } } diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 394f0eee72af..ec28f4741799 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1359,13 +1359,8 @@ TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, CXXRecordDecl *Record = cast(Owner); New->setAccess(Tmpl->getAccess()); - if (Tmpl->isVirtualAsWritten()) { - New->setVirtualAsWritten(true); - Record->setAggregate(false); - Record->setPOD(false); - Record->setEmpty(false); - Record->setPolymorphic(true); - } + if (Tmpl->isVirtualAsWritten()) + Record->setMethodAsVirtual(New); // FIXME: attributes // FIXME: New needs a pointer to Tmpl