1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|
2 <!-- |
|
3 Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. |
|
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 |
|
6 This code is free software; you can redistribute it and/or modify it |
|
7 under the terms of the GNU General Public License version 2 only, as |
|
8 published by the Free Software Foundation. Sun designates this |
|
9 particular file as subject to the "Classpath" exception as provided |
|
10 by Sun in the LICENSE file that accompanied this code. |
|
11 |
|
12 This code is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 version 2 for more details (a copy is included in the LICENSE file that |
|
16 accompanied this code). |
|
17 |
|
18 You should have received a copy of the GNU General Public License version |
|
19 2 along with this work; if not, write to the Free Software Foundation, |
|
20 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
21 |
|
22 Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
23 CA 95054 USA or visit www.sun.com if you need additional information or |
|
24 have any questions. |
|
25 --> |
|
26 |
|
27 <html> |
|
28 <head> |
|
29 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> |
|
30 <meta name="author" content="Jonathan Gibbons"> |
|
31 <link type="text/css" rel=stylesheet href="style.css"> |
|
32 <title>JavaCompiler's "to do" list</title> |
|
33 </head> |
|
34 <body> |
|
35 |
|
36 <h3>com.sun.tools.javac.main.JavaCompiler's "to do" list</h3> |
|
37 |
|
38 <p> |
|
39 After the source files have been parsed, and their symbols entered |
|
40 in the symbol table, the top level classes and some other items end |
|
41 up on JavaCompiler's "to do" list. |
|
42 </p> |
|
43 |
|
44 <p> |
|
45 For each entry on the "to do" list, <code>JavaCompiler</code> |
|
46 processes it as follows: |
|
47 </p> |
|
48 |
|
49 <ul> |
|
50 <li><p>Some parts of the compilation involve modifying the parse tree, |
|
51 so a copy of the root of the tree is kept prior to such manipulation. |
|
52 </p> |
|
53 <p class="note"> |
|
54 Note: this copy is just used to check whether the class is one of those |
|
55 found in a compilation unit on the command line (i.e. in rootClasses). |
|
56 </p> |
|
57 |
|
58 <li><p>The top level classes are "attributed", using |
|
59 <a href="../../src/share/classes/com/sun/tools/javac/comp/Attr.java" class="code">Attr</a>, |
|
60 meaning that names and other elements within the parse tree are resolved |
|
61 and associated with the corresponding types and symbols. Many semantic |
|
62 errors may be detected here, either by <code>Attr</code>, or by |
|
63 <a href="../../src/share/classes/com/sun/tools/javac/comp/Check.java" class="code">Check</a>. |
|
64 </p> |
|
65 <p>While attributing the tree, class files will be read as necessary. |
|
66 In addition, if a class is required, and a source file for the class is found |
|
67 that is newer than the class file, the source file will be automatically parsed |
|
68 and put on the "to do" list. This is done by registering JavaCompiler as an |
|
69 implementation of |
|
70 <a href="../../src/share/classes/com/sun/tools/javac/comp/Attr.java" class="code">Attr</a><span class=code>.SourceCompleter</span>. |
|
71 </p> |
|
72 <p class=note> |
|
73 Note: there is a hidden option <code>-attrparseonly</code> which can be used to skip |
|
74 the rest of the processing for this file. In so doing, it "breaks" the |
|
75 protocol use to save and restore the source file used to report error |
|
76 messages (Log.useSource). There is a "try finally" block which |
|
77 could reasonably be used/extended to restore the source file correctly. |
|
78 </p> |
|
79 </li> |
|
80 |
|
81 <li><p>If there are no errors so far, flow analysis will be done for the class, using |
|
82 <a href="../../src/share/classes/com/sun/tools/javac/comp/Flow.java" class="code">Flow</a>. |
|
83 Flow analysis is used to check for definite assignment to variables, |
|
84 and unreachable statements, which may result in additional errors. |
|
85 </p> |
|
86 <p class="note">Note: flow analysis can be suppressed with the hidden |
|
87 option <code>-relax</code>. |
|
88 </p> |
|
89 </li> |
|
90 |
|
91 <li>If the "to do" item is a TopLevel tree, it will be the contents of a |
|
92 <span class="code">package-info.java</span> file, containing annotations for a package. |
|
93 (See notes for <a href="Enter.html#package-info">Enter</a>.) |
|
94 <ul> |
|
95 <li>Syntactic sugar is processed, using |
|
96 <a href="../../src/share/classes/com/sun/tools/javac/comp/Lower.java" class="code">Lower</a>. |
|
97 <code>Lower</code> is defined to return a list of trees for the translated classes |
|
98 and all the translated inner classes.</li> |
|
99 <li>If <code>Lower</code> returns a non-empty list, there is an assertion that |
|
100 the list has a single element, in which case, code is generated, using |
|
101 <a href="../../src/share/classes/com/sun/tools/javac/jvm/Gen.java" class="code">Gen</a>, |
|
102 and the resulting code is written out using |
|
103 <a href="../../src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java" class="code">ClassWriter</a>. |
|
104 </li> |
|
105 <li>No further processing is done on this "to do" item.<br> |
|
106 </li> |
|
107 </ul> |
|
108 <p class=note>Note that <a href="Enter.html">Enter</a> will have processed all other TopLevel |
|
109 putting the individual classes that it finds there on the "to do" |
|
110 (and not the TopLevel node itself.) |
|
111 </p> |
|
112 |
|
113 <li>If stub outputs have been requested, with the hidden <code>-stubs</code> option, |
|
114 <ul> |
|
115 <li>If the class was one of those mentioned on the command line and is in |
|
116 <span class=code>java.lang</span>, |
|
117 pretty print the source with no method bodies.</li> |
|
118 <li>No further processing is done on this "to do" item. </li> |
|
119 </ul> |
|
120 |
|
121 <li>Code involving generic types is translated to code without generic types, using |
|
122 <a href="../../src/share/classes/com/sun/tools/javac/comp/TransTypes.java" class="code">TransTypes</a>. |
|
123 </li> |
|
124 |
|
125 <li>If source output has been requested, with the hidden <code>-s</code> option |
|
126 <ul> |
|
127 <li>If the original tree was from command line, pretty print the source code |
|
128 </li> |
|
129 <li>No further processing is done on this "to do" item.</li> |
|
130 </ul> |
|
131 |
|
132 <li>Syntactic sugar is processed, using |
|
133 <a href="../../src/share/classes/com/sun/tools/javac/comp/Lower.java" class="code">Lower</a>. |
|
134 This takes care of inner classes, class literals, assertions, foreach |
|
135 loops, etc. |
|
136 <code>Lower</code> is defined to return a list of trees for the translated classes |
|
137 and all the translated inner classes.</li> |
|
138 |
|
139 <p class=note> |
|
140 Note: see also the use of <code>Lower</code> earlier in the loop, when processing |
|
141 TopLevel trees.</p> |
|
142 |
|
143 <li>For each class returned by <code>Lower</code><br> |
|
144 <ul> |
|
145 <li>If source has been requestion with the hidden <code>-printflat</code> |
|
146 option, the source of the class is printed. |
|
147 <li>Otherwise, code for the class is generated, using |
|
148 <a href="../../src/share/classes/com/sun/tools/javac/jvm/Gen.java" class="code">Gen</a>, |
|
149 and the resulting code is written out using |
|
150 <a href="../../src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java" class="code">ClassWriter</a>. |
|
151 </ul> |
|
152 |
|
153 </ul> |
|
154 |
|
155 <h4>Issues</h4> |
|
156 The "to do" list is mostly organized by top level classes, and not by |
|
157 compilation units. This means that if a compilation unit contains several |
|
158 classes, it is possible for code to be generated for some of the classes |
|
159 in the file, at which point at error may be detected for one of the |
|
160 remaining classes, preventing code from being generated for that and any |
|
161 subsequent classes. This means that the compilation unit will be partially |
|
162 compiled, with some but not all of the class files being generated. |
|
163 (Bug <a href="http://monaco.sfbay.sun.com/detail.jsf?cr=5011101">5011101</a>) |
|
164 |
|
165 </body> |
|
166 </html> |
|
167 |
|