001: /*
002: * Bytecode Analysis Framework
003: * Copyright (C) 2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba;
021:
022: import org.apache.bcel.classfile.Method;
023: import org.apache.bcel.generic.InstructionHandle;
024:
025: public class ReturnPathAnalysis extends
026: ForwardDataflowAnalysis<ReturnPath> implements EdgeTypes {
027: public ReturnPathAnalysis(DepthFirstSearch dfs) {
028: super (dfs);
029: }
030:
031: public ReturnPath createFact() {
032: return new ReturnPath(ReturnPath.TOP);
033: }
034:
035: public void copy(ReturnPath source, ReturnPath dest) {
036: dest.copyFrom(source);
037: }
038:
039: public void initEntryFact(ReturnPath fact) {
040: fact.setKind(ReturnPath.RETURNS);
041: }
042:
043: public void makeFactTop(ReturnPath fact) {
044: fact.setKind(ReturnPath.TOP);
045: }
046:
047: public boolean isTop(ReturnPath fact) {
048: return fact.getKind() == ReturnPath.TOP;
049: }
050:
051: public boolean same(ReturnPath fact1, ReturnPath fact2) {
052: return fact1.sameAs(fact2);
053: }
054:
055: @Override
056: public void transferInstruction(InstructionHandle handle,
057: BasicBlock basicBlock, ReturnPath fact)
058: throws DataflowAnalysisException {
059: // Nothing to do
060: }
061:
062: @Override
063: public boolean isFactValid(ReturnPath fact) {
064: return true;
065: }
066:
067: public void meetInto(ReturnPath fact, Edge edge, ReturnPath result)
068: throws DataflowAnalysisException {
069: switch (edge.getType()) {
070: case UNHANDLED_EXCEPTION_EDGE:
071: fact = new ReturnPath(ReturnPath.UE);
072: break;
073: case EXIT_EDGE:
074: fact = new ReturnPath(ReturnPath.EXIT);
075: break;
076: }
077:
078: result.mergeWith(fact);
079: }
080:
081: public static void main(String[] argv) throws Exception {
082: if (argv.length != 1) {
083: System.err.println("Usage: "
084: + ReturnPathAnalysis.class.getName()
085: + " <classfile>");
086: System.exit(1);
087: }
088:
089: DataflowTestDriver<ReturnPath, ReturnPathAnalysis> driver = new DataflowTestDriver<ReturnPath, ReturnPathAnalysis>() {
090: @Override
091: public Dataflow<ReturnPath, ReturnPathAnalysis> createDataflow(
092: ClassContext classContext, Method method)
093: throws CFGBuilderException,
094: DataflowAnalysisException {
095: return classContext.getReturnPathDataflow(method);
096: }
097: };
098:
099: driver.execute(argv[0]);
100: }
101: }
102:
103: // vim:ts=4
|