Merge branch 'unify' of ssh://i13029@gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unify

This commit is contained in:
Florian Steurer 2016-04-02 11:29:43 +02:00
commit b12f301656
126 changed files with 2599 additions and 6157 deletions

View File

@ -1,6 +1,7 @@
eclipse.preferences.version=1
encoding//src/de/dhbwstuttgart/core/MyCompiler.java=UTF-8
encoding//src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java=UTF-8
encoding//src/de/dhbwstuttgart/typeinference/SingleConstraint.java=UTF-8
encoding//src/de/dhbwstuttgart/typeinference/UndConstraint.java=UTF-8
encoding//src/de/dhbwstuttgart/typeinference/UnifySingleConstraint.java=UTF-8
encoding//src/de/dhbwstuttgart/typeinference/UnifyUndConstraint.java=UTF-8
encoding/<project>=UTF-8

View File

@ -1,8 +1,12 @@
package de.dhbwstuttgart.bytecode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.apache.commons.bcel6.classfile.BootstrapMethod;
import org.apache.commons.bcel6.classfile.BootstrapMethods;
@ -10,6 +14,7 @@ import org.apache.commons.bcel6.classfile.ConstantPool;
import org.apache.commons.bcel6.classfile.InnerClass;
import org.apache.commons.bcel6.classfile.InnerClasses;
import org.apache.commons.bcel6.classfile.JavaClass;
import org.apache.commons.bcel6.classfile.Method;
import org.apache.commons.bcel6.classfile.Signature;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
@ -34,6 +39,7 @@ public class ClassGenerator extends ClassGen{
private Menge<TypePlaceholder> usedTPHs = new Menge<>();
private Map<String, ClassGenerator> extraClasses = new HashMap<>();
private List<String> methodsNamesAndTypes = new LinkedList<>();
public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings, TypeinferenceResults typeinferenceResults) {
super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen());
@ -163,6 +169,20 @@ public class ClassGenerator extends ClassGen{
return tiResult;
}
@Override
public void addMethod(Method m) {
String methodNameAndTypes = m.getName()+Arrays.toString(m.getArgumentTypes());
if(methodsNamesAndTypes.contains(methodNameAndTypes)){
return;
}
methodsNamesAndTypes.add(methodNameAndTypes);
super.addMethod(m);
}
}

View File

@ -2,6 +2,14 @@ package de.dhbwstuttgart.myexception;
public class NotImplementedException extends RuntimeException {
public NotImplementedException(String message) {
super(message);
}
public NotImplementedException() {
super("Nicht implementiert");
}
/**
*
*/

View File

@ -7,6 +7,8 @@ import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import javax.lang.model.element.Modifier;
@ -47,7 +49,6 @@ import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
import de.dhbwstuttgart.typeinference.unify.Unify;
import org.apache.commons.bcel6.generic.*;
@ -106,7 +107,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
}
//Zuerst die Methoden und Felder abarbeiten:
for(Method m : methods){
m.genByteCode(_cg);
m.genByteCode(_cg, this);
}
InstructionList fieldInitializations = new InstructionList();
for(FieldDeclaration f : fieldDeclarations){
@ -214,7 +215,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
private Menge<Field> fielddecl = new Menge<Field>();
private GenericDeclarationList genericClassParameters;
private int offset;
private Type superClass;
private RefType superClass;
// ino.method.Class.23041.definition
@ -240,7 +241,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
* @param modifiers
* @param supertypeGenPara - Eine Liste von Namen, welche die Generischen Parameter der Klasse darstellen.
*/
public Class(String name, Type superClass, Modifiers modifiers, Menge<String> supertypeGenPara) {
public Class(String name, RefType superClass, Modifiers modifiers, Menge<String> supertypeGenPara) {
this(name,superClass,modifiers,0);
if(supertypeGenPara == null)return;
Menge<GenericTypeVar> gtvs = new Menge<>();
@ -261,7 +262,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
this.setGenericParameter(new GenericDeclarationList(gtvs,0));
}
public Class(String name, Type superClass, Modifiers mod, int offset){
public Class(String name, RefType superClass, Modifiers mod, int offset){
this(name,mod,offset);
if(superClass == null)this.superClass = new Class("java.lang.Object",-1).getType();
else this.superClass = superClass;
@ -293,14 +294,14 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
public Class(String name2, Modifiers object, ClassBody classBody,
Menge<Type> containedTypes2, Menge<Type> typeMenge,
Menge<Type> paraMenge, int offset2) {
this(name2, object, classBody, containedTypes2,(Type)null, typeMenge, paraMenge, offset2);
this(name2, object, classBody, containedTypes2,(RefType)null, typeMenge, paraMenge, offset2);
}
private static Menge<Type> usedIdToRefType(Menge<UsedId> superif2) {
Menge<Type> ret = new Menge<>();
for(UsedId id : superif2)ret.add(usedIdToRefType(id));
return ret;
}
private static Type usedIdToRefType(UsedId superclass2) {
private static RefType usedIdToRefType(UsedId superclass2) {
RefType ret = new RefType(superclass2.getSimpleName(), null, superclass2.getOffset());
ret.set_ParaList(superclass2.get_ParaList());
return ret;
@ -314,7 +315,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
// ino.end
// ino.method.Class.23047.definition
public Class(String name, Modifiers mod, ClassBody cb, Menge<Type> ct,
Type superclass, Menge<Type> Menge, Menge<? extends Type> paralist, int offset)
RefType superclass, Menge<Type> Menge, Menge<? extends Type> paralist, int offset)
// ino.end
// ino.method.Class.23047.body
{
@ -625,7 +626,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
*/
// ino.end
// ino.method.TRProg.23110.definition
public ConstraintsSet typeReconstruction(FC_TTO supportData, TypeAssumptions globalAssumptions)
public ConstraintsSet typeReconstruction(TypeAssumptions globalAssumptions)
// ino.end
// ino.method.TRProg.23110.body
{
@ -637,7 +638,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
//////////////////////////////
inferencelog.info("Rufe TRStart()...", Section.TYPEINFERENCE);
typinferenzLog.debug("Erstellte FiniteClosure: "+supportData, Section.TYPEINFERENCE);
//////////////////////////////
// Ab hier ...
// @author A10023 - Andreas Stadelmeier:
@ -671,7 +671,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
//ConstraintsSet oderConstraints = this.TYPE(this.getMethodList(), fieldInitializers, assumptions);
this.superClass = this.superClass.TYPE(assumptions, this);
//Gibt es hier eine ClassCastException stimmt etwas grundsätzlich nicht!
this.superClass = (RefType)this.superClass.TYPE(assumptions, this);
for(Field f:this.getFields()){
oderConstraints.add(f.TYPE(assumptions));
@ -991,7 +992,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
}
@Override
public String getDescription(){
public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return "class "+this.getName();
}
@Override
@ -1028,7 +1029,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
* Die Super Klasse dieser Klasse.
* @return null ¼r Klasse Object
*/
public Type getSuperClass(){
public RefType getSuperClass(){
return this.superClass;
}
@Override

View File

@ -28,7 +28,6 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
@ -98,7 +97,7 @@ public class Constructor extends Method {
}
@Override
public void genByteCode(ClassGenerator cg) {
public void genByteCode(ClassGenerator cg, Class classObj) {
this.genByteCode(cg, new InstructionList());
}
// super statement muss drin sein

View File

@ -16,6 +16,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
@ -107,7 +108,7 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta
}
@Override
public String getDescription(){
public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return this.getIdentifier();
}

View File

@ -21,8 +21,8 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -148,13 +148,13 @@ public class FieldDeclaration extends Field{
}
*/
SingleConstraint c1 = new SingleConstraint(thisType, thisType);
UndConstraint c1 = ConstraintsSet.createSingleConstraint(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().TYPE(localAssumptions,this), thisType));
ret.add(ConstraintsSet.createSingleConstraint(this.wert.getType().TYPE(localAssumptions,this), thisType));
}
return ret;
}
@ -173,17 +173,23 @@ public class FieldDeclaration extends Field{
*/
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
//Das Feld an die Klasse anfügen:
FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(), cg.getConstantPool());
FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(cg, rs), cg.getConstantPool());
field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg, rs)));
cg.addField(field.getField());
//Die Felddekleration an den Konstruktor anhängen:
InstructionList il = new InstructionList();
il.append(new This(this).genByteCode(cg, rs));
if(wert != null){
il.append(this.wert.genByteCode(cg, rs));
}else{
//todo: default wert?
}
FieldInstruction putFieldInstruction =
cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(),
this.getDescription(), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD);
this.getDescription(cg, rs), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD);
il.append(putFieldInstruction );
return il;
}

View File

@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree;
// ino.module.FormalParameter.8561.import
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
@ -14,6 +14,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
@ -233,7 +234,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
}
@Override
public String getDescription() {
public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
String ret = "";
if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){
ret += this.getType().getBytecodeSignature(null, null);

View File

@ -1,6 +1,7 @@
// ino.module.Method.8564.package
package de.dhbwstuttgart.syntaxtree;
import java.util.Arrays;
// ino.end
// ino.module.Method.8564.import
import java.util.Enumeration;
@ -45,9 +46,9 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -465,39 +466,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
}
@Override
public void wandleRefTypeAttributes2GenericAttributes(
Menge<Type> classParalist) {
/*
* Menge<Type> paralist = new Menge<Type>();//Mit den Generischen Typen
* der Methode paralist.addAll(classParalist);
* paralist.addAll(this.genericMethodParameters);
*
* // Zuerst Returntype untersuchen Type returnType=getType(); Type
* pendantReturnType = null; if(returnType instanceof
* RefType)pendantReturnType =
* ((RefType)returnType).findGenericType(paralist, new
* Menge<GenericTypeVar>()); //GenericTypeVar
* pendantReturnType=ClassHelper.findGenericType(returnType,
* paralist,genericMethodParameters); if(pendantReturnType!=null){
* //Wenn generisch, dann modifizieren setReturnType(pendantReturnType);
* }
*
* // Dann parameterlist untersuchen for(int
* par=0;par<getParameterCount();par++){ FormalParameter
* fp=parameterlist.formalparameter.get(par); Type fpType=fp.getType();
* // Nur wenn es sich um ein RefType-Field handelt Type pendantPara =
* null; if(fpType instanceof RefType)pendantPara =
* ((RefType)fpType).findGenericType(paralist, new
* Menge<GenericTypeVar>()); //GenericTypeVar
* pendantPara=ClassHelper.findGenericType
* (fpType,paralist,genericMethodParameters); if(pendantPara!=null){
* //Wenn generisch, dann modifizieren fp.setType(pendantPara); } }
*
* // Zuletzt alle Lokalen Variablendeklarationen durchgehen
* if(block!=null){
* block.wandleRefTypeAttributes2GenericAttributes(paralist
* ,genericMethodParameters); }
*/
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> classParalist) {
}
public void set_Method_Name(String string) {
@ -520,36 +489,17 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// TypeCheck, falls es sich um einen RefType handelt:
this.returntype = this.returntype.checkTYPE(localAss, this);
/*
* if(this.returntype!=null && (this.returntype instanceof RefType)&&
* !(this.returntype instanceof mycompiler.mytype.Void)){//Sonderfall
* der Methode: Ihr Typ darf Void definiert werden. Type replaceType =
* null; replaceType = ass.getTypeFor((RefType)this.returntype);
* if(replaceType == null)throw new
* TypeinferenceException("Der Typ "+this
* .getType().getName()+" ist nicht korrekt",this); this.returntype =
* replaceType; }
*/
// Die Parameter zu den Assumptions hinzufügen:
if (this.parameterlist != null)
for (FormalParameter param : this.parameterlist) {
param.setType(param.getType().checkTYPE(localAss, this));
/*
* if(param.getType() instanceof RefType) { Type replaceType =
* null; replaceType = ass.getTypeFor((RefType)param.getType());
* if(replaceType == null) throw new
* TypeinferenceException("Der Typ "
* +param.getType().getName()+" ist nicht korrekt",param);
* param.setType(replaceType); }
*/
localAss.addAssumption(new ParameterAssumption(param));
}
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().TYPE(localAss, this), this.returntype.TYPE(localAss, this)));
ret.add(ConstraintsSet.createSingleConstraint(this.block.getType().TYPE(localAss, this), this.returntype.TYPE(localAss, this)));
return ret;
}
@ -587,107 +537,15 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
TypeAssumptions ret = new TypeAssumptions();
ret.addAssumption(new MethodAssumption(this, parentClass));
return ret;
/*
* TypeAssumptions assumptions = new TypeAssumptions(); this.assumedType
* = null; //if((this.get_Method_Name().equals(classmember.getName()) ||
* this.get_Method_Name().equals("<init>")) &&
* ((this.getType().equals(new mycompiler.mytype.Void(0))) ||
* this.getType() instanceof TypePlaceholder)){
* if((this.get_Method_Name().equals(classmember.getName()) ||
* this.get_Method_Name().equals("<init>"))) {
* this.set_Method_Name("<init>"); this.assumedType = new
* RefType(classmember.getName(),0);
* this.setReturnType(this.assumedType); this.assumedType = new
* RefType("void",0); //Return constructorReturnStatement = new
* Return(0,0); //constructorReturnStatement.retexpr =
* //this.block.statements.add(constructorReturnStatement); } //hoth:
* 06.04.2006 //durchlaufe Block und suche nach Objektvariablen fuer
* Offset-Markierung Iterator<CTypeAssumption> fieldVarIterator =
* assumptions.iterator(); while (fieldVarIterator.hasNext()) { //Wenn
* ObjektVariable CTypeAssumption dieAssum = fieldVarIterator.next();
* if(dieAssum instanceof CInstVarTypeAssumption) {
* Class.isFirstLocalVarDecl=false; if(this.get_Block() != null)
* this.get_Block
* ().addOffsetsToAssumption(dieAssum,dieAssum.getIdentifier(),true); }
* }
*
* //methodList.addElement(method);
*
* //¯Â¿Â½r V_fields_methods: CMethodTypeAssumption methodAssum
* = new CMethodTypeAssumption(classmember.getType(),
* this.get_Method_Name(), this.getType(),
* this.getParameterCount(),this.getLineNumber(),this.getOffset(),new
* Menge<Integer>(),this.getGenericMethodParameters()); // Typannahme
* bauen...
*
*
* //Methode in V_Fields_methods ablegen //Dabei wird die
* OverloadedMethodID ermittelt !! //=> Method setzenuct
*
*
* assumptions.add(methodAssum);
* this.setOverloadedID(methodAssum.getHashSetKey
* ().getOverloadedMethodID());
*
*
* //¯Â¿Â½r die V_i: CTypeAssumptionSet localAssum = new
* CTypeAssumptionSet();
*
* //Bauen... ParameterList parameterList = this.getParameterList();
* if(parameterList!=null){ for(int i=0;
* i<parameterList.sc_get_Formalparalist().size(); i++){ FormalParameter
* para = parameterList.sc_get_Formalparalist().elementAt(i); //
* ¯Â¿Â½r V_fields_methods: CParaTypeAssumption paraAssum = new
* CParaTypeAssumption(classmember.getName(), this.get_Method_Name(),
* this.getParameterCount(), this.getOverloadedID(),para.get_Name(),
* para.getType(), para.getLineNumber(),para.getOffset(),new
* Menge<Integer>()); //fuege Offsets fuer Parameter hinzu, hoth:
* 06.04.2006 Class.isFirstLocalVarDecl=false;
*
* if(this.get_Block() != null)
* this.get_Block().addOffsetsToAssumption(paraAssum
* ,paraAssum.getIdentifier(),true);
*
* methodAssum.addParaAssumption(paraAssum);
*
* // ¯Â¿Â½r die V_i: CLocalVarTypeAssumption varAssum = new
* CLocalVarTypeAssumption(classmember.getName(),
* this.get_Method_Name(), this.getParameterCount(),
* this.getOverloadedID(),"1", para.get_Name(),para.getType(),
* para.getLineNumber(),para.getOffset(),new Menge<Integer>());
* localAssum.addElement(varAssum);
* //rememberLocals.addElement(varAssum); } } //...und
* hinzuf�gen:
*
* assumptions.add(localAssum);//Assumptions ¼r lokale Variablen den
* Assumptions hinzufügen
*
* //Hier wird der Typ der als Assumption eingetragen wird in die
* Variable assumedType dieser Klasse geschrieben: if(this.assumedType
* == null) // Falls der Typ nicht schon gesetzt ist. Das ist der Fall,
* falls die Methode ein Konstruktor ist this.assumedType =
* methodAssum.getAssumedType();
*
* return assumptions;
*/
}
@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
if (this.getType() == null)
this.setType(TypePlaceholder.fresh(this));
// Bei dem Elterntyp der Methode darf es sich nur um eine Klasse
// handeln, daher Cast ohne Prüfung:
// Class parentClass = (Class)parent;
if (this.returntype == null)
this.returntype = TypePlaceholder.fresh(this);
super.parserPostProcessing(parent);
/*
* this.returntype.parserPostProcessing(this); if(this.parameterlist !=
* null){ for(FormalParameter fp : this.parameterlist){
* fp.parserPostProcessing(this); } } for(GenericTypeVar gtv :
* this.getGenericParameter()){ gtv.parserPostProcessing(this); }
*/
}
@Override
@ -728,7 +586,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
DImethod.set_Name(withSignature);
ret.set_DeclId(DImethod);
Block tempBlock = new Block();
// tempBlock.setType(new RefType(parent.getName(),0));
ret.set_Block(tempBlock);
ret.parserPostProcessing(parent);
return ret;
@ -751,7 +608,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
return super.equals(obj);
}
public void genByteCode(ClassGenerator cg) {
public void genByteCode(ClassGenerator cg, Class classObj) {
List<TypeinferenceResultSet> typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg);
for(TypeinferenceResultSet t: typeInterferenceResults){
@ -771,11 +628,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
argumentNames[i] = parameter.getIdentifier();
i++;
}
}
String nameAndSignature = get_Method_Name()+Arrays.toString(argumentTypes);
Logger.getLogger("nameAndSignature").error(nameAndSignature, Section.CODEGEN);
if(!createdMethods.contains(argumentTypes, new ArgumentTypeEquals())){
createdMethods.add(argumentTypes);
}
}
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
@ -788,44 +646,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
//Methode generieren und anfügen:
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t));
/*
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
Type returnType = this.getType();
//Methode generieren:
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
//Methode generieren und anfügen:
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block()));
*/
Logger.getLogger("createMethod").debug(this.toString(), Section.CODEGEN);
}
}
}
class ArgumentTypeEquals implements Equal<org.apache.commons.bcel6.generic.Type[]>{
@Override
public boolean equal(org.apache.commons.bcel6.generic.Type[] a, org.apache.commons.bcel6.generic.Type[] b) {
if(a.length != b.length){
Logger.getLogger("ArgumentTypeEquals").error("false(length)", Section.CODEGEN);
return false;
}
for(int i = 0; i < a.length; i++){
if(!a[i].equals(b[i])){
String as = a[i].toString();
String bs = b[i].toString();
Logger.getLogger("ArgumentTypeEquals").error("false "+as+" != "+bs, Section.CODEGEN);
return false;
}
}
Logger.getLogger("ArgumentTypeEquals").error("true", Section.CODEGEN);
return true;
}
}
// ino.end

View File

@ -0,0 +1,26 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.typeinference.Menge;
/**
* Dieser SyntaxTreeNode kann anstelle von null in einem Syntaxbaum eingesetzt werden.
* Vorsicht: Als Offset wird dann immer 0 zurück gegeben.
*/
public class NullSyntaxTreeNode extends SyntaxTreeNode {
@Override
public int getOffset() {
return 0;
}
@Override
public int getVariableLength() {
return 0;
}
@Override
public Menge<? extends SyntaxTreeNode> getChildren() {
return new Menge<>();
}
}

View File

@ -9,6 +9,8 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.function.Function;
import de.dhbwstuttgart.typeinference.Menge;
@ -23,6 +25,7 @@ import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.SCClassException;
import de.dhbwstuttgart.myexception.SCException;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
@ -37,29 +40,27 @@ import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.FunNInterface;
import de.dhbwstuttgart.typeinference.FunNMethod;
import de.dhbwstuttgart.typeinference.KomplexeMenge;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResults;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.UnifyConstraintsSet;
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.Unify;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
// ino.class.SourceFile.21355.declaration
public class SourceFile
extends SyntaxTreeNode
// ino.end
// ino.class.SourceFile.21355.body
{
// ino.attribute.LOAD_BASIC_ASSUMPTIONS_FROM_JRE.21358.decldescription type=javadoc
/**
@ -170,17 +171,13 @@ public class SourceFile
this.KlassenVektor = classDefinitions;
}
// ino.attribute.imports.21382.decldescription type=javadoc
/**
* HOTI 4.5.06
* Beinhaltet alle Imports des aktuell geparsten Files
* in Form einer UsedId
*/
// ino.end
// ino.attribute.imports.21382.declaration
private ImportDeclarations imports=new ImportDeclarations();
// ino.end
// ino.attribute.baseTypeTranslationTable.21385.decldescription type=javadoc
/**
* Table zum Übersetzen der nicht implementierten Base-Types:
* Überall im Compiler wird statt bspw. int Integer verwendet
@ -189,24 +186,13 @@ public class SourceFile
* der JRE gelieferten Base-Typen (int,char, etc) und die Objekt-
* Typen umwandeln nnen
*/
// ino.end
// ino.attribute.baseTypeTranslationTable.21385.declaration
private Hashtable<String,String> baseTypeTranslationTable;
// ino.end
// ino.method.addElement.21394.defdescription type=javadoc
/**
* Fuegt ein neues Element (Interface oder Klasse) hinzu.
* @param c
*/
// ino.end
// ino.method.addElement.21394.definition
public void addElement(AClassOrInterface e)
// ino.end
// ino.method.addElement.21394.body
{
if (e instanceof Class) {
KlassenVektor.addElement((Class) e);
@ -214,451 +200,8 @@ public class SourceFile
InterfaceVektor.addElement((Interface) e);
}
}
// ino.end
// ino.method.codegen.21397.defdescription type=javadoc
/**
* Startet die Bytecodegenerierung fuer alle in der Datei
* enthaltenen Klassen und Interfaces.
*
// ino.end
// ino.method.codegen.21397.definition
public Menge<ClassFile> codegen(ResultSet result)
throws JVMCodeException
// ino.end
// ino.method.codegen.21397.body
{
Menge<ClassFile> ret = new Menge<ClassFile>();
codegenlog.info("Anzahl der Interfaces: "
+ Integer.toString(InterfaceVektor.size()));
for(int i = 0; i < InterfaceVektor.size(); i++) {
InterfaceVektor.elementAt(i).codegen(result);
}
codegenlog.info("Anzahl der Klassen: "
+ Integer.toString(KlassenVektor.size()));
for(int i = 0; i < KlassenVektor.size(); i++) {
ret.add(KlassenVektor.elementAt(i).codegen(result));
}
return ret;
}
// ino.end
*/
// ino.method.createPairFromClassAndSuperclass.21400.defdescription type=javadoc
/**
* Erstellt ein Typ-Paar, welches im 1. Durchlauf in die Menge der Finite Closure
* aufgenommen wird Input: Klassenname, Name der Superklasse, ParameterDerKlasse,
* Parameter der Superklasse
* @return
*/
// ino.end
// ino.method.createPairFromClassAndSuperclass.21400.definition
private Pair createPairFromClassAndSuperclass(Class baseClass, Type superclass, Menge classParaOrg, Menge superclassParaOrg, TypeAssumptions ass)
// ino.end
// ino.method.createPairFromClassAndSuperclass.21400.body
{
// Paar erstellen
if(classParaOrg!=null && classParaOrg.size()==0){
classParaOrg=null;
}
if(superclassParaOrg!=null && superclassParaOrg.size()==0){
superclassParaOrg=null;
}
/*
Pair P = new Pair(
new RefType( className.toString(), classParaOrg,-1),
new RefType( superclassName.toString(), superclassParaOrg,-1)
);
*/
Pair P = new Pair(baseClass.getType().TYPE(ass, baseClass), superclass.TYPE(ass, baseClass));
//PL 04-12-29 freshe Variablen ANFANG
RefType r1 = (RefType)P.getTA1Copy();
RefType r2 = (RefType)P.getTA2Copy();
r1 = (RefType) r1.TYPE(ass, baseClass);
r2 = (RefType) r2.TYPE(ass, baseClass);
// #JB# 05.04.2005
// ###########################################################
Hashtable<JavaClassName,Type> substHash = new Hashtable<JavaClassName,Type>(); //fuer jedes Paar komplett neue Variablen
Unify.varSubst(r1, substHash);
Unify.varSubst(r2, substHash);
// ###########################################################
P = new Pair(r1, r2);
//PL 04-12-29 freshe Variablen ENDE
//HIER AUSKOMMENTIERT, SOLLTE MAN AM ENDE WIEDER DAZU NEHMEN PL 04-12-28
// gleiches Paar aufnehmen
//vFC.add( new Pair( P.getTA1Copy(), P.getTA1Copy() ) );
return(P);
}
// ino.end
// ino.method.makeFC.21403.defdescription type=javadoc
/**
* Erstellt die Finite Closure
* @return FC_TTO-Object, welches die Finite Closure repräsentiert
*/
// ino.end
// ino.method.makeFC.21403.definition
public FC_TTO makeFC( TypeAssumptions ass )
// ino.end
// ino.method.makeFC.21403.body
{
// Menge FC bilden
Menge<Pair> vFC = new Menge<Pair>(); // Menge FC
TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports, false);
globalAssumptions.add(this.getPublicFieldAssumptions());
// 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen
Menge<Type> ignoreTypes = new Menge<>(); //Enthält die Typen, welche nicht in der FC als Supertypen enthalten sein sollen.
ignoreTypes.add(new RefType("Long",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("Float",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("Double",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("String",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("Integer",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("Object",null,-1).TYPE(globalAssumptions, parent));
Menge<Class> basicAssumptionsClassMenge = new Menge<>(); //die Klassen aus den BasicAssumptions und den Importierten Klassen
for(ClassAssumption cAss : ass.getClassAssumptions()){
Type t1 = cAss.getAssumedClass().getType();
Type t2 = cAss.getAssumedClass().getSuperClass();
if(t2 != null){
Pair p = new Pair(t1, t2);
//System.out.println("FCPair: "+p);
if(! t1.equals(t2)){//Um FC_TTO darf kein T <. T stehen.
Type superTypeFromAssumptions = ass.getTypeFor(t2, t2); //In den Assumptions den SuperTyp nachschlagen
if(superTypeFromAssumptions != null && ! ignoreTypes.contains(superTypeFromAssumptions)){//Die Superklasse eines Typs nur anfügen, wenn er auch in den Assumptions vorkommt.
vFC.add(p);
}
basicAssumptionsClassMenge.add(cAss.getAssumedClass());//Klasse ohne die Superklasse anfügen
}else{
//System.out.println("Wurde nicht aufgenommen");
}
}
}
for( int i = 0; i < KlassenVektor.size(); i++ )
{
Class tempKlasse = KlassenVektor.elementAt(i);
inferencelog.debug("Verarbeite "+tempKlasse.getName(), Section.TYPEINFERENCE);
//TODO: SuperKlasse erstellen, dies sollte am besten beim Konstruktoraufruf von Class geschehen. Diese kann dann mit getSuperClass abgefragt werden.
if( tempKlasse.superclassid != null ) { // Klasse hat Superklasse
Pair P=createPairFromClassAndSuperclass(tempKlasse,tempKlasse.getSuperClass(),tempKlasse.get_ParaList(),tempKlasse.superclassid.get_ParaList(), globalAssumptions);
vFC.add( P );
}
if(tempKlasse.getSuperInterfaces()!=null){
Iterator<Type> interfaceIterator=tempKlasse.getSuperInterfaces().iterator();
while(interfaceIterator.hasNext()){
RefType intf=(RefType) interfaceIterator.next();
Pair P=createPairFromClassAndSuperclass(tempKlasse,intf,tempKlasse.get_ParaList(),intf.get_ParaList(),globalAssumptions);
vFC.add( P );
}
}
} // Schleifenende durch Klassenvektor
for(int i=0; i<InterfaceVektor.size();i++){
Interface intf= InterfaceVektor.get(i);
if(intf.getSuperInterfaces()!=null){
Iterator<Type> interfaceIterator=intf.getSuperInterfaces().iterator();
while(interfaceIterator.hasNext()){
RefType superintf=(RefType) interfaceIterator.next();
Pair P=createPairFromClassAndSuperclass(intf,superintf,intf.getParaList(), superintf.get_ParaList(),globalAssumptions);
vFC.add( P );
}
}
}
Menge tto = (Menge)vFC.clone();
Unify.printMenge( "FC", vFC, 6 );
/* z.B.
*******************************
Menge FC = {
(Vektor< A >, Vektor< A >),
(Vektor< A >, AbstractList< A >),
(Matrix< A >, Matrix< A >),
(Matrix< A >, Vektor< Vektor< A > >),
(ExMatrix< A >, ExMatrix< A >),
(ExMatrix< A >, Matrix< A >) }
*******************************
ODER
*******************************
Menge FC = {
(BB< A >, BB< A >),
(BB< A >, CC< A >),
(AA< A, B >, AA< A, B >),
(AA< A, B >, BB< DD< B, A > >) }
*******************************
*/
// 2. Regel 2 der Huellendefinition "eingeschraenkt" anwenden
// d.h. sinnvolle Substitutionen suchen (nicht alle)
boolean bPaarHinzu = true;
while( bPaarHinzu )
{
bPaarHinzu = false; //PL 04-12-29 nur wenn hinzugefuegt auf true setzen
// konkret: rechte Seite von FC nach Typkonstruktoren in der Parameterliste durchsuchen
for( int n = 0; n < vFC.size(); n++ )
{
// Elemente in FC ¯Â¿Â½nnen nur Pair's sein --> Cast ohne Abfrage
Pair PTypKonst = vFC.elementAt(n);
// Parameter des rechten Typausdrucks des betrachteten Paars extrahieren
Menge<Type> vPara = ((RefType)(PTypKonst.TA2)).get_ParaList();
Integer Subst = null; // Substitution
int nSubstStelle = 0;
inferencelog.debug("nSubstStelleStart" + nSubstStelle + " " + n, Section.FINITECLOSURE);
// Parameter durchlaufen und nach Typkonstruktor suchen
// #JB# 17.05.2005
// ###########################################################
if(vPara!=null){
// ###########################################################
for( ; nSubstStelle < vPara.size(); nSubstStelle++ )
{
inferencelog.debug("nSubstStelle" + nSubstStelle, Section.FINITECLOSURE);
if( vPara.elementAt(nSubstStelle) instanceof RefType && ((RefType)vPara.elementAt(nSubstStelle)).get_ParaList() != null )
{
// Typkonstruktor gefunden -> wird nun als Substitution verwendet
Subst = 1;//new RefType( (RefType)vPara.elementAt(nSubstStelle) ,-1);
inferencelog.debug( "Ausgangstyp:" + ((RefType)PTypKonst.TA2).getName() , Section.FINITECLOSURE);
inferencelog.debug( "RefType = " + ((RefType)vPara.elementAt(nSubstStelle)).getName() , Section.FINITECLOSURE);
break; // Einschraenkung - nur fuer ein RefType wird eine Substitution gesucht
}
}
// ###########################################################
}
// ###########################################################
if( Subst != null )
{
// Rechter Typ hat einen Typkonstruktor --> sinvolles neues Paar bilden
// d.h. Rechter Typ auf linker Paarseite suchen
// System.out.println("Subststelle = " + nSubstStelle );
for( int t = 0; t < vFC.size(); t++ )
{
Pair PSuchen = vFC.elementAt(t);
if( ((RefType)(PTypKonst.TA2)).getTypeName().equals( ((RefType)PSuchen.TA1).getTypeName() ) )
{
inferencelog.debug(" gefundener Typ links: " + ((RefType)(PSuchen.TA1)).getName(), Section.FINITECLOSURE );
inferencelog.debug(" gefundener Typ rechts: " + ((RefType)(PSuchen.TA2)).getName() , Section.FINITECLOSURE);
// Paar gefunden, das als linken Typ den gleichen Typen enth�lt, der als Parameter einen Typkonstruktor hat
// Substitution
//Pair P = new Pair( PSuchen.getTA1Copy( ), PSuchen.getTA2Copy( ) );
//linker Typterm bleibt gleich
//rechter Typterm wird aussen auf den Supertyp gesetzt.
//restliches FC erfolgt ueber die Transitivitaet
//siehe im unteren Teil
Pair P = new Pair( PTypKonst.getTA1Copy( ), PSuchen.getTA2Copy( ) );
// System.out.println(" Subst " + Subst.getName() );
// System.out.println(" Vor: P = " + P.toString() + P.TA1 );
// System.out.println(" Vor: PSuchen = " + PSuchen.toString() + PSuchen.TA1 );
// Parameter, der substituiert wird, sollte TV sein ???
//TypePlaceholder TV = null;
// if( ((RefType)P.TA1).isTV( nSubstStelle ) )
// try
// {
// TV = new TypePlaceholder( ((RefType)P.TA1).getParaN( nSubstStelle ) );
// }
// catch( Exception E )
// {
// continue;
// }
// else
// continue;
//es werden alle Parameter in einem Typeterm, der
//der Argumente hat ersetzt PL 04-12-28
Hashtable<JavaClassName,Type> hts = new Hashtable<JavaClassName,Type>();
//for(int u = nSubstStelle; u < vPara.size(); u++) {
for(int u = 0; u < vPara.size(); u++) {
try {
// #JB# 05.04.2005
// ###########################################################
//TV = new TypePlaceholder( ((RefType)PSuchen.TA1).getParaN(u) );
//System.out.println("TV_Name: " + u + TV.Type2String());
// ###########################################################
inferencelog.debug("Typterm_Name: " + vPara.elementAt(u), Section.FINITECLOSURE);
inferencelog.debug("Typterm_Name: " + ((Type)vPara.elementAt(u)).Type2String(), Section.FINITECLOSURE);
hts.put(new JavaClassName(((RefType)PSuchen.TA1).getParaN(u)), vPara.elementAt(u));
}
catch( Exception E ) {
inferencelog.error(E.getMessage(), Section.FINITECLOSURE);
//FIXME Throw Exception or Error instead of exiting!
System.exit(0);
}
// Subst( P,
// 2,
// TV,
// new RefType( (RefType)vPara.elementAt(u) ),
// false ); // rechte Seite substituieren
//Es genuegt die rechte Seite zu substituieren, da
//die linke Seite ein Typterm ausschlie�lich mit
//Typvariablen ist
}
//Unify.SubstHashtableGeneric(((RefType)P.TA1), hts); //funktioniert nicht
Unify.SubstHashtableGeneric(((RefType)P.TA2), hts); //funktioniert nicht
// System.out.println(" TV!!!= " + TV.getName() );
//Subst( P, 1, TV, Subst, false ); // linke Seite substituieren
//Subst( P, 2, TV, Subst, false ); // rechte Seite substituieren
// System.out.println(" nach Subst: P = " + P.toString() );
// System.out.println(" Nach: PSuchen = " + PSuchen.toString() );
// System.out.println(" Nach: " + P.toString() );
// Paar einfuegen, falls noch nicht vorhanden
// System.out.println("Paar alt:" + PSuchen.toString() );
// System.out.println("Paar neu:" + P.toString() );
if( !P.isInMenge( vFC ) )
{
vFC.add( P );
Unify.printMenge( "FC", vFC, 6 );
bPaarHinzu = true;
}
//PL 04-12-29
// else //unnoetig, da am Anfang bereits false gesetzt
// {
// bPaarHinzu = false;
// }
}
}
} // end if: Substitution gefunden???
} // end for: Typkonstruktor suchen
// Transitivitaet berechnen
for( int u = 0; u < vFC.size(); u++ )
{
Pair PTemp = vFC.elementAt(u);
// falls rechtes Paar = RefType
if( PTemp.TA2 instanceof RefType )
{
RefType R = (RefType)PTemp.TA2;
// rechte Seite auf linker Seite suchen
for( int e = 0; e < vFC.size(); e++ )
{
Pair PSuch = vFC.elementAt(e);
// als linke Paarseite theortisch nur RefType's moeglich --> Cast
RefType RSuch = (RefType)PSuch.TA1;
//if( R.getName().equals(RSuch.getName()) )
if (R.is_Equiv(RSuch, new Hashtable<JavaClassName,Type>())) //eingefuegt PL 05-01-07
{
// Paar einfuegen, falls noch nicht vorhanden
RefType L1 = (RefType)PTemp.getTA1Copy();
RefType L2 = (RefType)PTemp.getTA2Copy();
RefType R1 = (RefType)PSuch.getTA1Copy();
RefType R2 = (RefType)PSuch.getTA2Copy();
//zunaechst Variablen disjunkt machen ANFANG
// #JB# 05.04.2005
// ###########################################################
Hashtable<JavaClassName,Type> substHash1 = new Hashtable<JavaClassName,Type>();
Unify.varSubst(L1, substHash1);
Unify.varSubst(L2, substHash1);
Hashtable<JavaClassName,Type> substHash2 = new Hashtable<JavaClassName,Type>();
Unify.varSubst(R1, substHash2);
Unify.varSubst(R2, substHash2);
// ###########################################################
//zunaechst Variablen disjunkt machen ENDE
//Variablen so umbennen, dass transitiver Abschluss richtige
//Namen hat ANFANG
// #JB# 05.04.2005
// ###########################################################
Hashtable<JavaClassName,Type> h = new Hashtable<JavaClassName,Type>();
L2.Equiv2Equal(R1, h);
Hashtable<JavaClassName,Type> substHash3 = h;
Unify.varSubst(L1, substHash3);
Unify.varSubst(R2, substHash3);
// ###########################################################
//Variablen so umbennen, dass transitiver Abschluss richitge
//Namen hat ENDE
//Pair P = new Pair( (RefType)PTemp.TA1, (RefType)PSuch.TA2 );
Pair P = new Pair(L1, R2);
if( !P.isInMenge( vFC ) )
{
vFC.add( P );
bPaarHinzu = true;
}
else
{
bPaarHinzu = false;
}
}
} // end for: linke Seite suchen
} // end if: Element ist RefType
} // end for: Transitivit�ten berechnen
//PL HIER REFLEXIVE HUELLE EINFUEGEN
// 05-01-07
} // Ende WHILE
/* z.B.
*******************************
Menge nach trans: FC = {
(Vektor< A >, Vektor< A >),
(Vektor< A >, AbstractList< A >),
(Matrix< A >, Matrix< A >),
(Matrix< A >, Vektor< Vektor< A > >),
(ExMatrix< A >, ExMatrix< A >),
(ExMatrix< A >, Matrix< A >),
(Vektor< Vektor< A > >, Vektor< Vektor< A > >),
(Vektor< Vektor< A > >, AbstractList< Vektor< A > >),
(Matrix< A >, AbstractList< Vektor< A > >),
(ExMatrix< A >, Vektor< Vektor< A > >),
(ExMatrix< A >, AbstractList< Vektor< A > >) }
ODER
*******************************
Menge nach trans: FC = {
(BB< A >, BB< A >),
(BB< A >, CC< A >),
(AA< A, B >, AA< A, B >),
(AA< A, B >, BB< DD< B, A > >),
(BB< DD< B, A > >, BB< DD< B, A > >),
(BB< DD< B, A > >, CC< DD< B, A > >),
(AA< A, B >, CC< DD< B, A > >) }
*******************************
******************************* */
// printMenge( "nach trans: FC", vFC, 6 );
Menge<Class> KlassenVektorunImportierteKlassen = new Menge<>();
KlassenVektorunImportierteKlassen.addAll(basicAssumptionsClassMenge);
KlassenVektorunImportierteKlassen.addAll(KlassenVektor);
FC_TTO fctto = new FC_TTO(vFC, tto, KlassenVektorunImportierteKlassen);
return fctto;
}
public TypeAssumptions getPublicFieldAssumptions(){
TypeAssumptions publicAssumptions = new TypeAssumptions(null);
//Alle PublicAssumptions der in dieser SourceFile enthaltenen Klassen sammeln:
for(Class klasse : KlassenVektor){
publicAssumptions.add(klasse.getPublicFieldAssumptions());
}
return publicAssumptions;
}
/////////////////////////////////////////////////////////////////////////
// TypeReconstructionAlgorithmus
/////////////////////////////////////////////////////////////////////////
@ -695,63 +238,65 @@ public class SourceFile
typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions, Section.TYPEINFERENCE);
//FiniteClosure generieren:
FC_TTO finiteClosure = this.makeFC(globalAssumptions);
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(globalAssumptions);
typinferenzLog.debug("FiniteClosure: \n"+finiteClosure, Section.TYPEINFERENCE);
ConstraintsSet oderConstraints = new ConstraintsSet();
//Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln:
for(Class klasse : KlassenVektor){
oderConstraints.add(klasse.typeReconstruction(finiteClosure, globalAssumptions));
oderConstraints.add(klasse.typeReconstruction(globalAssumptions));
}
/*////////////////
* Paare in MPairs umwandeln
* (Wird zunächst mal weggelassen. Constraints werden erst beim Unifizieren umgewandelt
*/////////////////
//UnifyTypeFactory.convert(oderConstraints);
////////////////
//Karthesisches Produkt bilden:
//Typen in UnifyTypen umwandeln:
////////////////
UnifyConstraintsSet unifyConstraints = UnifyTypeFactory.convert(oderConstraints);
//UnmÃgliche ConstraintsSets aussortieren durch Unifizierung
Unifier unifier = (pairs)->{
Menge<Menge<Pair>> retValue = new Menge<>();
retValue = Unify.unify(pairs, finiteClosure);
Function<Menge<MPair>,Menge<Menge<MPair>>> unifier = (pairs)->{
Menge<Menge<MPair>> retValue = new Menge<>();
Set<Set<MPair>> unifiedPairs = new Unify().unify(pairs, finiteClosure);
return retValue;};
//oderConstraints.filterWrongConstraints(unifier);
//oderConstraints.unifyUndConstraints(unifier); //rausgeworfen für Tests (08.12.2015)
typinferenzLog.debug("Übriggebliebene Konstraints:\n"+oderConstraints+"\n", Section.TYPEINFERENCE);
//Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden):
Menge<Menge<Pair>> xConstraints = oderConstraints.cartesianProduct();
typinferenzLog.debug("Übriggebliebene Konvertierte Konstraints:\n"+unifyConstraints+"\n", Section.TYPEINFERENCE);
////////////////
//Karthesisches Produkt bilden:
////////////////
Set<Set<MPair>> xConstraints = unifyConstraints.cartesianProduct();
typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints, Section.TYPEINFERENCE);
finiteClosure.generateFullyNamedTypes(globalAssumptions);
//finiteClosure.generateFullyNamedTypes(globalAssumptions);
//////////////////////////////
// Unifizierung der Constraints:
//////////////////////////////
boolean unifyFail = true;
for(Menge<Pair> constraints : xConstraints){
for(Set<MPair> constraints : xConstraints){
//Alle durch das Karthesische Produkt entstandenen glichkeiten durchgehen:
Menge<Menge<Pair>> result = new Menge<Menge<Pair>>();
//Alle FunN-Typen werden per clone-methode in RefTypes verwandelt. (Die clone Methode in FunN darf nicht überschrieben werden.
for(Pair p : constraints){
if(p.TA1 instanceof FunN){
p.TA1 = p.TA1.clone();
}
if(p.TA2 instanceof FunN){
p.TA2 = p.TA2.clone();
}
}
//Erst die Unifizierung erstellen:
Menge<Pair> constraintsClone = (Menge<Pair>)constraints.clone();
//Menge<Menge<Pair>> result = new Menge<Menge<Pair>>();
//IDEE: Man bildet Zusammenhangskomponenten von Paaren, die gemeinsame Variablen haben
// und unifizert nur die Zusammenhangskomponenten in Schritten 1 - 5
/*
//Schritt 1: Alle Variablen in den Paaren von Elementen einsammeln
Menge<Menge<TypePlaceholder>> constraintsclonevars = constraintsClone.stream().map(p -> {Menge<TypePlaceholder> TPHs = new Menge<>();
Menge<Menge<TypePlaceholder>> constraintsclonevars = constraints.stream().map(p -> {Menge<TypePlaceholder> TPHs = new Menge<>();
TPHs.addAll(p.TA1.getInvolvedTypePlaceholder());
TPHs.addAll(p.TA2.getInvolvedTypePlaceholder());
return TPHs;}
@ -766,17 +311,17 @@ public class SourceFile
//Schritt 3: Umwandlung der Indizes in die zugehoerigen Elemente
// In streamconstraintsclone sind die Mengen von Paar enthalten die unifiziert werden muessen
Stream<Menge<Pair>> streamconstraintsclone = indexeset.stream().map(x -> x.stream()
Stream<Menge<MPair>> streamconstraintsclone = indexeset.stream().map(x -> x.stream()
.map(i -> constraintsClone.elementAt(i))
.<Menge<Pair>>collect(Menge::new, Menge::add, Menge::addAll));
.<Menge<MPair>>collect(Menge::new, Menge::add, Menge::addAll));
//Menge<Menge<Pair>> vecconstraintsclone = streamconstraintsclone.collect(Menge::new, Menge::add, Menge::addAll);
//System.out.println();
//Schritt 4: Unifikation
Menge<Menge<Menge<Pair>>> vecunifyResult =
Set<Set<Set<MPair>>> vecunifyResult =
//streamconstraintsclone.map(x -> Unify.unify(x, finiteClosure)).collect(Menge::new, Menge::add, Menge::addAll);
//DEBUG-Variante
streamconstraintsclone.map(x ->
{ Menge<Menge<Pair>> z = Unify.unify(x, finiteClosure);
{ Set<Set<MPair>> z = new Unify().unify(x, finiteClosure);
return z;
}
).collect(Menge::new, Menge::add, Menge::addAll);
@ -789,19 +334,19 @@ public class SourceFile
//Schritt 5: Bildung des cartesischen Produkts
//sollte wieder entfernt werden: Weiterarbeit mit:
//[[x_1 -> t_1, x_2 -> t2], [x_1 -> t'_1, x_2 -> t'_2]] x ... x [[x_n -> t_1n], [x_n -> t2n], [x_n -> t3n]]
Menge<Menge<Pair>> cardprodret_start = new Menge<>();
Set<Set<Pair>> cardprodret_start = new Menge<>();
cardprodret_start.add(new Menge<Pair>());
//cart. Produkt mit Linkverschiebung
Menge<Menge<Pair>> unifyResult = vecunifyResult.stream().reduce(cardprodret_start, (x, y) -> {
Menge<Menge<Pair>> cardprodret= new Menge<>();
Set<Set<Pair>> unifyResult = vecunifyResult.stream().reduce(cardprodret_start, (x, y) -> {
Set<Set<Pair>> cardprodret= new Menge<>();
if (y.size() > 0) {
//System.out.println(y);
//Menge<Menge<Pair>> cardprodretold = x;
//cardprodret = new Menge<>();
for(int j = 0; j < x.size(); j++) {
for (int k = 0; k < y.size(); k++){
Menge<Pair> help = new Menge<>();
Set<Pair> help = new Menge<>();
help.addAll(y.elementAt(k));
help.addAll(x.elementAt(j));
cardprodret.add(help);
@ -812,10 +357,22 @@ public class SourceFile
return new Menge<>(); //kein unifiziertes Ergebnis, damit wird das Geseamtergebnis []
return cardprodret;
});
*/
Set<Set<MPair>> unifyResult = new Unify().unify(constraints, finiteClosure);
Menge<Menge<Pair>> convertedResult = unifyResult.parallelStream().<Menge<Pair>>map((Set<MPair> resultSet)->{
Menge<Pair> innerConvert = resultSet.stream().map((MPair mp)->UnifyTypeFactory.convert(mp))
.collect(Menge<Pair>::new, Menge::add, Menge::addAll);
return innerConvert;
}).collect(Menge::new, Menge::add, Menge::addAll);
Menge<Pair> convertedConstraints = constraints.stream().map(
(MPair mp)->{return UnifyTypeFactory.convert(mp);}
).collect(Menge<Pair>::new, Menge::add, Menge::addAll);
//Dann den Ergebnissen anfügen
typinferenzLog.debug("\nErgebnis der Unifizierung:\n"+unifyResult, Section.TYPEINFERENCE);
result.addAll(unifyResult);
//result.addAll(convertedResult);
typinferenzLog.debug("\nJavaFiles:\n", Section.TYPEINFERENCE);
@ -825,10 +382,10 @@ public class SourceFile
//¼r jede Klasse in diesem SourceFile gilt das selbe ResultSet:
for(Class klasse : this.KlassenVektor){
//Der Unifikationsalgorithmus kann wiederum auch mehrere sungen errechnen, diese werden im folgenden durchlaufen:
for(Menge<Pair> resultSet : result){
for(Menge<Pair> resultSet : convertedResult){
unifyFail = false; //Ein Unifiziertes Ergebnis ist entstanden (es kann auch leer sein, das bedeutet nur, dass die Constraints mindestens in einem Fall Sinn ergaben)
//Add Result set as a new ReconstructionResult to ret:
TypeinferenceResultSet reconstructionResult = new TypeinferenceResultSet(klasse, constraints, new ResultSet(resultSet));
TypeinferenceResultSet reconstructionResult = new TypeinferenceResultSet(klasse, convertedConstraints, new ResultSet(resultSet));
ret.add(reconstructionResult);
//ResultSet res = new ResultSet(resultSet);
@ -850,7 +407,7 @@ public class SourceFile
* @param withSuptypes - Gibt an, ob auch die subklassen der Packages den Assumptions angefügt werden sollen.
* @return
*/
private TypeAssumptions makeBasicAssumptionsFromJRE(Menge<UsedId> imports, boolean withSubtypes)
public TypeAssumptions makeBasicAssumptionsFromJRE(Menge<UsedId> imports, boolean withSubtypes)
// ino.end
// ino.method.makeBasicAssumptionsFromJRE.21409.body
{

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Type;
@ -10,6 +11,7 @@ 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.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.GenericTypeInsertPoint;
@ -55,7 +57,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
* Eine Beschreibung/Name des SyntaxTree-Nodes
* @return
*/
public String getDescription(){
public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return this.toString();
}
@ -64,7 +66,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
public boolean equals(Object object){
if(!(object instanceof SyntaxTreeNode))return false;
SyntaxTreeNode equal = (SyntaxTreeNode)object;
if(!equal.getDescription().equals(this.getDescription()))return false;
if(!equal.getDescription(null, null).equals(this.getDescription(null, null)))return false;
if(this.getParent()!=null)
if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement überprüfen.
return true;

View File

@ -55,7 +55,7 @@ public class ASTFactory {
return new Constructor(method, superClass);
}
public static Class createClass(String className, Type type, Modifiers modifiers, Menge supertypeGenPara, SourceFile parent) {
public static Class createClass(String className, RefType type, Modifiers modifiers, Menge supertypeGenPara, SourceFile parent) {
// TODO bytecode createClass
//String name, RefType superClass, Modifiers modifiers, Menge<String> supertypeGenPara
Class generatedClass = new Class(className, type, modifiers, supertypeGenPara);

View File

@ -3,7 +3,7 @@ package de.dhbwstuttgart.syntaxtree.factory;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
public class UnifyPairMengenBuilder {

View File

@ -1,41 +1,174 @@
package de.dhbwstuttgart.syntaxtree.factory;
import java.util.HashSet;
import java.util.logging.Logger;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.NullSyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.ObjectType;
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.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.EinzelElement;
import de.dhbwstuttgart.typeinference.KomplexeMenge;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.OderMenge;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.UndMenge;
import de.dhbwstuttgart.typeinference.UnifyConstraintsSet;
import de.dhbwstuttgart.typeinference.UnifyOderConstraint;
import de.dhbwstuttgart.typeinference.UnifyUndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.SimpleType;
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
public class UnifyTypeFactory {
public RefType GetSimpleType(String name, Type... parameters) {
if(parameters.length == 0)
return new RefType(name, null, 0);
private final static NullSyntaxTreeNode NULL_NODE = new NullSyntaxTreeNode();
Menge<Type> typeParams = new Menge<Type>();
for(Type t : parameters)
typeParams.add(t);
return new RefType(name, typeParams, null, 0);
public static FiniteClosure generateFC(TypeAssumptions fromAss){
HashSet<MPair> pairs = new HashSet<>();
for(ClassAssumption cAss : fromAss.getClassAssumptions()){
UnifyType tl = UnifyTypeFactory.convert(cAss.getAssumedClass().getType());
RefType superClass = cAss.getAssumedClass().getSuperClass();
if(superClass != null){
UnifyType tr = UnifyTypeFactory.convert(superClass);
pairs.add(smaller(tl, tr));
}
}
return new FiniteClosure(pairs);
}
public ExtendsWildcardType GetExtendsType(ObjectType extendedType) {
return new ExtendsWildcardType(extendedType);
public static MPair smaller(UnifyType tl, UnifyType tr){
return new MPair(tl, tr, PairOperator.SMALLER);
}
public SuperWildcardType GetSuperType(ObjectType superedType) {
return new SuperWildcardType(superedType);
public static UnifyType convert(Type t){
//Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist
if(t instanceof GenericTypeVar){
return UnifyTypeFactory.convert((GenericTypeVar)t);
}else if(t instanceof RefType){
return UnifyTypeFactory.convert((RefType)t);
}else if(t instanceof TypePlaceholder){
return UnifyTypeFactory.convert((TypePlaceholder)t);
}else if(t instanceof ExtendsWildcardType){
return UnifyTypeFactory.convert((ExtendsWildcardType)t);
}else if(t instanceof SuperWildcardType){
return UnifyTypeFactory.convert((SuperWildcardType)t);
}
throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden");
}
public WildcardType GetWildcardType() {
return new WildcardType(null, null, 0);
public static UnifyType convert(RefType t){
UnifyType ret;
if(t.getParaList() != null && t.getParaList().size() > 0){
Menge<UnifyType> params = new Menge<>();
for(Type pT : t.getParaList()){
params.add(UnifyTypeFactory.convert(pT));
}
ret = new SimpleType(t.get_Name(),new TypeParams(params));
}else{
ret = new SimpleType(t.get_Name());
}
return ret;
}
public TypePlaceholder GetTypePlaceholder(String name) {
return TypePlaceholder.backdoorCreate(name);
public static UnifyType convert(TypePlaceholder tph){
return new PlaceholderType(tph.get_Name());
}
public static UnifyType convert(ExtendsWildcardType t){
return new ExtendsType(UnifyTypeFactory.convert(t.get_ExtendsType()));
}
public static UnifyType convert(SuperWildcardType t){
return new SuperType(UnifyTypeFactory.convert(t.get_SuperType()));
}
public static UnifyType convert(GenericTypeVar t){
return new SimpleType(t.get_Name());
}
public static UnifyConstraintsSet convert(ConstraintsSet constraints) {
UnifyConstraintsSet ret = new UnifyConstraintsSet();
for(OderConstraint oC : constraints.getOderConstraints()){
ret.add(UnifyTypeFactory.convert(oC));
}
return ret;
}
public static UnifyOderConstraint convert(OderConstraint set) {
UnifyOderConstraint ret = new UnifyOderConstraint();
for(UndConstraint oC : set.getUndConstraints()){
ret.addConstraint(UnifyTypeFactory.convert(oC));
}
return ret;
}
public static UnifyUndConstraint convert(UndConstraint set) {
UnifyUndConstraint ret = new UnifyUndConstraint();
for(EinzelElement<Pair> oC : set.getPairs()){
ret.add(UnifyTypeFactory.convert(oC));
}
return ret;
}
public static MPair convert(EinzelElement<Pair> p) {
return convert(p.getItem());
}
public static MPair convert(Pair p) {
if(!p.OperatorSmaller())throw new NotImplementedException();
MPair ret = smaller(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2));
return ret;
}
public static Pair convert(MPair mp) {
Type tl = UnifyTypeFactory.convert(mp.getLhsType());
Type tr = UnifyTypeFactory.convert(mp.getRhsType());
return new Pair(tl, tr, mp.getPairOp());
}
public static Type convert(SimpleType t) {
return new RefType(t.getName(),null,0);
}
public static Type convert(SuperType t) {
RefType innerType = new RefType(t.getSuperedType().getName(),NULL_NODE,0);
return new SuperWildcardType(innerType);
}
public static Type convert(ExtendsType t) {
RefType innerType = new RefType(t.getExtendedType().getName(),NULL_NODE,0);
return new ExtendsWildcardType(innerType);
}
public static Type convert(PlaceholderType t) {
return TypePlaceholder.getInstance(t.getName());
}
public static Type convert(UnifyType t) {
if(t instanceof SimpleType)return convert((SimpleType) t);
if(t instanceof SuperType)return convert((SuperType) t);
if(t instanceof ExtendsType)return convert((ExtendsType) t);
if(t instanceof PlaceholderType)return convert((PlaceholderType) t);
throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden");
}
}

View File

@ -2,7 +2,6 @@ package de.dhbwstuttgart.syntaxtree.factory;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
@ -24,10 +23,6 @@ public class Unify_FC_TTO_Builder {
fc.add(new Pair(t1, t2));
}
public FC_TTO Get_FC_TTO() {
return new FC_TTO(fc, (Menge<?>) fc.clone(), classes);
}
public void clear() {
fc = new Menge<Pair>();
classes = new Menge<Class>();

View File

@ -15,7 +15,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
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;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -7,7 +7,6 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
// ino.class.AndOp.24101.declaration

View File

@ -18,7 +18,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
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;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -19,54 +19,32 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
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;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.Unify;
// ino.class.Operator.24257.declaration
public abstract class Operator extends SyntaxTreeNode
// ino.end
// ino.class.Operator.24257.body
{
// ino.attribute.offset.24261.declaration
private int offset;
// ino.end
// ino.attribute.variableLength.24264.declaration
private int variableLength;
// ino.end
// ino.method.Operator.24267.definition
public Operator(int offset,int variableLength)
// ino.end
// ino.method.Operator.24267.body
{
this.offset=offset;
this.variableLength=variableLength;
}
// ino.end
// ino.method.getOffset.24270.definition
public int getOffset()
// ino.end
// ino.method.getOffset.24270.body
{
return offset;
}
// ino.end
// ino.method.getVariableLength.24273.definition
public int getVariableLength()
// ino.end
// ino.method.getVariableLength.24273.body
{
return variableLength;
}
// ino.end
/**

View File

@ -33,7 +33,6 @@ 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.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.Unify;
@ -107,8 +106,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().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)));
ret.add(ConstraintsSet.createSingleConstraint(expr2.getType().TYPE(assumptions, this), expr1.getType().TYPE(assumptions, this))); //expr2.type <. expr1.type
ret.add(ConstraintsSet.createSingleConstraint(expr1.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
return ret;
}

View File

@ -38,12 +38,10 @@ 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.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -32,12 +32,10 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -188,8 +186,8 @@ public class Block extends Statement
}
else {
TypePlaceholder tph = TypePlaceholder.fresh(this);
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), tph));
ret.add(new SingleConstraint(stmt.getType().TYPE(assumptions, this), tph));
ret.add(ConstraintsSet.createSingleConstraint(this.getType().TYPE(assumptions, this), tph));
ret.add(ConstraintsSet.createSingleConstraint(stmt.getType().TYPE(assumptions, this), tph));
this.setType(tph);
}
}
@ -252,7 +250,7 @@ public class Block extends Statement
}
@Override
public String getDescription(){
public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return "Block";
}

View File

@ -24,7 +24,6 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -25,7 +25,6 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -24,7 +24,6 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -27,7 +27,6 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -22,7 +22,6 @@ import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -33,7 +33,6 @@ 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.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;

View File

@ -44,11 +44,9 @@ 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.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.MUB;
import de.dhbwstuttgart.typeinference.unify.Unify;
@ -142,10 +140,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().TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
if(!(else_block.getType() instanceof Void))ret.add(ConstraintsSet.createSingleConstraint(else_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
}
ret.add(new SingleConstraint(expr.getType().TYPE(assumptions, this),new RefType("Boolean",this,0).TYPE(assumptions, this))); //(expressionDesIfStmt)<.boolean
if(!(then_block.getType() instanceof Void))ret.add(new SingleConstraint(then_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
ret.add(ConstraintsSet.createSingleConstraint(expr.getType().TYPE(assumptions, this),new RefType("Boolean",this,0).TYPE(assumptions, this))); //(expressionDesIfStmt)<.boolean
if(!(then_block.getType() instanceof Void))ret.add(ConstraintsSet.createSingleConstraint(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,this.getOffset()));
return ret;

View File

@ -28,7 +28,6 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -41,13 +41,11 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
/**
* @author A10023 - Andreas Stadelmeier
@ -199,7 +197,7 @@ public class LambdaExpression extends Expr{
}else{
this.lambdaType = new FunN(retType, modifiedParamTypes);
}
ret.add(new SingleConstraint(lambdaType.TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
ret.add(ConstraintsSet.createSingleConstraint(lambdaType.TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
return ret;
}

View File

@ -3,7 +3,6 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.end
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
// ino.class.Literal.25490.declaration
public abstract class Literal extends Expr

View File

@ -28,12 +28,10 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -27,7 +27,6 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.LocalVarAssumption;
@ -35,7 +34,6 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -372,14 +370,14 @@ public class LocalVarDecl extends Statement implements TypeInsertable
}
assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird.
//if(this.getType() == null)throw new DebugException("Parser Post Processing nicht aufgerufen");
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
ret.add(ConstraintsSet.createSingleConstraint(this.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
this.setReturnType(new Void(this,0)); //Return typ einer Variablendeklaration ist Void
return ret;
}
@Override
public String getDescription() {
public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
if(this.getType() == null)return "no type " + declid.toString();
if(this.getType() instanceof TypePlaceholder)return declid.toString();
return this.getType().toString() + " " + declid.toString();

View File

@ -24,7 +24,6 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -28,7 +28,6 @@ import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -22,7 +22,6 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -34,13 +34,11 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -202,11 +200,11 @@ public class NewClass extends Expr
if(arglist!=null){
il.append(arglist.generateBytecode(_cg, rs));
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(), "<init>",
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "<init>",
org.apache.commons.bcel6.generic.Type.VOID,
this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL));
}else{
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(), "<init>",
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "<init>",
org.apache.commons.bcel6.generic.Type.VOID,
new org.apache.commons.bcel6.generic.Type[]{}, Constants.INVOKESPECIAL));
}

View File

@ -28,7 +28,6 @@ import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -24,7 +24,6 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -22,7 +22,6 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -28,7 +28,6 @@ import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -33,7 +33,6 @@ import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -28,7 +28,6 @@ import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -28,7 +28,6 @@ import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify;

View File

@ -24,10 +24,8 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -96,7 +94,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().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
ret.add(ConstraintsSet.createSingleConstraint(retexpr.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
return ret;
}

View File

@ -119,7 +119,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
@Override
public String getDescription(){
public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return this.printJavaCode(new ResultSet(new Menge<Pair>())).toString();
}

View File

@ -32,7 +32,6 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -32,7 +32,6 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -24,7 +24,6 @@ import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;

View File

@ -28,11 +28,10 @@ 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.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify;
@ -113,7 +112,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().TYPE(assumptions, this), new RefType("Boolean",this, 0).TYPE(assumptions, this)); // while(expr){}; expr <. boolean
UndConstraint exprMustBeBool = ConstraintsSet.createSingleConstraint(expr.getType().TYPE(assumptions, this), new RefType("Boolean",this, 0).TYPE(assumptions, this)); // while(expr){}; expr <. boolean
ret.add(exprMustBeBool);
ret.add(this.loop_block.TYPEStmt(assumptions));
this.setType(loop_block.getType());

View File

@ -9,7 +9,6 @@ import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;

View File

@ -163,4 +163,10 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer,
return new de.dhbwstuttgart.bytecode.WildcardType(this.innerType.get_Name(), "+");
}
*/
@Override
public String get_Name() {
return "? extends "+this.innerType.get_Name();
}
}

View File

@ -11,7 +11,6 @@ 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;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;

View File

@ -29,8 +29,6 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResults;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionGenVar;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -182,41 +180,6 @@ public class RefType extends ObjectType implements IMatchable
return name + "<"+para + " >" ;
}
}
// ino.end
/**
* Wandelt die Parameter des RefTypes in TPHs um, sofern es sich um Generische Variablen handelt.
* @return
*/
// ino.method.GenericTypeVar2TypePlaceholder.26652.definition
public CSubstitutionSet GenericTypeVar2TypePlaceholder ()
// ino.end
// ino.method.GenericTypeVar2TypePlaceholder.26652.body
{
//throw new NotImplementedException();
///*
CSubstitutionSet sub = new CSubstitutionSet();
if(parameter != null)
{
for (int i = 0; i < parameter.size(); i++)
{
if (parameter.elementAt(i) instanceof GenericTypeVar)
{
TypePlaceholder tlv = TypePlaceholder.fresh(null);
sub.addElement(new CSubstitutionGenVar((GenericTypeVar)parameter.elementAt(i), tlv));
parameter.set(i, tlv);
}
if (parameter.elementAt(i) instanceof RefType)
{
CSubstitutionSet parasub = ((RefType)parameter.elementAt(i)).GenericTypeVar2TypePlaceholder();
sub.addAll(parasub); //korrigiert PL 07=07=29
}
}
}
return sub;
//*/
}
// ino.end
/**
* Wandelt die Parameter des RefTypes in TPHs um, sofern es sich um Generische Variablen handelt.
@ -875,6 +838,11 @@ public class RefType extends ObjectType implements IMatchable
return new GenericClassType(getName().toString(), getParaList(), parent, getOffset());
}
@Override
public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs) {
String signature = getBytecodeSignature(cg, rs);
return signature.substring(1, signature.length()-1);
}
}
// ino.end

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
@ -168,5 +169,9 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I
return "-" + this.innerType.getBytecodeSignature(cg, rs);
}
@Override
public String get_Name() {
return "? super "+this.innerType.get_Name();
}
}

View File

@ -17,7 +17,11 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
class Test {
void methode(ArrayList<? super Integer> t){
}
}
//TODO: Die Klasse Type muss abstract werden!
// ino.class.Type.26716.declaration

View File

@ -43,7 +43,7 @@ public class TypePlaceholder extends ObjectType
private static String strNextName = "A";
// ino.end
// ino.attribute.m_TypePlaceholdersRegistry.26788.declaration
private static Hashtable<JavaClassName, TypePlaceholder> m_TypePlaceholdersRegistry = new Hashtable<JavaClassName, TypePlaceholder>();
private static Hashtable<String, TypePlaceholder> m_TypePlaceholdersRegistry = new Hashtable<String, TypePlaceholder>();
// ino.end
private SyntaxTreeNode parent;
@ -102,10 +102,10 @@ public class TypePlaceholder extends ObjectType
// ino.method.fresh.26800.body
{
TypePlaceholder typeVar = new TypePlaceholder(name, parent);
TypePlaceholder oldTPH = m_TypePlaceholdersRegistry.put(typeVar.getName(), typeVar);
TypePlaceholder oldTPH = m_TypePlaceholdersRegistry.put(typeVar.getName().toString(), typeVar);
if(oldTPH != null){
oldTPH.name = new JavaClassName(makeNewName());
m_TypePlaceholdersRegistry.put(oldTPH.getName(), oldTPH);
m_TypePlaceholdersRegistry.put(oldTPH.getName().toString(), oldTPH);
}
return typeVar;
}
@ -121,7 +121,7 @@ public class TypePlaceholder extends ObjectType
*/
public static TypePlaceholder fresh(SyntaxTreeNode parent){
TypePlaceholder ret= new TypePlaceholder(makeNewName(), parent);
m_TypePlaceholdersRegistry.put(ret.getName(), ret);
m_TypePlaceholdersRegistry.put(ret.getName().toString(), ret);
return ret;
}
@ -260,7 +260,7 @@ public class TypePlaceholder extends ObjectType
// ino.method.deleteRegistry.26839.body
{
m_TypePlaceholdersRegistry.clear();
m_TypePlaceholdersRegistry = new Hashtable<JavaClassName, TypePlaceholder>();
m_TypePlaceholdersRegistry = new Hashtable<String, TypePlaceholder>();
}
// ino.end
@ -328,7 +328,7 @@ public class TypePlaceholder extends ObjectType
//auf den CSubstitution nicht registrierte Variablen zu
//Exceptions fuehrt
TypePlaceholder typeVar = new TypePlaceholder(makeNewName(), null);
m_TypePlaceholdersRegistry.put(typeVar.getName(), typeVar);
m_TypePlaceholdersRegistry.put(typeVar.getName().toString(), typeVar);
return typeVar;
//return new TypePlaceholder(makeNewName());
@ -378,7 +378,7 @@ public class TypePlaceholder extends ObjectType
//auf den CSubstitution nicht registrierte Variablen zu
//Exceptions fuehrt
TypePlaceholder typeVar = new TypePlaceholder(name, null);
m_TypePlaceholdersRegistry.put(typeVar.getName(), typeVar);
m_TypePlaceholdersRegistry.put(typeVar.getName().toString(), typeVar);
return typeVar;
//return new TypePlaceholder(name);

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
@ -111,6 +112,9 @@ public class WildcardType extends Type{
return this.innerType.getBytecodeSignature(cg, rs);
}
@Override
public JavaClassName getName() {
return new JavaClassName(this.get_Name());
}
}

View File

@ -1,8 +1,10 @@
package de.dhbwstuttgart.typeinference;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.logger.*;
import de.dhbwstuttgart.typeinference.unify.Unifier;
@ -35,20 +37,22 @@ public class ConstraintsSet extends UndMenge<Pair> implements Iterable<OderConst
return constraintsSet.iterator();
}
public void filterWrongConstraints(Unifier unify) {
/*
* Das ConstraintsSet enthält nur OderConstraints, welche UND-Verknüpft sind.
* Hier werden Constraints in den OderConstraints kontrolliert:
*/
public void filterWrongConstraints(Unifier unify) {
// * Das ConstraintsSet enthält nur OderConstraints, welche UND-Verknüpft sind.
// * Hier werden Constraints in den OderConstraints kontrolliert:
for(OderConstraint constraint : this){
constraint.filterWrongConstraints(unify);
}
}
*/
/**
* Nimmt alle UndConstraints und filtert mithilfe dieser die falschen Constraints aus den OderConstraints
* @param unifier
*/
public void unifyUndConstraints(Unifier unifier) {
Vector<UndConstraint> uCons = this.filterUndConstraints();
Vector<Pair> alleUndConstraints = new Vector<>();
@ -57,16 +61,16 @@ public class ConstraintsSet extends UndMenge<Pair> implements Iterable<OderConst
}
this.filterWrongConstraints(
(pairs)->{
Menge<Pair> undConstraintsUndPairs = new Menge<>();
Set<Pair> undConstraintsUndPairs = new Menge<>();
undConstraintsUndPairs.addAll(pairs);
undConstraintsUndPairs.addAll(alleUndConstraints);
log.debug("Versuche Pairs auszusondern:\n"+pairs, Section.TYPEINFERENCE);
log.debug("Unifiziere:\n"+undConstraintsUndPairs, Section.TYPEINFERENCE);
Menge<Menge<Pair>> unifyResult = unifier.apply(undConstraintsUndPairs);
Set<Set<Pair>> unifyResult = unifier.apply(undConstraintsUndPairs);
return unifyResult;
});
}
*/
/**
* Aus dem ConstraintsSet [ u1, u2, ... (OderConstraint), ... uN ] werden alle
* UndConstraints, welche sich nicht innerhalb eines OderConstraints befinden, herausgefiltert
@ -89,6 +93,20 @@ public class ConstraintsSet extends UndMenge<Pair> implements Iterable<OderConst
@Override
public Menge<? extends KomplexeMenge<Pair>> getSet() {
return this.getOderConstraints();
}
public Menge<OderConstraint> getOderConstraints() {
return this.constraintsSet;
}
public static UndConstraint createSingleConstraint(Type t1, Type t2){
UndConstraint ret = new UndConstraint();
ret.addConstraint(t1, t2);
return ret;
}
public static UndConstraint createSingleConstraint(Pair pair) {
return createSingleConstraint(pair.TA1, pair.TA2);
}
}

View File

@ -1,5 +1,7 @@
package de.dhbwstuttgart.typeinference;
import java.util.Set;
import com.rits.cloning.Cloner;
public class EinzelElement<A> implements KomplexeMenge<A>{
@ -16,9 +18,9 @@ public class EinzelElement<A> implements KomplexeMenge<A>{
}
@Override
public Menge<Menge<A>> cartesianProduct() {
public Set<Set<A>> cartesianProduct() {
Cloner cloner = new Cloner();
Menge<Menge<A>> ret = new Menge<>();
Set<Set<A>> ret = new Menge<>();
Menge<A> i = new Menge<A>();
i.add(cloner.deepClone(item));
ret.add(i);
@ -30,4 +32,8 @@ public class EinzelElement<A> implements KomplexeMenge<A>{
return item.toString();
}
public A getItem(){
return item;
}
}

View File

@ -1,6 +1,8 @@
package de.dhbwstuttgart.typeinference;
import java.util.Set;
public interface KomplexeMenge<A>{
Menge<? extends KomplexeMenge<A>> getSet();
Menge<Menge<A>> cartesianProduct();
Set<? extends KomplexeMenge<A>> getSet();
Set<Set<A>> cartesianProduct();
}

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.typeinference;
import java.util.Set;
import java.util.Vector;
import de.dhbwstuttgart.logger.Logger;
@ -10,7 +11,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier;
public class OderConstraint extends OderMenge<Pair>{
private Menge<UndConstraint> oderConstraintPairs;
private Set<UndConstraint> oderConstraintPairs;
private final static Logger logger = Logger.getLogger(OderConstraint.class.getName());
@ -70,7 +71,7 @@ public class OderConstraint extends OderMenge<Pair>{
return ret+"]";
}
public Vector<UndConstraint> getUndConstraints() {
public Set<UndConstraint> getUndConstraints() {
return this.oderConstraintPairs;
/*
Vector<UndConstraint> ret = new Vector<UndConstraint>();
@ -89,11 +90,11 @@ public class OderConstraint extends OderMenge<Pair>{
* Filtert die Constraints in diesem ODER-Verknüpften Constraint aus,
* welche keinen Sinn ergeben, also beim unifizieren scheitern.
* @param unifier - Wird für die Unifizierung benutzt
*/
void filterWrongConstraints(Unifier unifier) {
Menge<UndConstraint> filteredConstraints = new Menge<>();
Set<UndConstraint> filteredConstraints = new Menge<>();
for(UndConstraint cons : this.getUndConstraints()){
Menge<Menge<Pair>> unifierResult = unifier.apply(cons.getConstraintPairs());
Set<Set<Pair>> unifierResult = unifier.apply(cons.getConstraintPairs());
if(!unifierResult.isEmpty()){
filteredConstraints.add(cons);
}else{
@ -102,7 +103,6 @@ public class OderConstraint extends OderMenge<Pair>{
}
this.oderConstraintPairs = filteredConstraints;
}
UndConstraint filterUndConstraints() {
if(this.oderConstraintPairs.size()==1){
return this.oderConstraintPairs.firstElement();
@ -110,8 +110,9 @@ public class OderConstraint extends OderMenge<Pair>{
return null;
}
*/
@Override
public Menge<? extends KomplexeMenge<Pair>> getSet() {
public Set<? extends KomplexeMenge<Pair>> getSet() {
return this.oderConstraintPairs;
}

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -13,11 +14,11 @@ import de.dhbwstuttgart.typeinference.unify.Unifier;
public abstract class OderMenge<A> implements KomplexeMenge<A>{
public abstract Menge<? extends KomplexeMenge<A>> getSet();
public abstract Set<? extends KomplexeMenge<A>> getSet();
@Override
public Menge<Menge<A>> cartesianProduct() {
Menge<Menge<A>> ret = new Menge<>();
public Set<Set<A>> cartesianProduct() {
Set<Set<A>> ret = new Menge<>();
for(KomplexeMenge<A> km : this.getSet()){
ret.addAll(km.cartesianProduct());
}

View File

@ -11,10 +11,8 @@ import java.io.Serializable;
import java.util.Hashtable;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
// ino.end
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.type.FreshWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
@ -43,9 +41,8 @@ public class Pair implements Serializable, DeepCloneable
// ino.end
// ino.attribute.bEqual.26549.declaration
private PairOperator eOperator = PairOperator.Smaller;
private PairOperator eOperator = PairOperator.SMALLER;
public enum PairOperator { Smaller, SmallerExtends, Equal };
// ino.end
// ino.attribute.bSubst.26552.decldescription type=line
// false <--> vorinitialisierter Wert
@ -79,7 +76,7 @@ public class Pair implements Serializable, DeepCloneable
this.TA1 = TA1;
this.TA2 = TA2;
bSubst = false;
eOperator = PairOperator.Smaller;
eOperator = PairOperator.SMALLER;
}
// ino.end
@ -342,7 +339,7 @@ public class Pair implements Serializable, DeepCloneable
*/
public boolean OperatorEqual()
{
return eOperator == PairOperator.Equal;
return eOperator == PairOperator.EQUALSDOT;
}
/**
@ -351,7 +348,7 @@ public class Pair implements Serializable, DeepCloneable
*/
public boolean OperatorSmaller()
{
return eOperator == PairOperator.Smaller;
return eOperator == PairOperator.SMALLER;
}
/**
@ -360,7 +357,7 @@ public class Pair implements Serializable, DeepCloneable
*/
public boolean OperatorSmallerExtends()
{
return eOperator == PairOperator.SmallerExtends;
return eOperator == PairOperator.SMALLERDOTWC;
}
/**

View File

@ -1,71 +0,0 @@
package de.dhbwstuttgart.typeinference;
import java.util.Vector;
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.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
/**
* Beschreibung von Herrn Plümicke:
* "The set of constraints consists of constraints of the form θ R θ' , where θ and
* θ' are Java types and R (R { < , <? , = }) is a subtyping condition."
*
* @author AI10023 - Andreas Stadelmeier
*
* Die Klasse stellt ein OderConstraint-Set dar, welches nur aus einem Constraint besteht.
*
*/
public class SingleConstraint extends UndConstraint{
private Pair constraintPair; //entspricht θ condition θ'
//private R condition; //entspricht der condition (R)
public SingleConstraint(Type p1, Type p2){
//super(p1,p2);
if(p1 == null || p2 == null)throw new NullPointerException();
Pair constraintPair = new Pair(p1,p2);//super.getConstraintPairs().firstElement();
this.addConstraint(constraintPair);
}
@Override
public Menge<? extends KomplexeMenge<Pair>> getSet() {
Menge<EinzelElement<Pair>> ret = new Menge<>();
ret.add(new EinzelElement<>(constraintPair));
return ret;
}
public SingleConstraint(Pair toAdd) {
this.addConstraint(toAdd);
}
public Pair getPair(){
return constraintPair;
}
@Override //Methode überschreiben, damit immer nur ein Vector mit nur einem Element zurückgeliefert wird.
public Menge<Pair> getConstraintPairs(){
Menge<Pair> ret = new Menge<Pair>();
ret.add(constraintPair);
return ret;
}
public void addConstraint(Pair 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;
if(p1==null || p2 == null)throw new NullPointerException();
constraintPair = new Pair(p1,p2);
}
@Override
public String toString(){
return ""+constraintPair.TA1.toString()+" < "+constraintPair.TA2.toString();
}
}

View File

@ -15,7 +15,6 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
// ino.class.CTypeReconstructionResult.27238.description type=javadoc
/**

View File

@ -1,6 +1,7 @@
package de.dhbwstuttgart.typeinference;
import java.util.Collection;
import java.util.Set;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Type;
@ -21,13 +22,13 @@ public class UndConstraint extends UndMenge<Pair> {
return set;
}
public Menge<Pair> getConstraintPairs() {
Menge<Menge<Pair>> ret = this.cartesianProduct();
public Set<Pair> getConstraintPairs() {
Set<Set<Pair>> ret = this.cartesianProduct();
if(ret.size() != 1){
//UndConstraints enthalten nur SingleConstraints, wodurch das Karthesische Produkt nur aus einem Element bestehen kann.
throw new DebugException("Fehler in ConstraintPairs-Bildung");
}
return ret.firstElement();
return ret.iterator().next();
}
public void addConstraint(Type type, Type rT) {
@ -41,6 +42,9 @@ public class UndConstraint extends UndMenge<Pair> {
return ret;
}
public Set<EinzelElement<Pair>> getPairs(){
return set;
}
/*
public UndConstraint(ConstraintType p1, ConstraintType p2) {

View File

@ -3,32 +3,32 @@ package de.dhbwstuttgart.typeinference;
import de.dhbwstuttgart.typeinference.unify.Unify;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
//import com.rits.cloning.Cloner;
public abstract class UndMenge<A extends DeepCloneable> implements KomplexeMenge<A>{
public abstract class UndMenge<A> implements KomplexeMenge<A>{
public abstract Menge<? extends KomplexeMenge<A>> getSet();
@Override
public Menge<Menge<A>> cartesianProduct() {
Menge<Menge<A>> ret = null;
//Cloner cloner = new Cloner();
public Set<Set<A>> cartesianProduct() {
Set<Set<A>> ret = null;
for(KomplexeMenge<A> km : this.getSet()){
if(ret == null){
ret = km.cartesianProduct();
}else{
Menge<Menge<A>> cartesianProduct = new Menge<>();
for(Menge<A> r : ret)for(Menge<A> m : km.cartesianProduct()){ //¼r jedes Element aus dem Karthesischen Produkt:
Menge<A> undElement = new Menge<A>();
undElement.addAll(Unify.deepClone(r));
Set<Set<A>> cartesianProduct = new Menge<>();
for(Set<A> r : ret)for(Set<A> m : km.cartesianProduct()){ //¼r jedes Element aus dem Karthesischen Produkt:
Set<A> undElement = new Menge<A>();
undElement.addAll(r);
undElement.addAll(m);
cartesianProduct.add(undElement);
}
ret = cartesianProduct;
}
}
if(ret == null)return new Menge<Menge<A>>();
if(ret == null)return new Menge<>();
return ret;
}

View File

@ -0,0 +1,96 @@
package de.dhbwstuttgart.typeinference;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.*;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
public class UnifyConstraintsSet extends UndMenge<MPair> implements Iterable<UnifyOderConstraint>{
private static final Logger log = Logger.getLogger(UnifyConstraintsSet.class.getName());
private Menge<UnifyOderConstraint> constraintsSet;
public UnifyConstraintsSet(){
constraintsSet = new Menge<UnifyOderConstraint>();
}
public void add(UnifyConstraintsSet CSet){
for(UnifyOderConstraint element : CSet)
add(element);
}
public void add(UnifyOderConstraint constraint){
constraintsSet.add(constraint);
}
@Override
public String toString(){
String ret ="";
for(UnifyOderConstraint constraint : this){
ret += constraint.toString()+"\n";
}
return ret;
}
public Iterator<UnifyOderConstraint> iterator() {
return constraintsSet.iterator();
}
public void filterWrongConstraints(Unifier unify) {
/*
* Das ConstraintsSet enthält nur OderConstraints, welche UND-Verknüpft sind.
* Hier werden Constraints in den OderConstraints kontrolliert:
*/
for(UnifyOderConstraint constraint : this){
constraint.filterWrongConstraints(unify);
}
}
/**
* Nimmt alle UndConstraints und filtert mithilfe dieser die falschen Constraints aus den OderConstraints
* @param unifier
*/
public void unifyUndConstraints(Unifier unifier) {
Vector<UnifyUndConstraint> uCons = this.filterUndConstraints();
Vector<MPair> alleUndConstraints = new Vector<>();
for(UnifyUndConstraint undConstraint : uCons){
alleUndConstraints.addAll(undConstraint.getConstraintPairs());
}
this.filterWrongConstraints(
(pairs)->{
Set<MPair> undConstraintsUndPairs = new Menge<>();
undConstraintsUndPairs.addAll(pairs);
undConstraintsUndPairs.addAll(alleUndConstraints);
log.debug("Versuche Pairs auszusondern:\n"+pairs, Section.TYPEINFERENCE);
log.debug("Unifiziere:\n"+undConstraintsUndPairs, Section.TYPEINFERENCE);
Set<Set<MPair>> unifyResult = unifier.apply(undConstraintsUndPairs);
return unifyResult;
});
}
/**
* Aus dem ConstraintsSet [ u1, u2, ... (OderConstraint), ... uN ] werden alle
* UndConstraints, welche sich nicht innerhalb eines OderConstraints befinden, herausgefiltert
* @return [u1, ... , uN]
*/
private Vector<UnifyUndConstraint> filterUndConstraints() {
Vector<UnifyUndConstraint> ret = new Vector<>();
for(UnifyOderConstraint con : constraintsSet){
UnifyUndConstraint filtered = con.filterUndConstraints();
if(filtered != null)ret.add(filtered);
}
return ret;
}
public void add(UnifyUndConstraint singleConstraint) {
UnifyOderConstraint toAdd = new UnifyOderConstraint();
toAdd.addConstraint(singleConstraint);
constraintsSet.add(toAdd);
}
@Override
public Menge<? extends KomplexeMenge<MPair>> getSet() {
return this.constraintsSet;
}
}

View File

@ -0,0 +1,112 @@
package de.dhbwstuttgart.typeinference;
import java.util.Set;
import java.util.Vector;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
public class UnifyOderConstraint extends OderMenge<MPair>{
private Set<UnifyUndConstraint> oderConstraintPairs;
private final static Logger logger = Logger.getLogger(UnifyOderConstraint.class.getName());
/**
* Erstellt ein neues Oder Constraint und f<EFBFBD>gt bereits ein Constraint hinzu.
* @param p1
* @param p2
public OderConstraint(Pair p1, Pair p2){
if(p1 == null || p2 == null)throw new NullPointerException();
Pair constraintPair = new Pair(p1,p2);
oderConstraintPairs = new Menge<UndConstraint>();
this.addConstraint(constraintPair);
}
*/
public UnifyOderConstraint(){
oderConstraintPairs = new Menge<UnifyUndConstraint>();
}
/**
* Liefert alle in diesem OderConstraint enthaltene Constraints. Dabei gehen die Verkn<EFBFBD>pfungen (Oder/Und) verloren.
* @return
*/
public Menge<MPair> getConstraintPairs(){
Menge<MPair> ret = new Menge<MPair>();
for(UnifyUndConstraint oC : this.oderConstraintPairs){
ret.addAll(oC.getConstraintPairs());
}
return ret;
}
/**
* 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(MPair toAdd){
oderConstraintPairs.add(new UnifySingleConstraint(toAdd));
}
@Override
public String toString(){
String ret = "[";
for(UnifyUndConstraint p : this.getUndConstraints()){
ret += p.toString()+ "| ";
}
return ret+"]";
}
public Set<UnifyUndConstraint> getUndConstraints() {
return this.oderConstraintPairs;
/*
Vector<UndConstraint> ret = new Vector<UndConstraint>();
for(Pair p : this.getConstraintPairs()){
ret.add(new UndConstraint(p.TA1,p.TA2));
}
return ret;
*/
}
public void addConstraint(UnifyUndConstraint constraint) {
oderConstraintPairs.add(constraint);
}
/**
* Filtert die Constraints in diesem ODER-Verknüpften Constraint aus,
* welche keinen Sinn ergeben, also beim unifizieren scheitern.
* @param unifier - Wird für die Unifizierung benutzt
*/
void filterWrongConstraints(Unifier unifier) {
Set<UnifyUndConstraint> filteredConstraints = new Menge<>();
for(UnifyUndConstraint cons : this.getUndConstraints()){
Set<Set<MPair>> unifierResult = unifier.apply(cons.getConstraintPairs());
if(!unifierResult.isEmpty()){
filteredConstraints.add(cons);
}else{
logger.debug("Ausgesondertes Constraint: "+cons, Section.TYPEINFERENCE);
}
}
this.oderConstraintPairs = filteredConstraints;
}
UnifyUndConstraint filterUndConstraints() {
if(this.oderConstraintPairs.size()==1){
return this.oderConstraintPairs.iterator().next();
}
return null;
}
@Override
public Set<? extends KomplexeMenge<MPair>> getSet() {
return this.oderConstraintPairs;
}
}

View File

@ -0,0 +1,50 @@
package de.dhbwstuttgart.typeinference;
import java.util.Vector;
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.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
public class UnifySingleConstraint extends UnifyUndConstraint{
private MPair constraintPair; //entspricht θ condition θ'
@Override
public Menge<? extends KomplexeMenge<MPair>> getSet() {
Menge<EinzelElement<MPair>> ret = new Menge<>();
ret.add(new EinzelElement<>(constraintPair));
return ret;
}
public UnifySingleConstraint(MPair toAdd) {
this.addConstraint(toAdd);
}
public MPair getPair(){
return constraintPair;
}
@Override //Methode überschreiben, damit immer nur ein Vector mit nur einem Element zurückgeliefert wird.
public Menge<MPair> getConstraintPairs(){
Menge<MPair> ret = new Menge<>();
ret.add(constraintPair);
return ret;
}
public void addConstraint(MPair toAdd){
if(constraintPair != null)throw new DebugException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich.");
constraintPair = toAdd;
}
@Override
public String toString(){
return constraintPair.toString();
}
}

View File

@ -0,0 +1,45 @@
package de.dhbwstuttgart.typeinference;
import java.util.Collection;
import java.util.Set;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
/**
* Stellt ein Constraint dar, welches aus mehreren Constraint-Paaren besteht. Diese gelten alle stets gleichzeitig / sind per "Und" miteinander verknüpft.
* @author janulrich
*
*/
public class UnifyUndConstraint extends UndMenge<MPair> {
Menge<EinzelElement<MPair>> set = new Menge<>();
@Override
public Menge<? extends KomplexeMenge<MPair>> getSet() {
return set;
}
public Set<MPair> getConstraintPairs() {
Set<Set<MPair>> ret = this.cartesianProduct();
if(ret.size() != 1){
//UndConstraints enthalten nur SingleConstraints, wodurch das Karthesische Produkt nur aus einem Element bestehen kann.
throw new DebugException("Fehler in ConstraintPairs-Bildung");
}
return ret.iterator().next();
}
@Override
public String toString() {
String ret = this.getConstraintPairs().toString();
return ret;
}
public void add(MPair pair){
set.add(new EinzelElement<>(pair));
}
}

View File

@ -89,33 +89,6 @@ public class TypeAssumptions {
return null;
}
/**
* Ermittelt alle bekannten Methoden mit dem Namen withName
* @param withName
* @return
*/
@Deprecated
public Menge<MethodAssumption> getMethods2(String withName){
//TODO: Implementieren
return new Menge<MethodAssumption>();
}
/**
* Liefert den Typ einer lokalen Variable. Zuerst werden die Parameter dieses AssumptionSets durchsucht, dann die lokalen Variablen. Anschließend die Felder der, "this" repräsentierenden Klasse
* @param withName
* @return
*/
@Deprecated
public Type getTypeOfLocalVar2(String withName){
//TODO: Implementieren
return null;
}
/**
* Sucht nach Assumptions zu einer Methode mit dem Namen methodName und parameterCount Parametern.
* @param methodName

View File

@ -1,72 +0,0 @@
// ino.module.CSet.8698.package
package de.dhbwstuttgart.typeinference.unify;
// ino.end
// ino.module.CSet.8698.import
import java.util.Iterator;
// ino.end
// ino.class.CSet.27435.description type=javadoc
/**
*
* @author Jrg Buerle
* @version $date
*/
// ino.end
// ino.class.CSet.27435.declaration
public abstract class CSet<E> implements Iterable<E>
// ino.end
// ino.class.CSet.27435.body
{
// ino.method.addElement.27438.declaration
public abstract void addElement(E element);
// ino.end
// ino.method.removeElement.27441.declaration
public abstract void removeElement(E element);
// ino.end
// ino.method.unite.27444.declaration
public abstract void unite(CSet<E> anotherSet);
// ino.end
// ino.method.subtract.27447.declaration
public abstract void subtract(CSet<E> anotherSet);
// ino.end
// ino.method.shallowCopy.27450.declaration
public abstract CSet<E> shallowCopy();
// ino.end
// ino.method.deepCopy.27453.declaration
public abstract CSet<E> deepCopy();
// ino.end
// ino.method.contains.27456.declaration
public abstract boolean contains(E element);
// ino.end
// ino.method.getCardinality.27459.declaration
public abstract int getCardinality();
// ino.end
// ino.method.getIterator.27462.declaration
public abstract Iterator<E> getIterator();
// ino.end
// ino.method.equals.27465.declaration
public abstract boolean equals(Object obj);
// ino.end
// ino.method.toString.27468.definition
public String toString()
// ino.end
// ino.method.toString.27468.body
{
StringBuffer sb = new StringBuffer();
sb.append("Set {\n");
Iterator<E> it = this.getIterator();
while(it.hasNext()){
sb.append(it.next().toString());
sb.append(",\n");
}
if(this.getCardinality()>0){
sb.delete(sb.length()-2, sb.length()-1);
}
sb.append("}");
return sb.toString();
}
// ino.end
}
// ino.end

View File

@ -1,253 +0,0 @@
// ino.module.CSubstitution.8685.package
package de.dhbwstuttgart.typeinference.unify;
// ino.end
// ino.module.CSubstitution.8685.import
import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
// ino.end
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
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.Pair;
// ino.class.CSubstitution.27003.description type=javadoc
/**
* Implementierung einer Typsubstitution. Bildet eine zu ersetzende
* <code>TypePlaceholder</code> auf einen Substitutions-Typ ab. Instanzen dieser
* Klasse werden in der Regel aus
* <code>Pair</code>-Objekten erzeugt.
* @author ¯Â¿Â½rg ¯Â¿Â½uerle
* @version $Date: 2006/07/10 11:27:04 $
*/
// ino.end
// ino.class.CSubstitution.27003.declaration
public class CSubstitution
// ino.end
// ino.class.CSubstitution.27003.body
{
// ino.attribute.m_TypeVar.27006.declaration
private TypePlaceholder m_TypeVar = null;
// ino.end
// ino.attribute.m_Type.27009.declaration
protected Type m_Type = null;
// ino.end
// ino.attribute.inferencelog.27012.declaration
protected static Logger inferencelog = Logger.getLogger("inference");
// ino.end
// ino.method.CSubstitution.27015.definition
public CSubstitution()
// ino.end
// ino.method.CSubstitution.27015.body
{
this(null, null);
}
// ino.end
// ino.method.CSubstitution.27018.definition
public CSubstitution(TypePlaceholder typeVar, Type type)
// ino.end
// ino.method.CSubstitution.27018.body
{
m_TypeVar = typeVar;
m_Type = type;
}
// ino.end
// ino.method.CSubstitution.27021.definition
public CSubstitution(Pair unifier)
throws CTypeReconstructionException
// ino.end
// ino.method.CSubstitution.27021.body
{
if(!(unifier.TA1 instanceof TypePlaceholder)){
throw new CTypeReconstructionException("Unifier enth�lt keinen Typeplaceholder",unifier.TA1);
}
m_TypeVar = (TypePlaceholder)unifier.TA1;
m_Type = unifier.TA2;
}
// ino.end
// ino.method.getType.27024.defdescription type=javadoc
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
* @return Returns the Type.
*/
// ino.end
// ino.method.getType.27024.definition
public Type getType()
// ino.end
// ino.method.getType.27024.body
{
return m_Type;
}
// ino.end
// ino.method.setType.27027.defdescription type=javadoc
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
* @param type The Type to set.
*/
// ino.end
// ino.method.setType.27027.definition
public void setType(Type type)
// ino.end
// ino.method.setType.27027.body
{
m_Type = type;
}
// ino.end
// ino.method.getTypeVar.27030.defdescription type=javadoc
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
* @return Returns the TypeVar.
*/
// ino.end
// ino.method.getTypeVar.27030.definition
public Type getTypeVar()
// ino.end
// ino.method.getTypeVar.27030.body
{
return this.m_TypeVar;
}
// ino.end
// ino.method.setTypeVar.27033.defdescription type=javadoc
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
* @param typeVar The TypeVar to set.
*/
// ino.end
// ino.method.setTypeVar.27033.definition
public void setTypeVar(TypePlaceholder typeVar)
// ino.end
// ino.method.setTypeVar.27033.body
{
m_TypeVar = typeVar;
}
// ino.end
// ino.method.equals.27036.definition
public boolean equals(Object obj)
// ino.end
// ino.method.equals.27036.body
{
if(obj instanceof CSubstitution){
CSubstitution sub = (CSubstitution)obj;
boolean ret = true;
ret &= (m_TypeVar.equals(sub.m_TypeVar));
ret &= (m_Type.equals(sub.m_Type));
return ret;
}
else{
return false;
}
}
// ino.end
// ino.method.toString.27039.definition
public String toString()
// ino.end
// ino.method.toString.27039.body
{
//return m_TypeVar.getName() +" --> "+m_Type.getName();
return m_TypeVar.toString() +" --> "+m_Type.toString();
}
// ino.end
// ino.method.clone.27042.definition
public CSubstitution clone()
// ino.end
// ino.method.clone.27042.body
{
CSubstitution copy = new CSubstitution(m_TypeVar.clone(), m_Type.clone());
return copy;
}
// ino.end
// ino.method.applyUnifier.27048.defdescription type=javadoc
/**
* Wendet den Unifier auf die rechte Seite dieser Substitution an.
* <br/>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
* @param unifier
*/
// ino.end
// ino.method.applyUnifier.27048.definition
public void applyUnifier(CSubstitutionSet unifier)
// ino.end
// ino.method.applyUnifier.27048.body
{
Iterator pairIt = unifier.getIterator();
while(pairIt.hasNext()){
CSubstitution subst = (CSubstitution)pairIt.next();
//korrigiert PL 05-07-31 das erste duerfte doch richtig sein.
//subst.setType(this.applySubstitution(subst.getType(), subst));
this.setType(this.applySubstitution(this.getType(), subst));
}
}
// ino.end
// ino.method.applySubstitution.27051.defdescription type=javadoc
/**
* Wendet die �bergebene Substitution rekursiv auf den �bergebenen Typ an.
* <br/>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
* @param type Der zu untersuchende Typ
* @param unifierSub Die anzuwendende Substitution
* @return Den ermittelnden Typ
*/
// ino.end
// ino.method.applySubstitution.27051.definition
private Type applySubstitution(Type type, CSubstitution unifierSub)
// ino.end
// ino.method.applySubstitution.27051.body
{
if(type instanceof TypePlaceholder){
if(type.equals(unifierSub.getTypeVar())){
return unifierSub.getType();
}
}
else if(type instanceof GenericTypeVar){
if(type.equals(unifierSub.getTypeVar())){
return unifierSub.getType();
}
}
else if(type instanceof RefType){
Menge<Type> paras = ((RefType)type).get_ParaList();
if(paras != null){
for(int i=0; i<paras.size(); i++){
paras.setElementAt(this.applySubstitution((Type)paras.elementAt(i), unifierSub), i);
}
}
}
return type;
}
// ino.end
// ino.method.applyThisSubstitution.27054.definition
public Type applyThisSubstitution(Type type)
// ino.end
// ino.method.applyThisSubstitution.27054.body
{
return applySubstitution(type, this);
}
// ino.end
}
// ino.end

View File

@ -1,70 +0,0 @@
// ino.module.CSubstitutionGenVar.8686.package
package de.dhbwstuttgart.typeinference.unify;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
// ino.end
import de.dhbwstuttgart.syntaxtree.type.Type;
// ino.class.CSubstitutionGenVar.27057.description type=javadoc
/**
* Implementierung einer Typsubstitution der GenVar. Bildet eine zu ersetzende
* <code>TypePlaceholder</code> auf einen Substitutions-Typ ab. Instanzen dieser
* Klasse werden in der Regel aus
* <code>Pair</code>-Objekten erzeugt.
* @author Martin Pl�micke
* @version $Date: 2006/06/13 10:37:32 $
*/
// ino.end
// ino.class.CSubstitutionGenVar.27057.declaration
public class CSubstitutionGenVar extends CSubstitution
// ino.end
// ino.class.CSubstitutionGenVar.27057.body
{
// ino.attribute.m_TypeVar.27061.declaration
private GenericTypeVar m_TypeVar = null;
// ino.end
// ino.method.CSubstitutionGenVar.27064.definition
public CSubstitutionGenVar()
// ino.end
// ino.method.CSubstitutionGenVar.27064.body
{
this(null, null);
}
// ino.end
// ino.method.CSubstitutionGenVar.27067.definition
public CSubstitutionGenVar(GenericTypeVar typeVar, Type type)
// ino.end
// ino.method.CSubstitutionGenVar.27067.body
{
m_TypeVar = typeVar;
m_Type = type;
}
// ino.end
// ino.method.getTypeVar.27070.defdescription type=javadoc
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
* @return Returns the TypeVar.
*/
// ino.end
// ino.method.getTypeVar.27070.definition
public Type getTypeVar()
// ino.end
// ino.method.getTypeVar.27070.body
{
return this.m_TypeVar;
}
// ino.end
// ino.method.toString.27073.definition
public String toString()
// ino.end
// ino.method.toString.27073.body
{
return this.m_TypeVar.getName() +" --> "+this.m_Type.getName();
}
// ino.end
}
// ino.end

View File

@ -1,111 +0,0 @@
// ino.module.CSubstitutionSet.8699.package
package de.dhbwstuttgart.typeinference.unify;
// ino.end
// ino.module.CSubstitutionSet.8699.import
import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.Pair;
// ino.class.CSubstitutionSet.27471.description type=javadoc
/**
* @author ¯Â¿Â½rg ¯Â¿Â½uerle
* @version $Date: 2013/03/27 18:29:34 $
*/
// ino.end
// ino.class.CSubstitutionSet.27471.declaration
public class CSubstitutionSet extends CVectorSet<CSubstitution>
// ino.end
// ino.class.CSubstitutionSet.27471.body
{
// ino.method.CSubstitutionSet.27475.definition
public CSubstitutionSet()
// ino.end
// ino.method.CSubstitutionSet.27475.body
{
super();
}
// ino.end
// ino.method.CSubstitutionSet.27478.definition
public CSubstitutionSet(Menge<Pair> unifiers)
throws CTypeReconstructionException
// ino.end
// ino.method.CSubstitutionSet.27478.body
{
super();
for(int i=0; i<unifiers.size(); i++){
this.addElement(new CSubstitution(unifiers.elementAt(i)));
}
}
// ino.end
// ino.method.shallowCopy.27481.definition
public CSubstitutionSet shallowCopy()
// ino.end
// ino.method.shallowCopy.27481.body
{
CSubstitutionSet copy = new CSubstitutionSet();
copy.setMenge((Menge)this.getMenge().clone());
return copy;
}
// ino.end
// ino.method.deepCopy.27484.definition
public CSubstitutionSet deepCopy()
// ino.end
// ino.method.deepCopy.27484.body
{
CSubstitutionSet copy = new CSubstitutionSet();
Iterator<CSubstitution> substIter = this.getIterator();
while(substIter.hasNext()){
copy.addElement(substIter.next().clone());
}
return copy;
}
// ino.end
// ino.method.applyUnifier.27487.defdescription type=javadoc
/**
* Wendet den Unifier auf die rechten Seiten alle Substitutionen an.
* <br/>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
* @param unifier
*/
// ino.end
// ino.method.applyUnifier.27487.definition
public void applyUnifier(CSubstitutionSet unifier)
// ino.end
// ino.method.applyUnifier.27487.body
{
Iterator<CSubstitution> substIt = this.getIterator();
while(substIt.hasNext()){
substIt.next().applyUnifier(unifier);
}
}
// ino.end
// ino.method.applyThisSubstitutionSet.27490.definition
public Type applyThisSubstitutionSet(Type type)
// ino.end
// ino.method.applyThisSubstitutionSet.27490.body
{
Iterator<CSubstitution> substIt = this.getIterator();
Type ty = type;
while(substIt.hasNext()) {
ty = substIt.next().applyThisSubstitution(ty);
}
return ty;
}
// ino.end
public Iterator<CSubstitution> iterator() {
return this.getIterator();
}
}
// ino.end

View File

@ -1,165 +0,0 @@
// ino.module.CMengeSet.8702.package
package de.dhbwstuttgart.typeinference.unify;
// ino.end
// ino.module.CMengeSet.8702.import
import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge;
// ino.end
// ino.class.CMengeSet.27519.description type=javadoc
/**
* @author ¯Â¿Â½rg ¯Â¿Â½uerle
* @version $Date: 2013/02/07 05:08:51 $
*/
// ino.end
// ino.class.CMengeSet.27519.declaration
public abstract class CVectorSet<E> extends CSet<E>
// ino.end
// ino.class.CMengeSet.27519.body
{
// ino.attribute.m_Elements.27523.declaration
private Menge<E> m_Elements = null;
// ino.end
// ino.method.CMengeSet.27526.definition
public CVectorSet()
// ino.end
// ino.method.CMengeSet.27526.body
{
m_Elements = new Menge<E>();
}
// ino.end
// ino.method.addElement.27529.definition
public void addElement(E element)
// ino.end
// ino.method.addElement.27529.body
{
m_Elements.addElement(element);
}
// ino.end
// ino.method.removeElement.27532.definition
public void removeElement(E element)
// ino.end
// ino.method.removeElement.27532.body
{
m_Elements.addElement(element);
}
// ino.end
public void addAll( CVectorSet<E> set )
{
for( int i=0;i<set.getCardinality(); i++ ){
m_Elements.addElement(set.m_Elements.elementAt(i));
}
}
// ino.method.getIterator.27535.definition
public Iterator<E> getIterator()
// ino.end
// ino.method.getIterator.27535.body
{
return m_Elements.iterator();
}
// ino.end
// ino.method.getMenge.27538.definition
public Menge<E> getMenge()
// ino.end
// ino.method.getMenge.27538.body
{
return m_Elements;
}
// ino.end
// ino.method.setMenge.27541.definition
public void setMenge(Menge<E> elements)
// ino.end
// ino.method.setMenge.27541.body
{
m_Elements = elements;
}
// ino.end
/**
* ¼gt ein CMengeSet an!
* Es handelt sich um eine Vereinigung (es werden keine bereits vorhandenen Elemente übernommen)
* @param anotherSet Das hinzuzufügende CMengeSet (CSet wird ignoriert)
*/
// ino.method.unite.27544.definition
public void unite(CSet<E> anotherSet)
// ino.end
// ino.method.unite.27544.body
{
if(!(anotherSet instanceof CVectorSet)){
return;
}
CVectorSet<E> MengeSet = (CVectorSet<E>)anotherSet;
// Elemente der anderen Menge hinzuf�gen:
Iterator<E> it = MengeSet.getIterator();
while(it.hasNext()){
E elem = it.next();
if(!m_Elements.contains(elem)){
m_Elements.addElement(elem);
}
}
//m_Elements.addAll(MengeSet.m_Elements);
}
// ino.end
// ino.method.subtract.27547.definition
public void subtract(CSet<E> anotherSet)
// ino.end
// ino.method.subtract.27547.body
{
if(!(anotherSet instanceof CVectorSet)){
return;
}
CVectorSet<E> MengeSet = (CVectorSet<E>)anotherSet;
// Elemente der anderen Menge entfernen:
m_Elements.removeAll(MengeSet.m_Elements);
}
// ino.end
// ino.method.contains.27550.definition
public boolean contains(E element)
// ino.end
// ino.method.contains.27550.body
{
return m_Elements.contains(element);
}
// ino.end
// ino.method.equals.27553.definition
public boolean equals(Object obj)
// ino.end
// ino.method.equals.27553.body
{
if(obj instanceof CVectorSet){
CVectorSet tripSet= (CVectorSet)obj;
boolean ret = true;
ret &= (m_Elements.containsAll(tripSet.m_Elements));
ret &= (tripSet.m_Elements.containsAll(m_Elements));
return ret;
}
else{
return false;
}
}
// ino.end
// ino.method.getCardinality.27556.definition
public int getCardinality()
// ino.end
// ino.method.getCardinality.27556.body
{
return m_Elements.size();
}
// ino.end
}
// ino.end

View File

@ -1,82 +0,0 @@
// ino.module.FC_TTO.8719.package
package de.dhbwstuttgart.typeinference.unify;
// ino.end
// ino.module.FC_TTO.8719.import
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
// ino.class.FC_TTO.28013.description type=javadoc
/**
* Hilfsklasse ¯Â¿Â½r den Unifizierungsalgorithmus
* @author Martin Pl�micke
* @version $Date: 2013/05/12 14:00:05 $
*/
// ino.end
// ino.class.FC_TTO.28013.declaration
public class FC_TTO
// ino.end
// ino.class.FC_TTO.28013.body
{
// ino.attribute.FC.28016.declaration
Menge<Pair> FC;
// ino.end
// ino.attribute.TTO.28019.declaration
Menge TTO;
// ino.end
Menge<Class> CLASSVEC;
// ino.method.FC_TTO.28022.definition
public FC_TTO(Menge<Pair> fc, Menge tto, Menge<Class> classv)
// ino.end
// ino.method.FC_TTO.28022.body
{
this.FC = fc;
this.TTO = tto;
this.CLASSVEC = classv;
}
// ino.end
// ino.method.getFC.28025.definition
public Menge<Pair> getFC()
// ino.end
// ino.method.getFC.28025.body
{
return FC;
}
// ino.end
// ino.method.getTTO.28028.definition
public Menge getTTO()
// ino.end
// ino.method.getTTO.28028.body
{
return TTO;
}
// ino.end
public Menge<Class> getClasses()
{
return CLASSVEC;
}
@Override
public String toString(){
return "FC: "+getFC()+"\nTTO: "+getTTO()+"\nCLASSVEC: "+getClasses();
}
public void generateFullyNamedTypes(TypeAssumptions ass) {
for(Pair p : this.FC){
p.TA1 = p.TA1.TYPE(ass, p.TA1.getParent());//ass.getTypeFor(p.TA1, p.TA1.getParent()).getType();
p.TA2 = p.TA2.TYPE(ass, p.TA2.getParent());//ass.getTypeFor(p.TA2, p.TA2.getParent()).getType();
}
}
}
// ino.end

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.typeinference.unifynew;
package de.dhbwstuttgart.typeinference.unify;
import java.util.List;
import java.util.Set;

View File

@ -1,53 +0,0 @@
// ino.module.MUB.8720.package
package de.dhbwstuttgart.typeinference.unify;
// ino.end
// ino.module.MUB.8720.import
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.Pair;
// ino.class.MUB.28031.declaration
public class MUB
// ino.end
// ino.class.MUB.28031.body
{
// ino.attribute.Mub.28034.declaration
Menge<? extends Type> Mub;
// ino.end
// ino.attribute.sigma.28037.declaration
Menge<Pair> sigma;
// ino.end
// ino.method.MUB.28040.definition
MUB(Menge<? extends Type> M, Menge<Pair> s)
// ino.end
// ino.method.MUB.28040.body
{
Mub = M;
sigma = s;
}
// ino.end
// ino.method.getUnifier.28043.definition
public Menge<Pair> getUnifier()
// ino.end
// ino.method.getUnifier.28043.body
{
return sigma;
}
// ino.end
// ino.method.getMub.28046.definition
public Menge<? extends Type> getMub()
// ino.end
// ino.method.getMub.28046.body
{
return Mub;
}
// ino.end
}
// ino.end

View File

@ -0,0 +1,72 @@
package de.dhbwstuttgart.typeinference.unify;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
public class Mapping {
private HashMap<de.dhbwstuttgart.typeinference.unify.model.UnifyType, de.dhbwstuttgart.syntaxtree.type.Type> backwardMap = new HashMap<>();
private HashMap<de.dhbwstuttgart.syntaxtree.type.Type, de.dhbwstuttgart.typeinference.unify.model.UnifyType> forwardMap = new HashMap<>();
private Set<de.dhbwstuttgart.typeinference.unify.model.UnifyType> irreversible = new HashSet<>();
public Mapping(Set<de.dhbwstuttgart.syntaxtree.type.Type> types) {
for(de.dhbwstuttgart.syntaxtree.type.Type t : types) {
}
}
public de.dhbwstuttgart.typeinference.unify.model.UnifyType map(de.dhbwstuttgart.syntaxtree.type.Type type) {
return forwardMap.get(type);
}
public de.dhbwstuttgart.typeinference.unify.model.MPair map(de.dhbwstuttgart.typeinference.Pair pair) {
return new de.dhbwstuttgart.typeinference.unify.model.MPair(forwardMap.get(pair.TA1), forwardMap.get(pair.TA2), mapOp(pair.GetOperator()));
}
public Set<de.dhbwstuttgart.typeinference.unify.model.UnifyType> mapTypeSet(Set<de.dhbwstuttgart.syntaxtree.type.Type> types) {
return types.stream().map(this::map).collect(Collectors.toCollection(HashSet::new));
}
public Set<de.dhbwstuttgart.typeinference.unify.model.MPair> mapPairSet(Set<de.dhbwstuttgart.typeinference.Pair> pairs) {
return pairs.stream().map(this::map).collect(Collectors.toCollection(HashSet::new));
}
public Optional<de.dhbwstuttgart.syntaxtree.type.Type> unmap(de.dhbwstuttgart.typeinference.unify.model.UnifyType type) {
return irreversible.contains(type) ? Optional.of(backwardMap.get(type)) : Optional.empty();
}
public Optional<Pair> unmap(de.dhbwstuttgart.typeinference.unify.model.MPair mpair) {
de.dhbwstuttgart.typeinference.unify.model.UnifyType lhs = mpair.getLhsType();
de.dhbwstuttgart.typeinference.unify.model.UnifyType rhs = mpair.getRhsType();
if(irreversible.contains(lhs) || irreversible.contains(rhs))
return Optional.empty();
return Optional.of(new Pair(backwardMap.get(lhs), backwardMap.get(rhs), unmapOp(mpair.getPairOp())));
}
public Optional<Set<de.dhbwstuttgart.syntaxtree.type.Type>> unmapTypeSet(Set<de.dhbwstuttgart.typeinference.unify.model.UnifyType> types) {
Set<de.dhbwstuttgart.syntaxtree.type.Type> result = types.stream().map(this::unmap).filter(x -> x.isPresent()).map(x -> x.get()).collect(Collectors.toCollection(HashSet::new));
return result.size() == types.size() ? Optional.of(result) : Optional.empty();
}
public Optional<Set<de.dhbwstuttgart.typeinference.Pair>> unmapPairSet(Set<de.dhbwstuttgart.typeinference.unify.model.MPair> pairs) {
Set<de.dhbwstuttgart.typeinference.Pair> result = pairs.stream().map(this::unmap).filter(x -> x.isPresent()).map(x -> x.get()).collect(Collectors.toCollection(HashSet::new));
return result.size() == pairs.size() ? Optional.of(result) : Optional.empty();
}
private PairOperator mapOp(PairOperator op) {
//TODO: Methode kann entfernt werden:
return op;
}
private PairOperator unmapOp(PairOperator op) {
//TODO: Methode kann entfernt werden:
return op;
}
}

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.typeinference.unifynew;
package de.dhbwstuttgart.typeinference.unify;
import java.util.AbstractMap;
import java.util.ArrayList;
@ -11,9 +11,9 @@ import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.MPair.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.Type;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
@ -24,15 +24,15 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier;
public class MartelliMontanariUnify implements IUnify {
@Override
public Optional<Unifier> unify(Set<Type> terms) {
public Optional<Unifier> unify(Set<UnifyType> terms) {
if(terms.size() < 2)
return Optional.of(Unifier.Identity());
ArrayList<MPair> termsQ = new ArrayList<MPair>();
Iterator<Type> iter = terms.iterator();
Type prev = iter.next();
Iterator<UnifyType> iter = terms.iterator();
UnifyType prev = iter.next();
while(iter.hasNext()) {
Type next = iter.next();
UnifyType next = iter.next();
termsQ.add(new MPair(prev, next, PairOperator.EQUALSDOT));
prev = next;
}
@ -72,10 +72,10 @@ public class MartelliMontanariUnify implements IUnify {
&& pair.getRhsType().getTypeParams().occurs((PlaceholderType) pair.getLhsType()))
return Optional.empty();
Optional<Entry<PlaceholderType, Type>> optUni = eliminate(pair);
Optional<Entry<PlaceholderType, UnifyType>> optUni = eliminate(pair);
if(optUni.isPresent()) {
Entry<PlaceholderType, Type> substitution = optUni.get();
Entry<PlaceholderType, UnifyType> substitution = optUni.get();
mgu.Add(substitution.getKey(), substitution.getValue());
termsQ = termsQ.stream().map(mgu::apply).collect(Collectors.toCollection(ArrayList::new));
idx = idx+1 == termsQ.size() ? 0 : idx+1;
@ -95,8 +95,8 @@ public class MartelliMontanariUnify implements IUnify {
private Optional<Set<MPair>> decompose(MPair pair) {
Set<MPair> result = new HashSet<>();
Type rhs = pair.getRhsType();
Type lhs = pair.getLhsType();
UnifyType rhs = pair.getRhsType();
UnifyType lhs = pair.getLhsType();
TypeParams rhsTypeParams = rhs.getTypeParams();
TypeParams lhsTypeParams = lhs.getTypeParams();
@ -118,8 +118,8 @@ public class MartelliMontanariUnify implements IUnify {
}
private Optional<MPair> swap(MPair pair) {
Type rhs = pair.getRhsType();
Type lhs = pair.getLhsType();
UnifyType rhs = pair.getRhsType();
UnifyType lhs = pair.getLhsType();
if(!(lhs instanceof PlaceholderType) && (rhs instanceof PlaceholderType))
return Optional.of(new MPair(rhs, lhs, PairOperator.EQUALSDOT));
@ -127,15 +127,15 @@ public class MartelliMontanariUnify implements IUnify {
return Optional.empty();
}
private Optional<Entry<PlaceholderType, Type>> eliminate(MPair pair) {
Type rhs = pair.getRhsType();
Type lhs = pair.getLhsType();
private Optional<Entry<PlaceholderType, UnifyType>> eliminate(MPair pair) {
UnifyType rhs = pair.getRhsType();
UnifyType lhs = pair.getLhsType();
// TODO only apply when lhs is element of vars(termsQ)?
if(!(lhs instanceof PlaceholderType))
return Optional.empty();
return Optional.of(new AbstractMap.SimpleImmutableEntry<PlaceholderType, Type>((PlaceholderType) lhs, rhs));
return Optional.of(new AbstractMap.SimpleImmutableEntry<PlaceholderType, UnifyType>((PlaceholderType) lhs, rhs));
}
}

View File

@ -1,44 +0,0 @@
package de.dhbwstuttgart.typeinference.unify;
import de.dhbwstuttgart.typeinference.Menge;
import java.util.stream.Stream;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.Pair;
public class ParallelUnify {
public ParallelUnify(ConstraintsSet constraints){
//constraints.getConstraints();
}
private CartesianProduct parallelCartProd(){
return null;
}
private UnifyResult parallelUnify(Menge<Pair> pairs, FC_TTO fc){
UnifyResult ret = new UnifyResult();
return ret;
}
public UnifyResult unify(){
UnifyResult ret = new UnifyResult();
return ret;
}
}
class ParallelConstraintSet extends ConstraintsSet{
Stream parallelGetConstraints(){
return null;
}
}
class UnifyResult{
}
class CartesianProduct{
}

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.typeinference.unifynew;
package de.dhbwstuttgart.typeinference.unify;
import java.util.ArrayList;
import java.util.HashMap;
@ -11,7 +11,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import junit.framework.Assert;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
@ -20,10 +19,10 @@ import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.SimpleType;
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
import de.dhbwstuttgart.typeinference.unify.model.Type;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.MPair.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
public class RuleSet implements IRuleSet{
@ -38,11 +37,11 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
Type rhsType = pair.getRhsType();
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof SuperType))
return Optional.empty();
Type lhsType = pair.getLhsType();
UnifyType lhsType = pair.getLhsType();
if(!(lhsType instanceof SimpleType) && !(lhsType instanceof PlaceholderType))
return Optional.empty();
@ -54,11 +53,11 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
Type lhsType = pair.getLhsType();
UnifyType lhsType = pair.getLhsType();
if(!(lhsType instanceof ExtendsType))
return Optional.empty();
Type rhsType = pair.getRhsType();
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof SimpleType) && !(rhsType instanceof PlaceholderType))
return Optional.empty();
@ -70,11 +69,11 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
Type lhsType = pair.getLhsType();
UnifyType lhsType = pair.getLhsType();
if(!(lhsType instanceof ExtendsType))
return Optional.empty();
Type rhsType = pair.getRhsType();
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof SuperType))
return Optional.empty();
@ -86,8 +85,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type x = pair.getLhsType();
Type sTypeX;
UnifyType x = pair.getLhsType();
UnifyType sTypeX;
if(x instanceof SimpleType)
sTypeX = x;
@ -96,7 +95,7 @@ public class RuleSet implements IRuleSet{
else
return Optional.empty();
Type extY = pair.getRhsType();
UnifyType extY = pair.getRhsType();
if(!(extY instanceof ExtendsType))
return Optional.empty();
@ -104,7 +103,7 @@ public class RuleSet implements IRuleSet{
if(x.getTypeParams().empty() || extY.getTypeParams().size() != x.getTypeParams().size())
return Optional.empty();
Type xFromFc = finiteClosure.getLeftHandedType(sTypeX).orElse(null);
UnifyType xFromFc = finiteClosure.getLeftHandedType(sTypeX).orElse(null);
if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders())
return Optional.empty();
@ -112,7 +111,7 @@ public class RuleSet implements IRuleSet{
if(x instanceof ExtendsType)
xFromFc = new ExtendsType(xFromFc);
Type extYFromFc = finiteClosure.grArg(xFromFc).stream().filter(t -> t.getName().equals(extY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
UnifyType extYFromFc = finiteClosure.grArg(xFromFc).stream().filter(t -> t.getName().equals(extY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
if(extYFromFc == null || extYFromFc.getTypeParams() != xFromFc.getTypeParams())
return Optional.empty();
@ -138,8 +137,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type x = pair.getLhsType();
Type sTypeX;
UnifyType x = pair.getLhsType();
UnifyType sTypeX;
if(x instanceof SimpleType)
sTypeX = x;
@ -148,7 +147,7 @@ public class RuleSet implements IRuleSet{
else
return Optional.empty();
Type supY = pair.getRhsType();
UnifyType supY = pair.getRhsType();
if(!(supY instanceof SuperType))
return Optional.empty();
@ -156,7 +155,7 @@ public class RuleSet implements IRuleSet{
if(x.getTypeParams().empty() || supY.getTypeParams().size() != x.getTypeParams().size())
return Optional.empty();
Type xFromFc = finiteClosure.getLeftHandedType(sTypeX).orElse(null);
UnifyType xFromFc = finiteClosure.getLeftHandedType(sTypeX).orElse(null);
if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders())
return Optional.empty();
@ -164,7 +163,7 @@ public class RuleSet implements IRuleSet{
if(x instanceof SuperType)
xFromFc = new SuperType(xFromFc);
Type supYFromFc = finiteClosure.grArg(xFromFc).stream().filter(t -> t.getName().equals(supY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
UnifyType supYFromFc = finiteClosure.grArg(xFromFc).stream().filter(t -> t.getName().equals(supY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
if(supYFromFc == null || supYFromFc.getTypeParams() != xFromFc.getTypeParams())
return Optional.empty();
@ -189,11 +188,11 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type lhsType = pair.getLhsType();
UnifyType lhsType = pair.getLhsType();
if(lhsType instanceof PlaceholderType || lhsType.getTypeParams().empty())
return Optional.empty();
Type rhsType = pair.getRhsType();
UnifyType rhsType = pair.getRhsType();
if(!rhsType.getName().equals(lhsType.getName()))
return Optional.empty();
@ -220,11 +219,11 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
Type c = pair.getLhsType();
UnifyType c = pair.getLhsType();
if(!(c instanceof SimpleType))
return Optional.empty();
Type d = pair.getRhsType();
UnifyType d = pair.getRhsType();
if(!(d instanceof SimpleType))
return Optional.empty();
@ -234,12 +233,12 @@ public class RuleSet implements IRuleSet{
if(lhsSType.getTypeParams().empty() || lhsSType.getTypeParams().size() != rhsSType.getTypeParams().size())
return Optional.empty();
Type cFromFc = finiteClosure.getLeftHandedType(c).orElse(null);
UnifyType cFromFc = finiteClosure.getLeftHandedType(c).orElse(null);
if(cFromFc == null || !cFromFc.getTypeParams().arePlaceholders())
return Optional.empty();
Type dFromFc = finiteClosure.getAncestors(cFromFc).stream().filter(x -> x.getName().equals(d.getName())).findAny().orElse(null);
UnifyType dFromFc = finiteClosure.getAncestors(cFromFc).stream().filter(x -> x.getName().equals(d.getName())).findAny().orElse(null);
if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size())
return Optional.empty();
@ -264,7 +263,7 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.EQUALSDOT)
return Optional.empty();
Type lhsType = pair.getLhsType();
UnifyType lhsType = pair.getLhsType();
SimpleType lhsSType;
if(lhsType instanceof SimpleType)
@ -279,7 +278,7 @@ public class RuleSet implements IRuleSet{
if(lhsSType.getTypeParams().empty())
return Optional.empty();
Type rhsType = pair.getLhsType();
UnifyType rhsType = pair.getLhsType();
SimpleType rhsSType;
if(rhsType instanceof SimpleType)
@ -313,11 +312,11 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return false;
Type lhsType = pair.getLhsType();
UnifyType lhsType = pair.getLhsType();
if(!(lhsType instanceof SimpleType) && !(lhsType instanceof PlaceholderType))
return false;
Type rhsType = pair.getRhsType();
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof SimpleType) && !(rhsType instanceof PlaceholderType))
return false;
@ -329,8 +328,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return false;
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
return finiteClosure.grArg(lhsType).contains(rhsType);
}
@ -362,11 +361,11 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
Type typeD = pair.getLhsType();
UnifyType typeD = pair.getLhsType();
if(!(typeD instanceof SimpleType))
return Optional.empty();
Type typeDs = pair.getRhsType();
UnifyType typeDs = pair.getRhsType();
if(!(typeDs instanceof SimpleType))
return Optional.empty();
@ -376,22 +375,22 @@ public class RuleSet implements IRuleSet{
if(typeD.getName().equals(typeDs.getName()))
return Optional.empty();
Optional<Type> opt = finiteClosure.getLeftHandedType(typeD);
Optional<UnifyType> opt = finiteClosure.getLeftHandedType(typeD);
if(!opt.isPresent())
return Optional.empty();
// The generic Version of Type D (D<a1, a2, a3, ... >)
Type typeDgen = opt.get();
UnifyType typeDgen = opt.get();
// Actually greater+ because the types are ensured to have different names
Set<Type> greater = finiteClosure.getAncestors(typeDgen);
Set<UnifyType> greater = finiteClosure.getAncestors(typeDgen);
opt = greater.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
if(!opt.isPresent())
return Optional.empty();
Type newLhs = opt.get();
UnifyType newLhs = opt.get();
TypeParams typeDParams = typeD.getTypeParams();
TypeParams typeDgenParams = typeDgen.getTypeParams();
@ -408,36 +407,36 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type typeD = pair.getLhsType();
UnifyType typeD = pair.getLhsType();
if(!(typeD instanceof SimpleType) && !(typeD instanceof ExtendsType))
return Optional.empty();
Type typeExtDs = pair.getRhsType();
UnifyType typeExtDs = pair.getRhsType();
if(!(typeExtDs instanceof ExtendsType))
return Optional.empty();
if(typeD.getTypeParams().size() == 0 || typeExtDs.getTypeParams().size() == 0)
return Optional.empty();
Type typeDgen;
UnifyType typeDgen;
if(typeD instanceof SimpleType)
typeDgen = finiteClosure.getLeftHandedType(typeD).orElse(null);
else {
Optional<Type> opt = finiteClosure.getLeftHandedType(((ExtendsType) typeD).getExtendedType());
Optional<UnifyType> opt = finiteClosure.getLeftHandedType(((ExtendsType) typeD).getExtendedType());
typeDgen = opt.isPresent() ? new ExtendsType(opt.get()) : null;
}
if(typeDgen == null)
return Optional.empty();
Set<Type> grArg = finiteClosure.grArg(typeDgen);
Set<UnifyType> grArg = finiteClosure.grArg(typeDgen);
Optional<Type> opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny();
Optional<UnifyType> opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny();
if(!opt.isPresent())
return Optional.empty();
Type newLhs = ((ExtendsType) opt.get()).getExtendedType();
UnifyType newLhs = ((ExtendsType) opt.get()).getExtendedType();
TypeParams typeDParams = typeD.getTypeParams();
TypeParams typeDgenParams = typeDgen.getTypeParams();
@ -454,11 +453,11 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type typeDs = pair.getLhsType();
UnifyType typeDs = pair.getLhsType();
if(!(typeDs instanceof SimpleType) && !(typeDs instanceof SuperType))
return Optional.empty();
Type typeSupD = pair.getRhsType();
UnifyType typeSupD = pair.getRhsType();
if(!(typeSupD instanceof SuperType))
return Optional.empty();
@ -466,31 +465,31 @@ public class RuleSet implements IRuleSet{
return Optional.empty();
Optional<Type> opt = finiteClosure.getLeftHandedType(((SuperType) typeSupD).getSuperedType());
Optional<UnifyType> opt = finiteClosure.getLeftHandedType(((SuperType) typeSupD).getSuperedType());
if(!opt.isPresent())
return Optional.empty();
Type typeDgen = opt.get();
Type typeSupDgen = new SuperType(typeDgen);
UnifyType typeDgen = opt.get();
UnifyType typeSupDgen = new SuperType(typeDgen);
// Use of smArg instead of grArg because
// a in grArg(b) => b in smArg(a)
Set<Type> smArg = finiteClosure.smArg(typeSupDgen);
Set<UnifyType> smArg = finiteClosure.smArg(typeSupDgen);
opt = smArg.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
if(!opt.isPresent())
return Optional.empty();
// New RHS
Type newRhs = null;
UnifyType newRhs = null;
if(typeDs instanceof SimpleType)
newRhs = new ExtendsType(typeDs);
else
newRhs = new ExtendsType(((SuperType) typeDs).getSuperedType());
// New LHS
Type newLhs = opt.get();
UnifyType newLhs = opt.get();
TypeParams typeDParams = typeSupD.getTypeParams();
TypeParams typeSupDsgenParams = typeSupDgen.getTypeParams();
@ -514,7 +513,7 @@ public class RuleSet implements IRuleSet{
boolean succ = true;
for (int dArgIdx = 0; dArgIdx < dArgs.size() && succ; dArgIdx++) {
Type dArg = dArgs.get(dArgIdx);
UnifyType dArg = dArgs.get(dArgIdx);
succ = false;
for (int pi = 0; pi < cArgs.size(); pi++)
if (cArgs.get(pi).getName().equals(dArg.getName())) {
@ -529,11 +528,11 @@ public class RuleSet implements IRuleSet{
@Override
public Optional<Set<MPair>> subst(Set<MPair> pairs) {
HashMap<Type, Integer> typeMap = new HashMap<>();
HashMap<UnifyType, Integer> typeMap = new HashMap<>();
for(MPair pair : pairs) {
Type t1 = pair.getLhsType();
Type t2 = pair.getRhsType();
UnifyType t1 = pair.getLhsType();
UnifyType t2 = pair.getRhsType();
if(!typeMap.containsKey(t1))
typeMap.put(t1, 0);
if(!typeMap.containsKey(t2))
@ -549,7 +548,7 @@ public class RuleSet implements IRuleSet{
while(!result1.isEmpty()) {
MPair pair = result1.poll();
PlaceholderType lhsType = null;
Type rhsType;
UnifyType rhsType;
if(pair.getPairOp() == PairOperator.EQUALSDOT
&& pair.getLhsType() instanceof PlaceholderType)
@ -575,8 +574,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof ExtendsType))
return Optional.empty();
@ -588,8 +587,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof SimpleType) || !(rhsType instanceof ExtendsType))
return Optional.empty();
@ -601,8 +600,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof SuperType) || !(rhsType instanceof SuperType))
return Optional.empty();
@ -614,8 +613,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof SimpleType) || !(rhsType instanceof SuperType))
return Optional.empty();
@ -627,8 +626,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof SuperType))
return Optional.empty();
@ -640,8 +639,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof SuperType) || !(rhsType instanceof ExtendsType))
return Optional.empty();
@ -653,11 +652,11 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type rhsType = pair.getRhsType();
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof SimpleType))
return Optional.empty();
Type lhsType = pair.getLhsType();
UnifyType lhsType = pair.getLhsType();
if(lhsType instanceof SuperType)
return Optional.of(new MPair(((SuperType) lhsType).getSuperedType(), rhsType, PairOperator.EQUALSDOT));
@ -673,8 +672,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof FunNType) || !(rhsType instanceof FunNType))
return Optional.empty();
@ -699,8 +698,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof FunNType) || !(rhsType instanceof PlaceholderType))
return Optional.empty();
@ -709,7 +708,7 @@ public class RuleSet implements IRuleSet{
Set<MPair> result = new HashSet<MPair>();
Type[] freshPlaceholders = new Type[funNLhsType.getTypeParams().size()];
UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()];
for(int i = 0; i < freshPlaceholders.length; i++)
freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
@ -726,8 +725,8 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
Type lhsType = pair.getLhsType();
Type rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType))
return Optional.empty();
@ -736,7 +735,7 @@ public class RuleSet implements IRuleSet{
Set<MPair> result = new HashSet<MPair>();
Type[] freshPlaceholders = new Type[funNRhsType.getTypeParams().size()];
UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()];
for(int i = 0; i < freshPlaceholders.length; i++)
freshPlaceholders[i] = PlaceholderType.freshPlaceholder();

View File

@ -1,11 +1,11 @@
package de.dhbwstuttgart.typeinference.unify;
import de.dhbwstuttgart.typeinference.Menge;
import java.util.Set;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
public interface Unifier {
public Menge<Menge<Pair>> apply (Menge<Pair> E);
public Set<Set<MPair>> apply (Set<MPair> E);
}

3891
src/de/dhbwstuttgart/typeinference/unify/Unify.java Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ import de.dhbwstuttgart.typeinference.unify.model.FunNType;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.SimpleType;
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
import de.dhbwstuttgart.typeinference.unify.model.Type;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
public interface IFiniteClosure {
@ -16,45 +16,45 @@ public interface IFiniteClosure {
* Returns all types of the finite closure that are subtypes of the argument.
* @return The set of subtypes of the argument.
*/
public Set<Type> smaller(Type type);
public Set<UnifyType> smaller(UnifyType type);
/**
* Returns all types of the finite closure that are supertypes of the argument.
* @return The set of supertypes of the argument.
*/
public Set<Type> greater(Type type);
public Set<UnifyType> greater(UnifyType type);
/**
* Wo passt Type rein?
* @param type
* @return
*/
public Set<Type> grArg(Type type);
public Set<UnifyType> grArg(UnifyType type);
/**
* Was passt in Type rein?
* @param type
* @return
*/
public Set<Type> smArg(Type type);
public Set<UnifyType> smArg(UnifyType type);
public Set<Type> grArg(SimpleType type);
public Set<Type> smArg(SimpleType type);
public Set<UnifyType> grArg(SimpleType type);
public Set<UnifyType> smArg(SimpleType type);
public Set<Type> grArg(ExtendsType type);
public Set<Type> smArg(ExtendsType type);
public Set<UnifyType> grArg(ExtendsType type);
public Set<UnifyType> smArg(ExtendsType type);
public Set<Type> grArg(SuperType type);
public Set<Type> smArg(SuperType type);
public Set<UnifyType> grArg(SuperType type);
public Set<UnifyType> smArg(SuperType type);
public Set<Type> grArg(PlaceholderType type);
public Set<Type> smArg(PlaceholderType type);
public Set<UnifyType> grArg(PlaceholderType type);
public Set<UnifyType> smArg(PlaceholderType type);
public Set<Type> grArg(FunNType type);
public Set<Type> smArg(FunNType type);
public Set<UnifyType> grArg(FunNType type);
public Set<UnifyType> smArg(FunNType type);
public Optional<Type> getLeftHandedType(Type t);
public Set<Type> getAncestors(Type t);
public Set<Type> getChildren(Type t);
public Set<Type> getAllTypesByName(String typeName);
public Optional<UnifyType> getLeftHandedType(UnifyType t);
public Set<UnifyType> getAncestors(UnifyType t);
public Set<UnifyType> getChildren(UnifyType t);
public Set<UnifyType> getAllTypesByName(String typeName);
}

View File

@ -5,7 +5,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.unify.model.Type;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
/**
@ -14,9 +14,9 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier;
*/
public interface IUnify {
public Optional<Unifier> unify(Set<Type> terms);
public Optional<Unifier> unify(Set<UnifyType> terms);
default public Optional<Unifier> unify(Type... terms) {
default public Optional<Unifier> unify(UnifyType... terms) {
return unify(Arrays.stream(terms).collect(Collectors.toSet()));
}

View File

@ -7,18 +7,18 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
/**
* An extends wildcard type "? extends T".
*/
public final class ExtendsType extends Type {
public final class ExtendsType extends UnifyType {
/**
* The extended type
*/
private Type extendedType;
private UnifyType extendedType;
/**
* Creates a new extends wildcard type.
* @param extendedType The extended type e.g. Integer in "? extends Integer"
*/
public ExtendsType(Type extendedType) {
public ExtendsType(UnifyType extendedType) {
super("? extends " + extendedType.getName(), extendedType.getTypeParams());
this.extendedType = extendedType;
}
@ -27,7 +27,7 @@ public final class ExtendsType extends Type {
* Gets the type extended by this wildcard e.g. "Integer" for "? extends Integer"
* @return The extended type.
*/
public Type getExtendedType() {
public UnifyType getExtendedType() {
return extendedType;
}
@ -37,22 +37,22 @@ public final class ExtendsType extends Type {
}
@Override
public Type setTypeParams(TypeParams newTp) {
public UnifyType setTypeParams(TypeParams newTp) {
return new ExtendsType(extendedType.setTypeParams(newTp));
}
@Override
Set<Type> smArg(IFiniteClosure fc) {
Set<UnifyType> smArg(IFiniteClosure fc) {
return fc.smArg(this);
}
@Override
Set<Type> grArg(IFiniteClosure fc) {
Set<UnifyType> grArg(IFiniteClosure fc) {
return fc.grArg(this);
}
@Override
Type apply(Unifier unif) {
UnifyType apply(Unifier unif) {
return new ExtendsType(extendedType.apply(unif));
}
@ -74,4 +74,5 @@ public final class ExtendsType extends Type {
public String toString() {
return "? extends " + extendedType;
}
}

View File

@ -10,23 +10,23 @@ import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
import de.dhbwstuttgart.typeinference.unify.model.MPair.PairOperator;
import de.dhbwstuttgart.typeinference.unifynew.MartelliMontanariUnify;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
public class FiniteClosure implements IFiniteClosure {
private HashMap<Type, Node<Type>> inheritanceGraph;
private HashMap<String, HashSet<Node<Type>>> strInheritanceGraph;
private HashMap<UnifyType, Node<UnifyType>> inheritanceGraph;
private HashMap<String, HashSet<Node<UnifyType>>> strInheritanceGraph;
private Set<MPair> pairs;
private Set<Type> basicTypes;
private Set<UnifyType> basicTypes;
//TODO im konstruktor mitgeben um typenabzuhandeln die keine extends beziehung haben. (Damit die FC diese Typen auch kennt)
//(ALternative: immer die extends zu object beziehung einfügen)
public FiniteClosure(Set<MPair> pairs) {
this.pairs = new HashSet<>(pairs);
inheritanceGraph = new HashMap<Type, Node<Type>>();
inheritanceGraph = new HashMap<UnifyType, Node<UnifyType>>();
// Build the transitive closure of the inheritance tree
for(MPair pair : pairs) {
@ -35,12 +35,12 @@ public class FiniteClosure implements IFiniteClosure {
// Add nodes if not already in the graph
if(!inheritanceGraph.containsKey(pair.getLhsType()))
inheritanceGraph.put(pair.getLhsType(), new Node<Type>(pair.getLhsType()));
inheritanceGraph.put(pair.getLhsType(), new Node<UnifyType>(pair.getLhsType()));
if(!inheritanceGraph.containsKey(pair.getRhsType()))
inheritanceGraph.put(pair.getRhsType(), new Node<Type>(pair.getRhsType()));
inheritanceGraph.put(pair.getRhsType(), new Node<UnifyType>(pair.getRhsType()));
Node<Type> childNode = inheritanceGraph.get(pair.getLhsType());
Node<Type> parentNode = inheritanceGraph.get(pair.getRhsType());
Node<UnifyType> childNode = inheritanceGraph.get(pair.getLhsType());
Node<UnifyType> parentNode = inheritanceGraph.get(pair.getRhsType());
// Add edge
parentNode.AddDescendant(childNode);
@ -53,7 +53,7 @@ public class FiniteClosure implements IFiniteClosure {
// Build the alternative representation with strings as keys
strInheritanceGraph = new HashMap<>();
for(Type key : inheritanceGraph.keySet()) {
for(UnifyType key : inheritanceGraph.keySet()) {
if(!strInheritanceGraph.containsKey(key.getName()))
strInheritanceGraph.put(key.getName(), new HashSet<>());
@ -66,46 +66,46 @@ public class FiniteClosure implements IFiniteClosure {
* @return The set of subtypes of the argument.
*/
@Override
public Set<Type> smaller(Type type) {
public Set<UnifyType> smaller(UnifyType type) {
if(inheritanceGraph.containsKey(type)) {
Set<Type> result = new HashSet<>();
Set<UnifyType> result = new HashSet<>();
result.add(type);
result.addAll(inheritanceGraph.get(type).getContentOfDescendants());
return result;
}
IUnify unify = new MartelliMontanariUnify();
Set<Type> result1 = new HashSet<>();
Set<UnifyType> result1 = new HashSet<>();
// if T = T' then T <=* T'
result1.add(type);
{ArrayList<Set<Type>> paramCandidates = new ArrayList<>();
for (Type param : type.getTypeParams())
{ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
for (UnifyType param : type.getTypeParams())
paramCandidates.add(smArg(param));
Set<TypeParams> permResult = new HashSet<>();
permuteParams(paramCandidates, 0, permResult, new Type[paramCandidates.size()]);
permuteParams(paramCandidates, 0, permResult, new UnifyType[paramCandidates.size()]);
for (TypeParams newParams : permResult)
result1.add(type.setTypeParams(newParams));}
Set<Type> result2 = new HashSet<>();
Set<UnifyType> result2 = new HashSet<>();
if (strInheritanceGraph.containsKey(type.getName())) {
HashSet<Type> candidates = new HashSet<>();
HashSet<UnifyType> candidates = new HashSet<>();
strInheritanceGraph.get(type.getName()).forEach(x -> candidates.add(x.getContent()));
for(Type typePrime : result1) {
for (Type theta2 : candidates) {
for(UnifyType typePrime : result1) {
for (UnifyType theta2 : candidates) {
Optional<Unifier> sigma2 = unify.unify(typePrime, theta2);
if (!sigma2.isPresent())
continue;
if(type.equals(theta2))
continue;
Set<Type> theta1s = smaller(theta2);
for (Type theta1 : theta1s) {
Set<UnifyType> theta1s = smaller(theta2);
for (UnifyType theta1 : theta1s) {
// Because only the most general type is calculated, sigma1 = sigma2
Type sigma1Theta1 = sigma2.get().apply(theta1);
UnifyType sigma1Theta1 = sigma2.get().apply(theta1);
result2.add(sigma1Theta1);
}
}
@ -114,17 +114,17 @@ public class FiniteClosure implements IFiniteClosure {
else
result2 = result1;
Set<Type> result3 = new HashSet<>();
for(Type t : result2) {
ArrayList<Set<Type>> paramCandidates = new ArrayList<>();
for (Type param : t.getTypeParams())
Set<UnifyType> result3 = new HashSet<>();
for(UnifyType t : result2) {
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
for (UnifyType param : t.getTypeParams())
paramCandidates.add(smArg(param));
Set<TypeParams> permResult = new HashSet<>();
permuteParams(paramCandidates, 0, permResult, new Type[paramCandidates.size()]);
permuteParams(paramCandidates, 0, permResult, new UnifyType[paramCandidates.size()]);
for (TypeParams newParams : permResult) {
Type tPrime = t.setTypeParams(newParams);
UnifyType tPrime = t.setTypeParams(newParams);
if(tPrime.equals(t))
result3.add(t);
else
@ -141,9 +141,9 @@ public class FiniteClosure implements IFiniteClosure {
* @return The set of supertypes of the argument.
*/
@Override
public Set<Type> greater(Type type) {
public Set<UnifyType> greater(UnifyType type) {
IUnify unify = new MartelliMontanariUnify();
Set<Type> result1 = new HashSet<>();
Set<UnifyType> result1 = new HashSet<>();
if(inheritanceGraph.containsKey(type))
result1.addAll(inheritanceGraph.get(type).getContentOfPredecessors());
@ -151,32 +151,32 @@ public class FiniteClosure implements IFiniteClosure {
// if T = T' then T <=* T'
result1.add(type);
{ArrayList<Set<Type>> paramCandidates = new ArrayList<>();
for (Type param : type.getTypeParams())
{ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
for (UnifyType param : type.getTypeParams())
paramCandidates.add(grArg(param));
Set<TypeParams> permResult = new HashSet<>();
permuteParams(paramCandidates, 0, permResult, new Type[paramCandidates.size()]);
permuteParams(paramCandidates, 0, permResult, new UnifyType[paramCandidates.size()]);
for (TypeParams newParams : permResult)
result1.add(type.setTypeParams(newParams));}
Set<Type> result2 = new HashSet<>();
Set<UnifyType> result2 = new HashSet<>();
if (strInheritanceGraph.containsKey(type.getName()) && !inheritanceGraph.containsKey(type)) {
HashSet<Type> candidates = new HashSet<>();
HashSet<UnifyType> candidates = new HashSet<>();
strInheritanceGraph.get(type.getName()).forEach(x -> candidates.add(x.getContent()));
for(Type typePrime : result1) {
for (Type theta2 : candidates) {
for(UnifyType typePrime : result1) {
for (UnifyType theta2 : candidates) {
Optional<Unifier> sigma2 = unify.unify(typePrime, theta2);
if (!sigma2.isPresent())
continue;
if(type.equals(theta2))
continue;
Set<Type> theta1s = greater(theta2);
for (Type theta1 : theta1s) {
Set<UnifyType> theta1s = greater(theta2);
for (UnifyType theta1 : theta1s) {
// Because only the most general type is calculated, sigma1 = sigma2
Type sigma1Theta1 = sigma2.get().apply(theta1);
UnifyType sigma1Theta1 = sigma2.get().apply(theta1);
result2.add(sigma1Theta1);
}
}
@ -185,17 +185,17 @@ public class FiniteClosure implements IFiniteClosure {
result2.addAll(result1);
Set<Type> result3 = new HashSet<>();
for(Type t : result2) {
ArrayList<Set<Type>> paramCandidates = new ArrayList<>();
for (Type param : t.getTypeParams())
Set<UnifyType> result3 = new HashSet<>();
for(UnifyType t : result2) {
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
for (UnifyType param : t.getTypeParams())
paramCandidates.add(grArg(param));
Set<TypeParams> permResult = new HashSet<>();
permuteParams(paramCandidates, 0, permResult, new Type[paramCandidates.size()]);
permuteParams(paramCandidates, 0, permResult, new UnifyType[paramCandidates.size()]);
for (TypeParams newParams : permResult) {
Type tPrime = t.setTypeParams(newParams);
UnifyType tPrime = t.setTypeParams(newParams);
if(tPrime.equals(t))
result3.add(t);
else
@ -209,13 +209,13 @@ public class FiniteClosure implements IFiniteClosure {
}
@Override
public Set<Type> grArg(Type type) {
public Set<UnifyType> grArg(UnifyType type) {
return type.grArg(this);
}
@Override
public Set<Type> grArg(SimpleType type) {
Set<Type> result = new HashSet<Type>();
public Set<UnifyType> grArg(SimpleType type) {
Set<UnifyType> result = new HashSet<UnifyType>();
result.add(type);
smaller(type).forEach(x -> result.add(new SuperType(x)));
@ -225,16 +225,16 @@ public class FiniteClosure implements IFiniteClosure {
}
@Override
public Set<Type> grArg(FunNType type) {
public Set<UnifyType> grArg(FunNType type) {
throw new NotImplementedException();
}
@Override
public Set<Type> grArg(ExtendsType type) {
Set<Type> result = new HashSet<Type>();
public Set<UnifyType> grArg(ExtendsType type) {
Set<UnifyType> result = new HashSet<UnifyType>();
result.add(type);
Type t = type.getExtendedType();
UnifyType t = type.getExtendedType();
greater(t).forEach(x -> result.add(new ExtendsType(x)));
@ -242,11 +242,11 @@ public class FiniteClosure implements IFiniteClosure {
}
@Override
public Set<Type> grArg(SuperType type) {
Set<Type> result = new HashSet<Type>();
public Set<UnifyType> grArg(SuperType type) {
Set<UnifyType> result = new HashSet<UnifyType>();
result.add(type);
Type t = type.getSuperedType();
UnifyType t = type.getSuperedType();
smaller(t).forEach(x -> result.add(new SuperType(x)));
@ -254,8 +254,8 @@ public class FiniteClosure implements IFiniteClosure {
}
@Override
public Set<Type> grArg(PlaceholderType type) {
HashSet<Type> result = new HashSet<>();
public Set<UnifyType> grArg(PlaceholderType type) {
HashSet<UnifyType> result = new HashSet<>();
result.add(type);
//result.add(new SuperType(type));
//result.add(new ExtendsType(type));
@ -263,29 +263,29 @@ public class FiniteClosure implements IFiniteClosure {
}
@Override
public Set<Type> smArg(Type type) {
public Set<UnifyType> smArg(UnifyType type) {
return type.smArg(this);
}
@Override
public Set<Type> smArg(SimpleType type) {
Set<Type> result = new HashSet<Type>();
public Set<UnifyType> smArg(SimpleType type) {
Set<UnifyType> result = new HashSet<UnifyType>();
result.add(type);
return result;
}
@Override
public Set<Type> smArg(FunNType type) {
public Set<UnifyType> smArg(FunNType type) {
throw new NotImplementedException();
}
@Override
public Set<Type> smArg(ExtendsType type) {
Set<Type> result = new HashSet<Type>();
public Set<UnifyType> smArg(ExtendsType type) {
Set<UnifyType> result = new HashSet<UnifyType>();
result.add(type);
Type t = type.getExtendedType();
UnifyType t = type.getExtendedType();
result.add(t);
smaller(t).forEach(x -> {
@ -298,11 +298,11 @@ public class FiniteClosure implements IFiniteClosure {
@Override
public Set<Type> smArg(SuperType type) {
Set<Type> result = new HashSet<Type>();
public Set<UnifyType> smArg(SuperType type) {
Set<UnifyType> result = new HashSet<UnifyType>();
result.add(type);
Type t = type.getSuperedType();
UnifyType t = type.getSuperedType();
result.add(t);
greater(t).forEach(x -> {
@ -314,14 +314,14 @@ public class FiniteClosure implements IFiniteClosure {
}
@Override
public Set<Type> smArg(PlaceholderType type) {
HashSet<Type> result = new HashSet<>();
public Set<UnifyType> smArg(PlaceholderType type) {
HashSet<UnifyType> result = new HashSet<>();
result.add(type);
return result;
}
public boolean isGenericType(Type t) {
public boolean isGenericType(UnifyType t) {
if(t.getTypeParams().size() == 0)
return true;
@ -336,14 +336,14 @@ public class FiniteClosure implements IFiniteClosure {
}
@Override
public Set<Type> getAllTypesByName(String typeName) {
public Set<UnifyType> getAllTypesByName(String typeName) {
if(!strInheritanceGraph.containsKey(typeName))
return new HashSet<>();
return strInheritanceGraph.get(typeName).stream().map(x -> x.getContent()).collect(Collectors.toCollection(HashSet::new));
}
@Override
public Optional<Type> getLeftHandedType(Type t) {
public Optional<UnifyType> getLeftHandedType(UnifyType t) {
if(!strInheritanceGraph.containsKey(t.getName()))
return Optional.empty();
@ -355,32 +355,32 @@ public class FiniteClosure implements IFiniteClosure {
}
@Override
public Set<Type> getAncestors(Type t) {
public Set<UnifyType> getAncestors(UnifyType t) {
if(!inheritanceGraph.containsKey(t))
return new HashSet<>();
Set<Type> result = inheritanceGraph.get(t).getContentOfPredecessors();
Set<UnifyType> result = inheritanceGraph.get(t).getContentOfPredecessors();
result.add(t);
return result;
}
@Override
public Set<Type> getChildren(Type t) {
public Set<UnifyType> getChildren(UnifyType t) {
if(!inheritanceGraph.containsKey(t))
return new HashSet<>();
Set<Type> result = inheritanceGraph.get(t).getContentOfDescendants();
Set<UnifyType> result = inheritanceGraph.get(t).getContentOfDescendants();
result.add(t);
return result;
}
protected void permuteParams(ArrayList<Set<Type>> candidates, int idx, Set<TypeParams> result, Type[] current) {
protected void permuteParams(ArrayList<Set<UnifyType>> candidates, int idx, Set<TypeParams> result, UnifyType[] current) {
if(candidates.size() == idx) {
result.add(new TypeParams(Arrays.copyOf(current, current.length)));
return;
}
Set<Type> localCandidates = candidates.get(idx);
Set<UnifyType> localCandidates = candidates.get(idx);
for(Type t : localCandidates) {
for(UnifyType t : localCandidates) {
current[idx] = t;
permuteParams(candidates, idx+1, result, current);
}

View File

@ -4,7 +4,7 @@ import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
public class FunNType extends Type {
public class FunNType extends UnifyType {
public FunNType(TypeParams p) {
super("FuN", p);
@ -13,7 +13,7 @@ public class FunNType extends Type {
}
@Override
public Type setTypeParams(TypeParams newTp) {
public UnifyType setTypeParams(TypeParams newTp) {
if(newTp.size() == 0)
throw new IllegalArgumentException("Function types need at least one type parameter");
return new FunNType(newTp);
@ -24,17 +24,17 @@ public class FunNType extends Type {
}
@Override
Set<Type> smArg(IFiniteClosure fc) {
Set<UnifyType> smArg(IFiniteClosure fc) {
return fc.smArg(this);
}
@Override
Set<Type> grArg(IFiniteClosure fc) {
Set<UnifyType> grArg(IFiniteClosure fc) {
return fc.grArg(this);
}
@Override
Type apply(Unifier unif) {
UnifyType apply(Unifier unif) {
// TODO Auto-generated method stub
return null;
}

View File

@ -2,29 +2,8 @@ package de.dhbwstuttgart.typeinference.unify.model;
public class MPair {
public enum PairOperator {
SMALLER,
SMALLERDOT,
SMALLERDOTWC,
EQUALSDOT;
@Override
public String toString() {
switch (this) {
case SMALLER:
return "<";
case SMALLERDOT:
return "<.";
case SMALLERDOTWC:
return "<.?";
default:
return "=.";
}
};
}
private Type lhs;
private Type rhs;
private UnifyType lhs;
private UnifyType rhs;
private PairOperator pairOp;
/*public MPair(Type t1, Type t2) {
@ -33,17 +12,17 @@ public class MPair {
pairOp = PairOperator.SMALLER;
}*/
public MPair(Type t1, Type t2, PairOperator op) {
public MPair(UnifyType t1, UnifyType t2, PairOperator op) {
lhs = t1;
rhs = t2;
pairOp = op;
}
public Type getLhsType() {
public UnifyType getLhsType() {
return lhs;
}
public Type getRhsType() {
public UnifyType getRhsType() {
return rhs;
}
@ -69,11 +48,11 @@ public class MPair {
* @param subst The type replacing t.
* @return A pair where occurrences of t are replaced by subst.
*/
public MPair substitute(Type t, Type subst) {
Type newlhs = lhs;
public MPair substitute(UnifyType t, UnifyType subst) {
UnifyType newlhs = lhs;
if(lhs.equals(t)) newlhs = subst;
Type newrhs = rhs;
UnifyType newrhs = rhs;
if(rhs.equals(t)) newrhs = subst;
if(newlhs == lhs && newrhs == rhs) return this;

View File

@ -0,0 +1,22 @@
package de.dhbwstuttgart.typeinference.unify.model;
public enum PairOperator {
SMALLER,
SMALLERDOT,
SMALLERDOTWC,
EQUALSDOT;
@Override
public String toString() {
switch (this) {
case SMALLER:
return "<";
case SMALLERDOT:
return "<.";
case SMALLERDOTWC:
return "<.?";
default:
return "=.";
}
};
}

View File

@ -7,7 +7,7 @@ import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
public final class PlaceholderType extends Type{
public final class PlaceholderType extends UnifyType{
protected static final HashSet<String> EXISTING_PLACEHOLDERS = new HashSet<String>();
protected static String nextName = "gen_";
@ -34,17 +34,17 @@ public final class PlaceholderType extends Type{
}
@Override
Set<Type> smArg(IFiniteClosure fc) {
Set<UnifyType> smArg(IFiniteClosure fc) {
return fc.smArg(this);
}
@Override
Set<Type> grArg(IFiniteClosure fc) {
Set<UnifyType> grArg(IFiniteClosure fc) {
return fc.grArg(this);
}
@Override
public Type setTypeParams(TypeParams newTp) {
public UnifyType setTypeParams(TypeParams newTp) {
return this;
}
@ -54,7 +54,7 @@ public final class PlaceholderType extends Type{
}
@Override
Type apply(Unifier unif) {
UnifyType apply(Unifier unif) {
if(unif.hasSubstitute(this))
return unif.getSubstitute(this);
return this;

View File

@ -4,32 +4,32 @@ import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
public final class SimpleType extends Type {
public SimpleType(String name, Type... typeParams) {
public final class SimpleType extends UnifyType {
public SimpleType(String name, UnifyType... typeParams) {
super(name, new TypeParams(typeParams));
}
private SimpleType(String name, TypeParams params) {
public SimpleType(String name, TypeParams params) {
super(name, params);
}
@Override
Set<Type> smArg(IFiniteClosure fc) {
Set<UnifyType> smArg(IFiniteClosure fc) {
return fc.smArg(this);
}
@Override
Set<Type> grArg(IFiniteClosure fc) {
Set<UnifyType> grArg(IFiniteClosure fc) {
return fc.grArg(this);
}
@Override
Type apply(Unifier unif) {
UnifyType apply(Unifier unif) {
return new SimpleType(typeName, typeParams.apply(unif));
}
@Override
public Type setTypeParams(TypeParams newTp) {
public UnifyType setTypeParams(TypeParams newTp) {
return new SimpleType(new String(typeName), newTp);
}

View File

@ -4,16 +4,16 @@ import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
public final class SuperType extends Type {
public final class SuperType extends UnifyType {
private Type superedType;
private UnifyType superedType;
public SuperType(Type superedType) {
public SuperType(UnifyType superedType) {
super("? super " + superedType.getName(), superedType.getTypeParams());
this.superedType = superedType;
}
public Type getSuperedType() {
public UnifyType getSuperedType() {
return superedType;
}
@ -28,22 +28,22 @@ public final class SuperType extends Type {
}
@Override
public Type setTypeParams(TypeParams newTp) {
public UnifyType setTypeParams(TypeParams newTp) {
return new SuperType(superedType.setTypeParams(newTp));
}
@Override
Set<Type> smArg(IFiniteClosure fc) {
Set<UnifyType> smArg(IFiniteClosure fc) {
return fc.smArg(this);
}
@Override
Set<Type> grArg(IFiniteClosure fc) {
Set<UnifyType> grArg(IFiniteClosure fc) {
return fc.grArg(this);
}
@Override
Type apply(Unifier unif) {
UnifyType apply(Unifier unif) {
return new SuperType(superedType.apply(unif));
}
@ -60,4 +60,5 @@ public final class SuperType extends Type {
SuperType other = (SuperType) obj;
return other.getSuperedType().equals(superedType);
}
}

View File

@ -3,15 +3,24 @@ package de.dhbwstuttgart.typeinference.unify.model;
import java.util.Arrays;
import java.util.Iterator;
public final class TypeParams implements Iterable<Type>{
private final Type[] typeParams;
import de.dhbwstuttgart.typeinference.Menge;
public TypeParams(Type... types) {
public final class TypeParams implements Iterable<UnifyType>{
private final UnifyType[] typeParams;
public TypeParams(Menge<UnifyType> types){
typeParams = new UnifyType[types.size()];
for(int i=0;i<types.size();i++){
typeParams[i] = types.get(i);
}
}
public TypeParams(UnifyType... types) {
typeParams = types;
}
public boolean arePlaceholders() {
for(Type t : typeParams)
for(UnifyType t : typeParams)
if(!(t instanceof PlaceholderType))
return false;
return true;
@ -20,7 +29,7 @@ public final class TypeParams implements Iterable<Type>{
@Override
public String toString() {
String res = "";
for(Type t : typeParams)
for(UnifyType t : typeParams)
res += t + ",";
return "<" + res.substring(0, res.length()-1) + ">";
}
@ -34,14 +43,14 @@ public final class TypeParams implements Iterable<Type>{
}
public TypeParams apply(Unifier unif) {
Type[] newParams = new Type[typeParams.length];
UnifyType[] newParams = new UnifyType[typeParams.length];
for(int i = 0; i < typeParams.length; i++)
newParams[i] = typeParams[i].apply(unif);
return new TypeParams(newParams);
}
public boolean occurs(PlaceholderType t) {
for(Type p : typeParams)
for(UnifyType p : typeParams)
if(p instanceof PlaceholderType)
if(p.equals(t))
return true;
@ -51,26 +60,26 @@ public final class TypeParams implements Iterable<Type>{
return false;
}
public boolean contains(Type t) {
for(Type t1 : typeParams)
public boolean contains(UnifyType t) {
for(UnifyType t1 : typeParams)
if(t1.equals(t1))
return true;
return false;
}
public Type get(int i) {
public UnifyType get(int i) {
return typeParams[i];
}
public TypeParams set(Type t, int idx) {
Type[] newparams = Arrays.copyOf(typeParams, typeParams.length);
public TypeParams set(UnifyType t, int idx) {
UnifyType[] newparams = Arrays.copyOf(typeParams, typeParams.length);
newparams[idx] = t;
return new TypeParams(newparams);
}
@Override
public Iterator<Type> iterator() {
public Iterator<UnifyType> iterator() {
return Arrays.stream(typeParams).iterator();
}

Some files were not shown because too many files have changed in this diff Show More