Martin Odersky
Purpose
The Generic Java Compiler GJC translates Generic Java Programs into
Java bytecodes. It is meant to be a drop-in replacement for
javac
, with exactly the same functionality.
GJC is written in Generic Java. It compiles either conventional or
generic Java Programs. The Generic Java extensions are enabled
by setting a command line option ( -gj
).
GJC translates by default into Java bytecodes. There is a command
line option (-s
) which makes GJC emit conventional Java source
code instead. Generally, the generated code corresponds to what a
human programmer would have done to emulate the extensions of Generic
Java. Therefore, the source output option of Generic Java is a
convienient way to convert the compiler itself into a standard Java
format.
GJC has been written from scratch, with the experience gained from the EspressoGrinder and Pizza compilers. Great emphasis was put on a simple and clear design and a concise implementation which faithfully follows the Java spec.
GJC has been designed to be highly flexible and modular, so that the compiler itself, or some of its components, can be used in a variety of settings. This is reflected in a layered package structure which allows lower-level packages to be used without cooperation of higher-level packages.
GJC is completely functorized, without any global static data structures at all. This makes it easy to embed GJC in large software development environments where several projects can be run concurrently.
Package Structure
GJC package names have the structure gjc.v
X.
P where
gjc
is the common prefix, the X stands for
the current version number (currently, X = 3), and
P stands for the package's name. For simplicity, we will
omit the version part of package names in the rest of this
description.
The packages of GJC form a layered structure, with classes in higher level layers only needing the services of classes of the same or lower layers. Progressing from bottom to top, the layers are:
gjc.v8.util
provides utility classes of general
usefulness.
gjc.v8.code
provides all classes needed to map between
Java classfiles and theri internal interpretation in terms of symbol
tables, code buffers and constant pools. The package is useful on its
own for tools that read, interprete and write classfiles.
gjc.v8.tree
provides classes that define abstract Generic
Java syntax trees, as well as generic factory and visitor classes for
such trees. The package does not contain any classes or methods for
the semantic processing of such trees.
gjc.v8.parser
provides classes to convert a source file to
an abstract syntax tree. Combined with gjc.tree
, this package
is useful for tools that manipulate Java programs at an abstract
syntax tree level.
gjc.v8.comp
provides classes that implement all phases of
compilation after parsing.
gjc.v8
provides the two main interfaces to the compiler,
one as an internal component of a larger system, the other as a
command line interpreter.