01: /*
02: * Bytecode Analysis Framework
03: * Copyright (C) 2003,2004 University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs.ba;
21:
22: import java.util.Comparator;
23:
24: /**
25: * A BlockOrder for visiting the blocks of a CFG in
26: * the order they would be visited in a depth first search
27: * of the reversed CFG. This is the most efficient visitation
28: * order for backwards dataflow analyses.
29: *
30: * @see BlockOrder
31: * @see ReverseDepthFirstSearch
32: * @see CFG
33: * @see BasicBlock
34: */
35: public class ReverseDFSOrder extends AbstractBlockOrder {
36: public ReverseDepthFirstSearch rdfs;
37: public DepthFirstSearch dfs;
38:
39: private static class ReverseDFSComparator implements
40: Comparator<BasicBlock> {
41: public ReverseDepthFirstSearch rdfs;
42: public DepthFirstSearch dfs;
43:
44: public ReverseDFSComparator(ReverseDepthFirstSearch rdfs,
45: DepthFirstSearch dfs) {
46: if (rdfs == null)
47: throw new IllegalArgumentException();
48: this .rdfs = rdfs;
49: if (dfs == null)
50: throw new IllegalArgumentException();
51: this .dfs = dfs;
52: }
53:
54: public int compare(BasicBlock a, BasicBlock b) {
55: return dfs.getFinishTime(a) - dfs.getFinishTime(b);
56: }
57: }
58:
59: /**
60: * Constructor.
61: *
62: * @param cfg the CFG
63: * @param rdfs the ReverseDepthFirstSearch of the CFG
64: * @param dfs TODO
65: */
66: public ReverseDFSOrder(CFG cfg, ReverseDepthFirstSearch rdfs,
67: DepthFirstSearch dfs) {
68: super (cfg, new ReverseDFSComparator(rdfs, dfs));
69: this .rdfs = rdfs;
70: this .dfs = dfs;
71: }
72: }
73:
74: // vim:ts=4
|