net.sourceforge.czt.print.z
Class AstToPrintTreeVisitor

java.lang.Object
  extended by net.sourceforge.czt.print.z.AstToPrintTreeVisitor
All Implemented Interfaces:
net.sourceforge.czt.base.visitor.TermVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.util.Visitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.AndPredVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.ApplExprVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.AxParaVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.MemPredVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.RefExprVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.ZSectVisitor<net.sourceforge.czt.base.ast.Term>

public class AstToPrintTreeVisitor
extends java.lang.Object
implements net.sourceforge.czt.base.visitor.TermVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.AndPredVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.ApplExprVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.AxParaVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.MemPredVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.RefExprVisitor<net.sourceforge.czt.base.ast.Term>, net.sourceforge.czt.z.visitor.ZSectVisitor<net.sourceforge.czt.base.ast.Term>

This visitor transforms an AST into a print tree, that is an AST prepared for printing.

In order to print, precedences and associativity of operators needs to be known. This information is provided by an SectInfo object.

Note that fixed precedences and associativities are defined in the Z standard in Table 31; user defined precedences and associativities are obtained from an operator table. This implies that this visitor cannot be used for an arbitrary term, like an expression, without providing the operator table as well.

The recommended way to use this visitor is via the #run(ZSect) or #run(Spec) methods. In this case, the operator table is obtained from the SectInfo object (provided in the constructor of this class) as soon as the name of the current section to be visited becomes available (which happens when visiting a ZSect).

It is also possible to provide an operator table explicitly via the #run(Term, OpTable) method. This method enables the handling of arbitrary terms where the name of the section is not apparent. Note that this explicity provided operator table is discarded when a ZSect is visited. As soon as a ZSect is visited, the SectInfo object is consulted to provide an operator table for the given section and this operator table is used instead of the explicitly provided one (even if the new one is null).

It is not recommended to call the accept method of a term to use this visitor since it is not guaranteed that the correct operator table is used.

Author:
Petra Malik

Nested Class Summary
static class AstToPrintTreeVisitor.CannotPrintAstException
           
 
Field Summary
protected  WarningManager warningManager_
           
 
Constructor Summary
AstToPrintTreeVisitor(net.sourceforge.czt.session.SectionInfo sectInfo)
           
AstToPrintTreeVisitor(net.sourceforge.czt.session.SectionInfo sectInfo, WarningManager wm)
          Creates a new ast to print tree visitor.
 
Method Summary
protected  Precedence getPrec(net.sourceforge.czt.base.ast.Term term)
           
protected  net.sourceforge.czt.z.ast.ZFactory getZFactory()
           
protected  PrintFactory getZPrintFactory()
           
protected  PrintParagraph handleOldZ(java.util.List<java.lang.Object> anns, PrintParagraph pp)
           
protected  boolean isInfix(net.sourceforge.czt.z.util.OperatorName opName)
           
 net.sourceforge.czt.base.ast.Term run(java.lang.String sectionName)
           
 net.sourceforge.czt.base.ast.Term run(net.sourceforge.czt.base.ast.Term term, OpTable opTable)
          Visits a term and transforms it into a printable tree.
 net.sourceforge.czt.base.ast.Term run(net.sourceforge.czt.base.ast.Term term, java.lang.String sectionName)
          Visits a term and transforms it into a printable tree.
 void setOldZ(boolean value)
           
protected  net.sourceforge.czt.base.ast.Term visit(net.sourceforge.czt.base.ast.Term term)
           
 net.sourceforge.czt.base.ast.Term visitAndPred(net.sourceforge.czt.z.ast.AndPred andPred)
           
 net.sourceforge.czt.base.ast.Term visitApplExpr(net.sourceforge.czt.z.ast.ApplExpr applExpr)
          Transforms each function application (an application expression with Mixfix set to true) into an OperatorApplication, and each application (an application expression with Mixfix set to false) into an Application.
 net.sourceforge.czt.base.ast.Term visitAxPara(net.sourceforge.czt.z.ast.AxPara axPara)
           
 net.sourceforge.czt.base.ast.Term visitMemPred(net.sourceforge.czt.z.ast.MemPred memPred)
           
 net.sourceforge.czt.base.ast.Term visitRefExpr(net.sourceforge.czt.z.ast.RefExpr refExpr)
          Transforms each generic operator application, that is each reference expression with Mixfix set to true into an OperatorApplication.
 net.sourceforge.czt.base.ast.Term visitTerm(net.sourceforge.czt.base.ast.Term term)
          Visits all children of a term.
 net.sourceforge.czt.base.ast.Term visitZSect(net.sourceforge.czt.z.ast.ZSect zSect)
          Sets up the operator table for this Z section.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

warningManager_

protected final WarningManager warningManager_
Constructor Detail

AstToPrintTreeVisitor

