KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > coffi > BBQ


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997 Clark Verbrugge
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27
28
29
30
31
32 package soot.coffi;
33
34 import java.util.ArrayList JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.NoSuchElementException JavaDoc;
37
38 /** A queue of BasicBlocks.
39  * @author Clark Verbrugge
40  * @see BasicBlock
41  */

42 final class BBQ {
43
44    private ArrayList JavaDoc q = new ArrayList JavaDoc();
45
46    /** Adds a block to the end of the queue, but only if its <i>inq</i> flag is false.
47     * @param b the Basic Block in question.
48     * @see BasicBlock#inq
49     */

50    public void push(BasicBlock b) {
51       if (b.inq!=true) { // ensure only in queue once...
52
b.inq = true;
53          q.add(b);
54       }
55    }
56
57    /** Removes the first block in the queue (and resets its <i>inq</i> flag).
58     * @return BasicBlock which was first.
59     * @exception java.util.NoSuchElementException if the queue is empty.
60     * @see BasicBlock#inq
61     */

62    public BasicBlock pull() throws NoSuchElementException JavaDoc {
63       if(q.size()==0)
64          throw new
65             NoSuchElementException JavaDoc("Pull from empty BBQ");
66       BasicBlock b = (BasicBlock)(q.get(0));
67       q.remove(0);
68       b.inq = false;
69       return b;
70    }
71
72    /** Answers whether a block is in the queue or not.
73     * @param BasicBlock in question.
74     * @return <i>true</i> if it is, <i>false</i> if it ain't.
75     * @see BasicBlock#inq
76     */

77    public boolean contains(BasicBlock b) { return b.inq; }
78    /** Answers the size of the queue.
79     * @return size of the queue.
80     */

81    public int size() { return q.size(); }
82    /** Answers whether the queue is empty
83     * @return <i>true</i> if it is, <i>false</i> if it ain't.
84     */

85    public boolean isEmpty() { return q.isEmpty(); }
86
87    /** Empties the queue of all blocks (and resets their <i>inq</i> flags). */
88    public void clear() {
89       BasicBlock b;
90       for (Iterator JavaDoc e = q.iterator();e.hasNext();) {
91          b = (BasicBlock)(e.next());
92          b.inq = false;
93       }
94       q.clear();
95    }
96 }
97
98
Popular Tags