diff --git a/src/mycompiler/myoperator/AddOp.java b/src/mycompiler/myoperator/AddOp.java index 3e9a3024..38c96b10 100755 --- a/src/mycompiler/myoperator/AddOp.java +++ b/src/mycompiler/myoperator/AddOp.java @@ -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; diff --git a/src/mycompiler/myoperator/LogOp.java b/src/mycompiler/myoperator/LogOp.java index a7018b11..a8492dbf 100755 --- a/src/mycompiler/myoperator/LogOp.java +++ b/src/mycompiler/myoperator/LogOp.java @@ -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; } diff --git a/src/mycompiler/myoperator/MulOp.java b/src/mycompiler/myoperator/MulOp.java index 2007040e..6b598cf8 100755 --- a/src/mycompiler/myoperator/MulOp.java +++ b/src/mycompiler/myoperator/MulOp.java @@ -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; + } } diff --git a/src/mycompiler/myoperator/Operator.java b/src/mycompiler/myoperator/Operator.java index 2e47751a..c30876b2 100755 --- a/src/mycompiler/myoperator/Operator.java +++ b/src/mycompiler/myoperator/Operator.java @@ -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 diff --git a/src/mycompiler/myoperator/RelOp.java b/src/mycompiler/myoperator/RelOp.java index ab55a08b..e66df707 100755 --- a/src/mycompiler/myoperator/RelOp.java +++ b/src/mycompiler/myoperator/RelOp.java @@ -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