Add a preprocessor for array literals and basic generics
Back in the days when I developed mjtest I also wrote some other,
more sophisticated, preprocessors. This pull request contains
one of them. Examples can be found under extpreproc/examples
.
Why?
It allows to write array creation literals like new int[]{1, 2, 3}
and using simple generics.
It eases the development in MiniJava and gives lot's of possibilities to extend the MiniJava language without changing the compilers.
Why another preprocessor?
This one only operates on single files and utilizes the powerful javaparser. Thereby allowing to create more sophisticated preprocessing stages that just can't be done without parsing the MiniJava code properly.
Usage
run INPUT_FILE OUTPUT_FILE
Be sure to run build
once in a time.
Generics
It replaces generic types instantiations like B<Integer>
with a new class
with a mangled name and a occurrences of the type argument replaced with
int
(as Integer
and Boolean
are converted to their unboxed versions).
The behave (in their simplicity) mostly like class templates in C++.
What doesn't work:
- Any kind of type inference
- Using uninstantiated generic types
- Using
int
as a type argument and having a class namedInteger
- The same for
boolean
andBoolean