scale.common
Class Emit

java.lang.Object
  extended by scale.common.Emit
Direct Known Subclasses:
EmitToFile, EmitToString

public abstract class Emit
extends java.lang.Object

An abstract class for emitting code sequences.

$Id: Emit.java,v 1.17 2005-02-07 21:28:20 burrill Exp $

Copyright 2005 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

The interface supports indentation.


Field Summary
protected  int currentColumn
          The current output column.
protected  int currentLine
          The current line number in the generated output.
protected  boolean lineStart
          true if we are at the start of a line in the generated output.
protected  int numIndent
          Number of indentation levels - used to record the amount of identatation.
protected  int spaces
          The amount of indentation spaces per indentation level.
 
Constructor Summary
Emit(int indent)
          Create a class to use in writing out generated code.
Emit(int currentLine, int currentColumn, int indent)
          Create a class to use in writing out generated code.
 
Method Summary
 void decIndLevel()
          Decrease the amount of space for indentation
abstract  void emit(char c)
          Print a character to the output.
abstract  void emit(int n)
          Print an integer to the output.
abstract  void emit(long n)
          Print a long to the output.
abstract  void emit(java.lang.String s)
          Print a string to the output.
 void endLine()
          Signal the end of the current line and start a new one.
 int getCurrentColumn()
          Return the current output column.
 int getCurrentLine()
          Return the current line number of the line being generated.
 void incIndLevel()
          Increment the number of spaces to indent
protected  void indent()
          Add indentation to output
protected  void newLine()
          Specify that a new line has been started.
 void setIndentation(int n)
          Set the amount of indentation space for each level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lineStart

protected boolean lineStart
true if we are at the start of a line in the generated output.


currentLine

protected int currentLine
The current line number in the generated output.


numIndent

protected int numIndent
Number of indentation levels - used to record the amount of identatation.


spaces

protected int spaces
The amount of indentation spaces per indentation level.


currentColumn

protected int currentColumn
The current output column.

Constructor Detail

Emit

public Emit(int indent)
Create a class to use in writing out generated code.

Parameters:
indent - is the number of spaces to indent

Emit

public Emit(int currentLine,
            int currentColumn,
            int indent)
Create a class to use in writing out generated code.

Parameters:
currentLine - is the current output line number
currentColumn - is the current output column number
indent - is the number of spaces to indent
Method Detail

emit

public abstract void emit(java.lang.String s)
Print a string to the output. If we are at the beginning of a line, then generate some indentation.


emit

public abstract void emit(int n)
Print an integer to the output. If we are at the beginning of a line, then generate some indentation.


emit

public abstract void emit(long n)
Print a long to the output. If we are at the beginning of a line, then generate some indentation.


emit

public abstract void emit(char c)
Print a character to the output. If we are at the beginning of a line, then generate some indentation.


endLine

public void endLine()
Signal the end of the current line and start a new one.


indent

protected void indent()
Add indentation to output


newLine

protected void newLine()
Specify that a new line has been started.


incIndLevel

public void incIndLevel()
Increment the number of spaces to indent


decIndLevel

public void decIndLevel()
Decrease the amount of space for indentation


setIndentation

public void setIndentation(int n)
Set the amount of indentation space for each level.


getCurrentLine

public int getCurrentLine()
Return the current line number of the line being generated.


getCurrentColumn

public int getCurrentColumn()
Return the current output column.