JavaPatternMatching/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java

298 lines
8.0 KiB
Java
Raw Normal View History

2013-10-18 11:33:46 +00:00
// ino.module.Binary.8623.package
2014-09-02 08:33:54 +00:00
package de.dhbwstuttgart.syntaxtree.statement;
2013-10-18 11:33:46 +00:00
// ino.end
// ino.module.Binary.8623.import
import java.util.Enumeration;
import java.util.HashMap;
2013-10-18 11:33:46 +00:00
import java.util.Hashtable;
import java.util.Vector;
2013-10-18 11:33:46 +00:00
import org.apache.log4j.Logger;
2014-09-08 13:12:47 +00:00
2014-09-04 14:35:44 +00:00
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;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.syntaxtree.Class;
2014-09-04 14:35:44 +00:00
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
2014-09-02 08:33:54 +00:00
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;
2014-09-08 13:12:47 +00:00
import de.dhbwstuttgart.typeinference.ConstraintType;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint;
2014-09-08 13:12:47 +00:00
import de.dhbwstuttgart.typeinference.Pair;
2014-09-02 08:33:54 +00:00
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;
2013-10-18 11:33:46 +00:00
// 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();
2014-04-23 15:59:39 +00:00
ret.add(this.expr1.TYPEExpr(assumptions));
ret.add(this.expr2.TYPEExpr(assumptions));
/**
* Berechnet die Constraints dieses Operators f<EFBFBD>r die 2 gegebenen Parameter
* Die Operatoren sind meistens <EFBFBD>berladen. Es entstehen mehrere Oder-Verkn<EFBFBD>pfte Constraints.
* @param expr1
* @param expr2
* @return
*/
if(this.getType()==null)this.set_Type(TypePlaceholder.fresh(this));
OderConstraint oderCons = new OderConstraint();
2014-09-08 13:12:47 +00:00
HashMap<ConstraintType,ConstraintType> rMap = this.op.getReturnTypes(assumptions);
for(ConstraintType rT : rMap.keySet()){
UndConstraint c = new UndConstraint();
2014-09-08 13:12:47 +00:00
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);
2013-10-18 11:33:46 +00:00
return ret;
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
2014-04-23 15:59:39 +00:00
JavaCodeResult ret = new JavaCodeResult();
ret.attach(this.expr1.printJavaCode(resultSet)).attach(" ");
ret.attach(this.op.toString()+" ");
ret.attach(this.expr2.printJavaCode(resultSet));
return ret;
2013-10-18 11:33:46 +00:00
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
2014-04-09 13:54:20 +00:00
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
ret.add(this.expr1);
ret.add(this.expr2);
return ret;
}
2013-10-18 11:33:46 +00:00
}
// ino.end