Kaydet (Commit) 1798a443 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Michael Meeks

compilerplugin: check that necessary Window subclasses have a dispose method

i.e. the ones that declare any VclPtr fields

Change-Id: I7adfc3b3b190a2ede60bfccd08f85a269fae33ca
üst a6acccc6
......@@ -31,6 +31,8 @@ public:
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
bool VisitCXXRecordDecl(const CXXRecordDecl * decl);
bool VisitFieldDecl(const FieldDecl * decl);
bool VisitParmVarDecl(ParmVarDecl const * decl);
......@@ -76,6 +78,44 @@ bool isPointerToWindowSubclass(const QualType& pType) {
return isDerivedFromWindow(recordDecl);
}
bool VCLWidgets::VisitCXXRecordDecl(const CXXRecordDecl * recordDecl) {
if (ignoreLocation(recordDecl)) {
return true;
}
if (!recordDecl->isCompleteDefinition())
return true;
// check if this field is derived from Window
if (!isDerivedFromWindow(recordDecl)) {
return true;
}
bool foundVclPtr = false;
for(auto fieldDecl : recordDecl->fields()) {
if (fieldDecl->getType().getAsString().find("VclPtr")==0) {
foundVclPtr = true;
break;
}
}
if (!foundVclPtr) {
return true;
}
bool foundDispose = false;
for(auto methodDecl : recordDecl->methods()) {
if (methodDecl->isInstance() && methodDecl->param_size()==0 && methodDecl->getNameAsString() == "dispose") {
foundDispose = true;
break;
}
}
if (!foundDispose) {
report(
DiagnosticsEngine::Warning,
"vcl::Window subclass with VclPtr members should declare a dispose() method.",
recordDecl->getLocation())
<< recordDecl->getSourceRange();
}
return true;
}
bool VCLWidgets::VisitFieldDecl(const FieldDecl * fieldDecl) {
if (ignoreLocation(fieldDecl)) {
return true;
......
......@@ -91,6 +91,7 @@ protected:
bool IsDropDownBox() const { return mpFloatWin ? true : false; }
virtual void FillLayoutData() const SAL_OVERRIDE;
virtual void dispose() SAL_OVERRIDE;
public:
explicit ComboBox( vcl::Window* pParent, WinBits nStyle = 0 );
explicit ComboBox( vcl::Window* pParent, const ResId& );
......
......@@ -62,6 +62,7 @@ private:
protected:
using Window::ImplInit;
SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
virtual void dispose() SAL_OVERRIDE;
public:
SAL_DLLPRIVATE bool IsInClose() const { return mbInClose; }
......
......@@ -620,6 +620,8 @@ private:
};
VclPtr<EventBoxHelper> m_aEventBoxHelper;
protected:
virtual void dispose() SAL_OVERRIDE;
public:
VclEventBox(vcl::Window* pParent)
: VclBin(pParent)
......
......@@ -78,6 +78,12 @@ ComboBox::~ComboBox()
delete mpBtn;
}
void ComboBox::dispose()
{
mpSubEdit.disposeAndClear();
Edit::dispose();
}
void ComboBox::ImplInitComboBoxData()
{
mpSubEdit.disposeAndClear();
......
......@@ -542,6 +542,13 @@ Dialog::~Dialog()
mpDialogImpl = NULL;
}
void Dialog::dispose()
{
mpActionArea.disposeAndClear();
mpContentArea.disposeAndClear();
SystemWindow::dispose();
}
IMPL_LINK_NOARG(Dialog, ImplAsyncCloseHdl)
{
Close();
......
......@@ -1878,6 +1878,12 @@ void VclEventBox::Command(const CommandEvent&)
//discard events by default to block them reaching children
}
void VclEventBox::dispose()
{
m_aEventBoxHelper.disposeAndClear();
VclBin::dispose();
}
void VclSizeGroup::trigger_queue_resize()
{
//sufficient to trigger one widget to trigger all of them
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment