Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2011-05-20 18:31:20 +0000
committerSergey Prigogin2011-05-20 18:31:20 +0000
commitbf14a317b4e2942ea74bd86ae7c14c5cc8bb74ac (patch)
tree63bfaa53aca911a1ed3648dfbed20745e63a9f0c
parentbe065cee025616784c6062c46322c0131cfa9a1e (diff)
downloadorg.eclipse.cdt-bf14a317b4e2942ea74bd86ae7c14c5cc8bb74ac.tar.gz
org.eclipse.cdt-bf14a317b4e2942ea74bd86ae7c14c5cc8bb74ac.tar.xz
org.eclipse.cdt-bf14a317b4e2942ea74bd86ae7c14c5cc8bb74ac.zip
Code streamlining.
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java132
1 files changed, 65 insertions, 67 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java
index 2403bd93b38..e3296d11f06 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java
@@ -84,81 +84,79 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
private boolean hasErrorCondition(IASTDeclSpecifier decl) throws DOMException {
ICPPASTCompositeTypeSpecifier spec = (ICPPASTCompositeTypeSpecifier) decl;
className = spec.getName();
- IBinding binding = className.getBinding();
- if (binding == null) {
- binding = className.resolveBinding();
- }
+ IBinding binding = className.resolveBinding();
if (binding instanceof ICPPClassType) {
- ICPPClassType classType = (ICPPClassType) binding;
- virtualMethod = null;
- destructor = null;
- // check for the following conditions:
- // class has own virtual method and own non-virtual destructor
- // class has own virtual method and base non-virtual destructor
- // class has base virtual method and own non-virtual destructor
- ICPPMethod[] declaredMethods = classType.getDeclaredMethods();
- boolean hasOwnVirtualMethod = false;
- boolean hasOwnNonVirDestructor = false;
- boolean hasDestructor = false;
- boolean hasVirtualMethod = false;
- for (ICPPMethod method : declaredMethods) {
- if (method.isVirtual() && !method.isDestructor()) {
- hasOwnVirtualMethod = true;
- virtualMethod = method;
- }
- if (method.isDestructor()) {
- hasDestructor = true;
- if (!method.isVirtual()) {
- hasOwnNonVirDestructor = true;
- destructor = method;
- }
+ return false;
+ }
+ ICPPClassType classType = (ICPPClassType) binding;
+ virtualMethod = null;
+ destructor = null;
+ // check for the following conditions:
+ // class has own virtual method and own non-virtual destructor
+ // class has own virtual method and base non-virtual destructor
+ // class has base virtual method and own non-virtual destructor
+ ICPPMethod[] declaredMethods = classType.getDeclaredMethods();
+ boolean hasOwnVirtualMethod = false;
+ boolean hasOwnNonVirDestructor = false;
+ boolean hasDestructor = false;
+ boolean hasVirtualMethod = false;
+ for (ICPPMethod method : declaredMethods) {
+ if (method.isVirtual() && !method.isDestructor()) {
+ hasOwnVirtualMethod = true;
+ virtualMethod = method;
+ }
+ if (method.isDestructor()) {
+ hasDestructor = true;
+ if (!method.isVirtual()) {
+ hasOwnNonVirDestructor = true;
+ destructor = method;
}
}
- boolean hasVirtualDestructor = false;
- // Class has own virtual method and own non-virtual destructor.
- if (hasOwnVirtualMethod && hasOwnNonVirDestructor) {
- if (destructor instanceof ICPPMethod) {
- // Check if dtor is public or is accessible by friends.
- if (((ICPPMethod) destructor).getVisibility() != ICPPASTVisibilityLabel.v_public &&
- classType.getFriends().length == 0) {
- return false;
- }
+ }
+ boolean hasVirtualDestructor = false;
+ // Class has own virtual method and own non-virtual destructor.
+ if (hasOwnVirtualMethod && hasOwnNonVirDestructor) {
+ if (destructor instanceof ICPPMethod) {
+ // Check if dtor is public or is accessible by friends.
+ if (((ICPPMethod) destructor).getVisibility() != ICPPASTVisibilityLabel.v_public &&
+ classType.getFriends().length == 0) {
+ return false;
}
- // Check if one of its base classes has a virtual destructor.
- return !hasVirtualDtorInBaseClass(classType);
}
- // Class does not have virtual methods but has virtual destructor
- // - not an error
- if (!hasOwnVirtualMethod && hasDestructor && !hasOwnNonVirDestructor) {
- return false;
+ // Check if one of its base classes has a virtual destructor.
+ return !hasVirtualDtorInBaseClass(classType);
+ }
+ // Class does not have virtual methods but has virtual destructor
+ // - not an error
+ if (!hasOwnVirtualMethod && hasDestructor && !hasOwnNonVirDestructor) {
+ return false;
+ }
+ ICPPMethod[] allDeclaredMethods = classType.getAllDeclaredMethods();
+ for (ICPPMethod method : allDeclaredMethods) {
+ if (method.isVirtual() && !method.isDestructor()) {
+ hasVirtualMethod = true;
+ if (virtualMethod == null)
+ virtualMethod = method;
}
- ICPPMethod[] allDeclaredMethods = classType.getAllDeclaredMethods();
- for (ICPPMethod method : allDeclaredMethods) {
- if (method.isVirtual() && !method.isDestructor()) {
- hasVirtualMethod = true;
- if (virtualMethod == null)
- virtualMethod = method;
- }
- if (method.isDestructor()) {
- hasDestructor = true;
- if (method.isVirtual()) {
- hasVirtualDestructor = true;
- } else {
- if (destructor == null)
- destructor = method;
- }
+ if (method.isDestructor()) {
+ hasDestructor = true;
+ if (method.isVirtual()) {
+ hasVirtualDestructor = true;
+ } else {
+ if (destructor == null)
+ destructor = method;
}
}
- if (hasOwnVirtualMethod) {
- // Class has own virtual method and base non-virtual destructor.
- if (hasDestructor && !hasVirtualDestructor) {
- return true;
- }
- } else if (hasVirtualMethod) {
- // Class has base virtual method and own non-virtual destructor.
- if (hasOwnNonVirDestructor) {
- return true;
- }
+ }
+ if (hasOwnVirtualMethod) {
+ // Class has own virtual method and base non-virtual destructor.
+ if (hasDestructor && !hasVirtualDestructor) {
+ return true;
+ }
+ } else if (hasVirtualMethod) {
+ // Class has base virtual method and own non-virtual destructor.
+ if (hasOwnNonVirDestructor) {
+ return true;
}
}
return false;

Back to the top