📄 irtreeprettyprintinterp.java
字号:
/**
*This class is used for expressions using the AND operation.
*This class extends the Exp abstract class
**/
package CatDecaf.Utilities.Debugger;
import CatDecaf.IR.*;
import CatDecaf.Utilities.*;
public class IRTreePrettyPrintInterp implements Visitor{
public static int tab;
public IRTreePrettyPrintInterp(){
tab=0;
}
private void printTab(){
for (int i=0;i<tab;i++){
System.out.print(" ");
}
}
public void visit(Ir n){ } //abstract class
public void visit(IrProg n){
System.out.print("\n(IrProg: \n");
if(n.fdDeclList_!=null)
n.fdDeclList_.accept(this);
if(n.mdDeclList_ == null) System.out.println("ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!");
n.mdDeclList_.accept(this); //this should never be empty
System.out.print(")\n");
}
public void visit(FdDeclList n){ //not printing List classes
while(n!= null)
{
n.fdDecl_.accept(this);
n = n.fdDeclList_;
}
}
public void visit(FdDecl n){
tab++;
printTab();
System.out.print("(FdDecl: ");
if(n.glbVarList_==null) System.out.println("ERROR!!!!!!!!!!!!!!!");
n.typ_.accept(this);
n.glbVarList_.accept(this);
printTab();
System.out.print(")\n");
tab--;
}
public void visit(GlbVar n){ } //abstract class
public void visit(GlbVarArray n){
System.out.print("(GlbVarArray:");
n.identifier_.accept(this);
n.ltrInt_.accept(this);
System.out.print(")");
}
public void visit(GlbVarId n){
System.out.print("(GlbVarId:");
n.identifier_.accept(this);
System.out.print(")");
}
public void visit(GlbVarList n){ //not printing List classes
while(n!= null)
{
n.glbVar_.accept(this);
n = n.glbVarList_;
}
}
public void visit(Typ n){ } //abstract class
public void visit(TypInt n){
printTab();
System.out.print("(TypInt)");
}
public void visit(TypBool n){
printTab();
System.out.print("(TypBool)");
}
public void visit(TypVoid n){
printTab();
System.out.print("(TypVoid)");
}
public void visit(MdDeclList n){ //not printing List classes
while(n!= null)
{
n.mdDecl_.accept(this);
n = n.mdDeclList_;
}
}
public void visit(MdDecl n){
tab++;
printTab();
System.out.print("(MdDecl:");
n.typ_.accept(this);
n.identifier_.accept(this);
if(n.mdParaList_ !=null){ //method parameter list could be NULL
n.mdParaList_.accept(this);
}
System.out.print("\n");
n.block_.accept(this);
//System.out.print("\n");
printTab();
System.out.print(")\n");
tab--;
}
public void visit(MdParaList n){ //not printing List classes
while(n!= null)
{
n.mdPara_.accept(this);
n = n.mdParaList_;
}
}
public void visit(MdPara n){
System.out.print("(MdPara:");
n.typ_.accept(this);
n.identifier_.accept(this);
System.out.print(")");
}
public void visit(Block n){
tab++;
printTab();
System.out.print("(Block: \n");
if(n.varDeclList_!=null) //var declaration list could be empty
n.varDeclList_.accept(this);
if(n.stmtList_!=null)//list can be empty
n.stmtList_.accept(this);
printTab();
System.out.print(")\n");
tab--;
}
public void visit(VarDecl n){
tab++;
printTab();
System.out.print("(VarDecl:");
n.typ_.accept(this);
if(n.locVarList_==null) System.out.println("ERROR!!!!!!!!!!!!!!!");
n.locVarList_.accept(this);
//printTab();
System.out.print(")\n");
tab--;
}
public void visit(VarDeclList n){ //not printing List classes
while(n!= null)
{
n.varDecl_.accept(this);
n = n.varDeclList_;
}
}
public void visit(LocVar n){
System.out.print("(LocVar:");
n.identifier_.accept(this);
System.out.print(")");
}
public void visit(LocVarList n){ //not printing List classes
while(n!= null)
{
n.locVar_.accept(this);
n = n.locVarList_;
}
}
public void visit(StmtList n){ //not printing List classes
while(n!= null)
{
n.stmt_.accept(this);
n = n.stmtList_;
}
}
public void visit(Stmt n){ } //abstract class
public void visit(StmtLocation n){
tab++;
printTab();
System.out.print("(StmtLocation:");
n.location_.accept(this);
n.exp_.accept(this);
//printTab();
System.out.print(")\n");
tab--;
}
public void visit(StmtBlock n){
n.block_.accept(this);
}
public void visit(StmtMdCall n){
n.mdCall_.accept(this);
}
public void visit(Location n){ } //abstract class
public void visit(LocationId n){
printTab();
System.out.print("(LocationId:");
n.identifier_.accept(this);
System.out.print(")");
}
public void visit(LocationArray n){
printTab();
System.out.print("(LocationArray:");
n.identifier_.accept(this);
n.exp_.accept(this);
System.out.print(")");
}
public void visit(CallOutArgList n){ //not printing List classes
while(n!= null)
{
n.callOutArg_.accept(this);
n = n.callOutArgList_;
}
}
public void visit(CallOutArg n){ } //abstract class
public void visit(CallOutArgExp n){
printTab();
System.out.print("(CallOutArgExp:");
n.exp_.accept(this);
System.out.print(")");
}
public void visit(CallOutArgStr n){
printTab();
System.out.print("(CallOutArgStr:");
n.ltrString_.accept(this);
System.out.print(")");
}
public void visit(MdCall n){ } //abstract class
public void visit(MdCallOut n){
tab++;
printTab();
System.out.print("(MdCallOut:");
n.ltrString_.accept(this);
if(n.callOutArgList_!=null) //could be empty
n.callOutArgList_.accept(this);
System.out.print(")\n");
tab--;
}
public void visit(MdCallIn n){
tab++;
printTab();
System.out.print("(MdCallIn:");
n.identifier_.accept(this);
if(n.expList_!=null) //could be empty
n.expList_.accept(this);
//printTab();
System.out.print(")");
tab--;
}
public void visit(ExpList n){ //not printing List classes
while(n!= null)
{
n.exp_.accept(this);
n = n.expList_;
}
}
public void visit(StmtForLoop n){
tab++;
printTab();
System.out.print("(StmtForLoop:");
System.out.print("\n");
printTab();
n.identifier1_.accept(this);
n.exp1_.accept(this);
n.exp2_.accept(this);
n.identifier3_.accept(this);
n.exp3_.accept(this);
//System.out.print("\n");
n.block_.accept(this);
//System.out.print("\n");
printTab();
System.out.print(")\n");
tab--;
}
public void visit(StmtIfElse n){
tab++;
printTab();
System.out.print("(StmtIfElse:");
//System.out.print("\n");
//printTab();
n.exp_.accept(this);
System.out.print("\n");
n.ifBlock_.accept(this);
if(n.elseBlock_!=null) { //else block could be empty
System.out.print("\n");
n.elseBlock_.accept(this);
}
System.out.print("\n");
printTab();
System.out.print(")\n");
tab--;
}
public void visit(StmtReturn n){
tab++;
printTab();
System.out.print("(StmtReturn:");
System.out.print("\n");
printTab();
if(n.exp_ != null) //could return nothing
n.exp_.accept(this);
//System.out.print("\n");
//printTab();
System.out.print(")\n");
tab--;
}
public void visit(StmtWhileLoop n){
tab++;
printTab();
System.out.print("(StmtWhileLoop:");
System.out.print("\n");
printTab();
n.exp_.accept(this);
n.block_.accept(this);
System.out.print("\n");
printTab();
System.out.print(")\n");
tab--;
}
public void visit(Literal n){}//abstract
public void visit(Exp n){}//abstract
public void visit(ExpPlus n){
printTab();
System.out.print(" ( ExpPlus: " );
n.exp1_.accept(this);
//System.out.print(" + " );
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpMinus n){
printTab();
System.out.print(" ( ExpMinus: " );
n.exp1_.accept(this);
//System.out.print(" - ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpTimes n){
printTab();
System.out.print(" ( ExpTimes: " );
n.exp1_.accept(this);
//System.out.print(" * ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpDivide n){
printTab();
System.out.print(" ( ExpDivide: " );
n.exp1_.accept(this);
//System.out.print(" / ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpMod n){
printTab();
System.out.print(" ( ExpMod: " );
n.exp1_.accept(this);
//System.out.print(" % ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpUMinus n){
printTab();
System.out.print(" ( ExpUMinus: " );
//System.out.print(" -");
n.exp_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpShiftLeft n){
printTab();
System.out.print(" ( ExpShiftLeft: " );
n.exp1_.accept(this);
//System.out.print(" << ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpShiftRight n){
printTab();
System.out.print(" ( ExpShiftRight: " );
n.exp1_.accept(this);
//System.out.print(" >> ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpLessThan n){
printTab();
System.out.print(" ( ExpLessThan: " );
n.exp1_.accept(this);
//System.out.print(" < ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpGreaterThan n){
printTab();
System.out.print(" ( ExpGreaterThan: " );
n.exp1_.accept(this);
//System.out.print(" > ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpLessThEql n){
printTab();
System.out.print(" ( ExpLessThEql: " );
n.exp1_.accept(this);
//System.out.print(" <= ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpGreaterThEql n){
printTab();
System.out.print(" ( ExpGreaterThEql: " );
n.exp1_.accept(this);
//System.out.print(" >= ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpEqualTo n){
printTab();
System.out.print(" ( ExpEqualTo: " );
n.exp1_.accept(this);
//System.out.print(" == ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpNotEqualTo n){
printTab();
System.out.print(" ( ExpNotEqualTo: " );
n.exp1_.accept(this);
//System.out.print(" != ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpAndOp n){
printTab();
System.out.print(" ( ExpAndOp: " );
n.exp1_.accept(this);
//System.out.print(" AND ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(ExpOrOp n){
printTab();
System.out.print(" ( ExpOrOp: " );
n.exp1_.accept(this);
//System.out.print(" OR ");
n.exp2_.accept(this);
System.out.println(" ) " );
}
public void visit(LtrBoolFalse n){
System.out.print(" ( LtrBoolFalse: " );
System.out.print(n.ltrBoolFalse_);
System.out.print(" ) " );
}
public void visit(LtrBoolTrue n){
System.out.print(" ( LtrBoolTrue: " );
System.out.print(n.ltrBoolTrue_);
System.out.print(" ) " );
}
public void visit(LtrChar n){
System.out.print(" ( LtrChar: " );
System.out.print(n.ltrChar_);
System.out.print(" ) " );
}
public void visit(LtrInt n){
System.out.print(" ( LtrInt: " );
System.out.print(n.ltrInt_);
System.out.print(" ) " );
}
public void visit(LtrString n){
System.out.print(" ( LtrString: " );
System.out.print(n.ltrString_);
System.out.print(" ) " );
}
public void visit(Identifier n){
System.out.print(" ( ID: " );
System.out.print(n.identifier_);
System.out.print(" ) " );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -