// ino.module.WhileStmt.8659.package package de.dhbwstuttgart.syntaxtree.statement; // ino.end // ino.module.WhileStmt.8659.import import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.myexception.SCExcept; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.operator.LogOp; import de.dhbwstuttgart.syntaxtree.operator.Operator; import de.dhbwstuttgart.syntaxtree.operator.RelOp; import de.dhbwstuttgart.syntaxtree.type.BooleanType; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.Unify; // ino.class.WhileStmt.26326.declaration public class WhileStmt extends Statement // ino.end // ino.class.WhileStmt.26326.body { // ino.method.WhileStmt.26330.definition public WhileStmt(int offset, int variableLength) // ino.end // ino.method.WhileStmt.26330.body { super(offset,variableLength); } // ino.end // ino.attribute.expr.26333.declaration public Expr expr; // ino.end // ino.attribute.loop_block.26336.declaration public Statement loop_block; // ino.end // ino.attribute.parserlog.26339.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end // ino.method.set_Expr.26342.definition public void set_Expr(Expr exp) // ino.end // ino.method.set_Expr.26342.body { this.expr = exp; } // ino.end // ino.method.set_Loop_block.26345.definition public void set_Loop_block(Statement blk) // ino.end // ino.method.set_Loop_block.26345.body { this.loop_block = blk; } // ino.end // ino.method.codegen.26351.definition public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) throws JVMCodeException // ino.end // ino.method.codegen.26351.body { if(loop_block!=null && expr!=null) { code.add_code(JVMCode.goto_); int breakpoint = code.get_code_length(); code.add_code_short(0); loop_block.codegen(classfile, code, paralist); code.set_code_short(code.get_code_length() + 1 - breakpoint, breakpoint); loop_codegen(classfile, code, breakpoint, false, paralist); } } // ino.end // ino.method.loop_codegen.26354.definition public void loop_codegen(ClassFile classfile, CodeAttribute code, int breakpoint, boolean not, Vector paralist) throws JVMCodeException // ino.end // ino.method.loop_codegen.26354.body { if(expr instanceof NotExpr) { expr = ((NotExpr)expr).get_Expr(); loop_codegen(classfile, code, breakpoint, !not, paralist); } else if(expr instanceof Binary) { Operator op = ((Binary)expr).get_Operator(); if(op instanceof LogOp) ((LogOp)op).loop_codegen(classfile, code, expr, breakpoint, !not, paralist); else if(op instanceof RelOp) { Expr expr1 = ((Binary)expr).get_Expr1(); Expr expr2 = ((Binary)expr).get_Expr2(); expr1.codegen(classfile, code, paralist); expr2.codegen(classfile, code, paralist); if(expr1 instanceof Null || expr2 instanceof Null) ((RelOp)op).if_codegen(classfile, code, "null", !not); else ((RelOp)op).if_codegen(classfile, code, expr1.getTypeName(), !not); code.add_code_short(breakpoint + 3 - code.get_code_length()); } else throw new JVMCodeException("JVMCodeException: WhileStmt: void loop_codegen(ClassFile classfile, Code_attribute code, int breakpoint, boolean not)"); } else { expr.codegen(classfile, code, paralist); if(!not) code.add_code(JVMCode.ifne); else code.add_code(JVMCode.ifeq); code.add_code_short(breakpoint + 3 - code.get_code_length()); } } // ino.end // ino.method.toString.26360.defdescription type=javadoc /** *
Author: Martin Pl�micke * @return */ // ino.end // ino.method.toString.26360.definition public String toString() // ino.end // ino.method.toString.26360.body { return "WHILE " + loop_block.toString(); } // ino.end // ino.method.wandleRefTypeAttributes2GenericAttributes.26363.definition public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) // ino.end // ino.method.wandleRefTypeAttributes2GenericAttributes.26363.body { if(loop_block!=null){ loop_block.wandleRefTypeAttributes2GenericAttributes(paralist,genericMethodParameters); } } // ino.end @Override public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); ret.add(expr.TYPEExpr(assumptions)); SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType().TYPE(assumptions, this), new RefType("Boolean",this, 0).TYPE(assumptions, this)); // while(expr){}; expr <. boolean ret.add(exprMustBeBool); ret.add(this.loop_block.TYPEStmt(assumptions)); this.setType(loop_block.getType()); return ret; } public int getTypeLineNumber() { throw new NotImplementedException(); } @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { return new JavaCodeResult().attach("while(").attach(this.expr.printJavaCode(resultSet)).attach(")").attach(this.loop_block.printJavaCode(resultSet)); } @Override public Vector getChildren() { Vector ret = new Vector(); ret.add(this.expr); ret.add(this.loop_block); return ret; } } // ino.end