Operator unterstützt jetzt auch Double und Float statt nur Integer als Typ

This commit is contained in:
JanUlrich 2014-04-24 12:42:10 +02:00
parent ce61fdf3c7
commit e7db1e7494
5 changed files with 34 additions and 12 deletions

View File

@ -66,7 +66,7 @@ public abstract class AddOp extends Operator
@Override
public Type getReturnType(TypeAssumptions ass) {
public Type getReturnType(RefType inputType, TypeAssumptions ass) {
Type ret = ass.getTypeFor(new RefType("java.lang.Integer",-1));
if(ret == null)throw new DebugException("java.lang.Integer kann nicht aufgelöst werden");
return ret;

View File

@ -234,10 +234,10 @@ public abstract class LogOp extends Operator
}
@Override
public Type getReturnType(TypeAssumptions ass) {
Type ret = ass.getTypeFor(new RefType("java.lang.Boolean",-1));
if(ret == null)throw new DebugException("java.lang.Boolean kann nicht aufgelöst werden");
@Override
public Type getReturnType(RefType inputType, TypeAssumptions ass) {
Type iT = ass.getTypeFor(inputType);
Type ret = getOperatorTypes().get(iT);
return ret;
}

View File

@ -6,10 +6,14 @@ package mycompiler.myoperator;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.DebugException;
import mycompiler.myexception.CTypeReconstructionException;
import mycompiler.mystatement.Binary;
import mycompiler.mytype.Pair;
import mycompiler.mytype.RefType;
import mycompiler.mytype.Type;
import mycompiler.mytypereconstruction.CSupportData;
import mycompiler.mytypereconstruction.CTriple;
import mycompiler.mytypereconstruction.set.CSubstitutionSet;
@ -43,6 +47,13 @@ public abstract class MulOp extends Operator
return types;
}
@Override
public Type getReturnType(RefType inputType, TypeAssumptions ass) {
Type iT = ass.getTypeFor(inputType);
Type ret = getOperatorTypes().get(iT);
return ret;
}
}

View File

@ -9,6 +9,7 @@ import java.util.Vector;
import typinferenz.ConstraintsSet;
import typinferenz.SingleConstraint;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypeinferenceException;
import mycompiler.IItemWithOffset;
import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute;
@ -124,12 +125,22 @@ public abstract class Operator implements IItemWithOffset
*/
public ConstraintsSet TYPEExpr(Expr expr1, Expr expr2, TypeAssumptions ass) {
ConstraintsSet ret = new ConstraintsSet();
ret.add(new SingleConstraint(expr1.getType(), this.getReturnType(ass)));
ret.add(new SingleConstraint(expr2.getType(), this.getReturnType(ass)));
Type expr1Type = expr1.getType();
if(!(expr1Type instanceof RefType))throw new TypeinferenceException("Nicht erlaubter Typ", this);
Type expr2Type = expr1.getType();
if(!(expr2Type instanceof RefType))throw new TypeinferenceException("Nicht erlaubter Typ", this);
Type expr1RetType = this.getReturnType((RefType) expr1Type, ass);
if(expr1RetType == null)throw new TypeinferenceException("Nicht erlaubter Typ "+expr1Type, this);
Type expr2RetType = this.getReturnType((RefType) expr2Type, ass);
if(expr2RetType == null)throw new TypeinferenceException("Nicht erlaubter Typ "+expr2Type, this);
ret.add(new SingleConstraint(expr1Type, expr1RetType));
ret.add(new SingleConstraint(expr2Type, expr2RetType));
return ret;
}
public abstract Type getReturnType(TypeAssumptions ass);
public abstract Type getReturnType(RefType inputType, TypeAssumptions ass);
}
// ino.end

View File

@ -57,11 +57,11 @@ public abstract class RelOp extends Operator
}
@Override
public Type getReturnType(TypeAssumptions ass){
Type ret = ass.getTypeFor(new RefType("java.lang.Boolean",-1));
if(ret == null)throw new DebugException("java.lang.Boolean kann nicht aufgelöst werden");
public Type getReturnType(RefType inputType, TypeAssumptions ass) {
Type iT = ass.getTypeFor(inputType);
Type ret = getOperatorTypes().get(iT);
return ret;
}
}
}
// ino.end