public class GoloCompiler
extends java.lang.Object
Instances of this class may be reused to compile several sources.
Several methods are made public while they do not necessarily need so for the needs of the Golo compiler. Such deviations from a "good and clean" design are on-purpose, as this facilitates the implementation of Golo support in IDEs.
Constructor and Description |
---|
GoloCompiler() |
Modifier and Type | Method and Description |
---|---|
GoloModule |
check(ASTCompilationUnit compilationUnit)
Checks that the source code is minimally sound by converting a parse tree to an intermediate representation, and
running a few classic visitors over it.
|
java.util.List<CodeGenerationResult> |
compile(java.lang.String goloSourceFilename,
java.io.InputStream sourceCodeInputStream)
Compiles a Golo source file from an input stream, and returns a collection of results.
|
void |
compileTo(java.lang.String goloSourceFilename,
java.io.InputStream sourceCodeInputStream,
java.io.File targetFolder)
Compiles a Golo source file and writes the resulting JVM bytecode
.class files to a target
folder. |
void |
compileToJar(java.lang.String goloSourceFilename,
java.io.InputStream sourceCodeInputStream,
java.util.jar.JarOutputStream jarOutputStream)
Compiles a Golo source fila and writes the resulting JVM bytecode
.class files to a Jar file stream. |
protected GoloParser |
createGoloParser(java.io.Reader sourceReader)
Makes a Golo parser from a reader.
|
java.util.List<GoloCompilationException.Problem> |
getProblems()
Returns the list of problems encountered during the last compilation
|
GoloParser |
initParser(java.io.Reader sourceReader)
Initializes a parser from a reader.
|
GoloParser |
initParser(java.lang.String goloSourceFilename,
java.io.InputStream sourceCodeInputStream)
Initializes a parser from an input stream.
|
ASTCompilationUnit |
parse(java.lang.String goloSourceFilename) |
ASTCompilationUnit |
parse(java.lang.String goloSourceFilename,
GoloParser parser)
Produces a parse tree for a Golo source file.
|
void |
refine(GoloModule goloModule) |
void |
setExceptionBuilder(GoloCompilationException.Builder builder)
Initializes an ExceptionBuilder to collect errors instead of throwing immediately.
|
GoloModule |
transform(ASTCompilationUnit compilationUnit) |
public final void setExceptionBuilder(GoloCompilationException.Builder builder)
builder
- the exception builder to add problems into.public final GoloParser initParser(java.lang.String goloSourceFilename, java.io.InputStream sourceCodeInputStream) throws GoloCompilationException
sourceCodeInputStream
- the source code input stream.GoloCompilationException
public final GoloParser initParser(java.io.Reader sourceReader)
sourceReader
- the source code reader.public final java.util.List<CodeGenerationResult> compile(java.lang.String goloSourceFilename, java.io.InputStream sourceCodeInputStream) throws GoloCompilationException
goloSourceFilename
- the source file name.sourceCodeInputStream
- the source code input stream.GoloCompilationException
- if a problem occurs during any phase of the compilation work.public java.util.List<GoloCompilationException.Problem> getProblems()
public final void compileTo(java.lang.String goloSourceFilename, java.io.InputStream sourceCodeInputStream, java.io.File targetFolder) throws GoloCompilationException, java.io.IOException
.class
files to a target
folder. The class files are written in a directory structure that respects package names.goloSourceFilename
- the source file name.sourceCodeInputStream
- the source code input stream.targetFolder
- the output target folder.GoloCompilationException
- if a problem occurs during any phase of the compilation work.java.io.IOException
- if writing the .class
files fails for some reason.public final void compileToJar(java.lang.String goloSourceFilename, java.io.InputStream sourceCodeInputStream, java.util.jar.JarOutputStream jarOutputStream) throws java.io.IOException
.class
files to a Jar file stream.
The class files are written in a directory structure that respects package names.goloSourceFilename
- the source file name.sourceCodeInputStream
- the source code input stream.jarOutputStream
- the output Jar streamjava.io.IOException
- if writing the .class
files fails for some reason.public final ASTCompilationUnit parse(java.lang.String goloSourceFilename, GoloParser parser) throws GoloCompilationException
goloSourceFilename
- the source file name.parser
- the parser to use.GoloCompilationException
- if the parser encounters an error.public final ASTCompilationUnit parse(java.lang.String goloSourceFilename) throws GoloCompilationException, java.io.IOException
GoloCompilationException
java.io.IOException
public final GoloModule check(ASTCompilationUnit compilationUnit)
compilationUnit
- the source parse tree.GoloCompilationException
- if an error exists in the source represented by the input parse tree.public final GoloModule transform(ASTCompilationUnit compilationUnit)
public final void refine(GoloModule goloModule)
protected GoloParser createGoloParser(java.io.Reader sourceReader)
sourceReader
- the reader.sourceReader
.