at.dms.kjc.common
Class CodegenPrintWriter

java.lang.Object
  extended by at.dms.kjc.common.CodegenPrintWriter

public final class CodegenPrintWriter
extends Object

A PrintWriter incorporating common functions called from our code generators Delegates to at.dms.compiler.TabbedPrintWriter, which in turn delegates to java.io.PrintWriter.
Includes print and println at the base types commonly found in the compiler and for String. Printing of Object (as its toString()) is deliberately missing from this implementation since it was causing bugs in the printing of CType's. To print a CType see ToCCommon.printType(at.dms.kjc.CType).
Includes an optional debugging feature to dump the caller's line number and test to be printed on a print, println, or printnl.

Author:
Allyn Dimock

Field Summary
static boolean defaultDebug
          Static field to set to get debug dumps from all instantiations.
static int defaultDebugDepth
          How many stack frames to go up to print caller information.
 
Constructor Summary
CodegenPrintWriter()
          Construct with a StringWriter The contents of the string writer can be accessed with getString()
CodegenPrintWriter(Writer w)
          Construct with a Writer
 
Method Summary
 void close()
          Close underlying Writer, (and StringWriter if used CodegenPrintWriter().
 int getColumn()
          Get current column.
 int getIndentation()
          Get current amount of intentation.
 int getLine()
          Get line number.
 String getString()
          Get string if you used constructor CodegenPrintWriter().
 void indent()
          Increment indentation level.
 void newline()
          Synonym for newLine().
 void newLine()
          Start a new line.
 void outdent()
          Decrement indentation level.
 void print(boolean b)
           
 void print(char c)
           
 void print(double d)
           
 void print(float f)
           
 void print(int i)
           
 void print(String s)
          Print something in the current line.
 void println()
           
 void println(boolean b)
           
 void println(char c)
           
 void println(double d)
           
 void println(float f)
           
 void println(int i)
           
 void println(String s)
          Print something in the current line and terminate the line.
 void printSeveralLines(String s)
          Print a string, possibly containing \n characters.
 void setIndentation(int pos)
          Set current amount of indentation.
 void setTabSize(int tabSize)
          Set tab size to some number of spaces (if you don't like the default).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultDebug

public static boolean defaultDebug
Static field to set to get debug dumps from all instantiations.


defaultDebugDepth

public static int defaultDebugDepth
How many stack frames to go up to print caller information. This number is dependent on the internal coding of print routines! The default value should tell you where a print routine was called Setting the value larger may tell you what was being visited when the print routine was called.

Constructor Detail

CodegenPrintWriter

public CodegenPrintWriter(Writer w)
Construct with a Writer

Parameters:
w - A Writer that is already opened.

CodegenPrintWriter

public CodegenPrintWriter()
Construct with a StringWriter The contents of the string writer can be accessed with getString()

Method Detail

getLine

public int getLine()
Get line number.

Returns:
current line number.

getColumn

public int getColumn()
Get current column.

Returns:
current column number.

getIndentation

public int getIndentation()
Get current amount of intentation.

Returns:
number of spaces currently used for indentation

setIndentation

public void setIndentation(int pos)
Set current amount of indentation. You almost never want to use this, use indent() and outdent() instead.

Parameters:
pos - number of spaces to use for indentation

setTabSize

public void setTabSize(int tabSize)
Set tab size to some number of spaces (if you don't like the default).

Parameters:
tabSize - number of spaces added per indent() and removed per outdent()

getString

public String getString()
Get string if you used constructor CodegenPrintWriter().

Returns:
string from string writer or null

indent

public void indent()
Increment indentation level.


outdent

public void outdent()
Decrement indentation level.


close

public void close()
Close underlying Writer, (and StringWriter if used CodegenPrintWriter().


newLine

public void newLine()
Start a new line.


newline

public void newline()
Synonym for newLine().


print

public void print(String s)
Print something in the current line.

Parameters:
s - String to print. Also overloaded for base types boolean, int, char, float, double.

print

public void print(boolean b)

print

public void print(int i)

print

public void print(char c)

print

public void print(float f)

print

public void print(double d)

println

public void println(String s)
Print something in the current line and terminate the line.

Parameters:
s - String to print. Also overloaded at base types boolean, int, char, float, double. println() acts identically to newLine().

println

public void println()

println

public void println(boolean b)

println

public void println(int i)

println

public void println(char c)

println

public void println(float f)

println

public void println(double d)

printSeveralLines

public void printSeveralLines(String s)
Print a string, possibly containing \n characters. Prints the string, breaking at \n characters and starting new lines as needed at the current indentation level. Local indentation, in the forms of spaces at the beginning of lines will be printed.

Parameters:
s - String to print