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. --- org.eclipse.cdt.codan.checkers/plugin.xml | 11 - .../codan/checkers/CloseOpenedFilesChecker.java | 121 --- org.eclipse.cdt.codan.core/.settings/CVS/Entries | 1 + org.eclipse.cdt.codan.core/META-INF/CVS/Entries | 1 + org.eclipse.cdt.codan.core/schema/CVS/Entries | 1 + .../org/eclipse/cdt/codan/core/model/CVS/Entries | 1 + .../cdt/codan/internal/core/model/CVS/Entries | 1 + org.eclipse.cdt.codan.extension/.classpath | 7 + org.eclipse.cdt.codan.extension/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 8 + .../META-INF/MANIFEST.MF | 17 + org.eclipse.cdt.codan.extension/build.properties | 5 + org.eclipse.cdt.codan.extension/plugin.xml | 19 + .../org/eclipse/cdt/codan/extension/Activator.java | 72 ++ .../codan/extension/CloseOpenedFilesChecker.java | 157 ++++ org.eclipse.ptp.pldt.mpi.analysis.cdt/.classpath | 7 + org.eclipse.ptp.pldt.mpi.analysis.cdt/.project | 28 + org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Entries | 7 + .../CVS/Repository | 1 + org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Root | 1 + org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Tag | 1 + org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Template | 0 .../META-INF/CVS/Entries | 1 + .../META-INF/CVS/Repository | 1 + .../META-INF/CVS/Root | 1 + .../META-INF/CVS/Tag | 1 + .../META-INF/MANIFEST.MF | 15 + .../build.properties | 5 + .../plugin.properties | 11 + .../src/CVS/Entries | 1 + .../src/CVS/Repository | 1 + org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Root | 1 + org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Tag | 1 + .../src/org/CVS/Entries | 1 + .../src/org/CVS/Repository | 1 + .../src/org/CVS/Root | 1 + .../src/org/CVS/Tag | 1 + .../src/org/eclipse/CVS/Entries | 1 + .../src/org/eclipse/CVS/Repository | 1 + .../src/org/eclipse/CVS/Root | 1 + .../src/org/eclipse/CVS/Tag | 1 + .../src/org/eclipse/ptp/CVS/Entries | 1 + .../src/org/eclipse/ptp/CVS/Repository | 1 + .../src/org/eclipse/ptp/CVS/Root | 1 + .../src/org/eclipse/ptp/CVS/Tag | 1 + .../src/org/eclipse/ptp/pldt/CVS/Entries | 1 + .../src/org/eclipse/ptp/pldt/CVS/Repository | 1 + .../src/org/eclipse/ptp/pldt/CVS/Root | 1 + .../src/org/eclipse/ptp/pldt/CVS/Tag | 1 + .../src/org/eclipse/ptp/pldt/mpi/CVS/Entries | 1 + .../src/org/eclipse/ptp/pldt/mpi/CVS/Repository | 1 + .../src/org/eclipse/ptp/pldt/mpi/CVS/Root | 1 + .../src/org/eclipse/ptp/pldt/mpi/CVS/Tag | 1 + .../org/eclipse/ptp/pldt/mpi/analysis/CVS/Entries | 1 + .../eclipse/ptp/pldt/mpi/analysis/CVS/Repository | 1 + .../src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Root | 1 + .../src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Tag | 1 + .../ptp/pldt/mpi/analysis/cdt/Activator.java | 61 ++ .../eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Entries | 2 + .../ptp/pldt/mpi/analysis/cdt/CVS/Repository | 1 + .../org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Root | 1 + .../org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Tag | 1 + .../ptp/pldt/mpi/analysis/cdt/graphs/CVS/Entries | 6 + .../pldt/mpi/analysis/cdt/graphs/CVS/Repository | 1 + .../ptp/pldt/mpi/analysis/cdt/graphs/CVS/Root | 1 + .../ptp/pldt/mpi/analysis/cdt/graphs/CVS/Tag | 1 + .../pldt/mpi/analysis/cdt/graphs/GraphCreator.java | 192 +++++ .../ptp/pldt/mpi/analysis/cdt/graphs/IBlock.java | 145 ++++ .../pldt/mpi/analysis/cdt/graphs/ICallGraph.java | 88 +++ .../mpi/analysis/cdt/graphs/ICallGraphNode.java | 80 ++ .../mpi/analysis/cdt/graphs/IControlFlowGraph.java | 63 ++ .../pldt/mpi/analysis/cdt/graphs/impl/Block.java | 246 +++++++ .../pldt/mpi/analysis/cdt/graphs/impl/CVS/Entries | 5 + .../mpi/analysis/cdt/graphs/impl/CVS/Repository | 1 + .../ptp/pldt/mpi/analysis/cdt/graphs/impl/CVS/Root | 1 + .../ptp/pldt/mpi/analysis/cdt/graphs/impl/CVS/Tag | 1 + .../mpi/analysis/cdt/graphs/impl/CallGraph.java | 309 ++++++++ .../analysis/cdt/graphs/impl/CallGraphNode.java | 163 ++++ .../analysis/cdt/graphs/impl/ControlFlowGraph.java | 820 +++++++++++++++++++++ .../cdt/graphs/impl/ResourceCollector.java | 155 ++++ 80 files changed, 2770 insertions(+), 132 deletions(-) delete mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CloseOpenedFilesChecker.java create mode 100644 org.eclipse.cdt.codan.extension/.classpath create mode 100644 org.eclipse.cdt.codan.extension/.project create mode 100644 org.eclipse.cdt.codan.extension/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.cdt.codan.extension/META-INF/MANIFEST.MF create mode 100644 org.eclipse.cdt.codan.extension/build.properties create mode 100644 org.eclipse.cdt.codan.extension/plugin.xml create mode 100644 org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/Activator.java create mode 100644 org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/CloseOpenedFilesChecker.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/.classpath create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/.project create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Template create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/MANIFEST.MF create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/build.properties create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/plugin.properties create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/Activator.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/GraphCreator.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/IBlock.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/ICallGraph.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/ICallGraphNode.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/IControlFlowGraph.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/Block.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/CVS/Entries create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/CVS/Repository create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/CVS/Root create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/CVS/Tag create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/CallGraph.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/CallGraphNode.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/ControlFlowGraph.java create mode 100644 org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/ResourceCollector.java diff --git a/org.eclipse.cdt.codan.checkers/plugin.xml b/org.eclipse.cdt.codan.checkers/plugin.xml index 7ba8f3e..e2dac3e 100644 --- a/org.eclipse.cdt.codan.checkers/plugin.xml +++ b/org.eclipse.cdt.codan.checkers/plugin.xml @@ -40,16 +40,5 @@ name="Class has a virtual method and non-virtual destructor"> - - - - 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); - } - } - -} diff --git a/org.eclipse.cdt.codan.core/.settings/CVS/Entries b/org.eclipse.cdt.codan.core/.settings/CVS/Entries index cf3287f..b6cae13 100644 --- a/org.eclipse.cdt.codan.core/.settings/CVS/Entries +++ b/org.eclipse.cdt.codan.core/.settings/CVS/Entries @@ -1 +1,2 @@ /org.eclipse.jdt.core.prefs/1.3/Mon Aug 10 18:31:46 2009// +D diff --git a/org.eclipse.cdt.codan.core/META-INF/CVS/Entries b/org.eclipse.cdt.codan.core/META-INF/CVS/Entries index 3abafa4..86baf3a 100644 --- a/org.eclipse.cdt.codan.core/META-INF/CVS/Entries +++ b/org.eclipse.cdt.codan.core/META-INF/CVS/Entries @@ -1 +1,2 @@ /MANIFEST.MF/1.4/Sat Aug 22 21:16:49 2009// +D diff --git a/org.eclipse.cdt.codan.core/schema/CVS/Entries b/org.eclipse.cdt.codan.core/schema/CVS/Entries index d6ba65d..2905ba5 100644 --- a/org.eclipse.cdt.codan.core/schema/CVS/Entries +++ b/org.eclipse.cdt.codan.core/schema/CVS/Entries @@ -1 +1,2 @@ /checkers.exsd/1.1/Thu Apr 9 12:46:50 2009// +D diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries index 9043127..736d312 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries @@ -14,3 +14,4 @@ /IProblemReporter.java/1.1/Sat Aug 22 21:16:48 2009// /ProblemLocation.java/1.1/Sat Aug 22 21:16:48 2009// /ProblemProfile.java/1.4/Sat Aug 22 21:16:48 2009// +D diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Entries b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Entries index 19054e0..cf1f6cc 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Entries +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Entries @@ -1,3 +1,4 @@ /CodanMarkerProblemReporter.java/1.1/Sat Aug 22 21:16:48 2009// /CodanProblem.java/1.1/Sat Aug 22 21:16:48 2009// /CodanProblemCategory.java/1.1/Sat Aug 22 21:16:48 2009// +D diff --git a/org.eclipse.cdt.codan.extension/.classpath b/org.eclipse.cdt.codan.extension/.classpath new file mode 100644 index 0000000..ad32c83 --- /dev/null +++ b/org.eclipse.cdt.codan.extension/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.cdt.codan.extension/.project b/org.eclipse.cdt.codan.extension/.project new file mode 100644 index 0000000..5300627 --- /dev/null +++ b/org.eclipse.cdt.codan.extension/.project @@ -0,0 +1,28 @@ + + + org.eclipse.cdt.codan.extension + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.cdt.codan.extension/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.cdt.codan.extension/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..d0c24ad --- /dev/null +++ b/org.eclipse.cdt.codan.extension/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Sun Sep 20 15:26:36 EDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.eclipse.cdt.codan.extension/META-INF/MANIFEST.MF b/org.eclipse.cdt.codan.extension/META-INF/MANIFEST.MF new file mode 100644 index 0000000..fde603b --- /dev/null +++ b/org.eclipse.cdt.codan.extension/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Code Analysis Extension +Bundle-SymbolicName: org.eclipse.cdt.codan.extension;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Eclipse +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: org.eclipse.cdt.codan.core, + org.eclipse.cdt.codan.core.model, + org.eclipse.cdt.core.dom, + org.eclipse.cdt.core.dom.ast, + org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs, + org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.impl +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", + org.eclipse.ui;bundle-version="3.5.0", + org.eclipse.core.resources;bundle-version="3.5.0" +Bundle-Activator: org.eclipse.cdt.codan.extension.Activator diff --git a/org.eclipse.cdt.codan.extension/build.properties b/org.eclipse.cdt.codan.extension/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/org.eclipse.cdt.codan.extension/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/org.eclipse.cdt.codan.extension/plugin.xml b/org.eclipse.cdt.codan.extension/plugin.xml new file mode 100644 index 0000000..f0ae36c --- /dev/null +++ b/org.eclipse.cdt.codan.extension/plugin.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + diff --git a/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/Activator.java b/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/Activator.java new file mode 100644 index 0000000..4deea76 --- /dev/null +++ b/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/Activator.java @@ -0,0 +1,72 @@ +package org.eclipse.cdt.codan.extension; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +public class Activator extends AbstractUIPlugin { + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.cdt.codan.extension"; + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * @param e + */ + public static void log(Throwable e) { + getDefault().getLog().log(getStatus(e)); + } + + public static void log(String message) { + getDefault().getLog().log(new Status(Status.ERROR, PLUGIN_ID, message)); + } + + /** + * @param e + * @return + */ + public static IStatus getStatus(Throwable e) { + return new Status(Status.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); + } + +} diff --git a/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/CloseOpenedFilesChecker.java b/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/CloseOpenedFilesChecker.java new file mode 100644 index 0000000..8acdc81 --- /dev/null +++ b/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/CloseOpenedFilesChecker.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * 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.extension; + +import java.io.File; +import java.net.URI; +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.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.GraphCreator; +import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.IBlock; +import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.ICallGraph; +import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.ICallGraphNode; +import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.IControlFlowGraph; +import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.impl.ControlFlowGraph; + +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(); + + GraphCreator creator = new GraphCreator(); + + // Retrieve resource corresponding to this translation unit + String path = ast.getFilePath(); + URI fileURI = new File(path).toURI(); + IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); + IResource[] resources = wsRoot.findFilesForLocationURI(fileURI); + if (resources != null && resources.length > 0) { + IProject proj = resources[0].getProject(); + + // Create call graph for project + ICallGraph cg = creator.createCallGraph(proj); + creator.computeCallGraph(cg); + + // Create control flow graph + ICallGraphNode cgRoot = cg.topEntry(); + IASTStatement fnBody = cgRoot.getFuncDef().getBody(); + IControlFlowGraph cfg = new ControlFlowGraph(fnBody); + cfg.buildCFG(); + cfg.print(); + + 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); + } + } + +} diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/.classpath b/org.eclipse.ptp.pldt.mpi.analysis.cdt/.classpath new file mode 100644 index 0000000..751c8f2 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/.project b/org.eclipse.ptp.pldt.mpi.analysis.cdt/.project new file mode 100644 index 0000000..6afb3da --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/.project @@ -0,0 +1,28 @@ + + + org.eclipse.ptp.pldt.mpi.analysis.cdt + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Entries new file mode 100644 index 0000000..38a8b64 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Entries @@ -0,0 +1,7 @@ +/.classpath/1.1/Thu Apr 19 17:00:12 2007//TPTP_2_1 +/.project/1.1/Thu Apr 19 17:00:12 2007//TPTP_2_1 +D/META-INF//// +D/bin//// +/build.properties/1.2/Mon Oct 20 15:58:06 2008//TPTP_2_1 +/plugin.properties/1.1/Mon Oct 20 15:58:06 2008//TPTP_2_1 +D/src//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Repository new file mode 100644 index 0000000..5bc7e9f --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Tag new file mode 100644 index 0000000..a1f2841 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Tag @@ -0,0 +1 @@ +NPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Template b/org.eclipse.ptp.pldt.mpi.analysis.cdt/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Entries new file mode 100644 index 0000000..486ee66 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Entries @@ -0,0 +1 @@ +/MANIFEST.MF/1.6/Mon Oct 20 15:58:07 2008//TPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Repository new file mode 100644 index 0000000..a708b66 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Tag new file mode 100644 index 0000000..a1f2841 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/CVS/Tag @@ -0,0 +1 @@ +NPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/MANIFEST.MF b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c5a0be1 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.ptp.pldt.mpi.analysis.cdt +Bundle-Version: 2.1.0.qualifier +Bundle-Activator: org.eclipse.ptp.pldt.mpi.analysis.cdt.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.cdt.core, + org.eclipse.core.resources +Eclipse-LazyStart: true +Export-Package: org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs, + org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.impl +Bundle-Vendor: %pluginProvider diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/build.properties b/org.eclipse.ptp.pldt.mpi.analysis.cdt/build.properties new file mode 100644 index 0000000..aa1a008 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/plugin.properties b/org.eclipse.ptp.pldt.mpi.analysis.cdt/plugin.properties new file mode 100644 index 0000000..c1fb5bb --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/plugin.properties @@ -0,0 +1,11 @@ +############################################################################### +# Copyright (c) 2008 IBM Corporation. +# 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 +# +############################################################################### + +pluginName=PTP Parallel Language Development Tools CDT Analysis +pluginProvider=Eclipse.org diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Entries new file mode 100644 index 0000000..381094d --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Entries @@ -0,0 +1 @@ +D/org//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Repository new file mode 100644 index 0000000..e8479bc --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/src diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Tag new file mode 100644 index 0000000..09d5efe --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/CVS/Tag @@ -0,0 +1 @@ +TPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Entries new file mode 100644 index 0000000..0f148f8 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Entries @@ -0,0 +1 @@ +D/eclipse//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Repository new file mode 100644 index 0000000..c77b2d4 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Tag new file mode 100644 index 0000000..09d5efe --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/CVS/Tag @@ -0,0 +1 @@ +TPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Entries new file mode 100644 index 0000000..8e4d5af --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Entries @@ -0,0 +1 @@ +D/ptp//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Repository new file mode 100644 index 0000000..ca52c3f --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Tag new file mode 100644 index 0000000..09d5efe --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/CVS/Tag @@ -0,0 +1 @@ +TPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Entries new file mode 100644 index 0000000..605afd6 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Entries @@ -0,0 +1 @@ +D/pldt//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Repository new file mode 100644 index 0000000..58197ca --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Tag new file mode 100644 index 0000000..09d5efe --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/CVS/Tag @@ -0,0 +1 @@ +TPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Entries new file mode 100644 index 0000000..240016f --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Entries @@ -0,0 +1 @@ +D/mpi//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Repository new file mode 100644 index 0000000..d12bfd0 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Tag new file mode 100644 index 0000000..09d5efe --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/CVS/Tag @@ -0,0 +1 @@ +TPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Entries new file mode 100644 index 0000000..2aa317c --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Entries @@ -0,0 +1 @@ +D/analysis//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Repository new file mode 100644 index 0000000..fa76657 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Tag new file mode 100644 index 0000000..09d5efe --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/CVS/Tag @@ -0,0 +1 @@ +TPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Entries new file mode 100644 index 0000000..e524915 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Entries @@ -0,0 +1 @@ +D/cdt//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Repository new file mode 100644 index 0000000..85d81f6 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Tag new file mode 100644 index 0000000..09d5efe --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/CVS/Tag @@ -0,0 +1 @@ +TPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/Activator.java b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/Activator.java new file mode 100644 index 0000000..7b400e9 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/Activator.java @@ -0,0 +1,61 @@ +/********************************************************************** + * Copyright (c) 2007 IBM Corporation. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ptp.pldt.mpi.analysis.cdt; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.ptp.pldt.mpi.analysis.cdt"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Entries new file mode 100644 index 0000000..efc3a2b --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Entries @@ -0,0 +1,2 @@ +/Activator.java/1.1/Thu Apr 19 17:00:13 2007//TPTP_2_1 +D/graphs//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Repository new file mode 100644 index 0000000..0f016ee --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Tag new file mode 100644 index 0000000..a1f2841 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/CVS/Tag @@ -0,0 +1 @@ +NPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Entries b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Entries new file mode 100644 index 0000000..6790d78 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Entries @@ -0,0 +1,6 @@ +/GraphCreator.java/1.2/Thu Mar 13 04:04:38 2008//TPTP_2_1 +/IBlock.java/1.3/Sat Mar 15 04:08:30 2008//TPTP_2_1 +/ICallGraph.java/1.1/Thu Apr 19 17:00:12 2007//TPTP_2_1 +/ICallGraphNode.java/1.1/Thu Apr 19 17:00:12 2007//TPTP_2_1 +/IControlFlowGraph.java/1.1/Thu Apr 19 17:00:12 2007//TPTP_2_1 +D/impl//// diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Repository b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Repository new file mode 100644 index 0000000..1167f21 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Repository @@ -0,0 +1 @@ +org.eclipse.ptp/tools/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Root b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Root new file mode 100644 index 0000000..04efa23 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@dev.eclipse.org:/cvsroot/tools diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Tag b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Tag new file mode 100644 index 0000000..a1f2841 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/CVS/Tag @@ -0,0 +1 @@ +NPTP_2_1 diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/GraphCreator.java b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/GraphCreator.java new file mode 100644 index 0000000..1da923e --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/GraphCreator.java @@ -0,0 +1,192 @@ +/********************************************************************** + * Copyright (c) 2008 IBM Corporation. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.impl.CallGraph; +import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.impl.ResourceCollector; + +/** + * Convenience class for constructing various graphs from C source files + * + * @author Beth Tibbitts + * + */ +public class GraphCreator { + /** + * Convenience method for initializing and computing the call graph in one place. + *
This is done in two steps: + *
(1) initCallGraph(): initialize call graph with function information + *
(2) computeCallGraph(): compute caller/callee/recursive etc. info on the graph + * @param resource + * @return + */ + public ICallGraph createCallGraph(IResource resource) { + ICallGraph cg = initCallGraph(resource); + computeCallGraph(cg); + return cg; + + } + /** + * Create call graph structure from resources (C source files) but caller/callee + * calculations are not done yet; will descend to children of a container if + * called with a folder or project argument. + * @param resource + * @return call graph initialized with basic function information + */ + public ICallGraph initCallGraph(IResource resource) { + ICallGraph callGraph = new CallGraph(); + callGraph = initCallGraph(resource, callGraph); + return callGraph; + + } + /** + * Add information to an existing call graph. + *
Will descend to children if this is a container (folder or project) + * + * @param resource contains source file(s) whose functions will be found and added to the call graph. + * @param callGraph + * @return + */ + public ICallGraph initCallGraph(IResource resource, ICallGraph callGraph) { + boolean foundError = resourceCollector(resource, callGraph); + if(foundError) { + System.out.println("Error occurred during call graph creation."); + } + return callGraph; + } + /** + * Create an empty call graph, ready to fill with function information + * later with subsequent calls to initCallGraph(resource, callGraph) + * @return + */ + public ICallGraph initCallGraph() { + return new CallGraph(); + } + /** + * Calculate the caller/callee and recursive properties of the call graph + * @return + */ + public ICallGraph computeCallGraph(ICallGraph callGraph) { + callGraph.buildCG(); + return callGraph; + } + + + /** + * Run analysis ("Resource collector") on a resource (e.g. File or Folder) + * and add the function information found in/under the given resource (file or container) + * to the given call graph + *
Will descend to members of folder + * + * @param resource + * the resource selected by the user + * @param callGraph the call graph to which the information will be appended + * @return + */ + public boolean resourceCollector(IResource resource, ICallGraph callGraph) { + + boolean foundError = false; + + // if it's a C file, collect info in the call graph for this file + if (resource instanceof IFile) { + IFile file = (IFile) resource; + String filename = file.getName(); + if (filename.endsWith(".c")) { + ResourceCollector rc = new ResourceCollector(callGraph, file); + rc.run(); + } + // if it's a container, run resourceCollector on each of its members + } else if (resource instanceof IContainer) { + IContainer container = (IContainer) resource; + try { + IResource[] mems = container.members(); + for (int i = 0; i < mems.length; i++) { + boolean err = resourceCollector(mems[i], callGraph); + foundError = foundError || err; + } + } catch (CoreException e) { + e.printStackTrace(); + foundError=true; + } + } else { + // ????? + String name = ""; + if (resource instanceof IResource) { + IResource res = (IResource) resource; + // name=res.getName(); // simple filename only, no path info + IPath path = res.getProjectRelativePath(); + name = path.toString(); + } + System.out.println("Cancelled by User, aborting analysis on subsequent files... " + + name); + } + + return foundError; + } + /** + * Print a call graph structure + * @param cg the call graph to print + */ + public void showCallGraph(ICallGraph cg) { + System.out.println("Show call graph"); + List nodes = cg.getAllNodes(); + for (Iterator iterator = nodes.iterator(); iterator.hasNext();) { + ICallGraphNode cgNode = iterator.next(); + printCGNode(cgNode, ""); + //System.out.println(" callers: ==>"); + + for (Iterator iterator2 = cgNode.getCallers().iterator(); iterator2.hasNext();) { + ICallGraphNode caller = iterator2.next(); + printCGNode(caller," caller: "); + } + //System.out.println(" <== callees:"); + for (Iterator iterator3 = cgNode.getCallees().iterator(); iterator3.hasNext();) { + ICallGraphNode callee = iterator3.next(); + printCGNode(callee," callee: "); + + } + System.out.println(" "); + + } + List>cycles = cg.getCycles(); + System.out.println("Recursive cycles:"); + for (List cycle : cycles) { + System.out.println("Cycle: "); + for (Iterator iterator = cycle.iterator(); iterator.hasNext();) { + ICallGraphNode fn = iterator.next(); + System.out.print(" "+fn.getFuncName()); + + } + System.out.println(" \n"); + } + List vars= cg.getEnv(); + System.out.println("Global variables:"); + for (Iterator varit= vars.iterator(); varit.hasNext();) { + String var = varit.next(); + System.out.println("Global var: "+var); + + } + + } + public void printCGNode(ICallGraphNode cgNode, String prefix) { + System.out.println(prefix+" "+cgNode.getFuncName()+" in "+cgNode.getFileName()); + cgNode.getCFG(); + } +} diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/IBlock.java b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/IBlock.java new file mode 100644 index 0000000..f61b879 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/IBlock.java @@ -0,0 +1,145 @@ +/********************************************************************** + * Copyright (c) 2007 IBM Corporation. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs; + +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * A "Block" contains either a single statement or a predicate expression, + * and it can be entered only at the beginning and exited only at the end. + * + * @author Yuan Zhang + * + */ +public interface IBlock { + /** + * @return the unique ID + */ + public int getID(); + + /** + * @return the list of successors in the control flow graph + */ + public List getSuccs(); + + /** + * @return the list of predecessors in the control flow graph + */ + public List getPreds(); + + /** + * @return the next block in CFG according to the topological + * order (top-down order) + */ + public IBlock topNext(); + /** + * @return the next block in CFG according to the topological + * order (top-down order) + */ + public IBlock getTopNext(); + /** + * Set the next block in CFG according to the topological + * order (top-down order) + */ + public void setTopNext(IBlock b); + + /** + * Get the next block in CFG according to the reverse + * topological order (bottom-up order) + */ + public IBlock botNext(); + /** + * Get the next block in CFG according to the reverse + * topological order (bottom-up order) + */ + public IBlock getBotNext(); + /** + * Set the next block in CFG according to the reverse + * topological order (bottom-up order) + */ + public void setBotNext(IBlock b); + + /** + * @return the content (a predicate expression or a statement) + */ + public IASTNode getContent(); + + /** + * Search to determine if a block contains an expression + * @return true if this block contains expression expr + * which is the predicate of statement , false otherwise. + */ + public boolean search(IASTExpression expr, IASTStatement parent); + /** + * Search to determine if a block contains a statement + * @return true if this block contains statement stmt, + * false otherwise. + */ + public boolean search(IASTStatement stmt); + /** + * Search to determine if a block contains a given label + * @return true if this block contains label, false otherwise + */ + public boolean search(IASTName label); + + /** + * Get Dominators
+ * Block A dominates another block B if every path from the entry that + * reaches block B has to pass through block A. + * The entry block dominates all blocks. + * @return list of dominator IBlocks + */ + public List getDOM(); + /** + * Set dominators + * @param set list of dominators + */ + public void setDOM(List set); + + /** + * Get post-dominators
+ * Block A postdominates block B if every path from B to the exit has to pass through block A. + * The exit block postdominates all blocks. + * + * @return list of post-dominator IBlocks + */ + public List getPDOM(); + /** + * set post-dominators + * @param set + */ + public void setPDOM(List set); + + /** + * An attribute (identified by its name) of a block could be any + * property of it. + * @param name + * @param attr + */ + public void setAttr(String name, Object attr); + /** + * Get an attribute of a block + * @param name + * @return + */ + public Object getAttr(String name); + + /** + * Print IBlock information, include id, content, and successors + */ + public void print(); +} \ No newline at end of file diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/ICallGraph.java b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/ICallGraph.java new file mode 100644 index 0000000..60a0391 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/ICallGraph.java @@ -0,0 +1,88 @@ +/********************************************************************** + * Copyright (c) 2007 IBM Corporation. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs; + +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; + +/** + * A call graph is a directed graph which represents the calling relation + * among subroutines in a program. In CDT, it is partially determined + * by static analysis. + * + * @author Yuan Zhang + * + */ +public interface ICallGraph { + + /** + * @return all functions in the call graph + */ + public List getAllNodes(); + + /** + * @return all global variables + */ + public List getEnv(); + + /** + * @return one root function. A root function is never called by + * other functions. There may be multiple root functions in a call + * graph. + */ + public ICallGraphNode topEntry(); + public void setTopEntry(ICallGraphNode node); + + /** + * @return one leaf function. A leaf function never calls any other + * functions. There may be multiple leaf functions in a call graph. + */ + public ICallGraphNode botEntry(); + public void setBotEntry(ICallGraphNode node); + + /** + * @return list of recursive function calls + */ + public List> getCycles(); + + /** + * Search for a function according to its filename and function name. + * @param fileName + * @param funcName + * @return its call graph node if it is found; null otherwise. + */ + public ICallGraphNode getNode(String fileName, String funcName); + + /** + * Search for a function according to its declaration. + * @param fdef + * @return its call graph node if it is found; null otherwise. + */ + public ICallGraphNode getNode(IASTFunctionDefinition fdef); + + /** + * Add a function node to the call graph. Its calling relation + * is not constructed yet. + * @param node + */ + public void addNode(ICallGraphNode node); + + /** + * Build the calling relations. This method is not reponsible for + * collecting functions in a program. + */ + public void buildCG(); + + public void print(); + +} diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/ICallGraphNode.java b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/ICallGraphNode.java new file mode 100644 index 0000000..3574662 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/ICallGraphNode.java @@ -0,0 +1,80 @@ +/********************************************************************** + * Copyright (c) 2007 IBM Corporation. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs; + +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.core.resources.IResource; + +/** + * A call graph node corresponds to a user-defined function. + * + * @author Yuan Zhang + * + */ +public interface ICallGraphNode { + + /** + * @return the function name + */ + public String getFuncName(); + + /** + * @return the enclosing file name + */ + public String getFileName(); + + public IResource getResource(); + + /** + * @return the function declaration + */ + public IASTFunctionDefinition getFuncDef(); + + /** + * @return the set of functions that call this function + */ + public List getCallers(); + public void addCaller(ICallGraphNode caller); + + /** + * @return the set of functions that are called by this function + */ + public List getCallees(); + public void addCallee(ICallGraphNode callee); + + /** + * @return the control flow graph of this function + */ + public IControlFlowGraph getCFG(); + public void setCFG(IControlFlowGraph cfg); + + /** + * @return the next function according to the topological order + */ + public ICallGraphNode topNext(); + public void setTopNext(ICallGraphNode node); + + /** + * @return the next function according to the reverse topological order + */ + public ICallGraphNode botNext(); + public void setBotNext(ICallGraphNode node); + + public void setAttr(String name, Object attr); + public Object getAttr(String name); + public void removeAttr(String name); + + public void setRecursive(boolean val); + public boolean isRecursive(); +} diff --git a/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/IControlFlowGraph.java b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/IControlFlowGraph.java new file mode 100644 index 0000000..ecc4449 --- /dev/null +++ b/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/IControlFlowGraph.java @@ -0,0 +1,63 @@ +/********************************************************************** + * Copyright (c) 2007 IBM Corporation. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * A control flow graph is directed graph. Each node is a block, and + * each edge represents the jump in the control flow. + * + * @author Yuan Zhang + * + */ + +public interface IControlFlowGraph { + + /** + * @return the entry block + */ + public IBlock getEntry(); + + /** + * @return the exit block + */ + public IBlock getExit(); + + + /** Search for the block which contains the statement + */ + public IBlock getBlock(IASTStatement stmt); + /** + * Search for the block which contains the condition expression + * , and is the predicate of statement + * @return + */ + public IBlock getBlock(IASTExpression expr, IASTStatement parent); + + /** + * Search for the block which contains the