1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-05 22:53:13 +02:00

- updated to catch possible exceptions

This commit is contained in:
Alena Laskavaia 2010-03-29 15:34:44 +00:00
parent 0794acbd0f
commit 4967787769

View file

@ -8,9 +8,9 @@
* Contributors: * Contributors:
* Alena Laskavaia - initial API and implementation * Alena Laskavaia - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers; package org.eclipse.cdt.codan.internal.checkers;
import org.eclipse.cdt.codan.checkers.CodanCheckersActivator;
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; import org.eclipse.cdt.codan.core.cxx.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.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
@ -41,7 +41,6 @@ public class CatchUsesReference extends AbstractIndexAstChecker {
// traverse the ast using the visitor pattern. // traverse the ast using the visitor pattern.
ast.accept(new OnCatch()); ast.accept(new OnCatch());
} }
class OnCatch extends ASTVisitor { class OnCatch extends ASTVisitor {
OnCatch() { OnCatch() {
shouldVisitStatements = true; shouldVisitStatements = true;
@ -49,31 +48,36 @@ public class CatchUsesReference extends AbstractIndexAstChecker {
public int visit(IASTStatement stmt) { public int visit(IASTStatement stmt) {
if (stmt instanceof ICPPASTTryBlockStatement) { if (stmt instanceof ICPPASTTryBlockStatement) {
ICPPASTTryBlockStatement tblock = (ICPPASTTryBlockStatement) stmt; try {
ICPPASTCatchHandler[] catchHandlers = tblock.getCatchHandlers(); ICPPASTTryBlockStatement tblock = (ICPPASTTryBlockStatement) stmt;
next: for (int i = 0; i < catchHandlers.length; i++) { ICPPASTCatchHandler[] catchHandlers = tblock.getCatchHandlers();
ICPPASTCatchHandler catchHandler = catchHandlers[i]; next: for (int i = 0; i < catchHandlers.length; i++) {
IASTDeclaration decl = catchHandler.getDeclaration(); ICPPASTCatchHandler catchHandler = catchHandlers[i];
if (decl instanceof IASTSimpleDeclaration) { IASTDeclaration decl = catchHandler.getDeclaration();
IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) decl; if (decl instanceof IASTSimpleDeclaration) {
IASTDeclSpecifier spec = sdecl.getDeclSpecifier(); IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) decl;
if (!usesReference(catchHandler)) { IASTDeclSpecifier spec = sdecl.getDeclSpecifier();
if (spec instanceof ICPPASTNamedTypeSpecifier) { if (!usesReference(catchHandler)) {
IBinding typeName = ((ICPPASTNamedTypeSpecifier) spec).getName().getBinding(); if (spec instanceof ICPPASTNamedTypeSpecifier) {
// unwind typedef chain IBinding typeName = ((ICPPASTNamedTypeSpecifier) spec).getName().getBinding();
while (typeName instanceof ITypedef) { // unwind typedef chain
IType t = ((ITypedef) typeName).getType(); while (typeName instanceof ITypedef) {
if (t instanceof IBasicType) continue next; IType t = ((ITypedef) typeName).getType();
if (t instanceof IBinding) typeName = (IBinding) t; if (t instanceof IBasicType)
else break; continue next;
if (t instanceof IBinding)
typeName = (IBinding) t;
else
break;
}
reportProblem(ER_ID, decl);
} }
reportProblem(ER_ID, decl);
} }
} }
} }
} catch (Exception e) {
CodanCheckersActivator.log(e);
} }
return PROCESS_SKIP; return PROCESS_SKIP;
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
@ -92,13 +96,13 @@ public class CatchUsesReference extends AbstractIndexAstChecker {
IASTPointerOperator[] pointerOperators = d.getPointerOperators(); IASTPointerOperator[] pointerOperators = d.getPointerOperators();
for (int j = 0; j < pointerOperators.length; j++) { for (int j = 0; j < pointerOperators.length; j++) {
IASTPointerOperator po = pointerOperators[j]; IASTPointerOperator po = pointerOperators[j];
if (po instanceof ICPPASTReferenceOperator) { return true; } if (po instanceof ICPPASTReferenceOperator) {
return true;
}
} }
} }
} }
return false; return false;
} }
} }
} }