From e35f5131df28786841f5e09d9982b912bd3469d0 Mon Sep 17 00:00:00 2001 From: Elliott Baron Date: Mon, 21 Sep 2009 15:09:03 -0400 Subject: Created .extension plugin with my modifications. Initial use of CFG, pulled in from PTP. Fixed a bug in CFG printing in PTP plugin. * org.eclipse.cdt.codan.checkers: Moved changes to codan.extension. * org.eclipse.cdt.codan.extension: New plugin. * org.eclipse.ptp.pldt.mpi.analysis.cdt: Small bugfix to block printing. --- .../codan/checkers/CloseOpenedFilesChecker.java | 121 --------------------- 1 file changed, 121 deletions(-) delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CloseOpenedFilesChecker.java (limited to 'org.eclipse.cdt.codan.checkers/src') diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CloseOpenedFilesChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CloseOpenedFilesChecker.java deleted file mode 100644 index 5563ad9..0000000 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CloseOpenedFilesChecker.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Elliott Baron - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Elliott Baron - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.codan.checkers; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; -import org.eclipse.cdt.core.dom.ast.IASTDeclarator; -import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; -import org.eclipse.cdt.core.dom.ast.IASTIdExpression; -import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; -import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.IBinding; - -public class CloseOpenedFilesChecker extends AbstractIndexAstChecker { - private static final String ERR_ID = Activator.PLUGIN_ID + ".CloseOpenedFilesProblem"; - - public void processAst(IASTTranslationUnit ast) { - // traverse the AST using the visitor pattern - CloseOpenedFilesVisitor visitor = new CloseOpenedFilesVisitor(); - ast.accept(visitor); - } - - - private void reportProblem(IASTName closeFD) { - String message = MessageFormat.format("File descriptor \"{0}\" has not been opened", closeFD.toString()); - reportProblem(ERR_ID, closeFD, message); - } - - - class CloseOpenedFilesVisitor extends ASTVisitor { - - public static final String OPEN = "open"; - public static final String CLOSE = "close"; - - private List openedFDs; - - public CloseOpenedFilesVisitor() { - openedFDs = new ArrayList(); - shouldVisitExpressions = true; - } - - @Override - public int visit(IASTExpression expression) { - if (expression instanceof IASTFunctionCallExpression) { - IASTFunctionCallExpression callExpression = (IASTFunctionCallExpression) expression; - IASTExpression funcName = callExpression.getFunctionNameExpression(); - if (funcName instanceof IASTIdExpression) { - IASTName name = ((IASTIdExpression) funcName).getName(); - String simpleName = String.valueOf(name.getSimpleID()); - if (simpleName.equals(OPEN)) { - IASTNode parent = callExpression.getParent(); - // Handle initialization in declaration - if (parent instanceof IASTInitializerExpression) { - parent = parent.getParent(); - if (parent instanceof IASTDeclarator) { - openedFDs.add(((IASTDeclarator) parent).getName()); - } - } - // Assignment after declaration - else if (parent instanceof IASTBinaryExpression) { - IASTExpression op2 = ((IASTBinaryExpression) parent).getOperand2(); - int operator = ((IASTBinaryExpression) parent).getOperator(); - if (callExpression.equals(op2) && operator == IASTBinaryExpression.op_assign) { - IASTExpression op1 = ((IASTBinaryExpression) parent).getOperand1(); - if (op1 instanceof IASTIdExpression) { - openedFDs.add(((IASTIdExpression) op1).getName()); - } - } - } - } - else if (simpleName.equals(CLOSE)) { - IASTExpression paramExpression = callExpression.getParameterExpression(); - if (paramExpression instanceof IASTIdExpression) { - IASTName fd = ((IASTIdExpression) paramExpression).getName(); - // Add only if no matching opened FD - boolean match = false; - for (int i = 0; !match && i < openedFDs.size(); i++) { - IASTName opened = openedFDs.get(i); - match = matchingFileDescriptors(fd, opened); - } - - if (!match) { - reportProblem(fd); - } - } - } - } - - return PROCESS_SKIP; - } - else { - return PROCESS_CONTINUE; - } - } - - private boolean matchingFileDescriptors(IASTName closeFD, IASTName openFD) { - // FIXME elaborate - IBinding closeBinding = closeFD.getBinding(); - IBinding openBinding = openFD.getBinding(); - - return openBinding != null && closeBinding != null && openBinding.equals(closeBinding); - } - } - -} -- cgit