mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 06:45:43 +02:00
[ 273251] - fixed bugs in analyzer
This commit is contained in:
parent
1f13ed7bcc
commit
5ca73300ee
1 changed files with 15 additions and 13 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.codan.checkers.sample;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.codan.checkers.Activator;
|
||||||
import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker;
|
import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
|
@ -34,9 +35,6 @@ import org.eclipse.core.resources.IFile;
|
||||||
*/
|
*/
|
||||||
public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.NonVirtualDestructorProblem";
|
private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.NonVirtualDestructorProblem";
|
||||||
private IASTName className;
|
|
||||||
private IBinding virMethodName;
|
|
||||||
private IBinding destName;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processAst(IASTTranslationUnit ast) {
|
public void processAst(IASTTranslationUnit ast) {
|
||||||
|
@ -45,6 +43,10 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
class OnEachClass extends ASTVisitor {
|
class OnEachClass extends ASTVisitor {
|
||||||
|
private IASTName className;
|
||||||
|
private IBinding virMethodName;
|
||||||
|
private IBinding destName;
|
||||||
|
|
||||||
OnEachClass() {
|
OnEachClass() {
|
||||||
// shouldVisitDeclarations = true;
|
// shouldVisitDeclarations = true;
|
||||||
shouldVisitDeclSpecifiers = true;
|
shouldVisitDeclSpecifiers = true;
|
||||||
|
@ -76,6 +78,8 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
// ignore, no error
|
// ignore, no error
|
||||||
|
} catch (Exception e) {
|
||||||
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
@ -88,8 +92,6 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
*/
|
*/
|
||||||
private boolean hasErrorCondition(IASTDeclSpecifier decl)
|
private boolean hasErrorCondition(IASTDeclSpecifier decl)
|
||||||
throws DOMException {
|
throws DOMException {
|
||||||
virMethodName = null;
|
|
||||||
destName = null;
|
|
||||||
ICPPASTCompositeTypeSpecifier spec = (ICPPASTCompositeTypeSpecifier) decl;
|
ICPPASTCompositeTypeSpecifier spec = (ICPPASTCompositeTypeSpecifier) decl;
|
||||||
className = spec.getName();
|
className = spec.getName();
|
||||||
IBinding binding = className.getBinding();
|
IBinding binding = className.getBinding();
|
||||||
|
@ -98,6 +100,8 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
}
|
}
|
||||||
if (binding instanceof ICPPClassType) {
|
if (binding instanceof ICPPClassType) {
|
||||||
ICPPClassType type = (ICPPClassType) binding;
|
ICPPClassType type = (ICPPClassType) binding;
|
||||||
|
virMethodName = null;
|
||||||
|
destName = null;
|
||||||
// check for the following conditions:
|
// check for the following conditions:
|
||||||
// class has own virtual method and own non-virtual destructor
|
// class has own virtual method and own non-virtual destructor
|
||||||
// class has own virtual method and base non-virtual destructor
|
// class has own virtual method and base non-virtual destructor
|
||||||
|
@ -105,10 +109,8 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
ICPPMethod[] declaredMethods = type.getDeclaredMethods();
|
ICPPMethod[] declaredMethods = type.getDeclaredMethods();
|
||||||
boolean hasOwnVirtualMethod = false;
|
boolean hasOwnVirtualMethod = false;
|
||||||
boolean hasOwnNonVirDestructor = false;
|
boolean hasOwnNonVirDestructor = false;
|
||||||
boolean hasOwnDestructor = false;
|
|
||||||
boolean hasDestructor = false;
|
boolean hasDestructor = false;
|
||||||
boolean hasVirtualMethod = false;
|
boolean hasVirtualMethod = false;
|
||||||
boolean hasNonVirtualDestructor = false;
|
|
||||||
for (int i = 0; i < declaredMethods.length; i++) {
|
for (int i = 0; i < declaredMethods.length; i++) {
|
||||||
ICPPMethod icppMethod = declaredMethods[i];
|
ICPPMethod icppMethod = declaredMethods[i];
|
||||||
if (icppMethod.isVirtual() && !icppMethod.isDestructor()) {
|
if (icppMethod.isVirtual() && !icppMethod.isDestructor()) {
|
||||||
|
@ -123,7 +125,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean hasNonVirDestructor = false;
|
boolean hasVirDestructor = false;
|
||||||
// class has own virtual method and own non-virtual destructor
|
// class has own virtual method and own non-virtual destructor
|
||||||
if (hasOwnVirtualMethod && hasOwnNonVirDestructor) {
|
if (hasOwnVirtualMethod && hasOwnNonVirDestructor) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -132,7 +134,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
// destructor
|
// destructor
|
||||||
// - not an error
|
// - not an error
|
||||||
if (hasOwnVirtualMethod == false && hasDestructor == true
|
if (hasOwnVirtualMethod == false && hasDestructor == true
|
||||||
&& hasNonVirDestructor == false) {
|
&& hasOwnNonVirDestructor == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ICPPMethod[] allDeclaredMethods = type.getAllDeclaredMethods();
|
ICPPMethod[] allDeclaredMethods = type.getAllDeclaredMethods();
|
||||||
|
@ -145,8 +147,9 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
}
|
}
|
||||||
if (icppMethod.isDestructor()) {
|
if (icppMethod.isDestructor()) {
|
||||||
hasDestructor = true;
|
hasDestructor = true;
|
||||||
if (!icppMethod.isVirtual()) {
|
if (icppMethod.isVirtual()) {
|
||||||
hasNonVirDestructor = true;
|
hasVirDestructor = true;
|
||||||
|
} else {
|
||||||
if (destName == null)
|
if (destName == null)
|
||||||
destName = icppMethod;
|
destName = icppMethod;
|
||||||
}
|
}
|
||||||
|
@ -155,8 +158,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
if (hasOwnVirtualMethod) {
|
if (hasOwnVirtualMethod) {
|
||||||
// class has own virtual method and base non-virtual
|
// class has own virtual method and base non-virtual
|
||||||
// destructor
|
// destructor
|
||||||
if (hasOwnDestructor == false
|
if (hasDestructor == true && hasVirDestructor == false) {
|
||||||
&& hasNonVirtualDestructor == true) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (hasVirtualMethod) {
|
} else if (hasVirtualMethod) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue