JavaPatternMatching/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java
2014-10-09 12:01:16 +02:00

298 lines
8.0 KiB
Java
Executable File
Raw Blame History

// ino.module.Binary.8623.package
package de.dhbwstuttgart.syntaxtree.statement;
// ino.end
// ino.module.Binary.8623.import
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
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.AddOp;
import de.dhbwstuttgart.syntaxtree.operator.LogOp;
import de.dhbwstuttgart.syntaxtree.operator.MulOp;
import de.dhbwstuttgart.syntaxtree.operator.Operator;
import de.dhbwstuttgart.syntaxtree.operator.RelOp;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
// ino.class.Binary.24966.description type=line
// neu von Felix
// ino.end
// ino.class.Binary.24966.declaration
public class Binary extends BinaryExpr
// ino.end
// ino.class.Binary.24966.body
{
// ino.method.Binary.24970.definition
public Binary(int offset, int variableLength)
// ino.end
// ino.method.Binary.24970.body
{
super(offset,variableLength);
}
// ino.end
// ino.attribute.parserlog.24973.decldescription type=javadoc
/**
* Logger: log4j
*/
// ino.end
// ino.attribute.parserlog.24973.declaration
protected static Logger parserlog = Logger.getLogger("parser");
// ino.end
// ino.attribute.expr1.24976.declaration
public Expr expr1;
// ino.end
// ino.attribute.op.24979.declaration
public Operator op;
// ino.end
// ino.attribute.expr2.24982.declaration
public Expr expr2;
// ino.end
// ino.method.set_Expr1.24988.definition
public void set_Expr1(Expr exp)
// ino.end
// ino.method.set_Expr1.24988.body
{
this.expr1=exp;
}
// ino.end
// ino.method.set_Expr2.24991.definition
public void set_Expr2(Expr exp)
// ino.end
// ino.method.set_Expr2.24991.body
{
this.expr2=exp;
}
// ino.end
// ino.method.set_Operator.24994.definition
public void set_Operator(Operator Op)
// ino.end
// ino.method.set_Operator.24994.body
{
this.op=Op;
}
// ino.end
// ino.method.get_Name.24997.definition
public String get_Name()
// ino.end
// ino.method.get_Name.24997.body
{
return null;
}
// ino.end
// ino.method.get_Operator.25000.definition
public Operator get_Operator()
// ino.end
// ino.method.get_Operator.25000.body
{
return op;
}
// ino.end
// ino.method.get_Expr1.25003.definition
public Expr get_Expr1()
// ino.end
// ino.method.get_Expr1.25003.body
{
return expr1;
}
// ino.end
// ino.method.get_Expr2.25006.definition
public Expr get_Expr2()
// ino.end
// ino.method.get_Expr2.25006.body
{
return expr2;
}
// ino.end
// ino.method.codegen.25009.definition
public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
throws JVMCodeException
// ino.end
// ino.method.codegen.25009.body
{
if(type_check(code))
{
op.codegen(classfile, code, this, false, paralist);
}
else
{
throw new JVMCodeException("JVMCodeException: Binary: void codegen(ClassFile classfile, Code_attribute code)");
}
}
// ino.end
// ino.method.not_codegen.25012.definition
public void not_codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
throws JVMCodeException
// ino.end
// ino.method.not_codegen.25012.body
{
if(((op instanceof RelOp) || (op instanceof LogOp)) && type_check(code))
{
op.codegen(classfile, code, this, true, paralist);
}
else
{
throw new JVMCodeException("JVMCodeException: Binary: void not_codegen(ClassFile classfile, Code_attribute code)");
}
}
// ino.end
// ino.method.neg_codegen.25015.definition
public void neg_codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
throws JVMCodeException
// ino.end
// ino.method.neg_codegen.25015.body
{
if(((op instanceof AddOp) || (op instanceof MulOp)) && type_check(code))
{
op.codegen(classfile, code, this, true, paralist);
}
else
{
throw new JVMCodeException("JVMCodeException: Binary: void neg_codegen(ClassFile classfile, Code_attribute code)");
}
}
// ino.end
// ino.method.type_check.25018.definition
public boolean type_check(CodeAttribute code)
throws JVMCodeException
// ino.end
// ino.method.type_check.25018.body
{
int type1 = JVMCode.get_nType(expr1.getTypeName());
int type2 = JVMCode.get_nType(expr2.getTypeName());
if((type1 < type2) || ((type1==0 || type1==1) && (type2==2 || type2==3)))
{
return false;
}
if(type1 != type2)
{
code.add_code(JVMCode.n2n(expr2.getTypeName(), expr1.getTypeName()));
}
return true;
}
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.25027.definition
public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist, Vector<GenericTypeVar> genericMethodParameters)
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.25027.body
{
}
// ino.end
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
ret.add(this.expr1.TYPEExpr(assumptions));
ret.add(this.expr2.TYPEExpr(assumptions));
/**
* Berechnet die Constraints dieses Operators f<>r die 2 gegebenen Parameter
* Die Operatoren sind meistens <20>berladen. Es entstehen mehrere Oder-Verkn<6B>pfte Constraints.
* @param expr1
* @param expr2
* @return
*/
if(this.getType()==null)this.set_Type(TypePlaceholder.fresh(this));
OderConstraint oderCons = new OderConstraint();
HashMap<ConstraintType,ConstraintType> rMap = this.op.getReturnTypes(assumptions);
for(ConstraintType rT : rMap.keySet()){
UndConstraint c = new UndConstraint();
c.addConstraint(this.getType().TYPE(assumptions, this),rT);
c.addConstraint(this.expr1.getType().TYPE(assumptions, this), rMap.get(rT));
c.addConstraint(this.expr2.getType().TYPE(assumptions, this), rMap.get(rT));
oderCons.addConstraint(c);
}
ret.add(oderCons);
return ret;
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
JavaCodeResult ret = new JavaCodeResult();
ret.attach(this.expr1.printJavaCode(resultSet)).attach(" ");
ret.attach(this.op.toString()+" ");
ret.attach(this.expr2.printJavaCode(resultSet));
return ret;
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
ret.add(this.expr1);
ret.add(this.expr2);
return ret;
}
}
// ino.end