From 748308e11e6791284b302f61e5bc0d99a0957b6a Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Wed, 8 Oct 2014 21:15:43 +0800 Subject: First commit --- src/kanga/visitor/GJDepthFirst.java | 455 ++++++++++++++++++++++++++++++++++++ 1 file changed, 455 insertions(+) create mode 100644 src/kanga/visitor/GJDepthFirst.java (limited to 'src/kanga/visitor/GJDepthFirst.java') diff --git a/src/kanga/visitor/GJDepthFirst.java b/src/kanga/visitor/GJDepthFirst.java new file mode 100644 index 0000000..53ee768 --- /dev/null +++ b/src/kanga/visitor/GJDepthFirst.java @@ -0,0 +1,455 @@ +// +// Generated by JTB 1.3.2 +// + +package kanga.visitor; +import java.util.Enumeration; + +import kanga.syntaxtree.ALoadStmt; +import kanga.syntaxtree.AStoreStmt; +import kanga.syntaxtree.BinOp; +import kanga.syntaxtree.CJumpStmt; +import kanga.syntaxtree.CallStmt; +import kanga.syntaxtree.ErrorStmt; +import kanga.syntaxtree.Exp; +import kanga.syntaxtree.Goal; +import kanga.syntaxtree.HAllocate; +import kanga.syntaxtree.HLoadStmt; +import kanga.syntaxtree.HStoreStmt; +import kanga.syntaxtree.IntegerLiteral; +import kanga.syntaxtree.JumpStmt; +import kanga.syntaxtree.Label; +import kanga.syntaxtree.MoveStmt; +import kanga.syntaxtree.NoOpStmt; +import kanga.syntaxtree.Node; +import kanga.syntaxtree.NodeList; +import kanga.syntaxtree.NodeListOptional; +import kanga.syntaxtree.NodeOptional; +import kanga.syntaxtree.NodeSequence; +import kanga.syntaxtree.NodeToken; +import kanga.syntaxtree.Operator; +import kanga.syntaxtree.PassArgStmt; +import kanga.syntaxtree.PrintStmt; +import kanga.syntaxtree.Procedure; +import kanga.syntaxtree.Reg; +import kanga.syntaxtree.SimpleExp; +import kanga.syntaxtree.SpilledArg; +import kanga.syntaxtree.Stmt; +import kanga.syntaxtree.StmtList; + +/** + * Provides default methods which visit each node in the tree in depth-first + * order. Your visitors may extend this class. + */ +public class GJDepthFirst implements GJVisitor { + // + // Auto class visitors--probably don't need to be overridden. + // + public R visit(NodeList n, A argu) { + R _ret=null; + int _count=0; + for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + return _ret; + } + + public R visit(NodeListOptional n, A argu) { + if ( n.present() ) { + R _ret=null; + int _count=0; + for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + return _ret; + } + else + return null; + } + + public R visit(NodeOptional n, A argu) { + if ( n.present() ) + return n.node.accept(this,argu); + else + return null; + } + + public R visit(NodeSequence n, A argu) { + R _ret=null; + int _count=0; + for ( Enumeration e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + return _ret; + } + + public R visit(NodeToken n, A argu) { return null; } + + // + // User-generated visitor methods below + // + + /** + * f0 -> "MAIN" + * f1 -> "[" + * f2 -> IntegerLiteral() + * f3 -> "]" + * f4 -> "[" + * f5 -> IntegerLiteral() + * f6 -> "]" + * f7 -> "[" + * f8 -> IntegerLiteral() + * f9 -> "]" + * f10 -> StmtList() + * f11 -> "END" + * f12 -> ( Procedure() )* + * f13 -> + */ + public R visit(Goal n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + n.f8.accept(this, argu); + n.f9.accept(this, argu); + n.f10.accept(this, argu); + n.f11.accept(this, argu); + n.f12.accept(this, argu); + n.f13.accept(this, argu); + return _ret; + } + + /** + * f0 -> ( ( Label() )? Stmt() )* + */ + public R visit(StmtList n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> Label() + * f1 -> "[" + * f2 -> IntegerLiteral() + * f3 -> "]" + * f4 -> "[" + * f5 -> IntegerLiteral() + * f6 -> "]" + * f7 -> "[" + * f8 -> IntegerLiteral() + * f9 -> "]" + * f10 -> StmtList() + * f11 -> "END" + */ + public R visit(Procedure n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + n.f8.accept(this, argu); + n.f9.accept(this, argu); + n.f10.accept(this, argu); + n.f11.accept(this, argu); + return _ret; + } + + /** + * f0 -> NoOpStmt() + * | ErrorStmt() + * | CJumpStmt() + * | JumpStmt() + * | HStoreStmt() + * | HLoadStmt() + * | MoveStmt() + * | PrintStmt() + * | ALoadStmt() + * | AStoreStmt() + * | PassArgStmt() + * | CallStmt() + */ + public R visit(Stmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "NOOP" + */ + public R visit(NoOpStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "ERROR" + */ + public R visit(ErrorStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "CJUMP" + * f1 -> Reg() + * f2 -> Label() + */ + public R visit(CJumpStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> "JUMP" + * f1 -> Label() + */ + public R visit(JumpStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> "HSTORE" + * f1 -> Reg() + * f2 -> IntegerLiteral() + * f3 -> Reg() + */ + public R visit(HStoreStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + return _ret; + } + + /** + * f0 -> "HLOAD" + * f1 -> Reg() + * f2 -> Reg() + * f3 -> IntegerLiteral() + */ + public R visit(HLoadStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + return _ret; + } + + /** + * f0 -> "MOVE" + * f1 -> Reg() + * f2 -> Exp() + */ + public R visit(MoveStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> "PRINT" + * f1 -> SimpleExp() + */ + public R visit(PrintStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> "ALOAD" + * f1 -> Reg() + * f2 -> SpilledArg() + */ + public R visit(ALoadStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> "ASTORE" + * f1 -> SpilledArg() + * f2 -> Reg() + */ + public R visit(AStoreStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> "PASSARG" + * f1 -> IntegerLiteral() + * f2 -> Reg() + */ + public R visit(PassArgStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> "CALL" + * f1 -> SimpleExp() + */ + public R visit(CallStmt n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> HAllocate() + * | BinOp() + * | SimpleExp() + */ + public R visit(Exp n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "HALLOCATE" + * f1 -> SimpleExp() + */ + public R visit(HAllocate n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> Operator() + * f1 -> Reg() + * f2 -> SimpleExp() + */ + public R visit(BinOp n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> "LT" + * | "PLUS" + * | "MINUS" + * | "TIMES" + */ + public R visit(Operator n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "SPILLEDARG" + * f1 -> IntegerLiteral() + */ + public R visit(SpilledArg n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> Reg() + * | IntegerLiteral() + * | Label() + */ + public R visit(SimpleExp n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "a0" + * | "a1" + * | "a2" + * | "a3" + * | "t0" + * | "t1" + * | "t2" + * | "t3" + * | "t4" + * | "t5" + * | "t6" + * | "t7" + * | "s0" + * | "s1" + * | "s2" + * | "s3" + * | "s4" + * | "s5" + * | "s6" + * | "s7" + * | "t8" + * | "t9" + * | "v0" + * | "v1" + */ + public R visit(Reg n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> + */ + public R visit(IntegerLiteral n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> + */ + public R visit(Label n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + +} -- cgit v1.2.3