xtc.type
Class SourcePrinter

java.lang.Object
  extended by xtc.tree.Visitor
      extended by xtc.type.SourcePrinter

public class SourcePrinter
extends Visitor

A visitor to print types in C-like source form. This visitor's functionality is available through the print(Type) and print(Type,String) methods.

Version:
$Revision: 1.6 $
Author:
Robert Grimm

Field Summary
protected  Type base
          The base type.
protected  java.util.List<Type> derived
          The list of derived types, with the outer-most type first.
protected  java.lang.String name
          The optional variable name.
protected  boolean needsSpace
          The flag for whether the next token needs to be preceded by a space.
protected  Printer printer
          The printer utility.
 
Constructor Summary
SourcePrinter(Printer printer)
          Create a new source printer.
 
Method Summary
protected  void addDerived(Type type)
          Add the specified type to the list of derived types.
static boolean hasAttributes(Type type)
          Determine whether the specified type or any wrapped types have any printable attributes.
static boolean isPrintable(Attribute att)
          Determine whether the specified attribute is printable.
 void print(Type type)
          Print the specified type.
 void print(Type type, java.lang.String variable)
          Print the specified type and variable as a declaration.
protected  void printArray(Type type)
          Print the specified array type.
protected  void printAttributes(Type type)
          Print the attributes for the specified type and any wrapped types.
protected  void printDerived()
          Emit any derived types.
protected  void printFunction(Type type)
          Print the specified function type.
protected  void printPointer(Type type)
          Print the specified pointer type.
protected  void setVariable(java.lang.String variable)
          Set the variable name.
protected  void space()
          Emit a space.
 void visit(AliasT t)
          Print the specified alias type.
 void visit(ArrayT t)
          Print the specified array type.
 void visit(Attribute att)
          Print the specified attribute.
 void visit(ClassOrInterfaceT t)
          Print the specified class or interface type.
 void visit(EnumT t)
          Print the specified enum type.
 void visit(ErrorT t)
          Print the specified error type.
 void visit(FunctionT t)
          Print the specified function type.
 void visit(InternalT t)
          Print the specified internal type.
 void visit(NumberT t)
          Print the specified number type.
 void visit(PointerT t)
          Print the specified pointer type.
 void visit(StructT t)
          Print the specified struct type.
 void visit(UnionT t)
          Print the specified union type.
 void visit(VariableT t)
          Print the specified variable type.
 void visit(VoidT t)
          Print the specified void type.
 void visit(WrappedT t)
          Print the specified wrapped type.
 
Methods inherited from class xtc.tree.Visitor
dispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

printer

protected final Printer printer
The printer utility.


base

protected Type base
The base type.


derived

protected java.util.List<Type> derived
The list of derived types, with the outer-most type first.


name

protected java.lang.String name
The optional variable name.


needsSpace

protected boolean needsSpace
The flag for whether the next token needs to be preceded by a space.

Constructor Detail

SourcePrinter

public SourcePrinter(Printer printer)
Create a new source printer. Note that this visitor is not registered with the printer utility.

Parameters:
printer - The printer utility.
Method Detail

print

public void print(Type type)
Print the specified type. If the specified type contains a VariableT, this method prints a declaration for that type's name. Otherwise, it prints an abstract declaration. Note that the printed declaration is not followed by any delimiter such as a semicolon.

Parameters:
type - The type.
Throws:
java.lang.IllegalArgumentException - Signals that the specified type contains an error type or more than one field, member, parameter, or variable type.

print

public void print(Type type,
                  java.lang.String variable)
Print the specified type and variable as a declaration. Note that the printed declaration is not followed by any delimiter such as a semicolon.

Parameters:
type - The type.
variable - The variable name.
Throws:
java.lang.IllegalArgumentException - Signals that the specified type contains a field, member, parameter, variable, or error type.

setVariable

protected void setVariable(java.lang.String variable)
Set the variable name.

Parameters:
variable - The variable name.
Throws:
java.lang.IllegalArgumentException - Signals a duplicate variable name.

addDerived

protected void addDerived(Type type)
Add the specified type to the list of derived types.

Parameters:
type - The type.

space

protected void space()
Emit a space. If the needsSpace flag is set, this method emits the space and clears the flag.


printDerived

protected void printDerived()
Emit any derived types. This method also prints the variable name, if it is available. It must be invoked after printing a non-derived type.


printPointer

protected void printPointer(Type type)
Print the specified pointer type.

Parameters:
type - The pointer type, which may be wrapped

printArray

protected void printArray(Type type)
Print the specified array type.

Parameters:
type - The array type, which may be wrapped.

printFunction

protected void printFunction(Type type)
Print the specified function type.

Parameters:
type - The function type, which may be wrapped.

isPrintable

public static boolean isPrintable(Attribute att)
Determine whether the specified attribute is printable.

Parameters:
att - The attribute.
Returns:
true if the attribute is printable.

hasAttributes

public static boolean hasAttributes(Type type)
Determine whether the specified type or any wrapped types have any printable attributes.

Parameters:
type - The type.
Returns:
true if the type or any wrapped types have any printable attributes.

printAttributes

protected void printAttributes(Type type)
Print the attributes for the specified type and any wrapped types.

Parameters:
type - The type.

visit

public void visit(Attribute att)
Print the specified attribute.


visit

public void visit(VoidT t)
Print the specified void type.


visit

public void visit(NumberT t)
Print the specified number type.


visit

public void visit(StructT t)
Print the specified struct type.


visit

public void visit(UnionT t)
Print the specified union type.


visit

public void visit(EnumT t)
Print the specified enum type.


visit

public void visit(ClassOrInterfaceT t)
Print the specified class or interface type.


visit

public void visit(AliasT t)
Print the specified alias type.


visit

public void visit(InternalT t)
Print the specified internal type.


visit

public void visit(PointerT t)
Print the specified pointer type.


visit

public void visit(ArrayT t)
Print the specified array type.


visit

public void visit(FunctionT t)
Print the specified function type.


visit

public void visit(VariableT t)
Print the specified variable type.


visit

public void visit(WrappedT t)
Print the specified wrapped type.


visit

public void visit(ErrorT t)
Print the specified error type.



Copyright © 2012. All Rights Reserved.