package IC.Hierarchy; import IC.Error.*; import IC.Semantic.*; import IC.SymbolTable.*; import IC.LowIR.*; /** *
Title:
*Description:
*Copyright: Copyright (c) 2003
*Company:
* @author unascribed * @version 1.0 */ public class IfElseStmt extends Stmt { public Expr ife; public Stmt s; public Stmt elses; public IfElseStmt(Node i, Node st, Node stelse) { ife = (Expr) i; s = (Stmt) st; elses = (Stmt) stelse; } public Var translate(){ Var t1 = ife.translate(); //Var t = new Var(LIR.getNextName(),tableRef); //tableRef.put(t.name, new TableEntry(t.name, "temp var", null)); String trueLabel = LIR.getNextLabel(); String endLabel = LIR.getNextLabel(); LIR.irList.add(new JumpC(t1,trueLabel)); elses.translate(); //LIR.irList.add(new Copy(t,elses.translate())); LIR.irList.add(new Jump(endLabel)); LIR.irList.add(new Label(trueLabel)); s.translate(); //LIR.irList.add(new Copy(t,s.translate())); LIR.irList.add(new Label(endLabel)); return null; } public void print() { fprintln(nodenum + ": " + "IfElseStmt(N" + getNum(ife) + ",N" + getNum(s) + " N" + getNum(elses) + ");"); if (String.valueOf(ife) != "null") { ife.print(); } if (String.valueOf(s) != "null") { s.print(); } if (String.valueOf(elses) != "null") { elses.print(); } } public Object accept(Visitor v, SymTable st) throws SemanticError { return (v.visit(this, st)); } //This method converts AST to High IR public void convertToHIR() { if (s instanceof Block) { s = new BlockHIR( ( (Block) s).s); s.convertToHIR(); } if (elses instanceof Block) { elses = new BlockHIR( ( (Block) elses).s); elses.convertToHIR(); } } }