javac Is Ugly But Easy

Even though I’d sworn I wouldn’t look at the LAPT again until I’ve worked some more on the thread checker and the poster I have to make about it, I nonetheless looked at the source code of javac, got it to compile without a hitch — as promised by James — and began to study it.

I’m in the process of tracing local variable annotations from the parser to the ClassWriter. I haven’t made my entire way through yet — in some places, javac is written in incredibly ugly ways, I think, even though they have tried to use visitors, which I’ve been able to employ with great benefits already. I can definitely say that local variable annotations are parsed in javac’s parser (so there’s no reason Sun’s apt should not have access to them), and the annotations stay within the AST at least until just before the code generation.

In the code generation, I assume they get stripped. The MethodDef class has an array of parameters, which may contain annotations and which is read out and written into the class file, but it does not have a list of local variables. At least I haven’t found one yet, even though there ought to be one for the LocalVariableTable and LocalVariableTypeTable. I’ll have to find the place where the information needs to be passed on. Then it should be a very easy task to write out the right annotations. I think once I’ve found the right place, I’ll probably just need to modify two or three files in a few places.

All of that makes me wonder even more why Sun didn’t support annotations on local variables in the first place… at all!

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in xajavac. Bookmark the permalink.

Leave a Reply