KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > frontend > InnerJob


1 package polyglot.frontend;
2
3 import polyglot.ast.*;
4 import polyglot.types.*;
5 import polyglot.util.*;
6
7 import java.util.*;
8
9 /**
10  * An <code>InnerJob</code> encapsulates work done by the compiler for a
11  * nested class. In general <code>InnerJob</code>s are transient, in that they
12  * are not added to the worklist. An <code>InnerJob</code> will typically run
13  * only a few passes at a time.
14  */

15 public class InnerJob extends Job
16 {
17     /**
18      * The job that this InnerJob was spawned by.
19      */

20     protected Job outer;
21     
22     /**
23      * The context in which this Job was spawned.
24      */

25     protected Context context;
26     
27     /**
28      * Only the passes between <code>begin</code> and <code>end</code> will
29      * be performed.
30      */

31     protected Pass.ID begin;
32     /**
33      * Only the passes between <code>begin</code> and <code>end</code> will
34      * be performed.
35      */

36     protected Pass.ID end;
37
38     /**
39      * Constructor
40      */

41     public InnerJob(ExtensionInfo lang, JobExt ext, Node ast, Context context,
42                     Job outer, Pass.ID begin, Pass.ID end) {
43         super(lang, ext, ast);
44
45     this.context = context;
46     this.outer = outer;
47         this.begin = begin;
48         this.end = end;
49         if (ast == null) {
50             throw new InternalCompilerError("Null ast");
51         }
52         if (outer == null) {
53             throw new InternalCompilerError("Null outer job");
54         }
55     }
56
57     public String JavaDoc toString() {
58       String JavaDoc name = "inner-job[" + begin + ".." + end + "](code=" +
59           context.currentCode() + " class=" + context.currentClass() + ") [" + status() + "]";
60           
61        return name + " (" +
62             (isRunning() ? "running " : "before ") +
63                         nextPass() + ")" + " <<< passes = " + passes + " >>>";
64     }
65
66     /**
67      * The initial list of passes is the list that the language extension
68      * provides us with, limited to those between <code>begin</code> and
69      * <code>end</code> inclusive.
70      */

71     public List getPasses() {
72         List l = lang.passes(this, begin, end);
73
74         for (int i = 0; i < l.size(); i++) {
75             Pass pass = (Pass) l.get(i);
76             if (pass.id() == begin) {
77                 nextPass = i;
78             }
79 // if (i == 0 && pass.id() != begin)
80
// throw new InternalCompilerError("ExtensionInfo.passes returned incorrect list: " + l);
81
if (i == l.size()-1 && pass.id() != end)
82                 throw new InternalCompilerError("ExtensionInfo.passes returned incorrect list: " + l);
83         }
84
85         return l;
86     }
87
88     public Context context() {
89     return context;
90     }
91
92     /**
93      * The <code>SourceJob</code> associated with our outer <code>Job</code>.
94      */

95     public SourceJob sourceJob() {
96     return outer.sourceJob();
97     }
98 }
99
Popular Tags