public AstToPrintTreeVisitor(net.sourceforge.czt.session.SectionInfo sectInfo)

AstToPrintTreeVisitor

public AstToPrintTreeVisitor(net.sourceforge.czt.session.SectionInfo sectInfo,
                             WarningManager wm)
Creates a new ast to print tree visitor. The section information should be able to provide information of type net.sourceforge.czt.parser.util.OpTable.class.

Method Detail

getZFactory

protected net.sourceforge.czt.z.ast.ZFactory getZFactory()

getZPrintFactory

protected PrintFactory getZPrintFactory()

run

public net.sourceforge.czt.base.ast.Term run(java.lang.String sectionName)
                                      throws net.sourceforge.czt.session.CommandException
Throws:
net.sourceforge.czt.session.CommandException

run

public net.sourceforge.czt.base.ast.Term run(net.sourceforge.czt.base.ast.Term term,
                                             OpTable opTable)

Visits a term and transforms it into a printable tree. The given operator table is used to lookup precedence and associativity of user defined operators, but only if the name of the section is not apparent from the term.

For instance, the given operator table is used if the given term is an expression, predicate, or paragraph, but not if the given term is a Z section or specification.


run

public net.sourceforge.czt.base.ast.Term run(net.sourceforge.czt.base.ast.Term term,
                                             java.lang.String sectionName)
                                      throws net.sourceforge.czt.session.CommandException

Visits a term and transforms it into a printable tree. The given section name is used to lookup precedence and associativity of user defined operators, but only if the name of the section is not apparent from the term itself.

For instance, the given section name is used if the given term is an expression, predicate, or paragraph, but not if the given term is a Z section or specification.

Throws:
net.sourceforge.czt.session.CommandException

setOldZ

public void setOldZ(boolean value)

visitTerm

public net.sourceforge.czt.base.ast.Term visitTerm(net.sourceforge.czt.base.ast.Term term)
Visits all children of a term. If at least one of the children has changed during that visit, a new term of the same class is created that contains the new children. A child that has not changed is shared between the new and the old AST.

Specified by:
visitTerm in interface net.sourceforge.czt.base.visitor.TermVisitor<net.sourceforge.czt.base.ast.Term>

visitAndPred

public net.sourceforge.czt.base.ast.Term visitAndPred(net.sourceforge.czt.z.ast.AndPred andPred)
Specified by:
visitAndPred in interface net.sourceforge.czt.z.visitor.AndPredVisitor<net.sourceforge.czt.base.ast.Term>

visitApplExpr

public net.sourceforge.czt.base.ast.Term visitApplExpr(net.sourceforge.czt.z.ast.ApplExpr applExpr)
Transforms each function application (an application expression with Mixfix set to true) into an OperatorApplication, and each application (an application expression with Mixfix set to false) into an Application.

Specified by:
visitApplExpr in interface net.sourceforge.czt.z.visitor.ApplExprVisitor<net.sourceforge.czt.base.ast.Term>

handleOldZ

protected PrintParagraph handleOldZ(java.util.List<java.lang.Object> anns,
                                    PrintParagraph pp)

visitAxPara

public net.sourceforge.czt.base.ast.Term visitAxPara(net.sourceforge.czt.z.ast.AxPara axPara)
Specified by:
visitAxPara in interface net.sourceforge.czt.z.visitor.AxParaVisitor<net.sourceforge.czt.base.ast.Term>

visitMemPred

public net.sourceforge.czt.base.ast.Term visitMemPred(net.sourceforge.czt.z.ast.MemPred memPred)
Specified by:
visitMemPred in interface net.sourceforge.czt.z.visitor.MemPredVisitor<net.sourceforge.czt.base.ast.Term>

visitRefExpr

public net.sourceforge.czt.base.ast.Term visitRefExpr(net.sourceforge.czt.z.ast.RefExpr refExpr)
Transforms each generic operator application, that is each reference expression with Mixfix set to true into an OperatorApplication.

Specified by:
visitRefExpr in interface net.sourceforge.czt.z.visitor.RefExprVisitor<net.sourceforge.czt.base.ast.Term>

visitZSect

public net.sourceforge.czt.base.ast.Term visitZSect(net.sourceforge.czt.z.ast.ZSect zSect)
Sets up the operator table for this Z section.

Specified by:
visitZSect in interface net.sourceforge.czt.z.visitor.ZSectVisitor<net.sourceforge.czt.base.ast.Term>

isInfix

protected boolean isInfix(net.sourceforge.czt.z.util.OperatorName opName)

visit

protected net.sourceforge.czt.base.ast.Term visit(net.sourceforge.czt.base.ast.Term term)

getPrec

protected Precedence getPrec(net.sourceforge.czt.base.ast.Term term)


Copyright © 2003-2007 Community Z Tools Project. All Rights Reserved.