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

71 lines
2.1 KiB
Java
Executable File

// ino.module.UnaryExpr.8655.package
package de.dhbwstuttgart.syntaxtree.statement;
// ino.end
// ino.module.UnaryExpr.8655.import
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
// ino.class.UnaryExpr.26298.declaration
public abstract class UnaryExpr extends Expr
// ino.end
// ino.class.UnaryExpr.26298.body
{
public Expr expr;
// ino.method.UnaryExpr.26302.definition
public UnaryExpr(int offset,int variableLength)
// ino.end
// ino.method.UnaryExpr.26302.body
{
super(offset,variableLength);
}
// ino.end
private Menge<RefType> getNumericTypes(){
Menge<RefType> ret = new Menge<>();
ret.add(new RefType("Integer",this,-1));
ret.add(new RefType("Long",this,-1));
ret.add(new RefType("Double",this,-1));
ret.add(new RefType("Float",this,-1));
return ret ;
}
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
if(this.getType() == null)this.setType(TypePlaceholder.fresh(this));
ConstraintsSet ret = new ConstraintsSet();
OderConstraint oderConstraint = new OderConstraint();
ret.add(this.expr.TYPEExpr(assumptions));
for(RefType t : getNumericTypes()){
UndConstraint undConstraint = new UndConstraint();
undConstraint.addConstraint(this.getType().TYPE(assumptions, this), t.TYPE(assumptions, this));
undConstraint.addConstraint(this.expr.getType().TYPE(assumptions, this), t.TYPE(assumptions, this));
oderConstraint.addConstraint(undConstraint);
}
ret.add(oderConstraint);
return ret;
}
@Override
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
ConstraintsSet ret = this.TYPEExpr(assumptions);
this.setType(new de.dhbwstuttgart.syntaxtree.type.Void(this, -1).TYPE(assumptions, this));
return ret;
}
}
// ino.end