KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > frontend > AbstractPass


1 package polyglot.frontend;
2
3 /** The base class for most passes. */
4 public abstract class AbstractPass implements Pass
5 {
6     /** The id of the pass. */
7     protected Pass.ID id;
8
9     /**
10      * If the pass is running, the time that the pass started.
11      * If the pass has completed, the time in ms the pass took to run,
12      * excluding spawned passes.
13      */

14     protected long exclusive_time = 0;
15
16     /**
17      * If the pass is running, the time that the pass started.
18      * If the pass has completed, the time in ms the pass took to run,
19      * including spawned passes.
20      */

21     protected long inclusive_time = 0;
22
23     public AbstractPass(Pass.ID id) {
24         this.id = id;
25     }
26
27     /** The id of the pass. */
28     public Pass.ID id() {
29         return id;
30     }
31
32     /** The human-readable name of the pass. */
33     public String JavaDoc name() {
34         return id.toString();
35     }
36
37     /** Run the pass, returning true on success. */
38     public abstract boolean run();
39
40     /** Start or stop the pass timer. */
41     public void toggleTimers(boolean exclusive_only) {
42         // How this works:
43
// reset: time = 0
44
// start: time = T - 0 = T
45
// stop: time = T' - T = delta1
46
// start: time = T'' - delta1 = T'' - T' + T
47
// stop: time = T''' - (T'' - T' + T) = delta2 + delta1
48
if (! exclusive_only) {
49             inclusive_time = System.currentTimeMillis() - inclusive_time;
50         }
51         exclusive_time = System.currentTimeMillis() - exclusive_time;
52     }
53
54     /** Reset the pass timer. */
55     public void resetTimers() {
56         inclusive_time = 0;
57         exclusive_time = 0;
58     }
59
60     /** Return the time in ms taken to run the pass, excluding the time in
61      * spawned passes */

62     public long exclusiveTime() {
63         return exclusive_time;
64     }
65
66     /** Return the time in ms taken to run the pass, including the time in
67      * spawned passes */

68     public long inclusiveTime() {
69         return inclusive_time;
70     }
71
72     public String JavaDoc toString() {
73     return getClass().getName() + ":" + id;
74     }
75 }
76
Popular Tags