Einführung von ConstraintType

This commit is contained in:
JanUlrich 2014-09-08 15:12:47 +02:00
parent 9f97bef6cd
commit 6858092ef1
79 changed files with 628 additions and 638 deletions

View File

@ -37,11 +37,11 @@ import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.IMatchable;
import de.dhbwstuttgart.syntaxtree.type.ITypeContainer;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.FunNInterface;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;

View File

@ -7,7 +7,7 @@
********************************************/
// user code:
package mycompiler.myparser;
package de.dhbwstuttgart.parser;
%%

File diff suppressed because it is too large Load Diff

View File

@ -4,105 +4,25 @@
Backup von JavaParser.jay 10.April 17 Uhr
*/
package mycompiler.myparser;
package de.dhbwstuttgart.parser;
import mycompiler.myclass.FieldDeclaration;
import mycompiler.myclass.GenericDeclarationList;
import mycompiler.myclass.Field;
import de.dhbwstuttgart.core.AClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.ImportDeclarations;
import de.dhbwstuttgart.syntaxtree.Interface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.*;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.misc.*;
import de.dhbwstuttgart.syntaxtree.modifier.*;
import de.dhbwstuttgart.syntaxtree.operator.*;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.syntaxtree.statement.*;
import java.util.Vector;
import mycompiler.SourceFile;
import mycompiler.AClassOrInterface;
import mycompiler.myclass.Class;
import mycompiler.myclass.ClassBody;
import mycompiler.myclass.Constructor;
import mycompiler.myclass.Constant;
import mycompiler.myclass.ImportDeclarations;
import mycompiler.myclass.DeclId;
import mycompiler.myclass.ExceptionList;
import mycompiler.myclass.FormalParameter;
import mycompiler.myclass.Method;
import mycompiler.myclass.ParameterList;
import mycompiler.myclass.UsedId;
import mycompiler.myinterface.Interface;
import mycompiler.myinterface.InterfaceBody;
import mycompiler.mymodifier.Abstract;
import mycompiler.mymodifier.Final;
import mycompiler.mymodifier.Modifier;
import mycompiler.mymodifier.Modifiers;
import mycompiler.mymodifier.Private;
import mycompiler.mymodifier.Protected;
import mycompiler.mymodifier.Public;
import mycompiler.mymodifier.Static;
import mycompiler.myoperator.AndOp;
import mycompiler.myoperator.DivideOp;
import mycompiler.myoperator.EqualOp;
import mycompiler.myoperator.GreaterEquOp;
import mycompiler.myoperator.GreaterOp;
import mycompiler.myoperator.LessEquOp;
import mycompiler.myoperator.LessOp;
import mycompiler.myoperator.MinusOp;
import mycompiler.myoperator.ModuloOp;
import mycompiler.myoperator.NotEqualOp;
import mycompiler.myoperator.Operator;
import mycompiler.myoperator.OrOp;
import mycompiler.myoperator.PlusOp;
import mycompiler.myoperator.TimesOp;
import mycompiler.mystatement.ArgumentList;
import mycompiler.mystatement.Assign;
import mycompiler.mystatement.Binary;
import mycompiler.mystatement.Block;
import mycompiler.mystatement.BoolLiteral;
import mycompiler.mystatement.FloatLiteral;
import mycompiler.mystatement.DoubleLiteral;
import mycompiler.mystatement.LongLiteral;
import mycompiler.mystatement.CastExpr;
import mycompiler.mystatement.CharLiteral;
import mycompiler.mystatement.EmptyStmt;
import mycompiler.mystatement.Expr;
import mycompiler.mystatement.ExprStmt;
import mycompiler.mystatement.IfStmt;
import mycompiler.mystatement.InstanceOf;
import mycompiler.mystatement.IntLiteral;
import mycompiler.mystatement.Literal;
import mycompiler.mystatement.InstVar;
import mycompiler.mystatement.LocalOrFieldVar;
import mycompiler.mystatement.LocalVarDecl;
import mycompiler.mystatement.MethodCall;
import mycompiler.mystatement.NegativeExpr;
import mycompiler.mystatement.NewClass;
import mycompiler.mystatement.NotExpr;
import mycompiler.mystatement.Null;
import mycompiler.mystatement.PositivExpr;
import mycompiler.mystatement.PostDecExpr;
import mycompiler.mystatement.PostIncExpr;
import mycompiler.mystatement.PreDecExpr;
import mycompiler.mystatement.PreIncExpr;
import mycompiler.mystatement.Receiver;
import mycompiler.mystatement.Return;
import mycompiler.mystatement.Statement;
import mycompiler.mystatement.StringLiteral;
import mycompiler.mystatement.This;
import mycompiler.mystatement.UnaryMinus;
import mycompiler.mystatement.UnaryNot;
import mycompiler.mystatement.UnaryPlus;
import mycompiler.mystatement.WhileStmt;
import mycompiler.mystatement.ForStmt;
import mycompiler.mystatement.LambdaExpression;
import mycompiler.mytype.BaseType;
import mycompiler.mytype.BooleanType;
import mycompiler.mytype.CharacterType;
import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.BoundedGenericTypeVar;
import mycompiler.mytype.IntegerType;
import mycompiler.mytype.ParaList;
import mycompiler.mytype.RefType;
import mycompiler.mytype.Type;
import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytype.Void;
import mycompiler.mytype.WildcardType;
import mycompiler.mytype.ExtendsWildcardType;
import mycompiler.mytype.SuperWildcardType;
import mycompiler.mytype.Pair;
public class JavaParser{
public Vector path = new Vector();

View File

@ -20,7 +20,6 @@ import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.Type;

View File

@ -10,6 +10,7 @@ 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;
@ -136,7 +137,7 @@ public class FieldDeclaration extends Field{
*/
//TypeCheck, falls es sich um einen RefType handelt:
this.getType().checkType(localAssumptions, this);
ConstraintType thisType = this.getType().TYPE(localAssumptions, this);
/*
if(this.getType()!=null && (this.getType() instanceof RefType)){
Type replaceType = null;
@ -146,13 +147,13 @@ public class FieldDeclaration extends Field{
}
*/
SingleConstraint c1 = new SingleConstraint(this.getType(), this.getType());
SingleConstraint c1 = new SingleConstraint(thisType, thisType);
ret.add(c1); //Damit die TypVariable des Felds in den Constraints auftaucht
if(this.wert!=null){
//Falls bei der Deklaration ein Wert zugewiesen wird, verhält sich das Constraintserzeugen wie bei dem Assign-Statement:
ret.add(this.wert.TYPEExpr(localAssumptions));
ret.add(new SingleConstraint(this.wert.getType(), this.getType()));
ret.add(new SingleConstraint(this.wert.getType().TYPE(localAssumptions,this), thisType));
}
return ret;
}

View File

@ -527,7 +527,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
}
//TypeCheck, falls es sich um einen RefType handelt:
this.returntype = this.returntype.checkType(localAss, this);
this.returntype = this.returntype.TYPE(localAss, this).getType();
/*
if(this.returntype!=null && (this.returntype instanceof RefType)&&
!(this.returntype instanceof mycompiler.mytype.Void)){//Sonderfall der Methode: Ihr Typ darf Void definiert werden.
@ -540,7 +540,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
//Die Parameter zu den Assumptions hinzufügen:
if(this.parameterlist!=null)for(FormalParameter param : this.parameterlist){
param.setType(param.getType().checkType(localAss, this));
param.setType(param.getType().TYPE(localAss, this).getType());
/*
if(param.getType() instanceof RefType)
{
@ -556,7 +556,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
}
ret.add(this.block.TYPEStmt(localAss));
//eine Verknüpfung mit der Type Assumption aus dem Assumption Set und dem ermittelten Typ der Methode:
ret.add(new SingleConstraint(this.block.getType(), this.returntype));
ret.add(new SingleConstraint(this.block.getType().TYPE(localAss, this), this.returntype.TYPE(localAss, this)));
return ret;
}

View File

@ -26,7 +26,6 @@ import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.modifier.Public;
import de.dhbwstuttgart.syntaxtree.type.BooleanType;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -35,6 +34,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.FunN;
import de.dhbwstuttgart.typeinference.FunNInterface;
import de.dhbwstuttgart.typeinference.FunNMethod;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint;
@ -1631,5 +1631,21 @@ public class SourceFile
//this.filename = filename;
}
@Override
public int getOffset() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getVariableLength() {
// TODO Auto-generated method stub
return 0;
}
}
// ino.end

View File

@ -2,10 +2,11 @@ package de.dhbwstuttgart.syntaxtree;
import java.util.Vector;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
@ -14,7 +15,7 @@ import de.dhbwstuttgart.typeinference.typedeployment.GenericTypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public abstract class SyntaxTreeNode{
public abstract class SyntaxTreeNode implements IItemWithOffset{
protected SyntaxTreeNode parent;

View File

@ -312,7 +312,7 @@ public class UsedId implements IItemWithOffset
// ino.end
public JavaCodeResult printJavaCode(ResultSet resultSet) {
if(this.name.size()>1)throw new TypeinferenceException("Es kann maximal nur eine Superklasse pro Klasse geben", this);
if(this.name.size()>1)throw new TypeinferenceException("Es kann maximal nur eine Superklasse pro Klasse geben", null);
JavaCodeResult ret = new JavaCodeResult(this.getQualifiedName().toString());
if(this.paralist != null){
ret.attach( "<" );

View File

@ -14,10 +14,11 @@ import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.type.IntegerType;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
@ -59,8 +60,8 @@ public abstract class AddOp extends Operator
}
@Override
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<Type,Type>();
public HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass) {
HashMap<ConstraintType,ConstraintType> ret = new HashMap<ConstraintType,ConstraintType>();
ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1),this));
ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1),this));
ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1),this));

View File

@ -1,6 +1,9 @@
// ino.module.AndOp.8595.package
package de.dhbwstuttgart.syntaxtree.operator;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.type.BooleanType;
import de.dhbwstuttgart.syntaxtree.type.IntegerType;

View File

@ -8,6 +8,7 @@ import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
@ -41,7 +42,7 @@ public class DivideOp extends MulOp
code.add_code(JVMCode.ndiv(expr1.getTypeName()));
}
// ino.end
}

View File

@ -10,11 +10,12 @@ import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.statement.Null;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.unify.Unify;
@ -75,6 +76,8 @@ public class EqualOp extends RelOp
else code.add_code(JVMCode.if_ncmpeq(type));
}
// ino.end
}
// ino.end

View File

@ -8,6 +8,7 @@ import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Expr;

View File

@ -18,10 +18,11 @@ import de.dhbwstuttgart.syntaxtree.statement.NotExpr;
import de.dhbwstuttgart.syntaxtree.statement.Null;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
import de.dhbwstuttgart.syntaxtree.type.BooleanType;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
@ -229,8 +230,8 @@ public abstract class LogOp extends Operator
}
@Override
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<Type,Type>();
public HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass) {
HashMap<ConstraintType,ConstraintType> ret = new HashMap<>();
ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Boolean",-1), this));
return ret;

View File

@ -10,9 +10,10 @@ import java.util.Vector;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.unify.Unify;
@ -40,8 +41,8 @@ public abstract class MulOp extends Operator
}
@Override
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<Type,Type>();
public HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass) {
HashMap<ConstraintType,ConstraintType> ret = new HashMap<>();
ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1), this));
ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1), this));
ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1), this));

View File

@ -13,8 +13,8 @@ import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.statement.Null;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.unify.Unify;
// ino.class.NotEqualOp.24241.declaration

View File

@ -13,14 +13,16 @@ import de.dhbwstuttgart.bytecode.JVMCode;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.type.Pair;
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.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -30,7 +32,7 @@ import de.dhbwstuttgart.typeinference.unify.Unify;
// ino.class.Operator.24257.declaration
public abstract class Operator implements IItemWithOffset
public abstract class Operator extends SyntaxTreeNode
// ino.end
// ino.class.Operator.24257.body
{
@ -120,7 +122,12 @@ public abstract class Operator implements IItemWithOffset
* @param ass
* @return
*/
public abstract HashMap<Type,Type> getReturnTypes(TypeAssumptions ass);
public abstract HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass);
@Override
public Vector<SyntaxTreeNode> getChildren() {
return new Vector<>();
}
}
// ino.end

View File

@ -13,9 +13,10 @@ import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.unify.Unify;
@ -51,8 +52,8 @@ public abstract class RelOp extends Operator
}
@Override
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<Type,Type>();
public HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass) {
HashMap<ConstraintType,ConstraintType> ret = new HashMap<>();
ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1), this));
ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1), this));
ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1), this));

View File

@ -20,13 +20,13 @@ import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.FreshTypeVariable;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -189,8 +189,8 @@ public class Assign extends Expr
ret.add(expr2.TYPEExpr(assumptions));
//this.setTypeVariable( TypePlaceholder.fresh(this));
this.setType(TypePlaceholder.fresh(this));
ret.add(new SingleConstraint(expr2.getType(), expr1.getType())); //expr2.type <. expr1.type
ret.add(new SingleConstraint(expr1.getType(), this.getType()));
ret.add(new SingleConstraint(expr2.getType().TYPE(assumptions, this), expr1.getType().TYPE(assumptions, this))); //expr2.type <. expr1.type
ret.add(new SingleConstraint(expr1.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
return ret;
}

View File

@ -7,8 +7,8 @@ import java.util.HashMap;
import java.util.Hashtable;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
@ -24,13 +24,14 @@ 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.Pair;
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;
@ -259,12 +260,12 @@ public class Binary extends BinaryExpr
*/
if(this.getType()==null)this.set_Type(TypePlaceholder.fresh(this));
OderConstraint oderCons = new OderConstraint();
HashMap<Type,Type> rMap = this.op.getReturnTypes(assumptions);
for(Type rT : rMap.keySet()){
HashMap<ConstraintType,ConstraintType> rMap = this.op.getReturnTypes(assumptions);
for(ConstraintType rT : rMap.keySet()){
UndConstraint c = new UndConstraint();
c.addConstraint(this.getType(),rT);
c.addConstraint(this.expr1.getType(), rMap.get(rT));
c.addConstraint(this.expr2.getType(), rMap.get(rT));
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);

View File

@ -7,8 +7,8 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
@ -21,6 +21,7 @@ import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.FreshTypeVariable;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
@ -192,8 +193,8 @@ public class Block extends Statement
}
else {
TypePlaceholder tph = TypePlaceholder.fresh(this);
ret.add(new SingleConstraint(this.getType(), tph));
ret.add(new SingleConstraint(stmt.getType(), tph));
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), new ConstraintType(tph)));
ret.add(new SingleConstraint(stmt.getType().TYPE(assumptions, this), new ConstraintType(tph)));
this.setType(tph);
}
}

View File

@ -126,12 +126,10 @@ public class BoolLiteral extends Literal
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
this.type = assumptions.getTypeFor(new RefType("java.lang.Boolean",-1), this);
this.type = assumptions.getTypeFor(new RefType("java.lang.Boolean",-1), this).getType();
return new ConstraintsSet();
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
if(Bool)return new JavaCodeResult("true");

View File

@ -164,7 +164,7 @@ public class DoubleLiteral extends Literal
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
this.setType(assumptions.getTypeFor(new RefType("Double",this.getOffset()), this));
this.setType(assumptions.getTypeFor(new RefType("Double",this.getOffset()), this).getType());
return new ConstraintsSet();
}

View File

@ -7,10 +7,11 @@ import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.unify.Unify;
// ino.class.ExprStmt.25265.declaration

View File

@ -5,7 +5,6 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
@ -21,11 +20,11 @@ import de.dhbwstuttgart.syntaxtree.operator.LogOp;
import de.dhbwstuttgart.syntaxtree.operator.Operator;
import de.dhbwstuttgart.syntaxtree.operator.RelOp;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -8,6 +8,7 @@ import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
@ -22,7 +23,6 @@ import de.dhbwstuttgart.syntaxtree.operator.Operator;
import de.dhbwstuttgart.syntaxtree.operator.RelOp;
import de.dhbwstuttgart.syntaxtree.type.BooleanType;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -30,6 +30,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.FreshTypeVariable;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -256,10 +257,10 @@ public class IfStmt extends Statement
ret.add(this.then_block.TYPEStmt(assumptions));
if(else_block!=null){
ret.add(this.else_block.TYPEStmt(assumptions));
if(!(else_block.getType() instanceof Void))ret.add(new SingleConstraint(else_block.getType(),this.getType()));
if(!(else_block.getType() instanceof Void))ret.add(new SingleConstraint(else_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
}
ret.add(new SingleConstraint(expr.getType(),assumptions.getTypeFor(new RefType("Boolean",0), this))); //(expressionDesIfStmt)<.boolean
if(!(then_block.getType() instanceof Void))ret.add(new SingleConstraint(then_block.getType(),this.getType()));
ret.add(new SingleConstraint(expr.getType().TYPE(assumptions, this),assumptions.getTypeFor(new RefType("Boolean",0), this))); //(expressionDesIfStmt)<.boolean
if(!(then_block.getType() instanceof Void))ret.add(new SingleConstraint(then_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
if(then_block.getType() instanceof Void &&
(else_block == null || else_block.getType() instanceof Void))this.setType(new Void(this.getOffset()));
return ret;

View File

@ -6,6 +6,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
@ -17,7 +18,6 @@ import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -25,6 +25,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.FreshTypeVariable;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint;
@ -211,8 +212,8 @@ public class InstVar extends Expr
OderConstraint oderConstraint = new OderConstraint();
for(FieldAssumption fa : assumptions.getFieldVars(this.get_Name())){
UndConstraint undConstraint = new UndConstraint();
undConstraint.addConstraint(fa.getAssumedType(),this.getType());
undConstraint.addConstraint(this.expr.getType(),fa.getParentClass().getType());
undConstraint.addConstraint(fa.getAssumedType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this));
undConstraint.addConstraint(this.expr.getType().TYPE(assumptions, this),fa.getParentClass().getType().TYPE(assumptions, this));
oderConstraint.addConstraint(undConstraint);
}
ret.add(oderConstraint);

View File

@ -161,7 +161,7 @@ public class IntLiteral extends Literal
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
//this.setType(new IntegerType());
this.set_Type(assumptions.getTypeFor(new RefType("java.lang.Integer",-1), this));
this.set_Type(assumptions.getTypeFor(new RefType("java.lang.Integer",-1), this).getType());
return ret;
}

View File

@ -149,7 +149,7 @@ public class LambdaExpression extends Expr{
this.setType(TypePlaceholder.fresh(this));
//ArgumentAssumptions + assumptions ergeben die Assumptions für die Statements innerhalb des Lambda-Bodys:
ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression
ret.add(new SingleConstraint(new FunN(method_body.getType(), paramTypes),this.getType()));
ret.add(new SingleConstraint(new FunN(method_body.getType(), paramTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
return ret;
}

View File

@ -379,13 +379,11 @@ public class LocalVarDecl extends Statement implements TypeInsertable
ConstraintsSet ret = new ConstraintsSet();
if((this.getType() instanceof RefType)){
Type replaceType = null;
replaceType = assumptions.getTypeFor((RefType)this.getType(), this);
if(replaceType == null)
throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this);
replaceType = assumptions.getTypeFor((RefType)this.getType(), this).getType();
this.setType(replaceType);
}
assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird.
ret.add(new SingleConstraint(this.getType(), this.getType()));
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
this.setReturnType(new Void(0)); //Return typ einer Variablendeklaration ist Void
return ret;

View File

@ -6,8 +6,8 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
@ -17,12 +17,12 @@ import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -219,13 +219,13 @@ public class NewClass extends Expr
for(int i=0; i<cA.getParaCount();i++){
ret.add(this.arglist.expr.elementAt(i).TYPEExpr(assumptions));
callConstraints.addConstraint( this.arglist.expr.elementAt(i).getType(), cA.getParameterType(i));
callConstraints.addConstraint( this.arglist.expr.elementAt(i).getType().TYPE(assumptions, this), cA.getParameterType(i).TYPE(assumptions, this));
}
//if(this.arglist != null && this.arglist.expr != null)for(Expr arg : this.arglist.expr){
// ret.add(arg.TYPEExpr(assumptions));
//}
this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),0), this));
this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),0), this).getType());
/*

View File

@ -7,6 +7,7 @@ import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
@ -16,13 +17,13 @@ import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.BooleanType;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.Void;
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.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -144,7 +145,7 @@ public class NotExpr extends UnaryExpr
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
OderConstraint constraint = new OderConstraint();
constraint.addConstraint(new Pair(this.getType(), new BooleanType()));
constraint.addConstraint(this.getType().TYPE(assumptions, this), assumptions.getTypeFor(new RefType("Boolean",-1),this));
ret.add(constraint);
return ret;
}

View File

@ -6,8 +6,8 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
@ -18,12 +18,12 @@ import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -7,6 +7,7 @@ import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
@ -17,7 +18,6 @@ import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -25,6 +25,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
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.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;

View File

@ -7,6 +7,7 @@ import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
@ -17,12 +18,12 @@ import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -7,6 +7,7 @@ import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
@ -17,12 +18,12 @@ import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -104,7 +104,7 @@ public class Return extends Statement
ret.add(this.retexpr.TYPEExpr(assumptions));
//this.setTypeVariable(TypePlaceholder.fresh("Return Type"));
this.setType(TypePlaceholder.fresh(this));
ret.add(new SingleConstraint(retexpr.getType(), this.getType()));
ret.add(new SingleConstraint(retexpr.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
return ret;
}

View File

@ -15,11 +15,11 @@ import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;

View File

@ -121,8 +121,7 @@ public class StringLiteral extends Literal
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
this.set_Type(assumptions.getTypeFor(new RefType("String",0), this));
if(this.getType() == null)throw new TypeinferenceException("java.lang.String nicht importiert",this);
this.set_Type(assumptions.getTypeFor(new RefType("String",0), this).getType());
return new ConstraintsSet();
}

View File

@ -54,8 +54,8 @@ public abstract class UnaryExpr extends Expr
ret.add(this.expr.TYPEExpr(assumptions));
for(RefType t : getNumericTypes()){
UndConstraint undConstraint = new UndConstraint();
undConstraint.addConstraint(this.getType(), t);
undConstraint.addConstraint(this.expr.getType(), t);
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);
}

View File

@ -7,8 +7,8 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.bytecode.JVMCode;
@ -23,11 +23,11 @@ import de.dhbwstuttgart.syntaxtree.operator.Operator;
import de.dhbwstuttgart.syntaxtree.operator.RelOp;
import de.dhbwstuttgart.syntaxtree.type.BooleanType;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -165,7 +165,7 @@ public class WhileStmt extends Statement
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
ret.add(expr.TYPEExpr(assumptions));
SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType(), assumptions.getTypeFor(new RefType("Boolean", 0), this)); // while(expr){}; expr <. boolean
SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType().TYPE(assumptions, this), assumptions.getTypeFor(new RefType("Boolean", 0), this)); // while(expr){}; expr <. boolean
ret.add(exprMustBeBool);
ret.add(this.loop_block.TYPEStmt(assumptions));
this.setType(loop_block.getType());

View File

@ -2,6 +2,8 @@
package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
// ino.end
@ -82,8 +84,8 @@ public abstract class BaseType extends Type
}
@Override
public Type checkType(TypeAssumptions ass, IItemWithOffset parent) {
return this; //Die Base-Types müssen nicht nachgeschlagen werden.
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
return super.TYPE(ass, parent); //Die Base-Types müssen nicht nachgeschlagen werden.
}

View File

@ -5,8 +5,9 @@ package de.dhbwstuttgart.syntaxtree.type;
// ino.module.BoundedGenericTypeVar.8669.import
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -90,7 +91,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar
//Die Type methode der BoundedGenericTypeVar schreibt zusätzlich noch die Constraints für die bounds
if(this.bounds != null){
for(Type ev : this.bounds){
Type extendsType = ass.getTypeFor(ev, this);
ConstraintType extendsType = ass.getTypeFor(ev, this);
if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this);
ret.add(new SingleConstraint(ass.getTypeFor(this, this), extendsType ));
}

View File

@ -6,8 +6,11 @@ package de.dhbwstuttgart.syntaxtree.type;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeInsertable;
@ -15,6 +18,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
// ino.class.GenericTypeVar.26505.description type=javadoc
/**
* TODO: Diese Klasse überarbeiten. Pair genericTypeVar ist nicht implementiert.
@ -63,6 +67,7 @@ public class GenericTypeVar extends Type
{
super(offset);
this.name = new JavaClassName(s);
this.parent = parentClass;
}
// ino.end

View File

@ -14,7 +14,9 @@ import de.dhbwstuttgart.bytecode.JVMCode;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.myexception.SCException;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
@ -790,14 +792,17 @@ public class RefType extends Type implements IMatchable
}
@Override
public Type checkType(TypeAssumptions ass, IItemWithOffset parent){
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
//Der RefType muss zusätzlich seine Parameter prüfen.
Vector<Type> parameterList = new Vector<>();
Vector<ConstraintType> parameterList = new Vector<>();
Vector<Type> parameterList2 = new Vector<>();
if(this.parameter!=null)for(Type param : this.parameter){
parameterList.add(param.checkType(ass, parent));
ConstraintType ct = param.TYPE(ass, parent);
parameterList.add(ct);
parameterList2.add(ct.getType());
}
this.parameter = parameterList;
Type t = super.checkType(ass,parent);
this.parameter = parameterList2;
ConstraintType t = super.TYPE(ass,parent);
return t;
}

View File

@ -5,11 +5,13 @@ package de.dhbwstuttgart.syntaxtree.type;
import java.util.ArrayList;
import java.util.Vector;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import de.dhbwstuttgart.bytecode.JVMCode;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -285,9 +287,17 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset
* Prüft ob der Typ in den Assumptions ass vorhanden ist.
* Dabei kann eine neue Instanz eines Typs entstehen, welche von der Methode zurückgegeben wird.
* @param ass - Die Assumptions für den jeweiligen Kontext in dem sich der Typ befindet.
*/
public Type checkType(TypeAssumptions ass, IItemWithOffset parent){
Type t = ass.getTypeFor(this, this);
public ConstraintType checkType(TypeAssumptions ass, SyntaxTreeNode parent){
ConstraintType t = ass.getTypeFor(this, this);
if(t==null)
throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent);
return t;
}
*/
//TODO: checkType wird nicht mehr gebraucht. TYPE übernimmt dessen Aufgabe. Es muss nur sichergestellt werden, dass jeder Typ in den Constraints landet, dadurch wird für jeden Typ die Methode TYPE aufgerufen.
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
ConstraintType t = ass.getTypeFor(this, this);
if(t==null)
throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent);
return t;

View File

@ -3,6 +3,8 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -69,8 +71,8 @@ public class Void extends RefType
// ino.end
@Override
public Type checkType(TypeAssumptions ass, IItemWithOffset parent){
return this;
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
return new ConstraintType(this);
}
}
// ino.end

View File

@ -0,0 +1,15 @@
package de.dhbwstuttgart.typeinference;
public class ConstraintPair {
private Pair p;
public ConstraintPair(ConstraintType t1, ConstraintType t2){
p = new Pair(t1.getType(), t2.getType());
}
public Pair getPair(){
return p;
}
}

View File

@ -0,0 +1,22 @@
package de.dhbwstuttgart.typeinference;
import de.dhbwstuttgart.syntaxtree.type.*;
public class ConstraintType{
private Type t;
public ConstraintType(TypePlaceholder t){
this.t = t;
}
public ConstraintType(GenericTypeVar t){
this.t = t;
}
public ConstraintType(RefType t){
this.t = t;
}
public Type getType() {
return t;
}
}

View File

@ -3,8 +3,6 @@ package de.dhbwstuttgart.typeinference;
import java.util.Iterator;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Pair;
public class ConstraintsSet implements Iterable<OderConstraint>{
private Vector<OderConstraint> constraintsSet;

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference;
import java.util.Vector;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Type;
@ -18,17 +19,27 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
public class FunNInterface extends Class{
//TODO: Diese Klasse sollte eigentlich von Interface erben
//TODO: getType muss einen Typ mit der ParameterListe zurückliefern.
private Vector<GenericTypeVar> gtvparalist;
/**
* Ein FunN-Interface enthält nur eine Methode (namens apply). Ist also ein Funktionales Interface.
* @param N - Die Anzahl der Parameter der apply-Methode. Beispiel N = 1 ergibt <code>R apply(T1 par1);</code>
*/
public FunNInterface(int N) {
super("Fun"+N, 0);
Vector<Type> paralist = new Vector<Type>();
paralist.add(new GenericTypeVar("R",this, 0));
GenericTypeVar gtv;
Vector<Type> paralist = new Vector<>();
gtv = new GenericTypeVar("R",this, 0);
this.gtvparalist = new Vector<GenericTypeVar>();
paralist.add(gtv);
this.gtvparalist.add(gtv);
//paralist.add(TypePlaceholder.fresh());
for(int i = 1; i<=N;i++){
paralist.add(new GenericTypeVar("T"+i,this, 0));
gtv=new GenericTypeVar("T"+i,this, 0);
paralist.add(gtv);
this.gtvparalist.add(gtv);
//paralist.add(TypePlaceholder.fresh());
}
this.set_ParaList(paralist);
@ -43,6 +54,7 @@ public class FunNInterface extends Class{
TypeAssumptions ret = new TypeAssumptions();
ret.addAssumption(new MethodAssumption(this.getApplyFunction(), this));
ret.addClassAssumption(new ClassAssumption(this));
for(GenericTypeVar gtv : this.gtvparalist)ret.addGenericVarAssumption(gtv);
return ret;
}

View File

@ -2,7 +2,6 @@ package de.dhbwstuttgart.typeinference;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -15,9 +14,9 @@ public class OderConstraint{
* @param p1
* @param p2
*/
public OderConstraint(Type p1, Type p2){
public OderConstraint(ConstraintType p1, ConstraintType p2){
if(p1 == null || p2 == null)throw new NullPointerException();
Pair constraintPair = new Pair(p1,p2);
ConstraintPair constraintPair = new ConstraintPair(p1,p2);
oderConstraintPairs = new Vector<UndConstraint>();
this.addConstraint(constraintPair);
}
@ -44,16 +43,16 @@ public class OderConstraint{
* @param p1
* @param p2
*/
public void addConstraint(Type p1, Type p2){
addConstraint(new Pair(p1,p2));
public void addConstraint(ConstraintType p1, ConstraintType p2){
addConstraint(new ConstraintPair(p1,p2));
}
/**
* Falls die Type des toAdd-Pairs nicht vom Typ RefType bzw. TypePlaceholder sind, so werden sie in einen RefType umgewandelt.
* @param toAdd
*/
public void addConstraint(Pair toAdd){
oderConstraintPairs.add(new SingleConstraint(toAdd.TA1, toAdd.TA2));
public void addConstraint(ConstraintPair toAdd){
oderConstraintPairs.add(new SingleConstraint(toAdd));
}
@Override

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import de.dhbwstuttgart.syntaxtree.type.RefType;
@ -65,12 +66,14 @@ public class Overloading{
if(!(this.type instanceof TypePlaceholder) && !this.type.equals(methodAssumption.getAssumedType()))break;
UndConstraint methodConstraint = new UndConstraint();
//Ein Constraint für den ReturnType der Methode...
methodConstraint.addConstraint(methodAssumption.getAssumedType(), type);
methodConstraint.addConstraint(methodAssumption.getAssumedType().TYPE(assumptions, methodCall), type.TYPE(assumptions, methodCall));
//Ein Constraint für die Parameter der Methode...
for(int i=0; i<methodAssumption.getParaCount();i++){
//CParaTypeAssumption pAss = assumption.getParaAssumption(i);
//Type der Argument Expressions <. AssumedType der Parameter
methodConstraint.addConstraint( methodCall.getArgumentList().argumentAt(i).getType(), methodAssumption.getParameterType(i));
ConstraintType ct1 = methodCall.getArgumentList().argumentAt(i).getType().TYPE(assumptions, methodCall);
ConstraintType ct2 = methodAssumption.getParameterType(i).TYPE(assumptions, methodCall);
methodConstraint.addConstraint(ct1 , ct2);
}
/*
Vector<Type> parameterAssumptions = new Vector<Type>();
@ -83,7 +86,7 @@ public class Overloading{
//ret.add(new Constraint(methodCall.get_Receiver().get_Expr().getTypeVariable(), new RefType(assumption.getClassName(), null, 0)));
if(methodCall.get_Receiver() != null && methodCall.get_Receiver().get_Expr() != null)
//TODO: FunN-MethodAssumption darf keine Klasse (Class) als ParentClass besitzen. Denn der Typ der Klasse steht noch nicht fest (bisher ist es immer "FunN").
methodConstraint.addConstraint(methodCall.get_Receiver().get_Expr().getType(), methodAssumption.getParentClassType());
methodConstraint.addConstraint(methodCall.get_Receiver().get_Expr().getType().TYPE(assumptions, methodCall), methodAssumption.getParentClassType().TYPE(assumptions, methodCall));
//ret.add(new Constraint(methodCall.get_Receiver().get_Expr().getTypeVariable(), new RefType(assumption.getClassName(), parameterAssumptions, 0)));
//return ret; //Bereits nach der ersten Assumption abbrechen...

View File

@ -1,5 +1,5 @@
// ino.module.Pair.8673.package
package de.dhbwstuttgart.syntaxtree.type;
package de.dhbwstuttgart.typeinference;
// ino.end
// ino.module.Pair.8673.import
import java.util.Hashtable;
@ -7,7 +7,14 @@ import java.util.Vector;
// ino.end
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.type.FreshWildcardType;
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.syntaxtree.type.WildcardType;

View File

@ -3,7 +3,6 @@ package de.dhbwstuttgart.typeinference;
import java.util.Iterator;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;

View File

@ -3,7 +3,6 @@ package de.dhbwstuttgart.typeinference;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -25,12 +24,16 @@ public class SingleConstraint extends UndConstraint{
private Pair constraintPair; //entspricht θ condition θ'
//private R condition; //entspricht der condition (R)
public SingleConstraint(Type p1, Type p2){
public SingleConstraint(ConstraintType p1, ConstraintType p2){
//super(p1,p2);
Pair constraintPair = new Pair(p1,p2);//super.getConstraintPairs().firstElement();
ConstraintPair constraintPair = new ConstraintPair(p1,p2);//super.getConstraintPairs().firstElement();
this.addConstraint(constraintPair);
}
public SingleConstraint(ConstraintPair toAdd) {
this.addConstraint(toAdd);
}
public Pair getPair(){
return constraintPair;
}
@ -42,11 +45,11 @@ public class SingleConstraint extends UndConstraint{
return ret;
}
public void addConstraint(Pair toAdd){
public void addConstraint(ConstraintPair toAdd){
if(constraintPair != null)throw new DebugException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich.");
Type p1 = toAdd.TA1;
Type p2 = toAdd.TA2;
Type p1 = toAdd.getPair().TA1;
Type p2 = toAdd.getPair().TA2;
if(p1==null || p2 == null)throw new NullPointerException();
@ -58,15 +61,15 @@ public class SingleConstraint extends UndConstraint{
//if((p2 instanceof GenericTypeVar))p2 = ((GenericTypeVar)p2).getTypePlaceHolder();//throw new DebugException("GenericTypeVar sind in den Constraints nicht erlaubt");//
// BaseTypes werden in RefTypes umgewandelt. Constraints dürfen nur RefTypes oder TypePlaceholder enthalten, da sonst der Unify-Algorithmus nicht funktioniert.
if(!(p1 instanceof RefType) && !(p1 instanceof TypePlaceholder) && !(p1 instanceof GenericTypeVar))p1 = new RefType(p1);
if(!(p2 instanceof RefType) && !(p2 instanceof TypePlaceholder) && !(p2 instanceof GenericTypeVar))p2 = new RefType(p2);
//if(!(p1 instanceof RefType) && !(p1 instanceof TypePlaceholder) && !(p1 instanceof GenericTypeVar))p1 = new RefType(p1);
//if(!(p2 instanceof RefType) && !(p2 instanceof TypePlaceholder) && !(p2 instanceof GenericTypeVar))p2 = new RefType(p2);
//if(!(TypePlaceholder.class.isInstance(p1)) || !(RefType.class.isInstance(p1)) || !(TypePlaceholder.class.isInstance(p2)) || !(RefType.class.isInstance(p2)))
//{//Wenn die beiden übergebenen Typen weder RefTypes noch TypePlaceholder sind:
// throw new TypinferenzException("Ein Constraint darf nur aus TypePlaceholdern und Reftypes bestehen");
//}
if(!(p1 instanceof RefType) && !(p1 instanceof TypePlaceholder))throw new DebugException("Fehler: "+p2+" kann nicht in TPH oder RefType umgewandelt werden");
if(!(p2 instanceof RefType) && !(p2 instanceof TypePlaceholder))throw new DebugException("Fehler: "+p2+" kann nicht in TPH oder RefType umgewandelt werden");
//if(!(p1 instanceof RefType) && !(p1 instanceof TypePlaceholder))throw new DebugException("Fehler: "+p2+" kann nicht in TPH oder RefType umgewandelt werden");
//if(!(p2 instanceof RefType) && !(p2 instanceof TypePlaceholder))throw new DebugException("Fehler: "+p2+" kann nicht in TPH oder RefType umgewandelt werden");
constraintPair = new Pair(p1,p2);
}

View File

@ -8,7 +8,6 @@ import java.util.Iterator;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;

View File

@ -2,7 +2,6 @@ package de.dhbwstuttgart.typeinference;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.Type;
/**
@ -12,7 +11,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
*/
public class UndConstraint extends OderConstraint {
public UndConstraint(Type p1, Type p2) {
public UndConstraint(ConstraintType p1, ConstraintType p2) {
super(p1, p2);
}

View File

@ -6,10 +6,12 @@ import java.util.Vector;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
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.FunN;
import de.dhbwstuttgart.typeinference.FunNInterface;
import de.dhbwstuttgart.typeinference.FunNMethod;
@ -288,10 +290,10 @@ public class TypeAssumptions {
* @param t
* @return null, falls der Typ nicht vorhanden ist.
*/
public Type getTypeFor(Type t, IItemWithOffset inNode){
public ConstraintType getTypeFor(Type t, SyntaxTreeNode inNode){
if(t instanceof TypePlaceholder)
return t; //Handelt es sich um einen TypePlaceholder kann dieser nicht in den Assumptions vorkommen.
return new ConstraintType((TypePlaceholder)t); //Handelt es sich um einen TypePlaceholder kann dieser nicht in den Assumptions vorkommen.
//Alle bekannten Klassen nach diesem Typ durchsuchen:
JavaClassName typName = t.getName();
@ -303,7 +305,7 @@ public class TypeAssumptions {
RefType tr = (RefType)t;
RefType ret = ass.getAssumedClass().getType(); //Dadurch erhält der RefType den vollen Namen (bsp. java.lang.Integer)
ret.set_ParaList(tr.get_ParaList());
return ret;
return new ConstraintType(ret);
}
}
//Auch die generischen Variablen durchsuchen:
@ -312,12 +314,11 @@ public class TypeAssumptions {
if(ass.getIdentifier().equals(t.getName())){
if(! ass.getAssumedType().getParentClass().getName().equals(this.thisClassName)){
//Ist die Generische Variable nicht aus dieser Klasse, so muss sie zu einem TPH umgewandelt werden:
return new ConstraintType(ass.getAssumedType().getTypePlaceHolder());
}
return ass.getAssumedType();
return new ConstraintType(ass.getAssumedType());
}
}
//return null;
throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode);
}

View File

@ -1,6 +1,7 @@
package de.dhbwstuttgart.typeinference.exceptions;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
/**
* Eine RuntimeException, welche bei einem Fehler während des Typinferenzalgorithmus ausgelöst wird.
@ -17,7 +18,7 @@ public class TypeinferenceException extends RuntimeException {
private int offset;
private String message;
public TypeinferenceException(String message, IItemWithOffset problemSource)
public TypeinferenceException(String message, SyntaxTreeNode problemSource)
{
super(message);
this.message=message;

View File

@ -6,12 +6,12 @@ import java.util.Vector;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.GenericTypeInsertable;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;

View File

@ -10,10 +10,10 @@ import org.apache.log4j.Logger;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;

View File

@ -16,12 +16,13 @@ import org.apache.log4j.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.Pair;
// ino.class.CSubstitution.27003.description type=javadoc
/**

View File

@ -7,8 +7,8 @@ import java.util.Iterator;
import java.util.Vector;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.Pair;
// ino.class.CSubstitutionSet.27471.description type=javadoc
/**

View File

@ -6,7 +6,7 @@ package de.dhbwstuttgart.typeinference.unify;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
// ino.class.FC_TTO.28013.description type=javadoc
@ -74,8 +74,8 @@ public class FC_TTO
public void generateFullyNamedTypes(TypeAssumptions ass) {
for(Pair p : this.FC){
p.TA1 = ass.getTypeFor(p.TA1, null);
p.TA2 = ass.getTypeFor(p.TA2, null);
p.TA1 = ass.getTypeFor(p.TA1, null).getType();
p.TA2 = ass.getTypeFor(p.TA2, null).getType();
}
}
}

View File

@ -5,8 +5,8 @@ package de.dhbwstuttgart.typeinference.unify;
// ino.module.MUB.8720.import
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.Pair;
// ino.class.MUB.28031.declaration
public class MUB

View File

@ -24,13 +24,13 @@ import de.dhbwstuttgart.syntaxtree.type.FreshSuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.FreshWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.IMatchable;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import de.dhbwstuttgart.syntaxtree.type.Pair.PairOperator;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
// ino.end

View File

@ -14,9 +14,9 @@ import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
public class TrMakeFCTest extends TestCase{

View File

@ -19,12 +19,12 @@ import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.Pair.PairOperator;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -16,12 +16,12 @@ import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.Pair.PairOperator;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -13,14 +13,14 @@ import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.Pair;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.Pair.PairOperator;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
import junit.framework.TestCase;

View File

@ -24,7 +24,6 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
import junit.framework.TestCase;
import mycompiler.mytest.LambdaTest;
public class TypeInsertTester{

View File

@ -0,0 +1,10 @@
class OverloadingInMethod{
m () {
op;
op = (m) -> (f) -> f.apply(m);
return op;
}
}

View File

@ -0,0 +1,19 @@
package plugindevelopment.TypeInsertTests;
import java.util.Vector;
import org.junit.Test;
public class OverloadingInMethod {
private static final String TEST_FILE = "OverloadingInMethod.jav";
@Test
public void run(){
Vector<String> mustContain = new Vector<String>();
//mustContain.add("Fun0<Fun1<java.lang.String, Fun2<AH, LambdaTest, java.lang.String>>> op");
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="JavaCompiler.buildParser" default="JavaParser" basedir=".">
<property name="ParserSrcDir" value="./../src/mycompiler/myparser/"/>
<property name="ParserSrcDir" value="./../src/de/dhbwstuttgart/parser/"/>
<target name ="JavaParser" depends="JavaLexer" description="Create the file JavaParser.java">

View File

@ -1 +1 @@
./../tools/jay -v ./../src/mycompiler/myparser/JavaParser.jay < skeleton > ./../src/mycompiler/myparser/JavaParser.java
./../tools/jay -v ./../src/de/dhbwstuttgart/parser/JavaParser.jay < skeleton > ./../src/de/dhbwstuttgart/parser/JavaParser.java