|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.adamcornett.cminus.codegen.ClassGenerator
public class ClassGenerator
Generates a Jasmin class file from an abstract syntax tree.
Uses the CMTree.emitCode(ClassGenerator) method to generate code.
That method should recursively traverse the tree to generate the appropriate
Jasmin code.
| Field Summary | |
|---|---|
private String |
className
The name of the class, the same as name of the source file. |
private int |
indentLevel
The current indent level, for making pretty code. |
private org.apache.commons.logging.Log |
log
|
private PrintStream |
output
The output print stream |
private org.antlr.runtime.tree.CommonTree |
progTree
The root node of the AST |
| Constructor Summary | |
|---|---|
ClassGenerator(String className,
org.antlr.runtime.tree.CommonTree programTree)
Create a new Class Generator, based on the class name and AST parameters |
|
| Method Summary | |
|---|---|
void |
emitComment(String message,
Object... args)
Emit a comment in to the Jasmin file. Should be called from a AST node's emit code method. |
private void |
emitConstructor()
|
private void |
emitFoot()
emit the footer code |
private void |
emitHead()
Emit the class header code |
private void |
emitLB()
Emit a blank line |
void |
emitLine(String code,
Object... args)
Emit a line of code. |
private void |
emitNode(ProgramTree node)
Begin emiting code starting with the root node |
private void |
emitPrintFunctions()
|
void |
generateCode()
Generate the Jasmin code for the class |
String |
getClassName()
|
private String |
getIndents()
Get a string with the appropriate number of tabs |
void |
popIndent()
Decrease the indent level |
void |
pushIndent()
Increase the indent level |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final String className
private int indentLevel
private final org.apache.commons.logging.Log log
private final PrintStream output
private final org.antlr.runtime.tree.CommonTree progTree
| Constructor Detail |
|---|
public ClassGenerator(String className,
org.antlr.runtime.tree.CommonTree programTree)
throws FileNotFoundException
className - The name of the class to createprogramTree - The AST of the program
FileNotFoundException - If there is an error creating the output file.| Method Detail |
|---|
public void emitComment(String message,
Object... args)
message - The formatted stringargs - The arguments for printfString.format(String, Object...)
public void emitLine(String code,
Object... args)
code - The formatted line of code to emitargs - The arguments for printfString.format(String, Object...)public void generateCode()
public String getClassName()
public void popIndent()
public void pushIndent()
private void emitConstructor()
private void emitFoot()
private void emitHead()
private void emitLB()
private void emitNode(ProgramTree node)
node - The root node of the ASTprivate void emitPrintFunctions()
private String getIndents()
indentLevel number of tabs.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||