summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2015-01-08 14:09:13 +0200
committerMichael Meeks <michael.meeks@collabora.com>2015-04-09 20:03:21 +0100
commit1798a4433280a6cae38fe535fb043a8e27d7f95a (patch)
treeb08acb0329cd59ffcf18466b4efe30406ef421a0 /compilerplugins
parenta6acccc6d2e6a49691d2612af9898e4018c68861 (diff)
compilerplugin: check that necessary Window subclasses have a dispose method
i.e. the ones that declare any VclPtr fields Change-Id: I7adfc3b3b190a2ede60bfccd08f85a269fae33ca
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/vclwidgets.cxx40
1 files changed, 40 insertions, 0 deletions
diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx
index aa2af7fe5962..896cd3f38889 100644
--- a/compilerplugins/clang/vclwidgets.cxx
+++ b/compilerplugins/clang/vclwidgets.cxx
@@ -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;