compilerplugin: check that necessary Window subclasses have a dispose method
i.e. the ones that declare any VclPtr fields Change-Id: I7adfc3b3b190a2ede60bfccd08f85a269fae33ca
This commit is contained in:
committed by
Michael Meeks
parent
a6acccc6d2
commit
1798a44332
@@ -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;
|
||||
|
Reference in New Issue
Block a user