Browse Source

Made entries in v-tables use the same method objects as regular methods.

Besides being obviously correct, this fixes a memory leak.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/600/head
Dimitar Dobrev 10 years ago
parent
commit
6db0676b5a
  1. 17
      src/CppParser/Parser.cpp
  2. 2
      src/CppParser/Parser.h

17
src/CppParser/Parser.cpp

@ -525,28 +525,28 @@ Parser::WalkVTableComponent(const clang::VTableComponent& Component)
{ {
VTC.Kind = VTableComponentKind::FunctionPointer; VTC.Kind = VTableComponentKind::FunctionPointer;
auto MD = const_cast<CXXMethodDecl*>(Component.getFunctionDecl()); auto MD = const_cast<CXXMethodDecl*>(Component.getFunctionDecl());
VTC.Declaration = WalkMethodCXX(MD, /*AddToClass=*/false); VTC.Declaration = WalkMethodCXX(MD);
break; break;
} }
case clang::VTableComponent::CK_CompleteDtorPointer: case clang::VTableComponent::CK_CompleteDtorPointer:
{ {
VTC.Kind = VTableComponentKind::CompleteDtorPointer; VTC.Kind = VTableComponentKind::CompleteDtorPointer;
auto MD = const_cast<CXXDestructorDecl*>(Component.getDestructorDecl()); auto MD = const_cast<CXXDestructorDecl*>(Component.getDestructorDecl());
VTC.Declaration = WalkMethodCXX(MD, /*AddToClass=*/false); VTC.Declaration = WalkMethodCXX(MD);
break; break;
} }
case clang::VTableComponent::CK_DeletingDtorPointer: case clang::VTableComponent::CK_DeletingDtorPointer:
{ {
VTC.Kind = VTableComponentKind::DeletingDtorPointer; VTC.Kind = VTableComponentKind::DeletingDtorPointer;
auto MD = const_cast<CXXDestructorDecl*>(Component.getDestructorDecl()); auto MD = const_cast<CXXDestructorDecl*>(Component.getDestructorDecl());
VTC.Declaration = WalkMethodCXX(MD, /*AddToClass=*/false); VTC.Declaration = WalkMethodCXX(MD);
break; break;
} }
case clang::VTableComponent::CK_UnusedFunctionPointer: case clang::VTableComponent::CK_UnusedFunctionPointer:
{ {
VTC.Kind = VTableComponentKind::UnusedFunctionPointer; VTC.Kind = VTableComponentKind::UnusedFunctionPointer;
auto MD = const_cast<CXXMethodDecl*>(Component.getUnusedFunctionDecl()); auto MD = const_cast<CXXMethodDecl*>(Component.getUnusedFunctionDecl());
VTC.Declaration = WalkMethodCXX(MD, /*AddToClass=*/false); VTC.Declaration = WalkMethodCXX(MD);
break; break;
} }
default: default:
@ -1145,7 +1145,7 @@ FunctionTemplate* Parser::WalkFunctionTemplate(clang::FunctionTemplateDecl* TD)
auto TemplatedDecl = TD->getTemplatedDecl(); auto TemplatedDecl = TD->getTemplatedDecl();
if (auto MD = dyn_cast<CXXMethodDecl>(TemplatedDecl)) if (auto MD = dyn_cast<CXXMethodDecl>(TemplatedDecl))
Function = WalkMethodCXX(MD, /*AddToClass=*/false); Function = WalkMethodCXX(MD);
else else
Function = WalkFunction(TemplatedDecl, /*IsDependent=*/true, Function = WalkFunction(TemplatedDecl, /*IsDependent=*/true,
/*AddToNamespace=*/false); /*AddToNamespace=*/false);
@ -1230,13 +1230,13 @@ static CXXOperatorKind GetOperatorKindFromDecl(clang::DeclarationName Name)
llvm_unreachable("Unknown OverloadedOperator"); llvm_unreachable("Unknown OverloadedOperator");
} }
Method* Parser::WalkMethodCXX(clang::CXXMethodDecl* MD, bool AddToClass) Method* Parser::WalkMethodCXX(clang::CXXMethodDecl* MD)
{ {
using namespace clang; using namespace clang;
// We could be in a redeclaration, so process the primary context. // We could be in a redeclaration, so process the primary context.
if (MD->getPrimaryContext() != MD) if (MD->getPrimaryContext() != MD)
return WalkMethodCXX(cast<CXXMethodDecl>(MD->getPrimaryContext()), AddToClass); return WalkMethodCXX(cast<CXXMethodDecl>(MD->getPrimaryContext()));
auto RD = MD->getParent(); auto RD = MD->getParent();
auto Decl = WalkDeclaration(RD, /*IgnoreSystemDecls=*/false); auto Decl = WalkDeclaration(RD, /*IgnoreSystemDecls=*/false);
@ -1288,8 +1288,7 @@ Method* Parser::WalkMethodCXX(clang::CXXMethodDecl* MD, bool AddToClass)
Method->ConversionType = GetQualifiedType(CD->getConversionType(), ConvTy); Method->ConversionType = GetQualifiedType(CD->getConversionType(), ConvTy);
} }
if (AddToClass) Class->Methods.push_back(Method);
Class->Methods.push_back(Method);
return Method; return Method;
} }

2
src/CppParser/Parser.h

@ -79,7 +79,7 @@ protected:
WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl* CTS); WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl* CTS);
ClassTemplatePartialSpecialization* ClassTemplatePartialSpecialization*
WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecializationDecl* CTS); WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecializationDecl* CTS);
Method* WalkMethodCXX(clang::CXXMethodDecl* MD, bool AddToClass = true); Method* WalkMethodCXX(clang::CXXMethodDecl* MD);
Field* WalkFieldCXX(clang::FieldDecl* FD, Class* Class); Field* WalkFieldCXX(clang::FieldDecl* FD, Class* Class);
ClassTemplate* WalkClassTemplate(clang::ClassTemplateDecl* TD); ClassTemplate* WalkClassTemplate(clang::ClassTemplateDecl* TD);
FunctionTemplate* WalkFunctionTemplate(clang::FunctionTemplateDecl* TD); FunctionTemplate* WalkFunctionTemplate(clang::FunctionTemplateDecl* TD);

Loading…
Cancel
Save