mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Code streamlining.
This commit is contained in:
parent
be065cee02
commit
bf14a317b4
1 changed files with 67 additions and 69 deletions
|
@ -84,81 +84,79 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
private boolean hasErrorCondition(IASTDeclSpecifier decl) throws DOMException {
|
private boolean hasErrorCondition(IASTDeclSpecifier decl) throws DOMException {
|
||||||
ICPPASTCompositeTypeSpecifier spec = (ICPPASTCompositeTypeSpecifier) decl;
|
ICPPASTCompositeTypeSpecifier spec = (ICPPASTCompositeTypeSpecifier) decl;
|
||||||
className = spec.getName();
|
className = spec.getName();
|
||||||
IBinding binding = className.getBinding();
|
IBinding binding = className.resolveBinding();
|
||||||
if (binding == null) {
|
|
||||||
binding = className.resolveBinding();
|
|
||||||
}
|
|
||||||
if (binding instanceof ICPPClassType) {
|
if (binding instanceof ICPPClassType) {
|
||||||
ICPPClassType classType = (ICPPClassType) binding;
|
return false;
|
||||||
virtualMethod = null;
|
}
|
||||||
destructor = null;
|
ICPPClassType classType = (ICPPClassType) binding;
|
||||||
// check for the following conditions:
|
virtualMethod = null;
|
||||||
// class has own virtual method and own non-virtual destructor
|
destructor = null;
|
||||||
// class has own virtual method and base non-virtual destructor
|
// check for the following conditions:
|
||||||
// class has base virtual method and own non-virtual destructor
|
// class has own virtual method and own non-virtual destructor
|
||||||
ICPPMethod[] declaredMethods = classType.getDeclaredMethods();
|
// class has own virtual method and base non-virtual destructor
|
||||||
boolean hasOwnVirtualMethod = false;
|
// class has base virtual method and own non-virtual destructor
|
||||||
boolean hasOwnNonVirDestructor = false;
|
ICPPMethod[] declaredMethods = classType.getDeclaredMethods();
|
||||||
boolean hasDestructor = false;
|
boolean hasOwnVirtualMethod = false;
|
||||||
boolean hasVirtualMethod = false;
|
boolean hasOwnNonVirDestructor = false;
|
||||||
for (ICPPMethod method : declaredMethods) {
|
boolean hasDestructor = false;
|
||||||
if (method.isVirtual() && !method.isDestructor()) {
|
boolean hasVirtualMethod = false;
|
||||||
hasOwnVirtualMethod = true;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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;
|
virtualMethod = method;
|
||||||
}
|
}
|
||||||
if (method.isDestructor()) {
|
if (method.isDestructor()) {
|
||||||
hasDestructor = true;
|
hasDestructor = true;
|
||||||
if (!method.isVirtual()) {
|
if (method.isVirtual()) {
|
||||||
hasOwnNonVirDestructor = true;
|
hasVirtualDestructor = true;
|
||||||
|
} else {
|
||||||
|
if (destructor == null)
|
||||||
destructor = method;
|
destructor = method;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean hasVirtualDestructor = false;
|
}
|
||||||
// Class has own virtual method and own non-virtual destructor.
|
if (hasOwnVirtualMethod) {
|
||||||
if (hasOwnVirtualMethod && hasOwnNonVirDestructor) {
|
// Class has own virtual method and base non-virtual destructor.
|
||||||
if (destructor instanceof ICPPMethod) {
|
if (hasDestructor && !hasVirtualDestructor) {
|
||||||
// Check if dtor is public or is accessible by friends.
|
return true;
|
||||||
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
|
} else if (hasVirtualMethod) {
|
||||||
// - not an error
|
// Class has base virtual method and own non-virtual destructor.
|
||||||
if (!hasOwnVirtualMethod && hasDestructor && !hasOwnNonVirDestructor) {
|
if (hasOwnNonVirDestructor) {
|
||||||
return false;
|
return true;
|
||||||
}
|
|
||||||
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 (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;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue