Finite Closure ohne Subtypes. checkType statt TYPE

This commit is contained in:
JanUlrich 2014-10-08 19:00:17 +02:00
parent 51e0d96174
commit 2b33576488
27 changed files with 143 additions and 117 deletions

View File

@ -17,6 +17,7 @@ public class JavaClassName {
private PackageName packageName; private PackageName packageName;
public JavaClassName(String name){ public JavaClassName(String name){
if(name == null)throw new NullPointerException();
String[] names = name.split("[.]"); String[] names = name.split("[.]");
boolean match = true; boolean match = true;
if(names.length == 1){ if(names.length == 1){

View File

@ -112,7 +112,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
private Block class_block; private Block class_block;
// ino.end // ino.end
// ino.attribute.paralist.23023.declaration // ino.attribute.paralist.23023.declaration
private Vector<Type> paralist = new Vector<Type>(); // Parameterliste 'class xy<para1, para2,...>{}' wird gespeichert //private Vector<Type> paralist = new Vector<Type>(); // Parameterliste 'class xy<para1, para2,...>{}' wird gespeichert
// ino.end // ino.end
// ino.attribute.parahash.23026.declaration // ino.attribute.parahash.23026.declaration
private Hashtable<String,String> parahash = new Hashtable<String,String>(); // parametrisierten Attrib. werden mit den Paramet.aus paralist verk. private Hashtable<String,String> parahash = new Hashtable<String,String>(); // parametrisierten Attrib. werden mit den Paramet.aus paralist verk.
@ -184,7 +184,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
public Class(String name, RefType superClass, Modifiers mod, int offset){ public Class(String name, RefType superClass, Modifiers mod, int offset){
this(name,mod,offset); this(name,mod,offset);
this.superClass = superClass; if(superClass == null)this.superClass = new Class("Object",-1).getType();
} }
// ino.method.Class.23044.definition // ino.method.Class.23044.definition
@ -247,7 +247,15 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
} }
if (vector != null) setSuperInterfaces(vector); if (vector != null) setSuperInterfaces(vector);
if (paralist != null){ if (paralist != null){
this.set_ParaList(paralist); //this.set_ParaList(paralist);
Vector<GenericTypeVar> gtvList = new Vector<>();
int lastItemOffset = 0;
for(Type paraT : paralist){
GenericTypeVar gtv = new GenericTypeVar(paraT.get_Name(),this, paraT.getOffset());
gtvList.add(gtv);
lastItemOffset = paraT.getOffset() + paraT.get_Name().length();
}
this.genericClassParameters = new GenericDeclarationList(gtvList, lastItemOffset);
} }
if(usedIdsToCheck!=null) this.usedIdsToCheck=usedIdsToCheck; if(usedIdsToCheck!=null) this.usedIdsToCheck=usedIdsToCheck;
@ -264,7 +272,6 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
} }
// ino.end // ino.end
public Vector<Field> getFields() public Vector<Field> getFields()
{ {
return fielddecl; return fielddecl;
@ -308,7 +315,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
} }
// ino.end // ino.end
/*
// ino.method.complete_paralist.23062.definition // ino.method.complete_paralist.23062.definition
public Vector<Type> complete_paralist(boolean ext) public Vector<Type> complete_paralist(boolean ext)
// ino.end // ino.end
@ -327,7 +334,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
return this.paralist; return this.paralist;
} }
// ino.end // ino.end
*/
/** /**
@ -478,6 +485,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
} }
// ino.end // ino.end
/*
// ino.method.set_ParaList.23098.definition // ino.method.set_ParaList.23098.definition
public void set_ParaList(Vector<Type> para) public void set_ParaList(Vector<Type> para)
// ino.end // ino.end
@ -486,13 +494,15 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
this.paralist = para; this.paralist = para;
} }
// ino.end // ino.end
*/
// ino.method.get_ParaList.23101.definition // ino.method.get_ParaList.23101.definition
public Vector<Type> get_ParaList() public Vector<? extends Type> get_ParaList()
// ino.end // ino.end
// ino.method.get_ParaList.23101.body // ino.method.get_ParaList.23101.body
{ {
return this.paralist; //if(this.paralist == null)return new Vector<Type>();
return this.getGenericParameter();
} }
// ino.end // ino.end
@ -660,10 +670,10 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
ConstraintsSet oderConstraints = new ConstraintsSet(); ConstraintsSet oderConstraints = new ConstraintsSet();
for(Type gparam : this.paralist){ for(Type gparam : this.get_ParaList()){
if(gparam instanceof GenericTypeVar)assumptions.add(((GenericTypeVar)gparam).createAssumptions()); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen if(gparam instanceof GenericTypeVar)assumptions.add(((GenericTypeVar)gparam).createAssumptions()); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen
} }
for(Type gparam : this.paralist){ for(Type gparam : this.get_ParaList()){
if(gparam instanceof GenericTypeVar)oderConstraints.add(((GenericTypeVar)gparam).TYPE(assumptions)); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen if(gparam instanceof GenericTypeVar)oderConstraints.add(((GenericTypeVar)gparam).TYPE(assumptions)); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen
} }
@ -1193,10 +1203,12 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
} }
if(this.genericClassParameters == null)this.setGenericParameter(new GenericDeclarationList(new Vector<GenericTypeVar>(), 0)); if(this.genericClassParameters == null)this.setGenericParameter(new GenericDeclarationList(new Vector<GenericTypeVar>(), 0));
/*//Nicht mehr notwendig, Generische Klassenparameter werden nun immer direkt in die genericClassParameters gespeichert.
for(Type t : this.get_ParaList()){ for(Type t : this.get_ParaList()){
if(t instanceof GenericTypeVar)this.genericClassParameters.add((GenericTypeVar)t); if(t instanceof GenericTypeVar)this.genericClassParameters.add((GenericTypeVar)t);
else this.genericClassParameters.add(new GenericTypeVar(t.get_Name(),this,-1)); else this.genericClassParameters.add(new GenericTypeVar(t.get_Name(),this,-1));
} }
*/
for(Type t : this.get_ParaList()){ for(Type t : this.get_ParaList()){
t.parserPostProcessing(this); t.parserPostProcessing(this);
} }

View File

@ -6,6 +6,7 @@ package de.dhbwstuttgart.syntaxtree;
import java.util.Vector; import java.util.Vector;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.CodeAttribute;
import de.dhbwstuttgart.syntaxtree.misc.DeclId; import de.dhbwstuttgart.syntaxtree.misc.DeclId;
@ -15,10 +16,10 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.Typeable; import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
// ino.class.FormalParameter.23391.declaration // ino.class.FormalParameter.23391.declaration
public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeInsertable public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeInsertable

View File

@ -527,7 +527,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
} }
//TypeCheck, falls es sich um einen RefType handelt: //TypeCheck, falls es sich um einen RefType handelt:
this.returntype = this.returntype.TYPE(localAss, this).getType(); this.returntype = this.returntype.checkTYPE(localAss, this);
/* /*
if(this.returntype!=null && (this.returntype instanceof RefType)&& if(this.returntype!=null && (this.returntype instanceof RefType)&&
!(this.returntype instanceof mycompiler.mytype.Void)){//Sonderfall der Methode: Ihr Typ darf Void definiert werden. !(this.returntype instanceof mycompiler.mytype.Void)){//Sonderfall der Methode: Ihr Typ darf Void definiert werden.
@ -540,7 +540,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
//Die Parameter zu den Assumptions hinzufügen: //Die Parameter zu den Assumptions hinzufügen:
if(this.parameterlist!=null)for(FormalParameter param : this.parameterlist){ if(this.parameterlist!=null)for(FormalParameter param : this.parameterlist){
param.setType(param.getType().TYPE(localAss, this).getType()); param.setType(param.getType().checkTYPE(localAss, this));
/* /*
if(param.getType() instanceof RefType) if(param.getType() instanceof RefType)
{ {

View File

@ -305,19 +305,21 @@ public class SourceFile
// Menge FC bilden // Menge FC bilden
Vector<Pair> vFC = new Vector<Pair>(); // Menge FC Vector<Pair> vFC = new Vector<Pair>(); // Menge FC
TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports); TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports, false);
globalAssumptions.add(this.getPublicFieldAssumptions()); globalAssumptions.add(this.getPublicFieldAssumptions());
// 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen
Vector<Class> basicAssumptionsClassVector = new Vector<>(); //die Klassen aus den BasicAssumptions
for(ClassAssumption cAss : ass.getClassAssumptions()){ for(ClassAssumption cAss : ass.getClassAssumptions()){
Type t1 = cAss.getAssumedClass().getType(); Type t1 = cAss.getAssumedClass().getType();
Type t2 = cAss.getAssumedClass().getSuperClass(); Type t2 = cAss.getAssumedClass().getSuperClass();
Pair p = new Pair(t1, t2); Pair p = new Pair(t1, t2);
System.out.println("FCPair: "+p); //System.out.println("FCPair: "+p);
if(! t1.equals(t2)){ if(! t1.equals(t2)){//Um FC_TTO darf kein T <. T stehen.
vFC.add(p); //Um FC_TTO darf kein T <. T stehen. //vFC.add(p); //Wird momentan nicht hinzugefügt
basicAssumptionsClassVector.add(cAss.getAssumedClass());//Klasse ohne die Superklasse anfügen
}else{ }else{
System.out.println("Wurde nicht aufgenommen"); //System.out.println("Wurde nicht aufgenommen");
} }
} }
@ -621,10 +623,13 @@ public class SourceFile
// printMenge( "nach trans: FC", vFC, 6 ); // printMenge( "nach trans: FC", vFC, 6 );
FC_TTO fctto = new FC_TTO(vFC, tto,KlassenVektor); Vector<Class> KlassenVektorunImportierteKlassen = new Vector<>();
KlassenVektorunImportierteKlassen.addAll(basicAssumptionsClassVector);
KlassenVektorunImportierteKlassen.addAll(KlassenVektor);
FC_TTO fctto = new FC_TTO(vFC, tto, KlassenVektorunImportierteKlassen);
return fctto; return fctto;
} }
// ino.end
public TypeAssumptions getPublicFieldAssumptions(){ public TypeAssumptions getPublicFieldAssumptions(){
TypeAssumptions publicAssumptions = new TypeAssumptions(null); TypeAssumptions publicAssumptions = new TypeAssumptions(null);
@ -666,7 +671,7 @@ public class SourceFile
} }
//Assumptions der importierten Klassen sammeln: //Assumptions der importierten Klassen sammeln:
TypeAssumptions importAssumptions = this.makeBasicAssumptionsFromJRE(imports); TypeAssumptions importAssumptions = this.makeBasicAssumptionsFromJRE(imports, true);
globalAssumptions.add(importAssumptions); globalAssumptions.add(importAssumptions);
typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions); typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions);
@ -1094,8 +1099,13 @@ public class SourceFile
return ret; return ret;
}*/ }*/
// ino.method.makeBasicAssumptionsFromJRE.21409.definition /**
private TypeAssumptions makeBasicAssumptionsFromJRE(Vector<UsedId> imports) * Erstellt die Assumptions der standardmäßig importierten Packages (java.lang.) sowie der von imports übergebenen Klassen zusammen.
* @param imports
* @param withSuptypes - Gibt an, ob auch die subklassen der Packages den Assumptions angefügt werden sollen.
* @return
*/
private TypeAssumptions makeBasicAssumptionsFromJRE(Vector<UsedId> imports, boolean withSubtypes)
// ino.end // ino.end
// ino.method.makeBasicAssumptionsFromJRE.21409.body // ino.method.makeBasicAssumptionsFromJRE.21409.body
{ {
@ -1132,26 +1142,30 @@ public class SourceFile
String className=x.getName(); String className=x.getName();
//Ermittle die Superklasse: //Ermittle die Superklasse:
Class sClass; Class sClass = new Class("Object",0);
sClass = getSuperClassOfJREClass(x, basicAssumptions); if(withSubtypes)sClass = getSuperClassOfJREClass(x, basicAssumptions);
Class parentClass = new Class(className, sClass.getType(),mod , 0); // Namen von Generische Typen erzeugen
// Generische Typen erzeugen
Hashtable<String,GenericTypeVar> jreSpiderRegistry=new Hashtable<String,GenericTypeVar>(); Hashtable<String,GenericTypeVar> jreSpiderRegistry=new Hashtable<String,GenericTypeVar>();
Vector<GenericTypeVar> typeGenPara = new Vector<GenericTypeVar>(); Vector<String> typeGenPara = new Vector<String>();
for(int j=0;j<tvs.length;j++){ for(int j=0;j<tvs.length;j++){
GenericTypeVar gtv=new GenericTypeVar(tvs[j].getName(), parentClass,-1); //GenericTypeVar gtv=new GenericTypeVar(tvs[j].getName(), parentClass,-1);
typeGenPara.addElement(gtv); typeGenPara.addElement(tvs[j].getName());
jreSpiderRegistry.put(tvs[j].getName(),gtv); //jreSpiderRegistry.put(tvs[j].getName(),gtv);
} }
Class parentClass = new Class(className, sClass.getType(),mod, typeGenPara);
//BasicAssumptionClass myCl = new BasicAssumptionClass(className, mod); //BasicAssumptionClass myCl = new BasicAssumptionClass(className, mod);
for(GenericTypeVar classParam : parentClass.getGenericParameter()){
jreSpiderRegistry.put(classParam.getName().toString(),classParam);
}
if(typeGenPara.size()>0){ if(typeGenPara.size()>0){
//auskommentiert von Andreas Stadelmeier: //auskommentiert von Andreas Stadelmeier:
//basicAssumptions.addGenericTypeVars(className, typeGenPara); //basicAssumptions.addGenericTypeVars(className, typeGenPara);
parentClass.set_ParaList((Vector)typeGenPara);//myCl.set_ParaList((Vector)typeGenPara); //parentClass.set_ParaList((Vector)typeGenPara);//myCl.set_ParaList((Vector)typeGenPara);
} }

View File

@ -126,7 +126,7 @@ public class BoolLiteral extends Literal
@Override @Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
this.type = assumptions.getTypeFor(new RefType("java.lang.Boolean",this,-1), this).getType(); this.type = assumptions.checkType(new RefType("java.lang.Boolean",this,-1), this);
return new ConstraintsSet(); return new ConstraintsSet();
} }

View File

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

View File

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

View File

@ -177,7 +177,8 @@ public class LocalOrFieldVar extends Expr
//gibt es eine Assumption für den die LocalOrFieldVar-Variablen, dann folgendes ausführen: //gibt es eine Assumption für den die LocalOrFieldVar-Variablen, dann folgendes ausführen:
Type thisTypeAssumption = assumptions.getVarType(this.get_Name(), this.getParentClass()); Type thisTypeAssumption = assumptions.getVarType(this.get_Name(), this.getParentClass());
if(thisTypeAssumption == null)throw new TypeinferenceException("Eine Variable "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this); if(thisTypeAssumption == null)throw new TypeinferenceException("Eine Variable "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this);
this.setType(thisTypeAssumption); Type thisType = thisTypeAssumption.checkTYPE(assumptions, this);
this.setType(thisType);
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable())); //ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
return ret; return ret;
} }

View File

@ -378,7 +378,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
ConstraintsSet ret = new ConstraintsSet(); ConstraintsSet ret = new ConstraintsSet();
if((this.getType() instanceof RefType)){ if((this.getType() instanceof RefType)){
Type replaceType = null; Type replaceType = null;
replaceType = assumptions.getTypeFor((RefType)this.getType(), this).getType(); replaceType = assumptions.checkType((RefType)this.getType(), this);
this.setType(replaceType); this.setType(replaceType);
} }
assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird. assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird.

View File

@ -88,46 +88,6 @@ public class NewClass extends Expr
} }
// ino.end // ino.end
// ino.method.sc_check.25852.definition
public void sc_check(Vector<Class> classname, Hashtable bh, Hashtable<String, String> ch, boolean ext, Hashtable parach, Hashtable<String, Hashtable> parabh)
throws SCStatementException
// ino.end
// ino.method.sc_check.25852.body
{
if(ext)
parserlog.debug(" ---NewClass---");
Class cl;
String usedid = this.usedid.get_Name_1Element();
String next = null;
for(Enumeration<Class> el = classname.elements(); el.hasMoreElements();)
{
cl = el.nextElement();
next = (String)cl.getName().toString();
if(ext)
parserlog.debug("Vergleiche "+usedid+" mit "+next);
if(usedid.equals(next))
{
this.set_Type(new Type(next,this,getOffset()));
break;
}
else next = null;
}
if(next == null)
{
if(ext)
parserlog.error("Typfehler --> NewClass.sc_check()" );
SCStatementException stex = new SCStatementException();
SCExcept ex = new SCExcept();
ex.set_error("Typfehler");
ex.set_statement("NewClass: Klasse "+usedid+" existiert nicht im Vector classname.");
stex.addException(ex);
throw stex;
}
if(ext)
parserlog.debug("Klasse "+usedid+" im class-Vector gefunden");
}
// ino.end
// ino.method.set_ArgumentList.25855.definition // ino.method.set_ArgumentList.25855.definition
public void set_ArgumentList(ArgumentList al) public void set_ArgumentList(ArgumentList al)
// ino.end // ino.end
@ -223,8 +183,8 @@ public class NewClass extends Expr
//if(this.arglist != null && this.arglist.expr != null)for(Expr arg : this.arglist.expr){ //if(this.arglist != null && this.arglist.expr != null)for(Expr arg : this.arglist.expr){
// ret.add(arg.TYPEExpr(assumptions)); // ret.add(arg.TYPEExpr(assumptions));
//} //}
Type thisT = assumptions.checkType(new RefType(this.get_Name(),this,0), (SyntaxTreeNode)this);
this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),this,0), this).getType()); this.setType(thisT);
/* /*

View File

@ -42,7 +42,7 @@ public class Null extends Literal
// ino.method.Null.25926.body // ino.method.Null.25926.body
{ {
super(-1,-1); super(-1,-1);
this.setType(new Type("__NULL__",this,getOffset())); //this.setType(new Type("__NULL__",this,getOffset()));
} }
// ino.end // ino.end

View File

@ -121,7 +121,7 @@ public class StringLiteral extends Literal
@Override @Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
this.set_Type(assumptions.getTypeFor(new RefType("String",this,0), this).getType()); this.set_Type(assumptions.checkType(new RefType("String",this,0), this));
return new ConstraintsSet(); return new ConstraintsSet();
} }

View File

@ -13,8 +13,6 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
// ino.end
// ino.class.BoundedGenericTypeVar.26464.description type=javadoc // ino.class.BoundedGenericTypeVar.26464.description type=javadoc
/** /**
@ -93,7 +91,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar
if(this.bounds != null){ if(this.bounds != null){
for(Type ev : this.bounds){ for(Type ev : this.bounds){
ConstraintType extendsType = ass.getTypeFor(ev, this); ConstraintType extendsType = ass.getTypeFor(ev, this);
if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this); //if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this);
ret.add(new SingleConstraint(ass.getTypeFor(this, this), extendsType )); ret.add(new SingleConstraint(ass.getTypeFor(this, this), extendsType ));
} }
} }

View File

@ -6,7 +6,7 @@ import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import sun.reflect.generics.reflectiveObjects.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
public class FreshWildcardType extends Type { public class FreshWildcardType extends Type {

View File

@ -268,6 +268,7 @@ public class RefType extends Type implements IMatchable
// ino.end // ino.end
public void setName( JavaClassName name ){ public void setName( JavaClassName name ){
if(name == null)throw new NullPointerException();
this.name = name; this.name = name;
} }
@ -800,16 +801,16 @@ public class RefType extends Type implements IMatchable
@Override @Override
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){ public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
//Der RefType muss zusätzlich seine Parameter prüfen.
Vector<ConstraintType> parameterList = new Vector<>();
Vector<Type> parameterList2 = new Vector<>();
if(this.parameter!=null)for(Type param : this.parameter){
ConstraintType ct = param.TYPE(ass, parent);
parameterList.add(ct);
parameterList2.add(ct.getType());
}
this.parameter = parameterList2;
ConstraintType t = super.TYPE(ass,parent); ConstraintType t = super.TYPE(ass,parent);
//((RefType)t.getType()).set_ParaList(this.get_ParaList());
return t;
}
@Override
public Type checkTYPE(TypeAssumptions ass, SyntaxTreeNode method) {
Type t = ass.checkType(this, parent);
if(t==null)
throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent);
return t; return t;
} }

View File

@ -5,7 +5,6 @@ package de.dhbwstuttgart.syntaxtree.type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import de.dhbwstuttgart.bytecode.JVMCode; import de.dhbwstuttgart.bytecode.JVMCode;
import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.parser.JavaClassName;
@ -19,9 +18,9 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
//TODO: Die Klasse Type muss abstract werden!
// ino.class.Type.26716.declaration // ino.class.Type.26716.declaration
public class Type extends SyntaxTreeNode implements IItemWithOffset public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
// ino.end // ino.end
// ino.class.Type.26716.body // ino.class.Type.26716.body
{ {
@ -181,6 +180,7 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset
if(obj instanceof Type){ if(obj instanceof Type){
// String name2 = ((Type)obj).printJavaCode(new ResultSet()).toString(); // String name2 = ((Type)obj).printJavaCode(new ResultSet()).toString();
//return printJavaCode(new ResultSet()).toString().equals(name2); //return printJavaCode(new ResultSet()).toString().equals(name2);
if(((Type)obj).name == null)return false; //Auch wenn der Name dieses Typs auch null ist. Typen sind nur gleich wenn sie einen gleichen Namen haben, welcher nicht null ist.
return ((Type)obj).name.equals(name); return ((Type)obj).name.equals(name);
} }
else{ else{
@ -200,7 +200,7 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset
// ino.end // ino.end
// ino.method.clone.26768.body // ino.method.clone.26768.body
{ {
return new Type(this.getName().toString(), this.getParent(),getOffset()); return new RefType(this.getName().toString(), this.getParent(),getOffset());
} }
// ino.end // ino.end
@ -318,5 +318,9 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset
return new Vector<>(); return new Vector<>();
} }
public Type checkTYPE(TypeAssumptions ass, SyntaxTreeNode method){
return this;
}
} }
// ino.end // ino.end

View File

@ -3,7 +3,8 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import sun.reflect.generics.reflectiveObjects.NotImplementedException; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
/** /**
* Stellt eine Wildcard in Java dar. * Stellt eine Wildcard in Java dar.

View File

@ -1,6 +1,7 @@
package de.dhbwstuttgart.typeinference; package de.dhbwstuttgart.typeinference;
import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
public class ConstraintType{ public class ConstraintType{
@ -18,5 +19,4 @@ public class ConstraintType{
public Type getType() { public Type getType() {
return t; return t;
} }
} }

View File

@ -4,7 +4,9 @@ import java.util.Vector;
import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
@ -21,14 +23,15 @@ public class FunNInterface extends Class{
//TODO: getType muss einen Typ mit der ParameterListe zurückliefern. //TODO: getType muss einen Typ mit der ParameterListe zurückliefern.
private Vector<GenericTypeVar> gtvparalist; //private Vector<GenericTypeVar> gtvparalist;
/** /**
* Ein FunN-Interface enthält nur eine Methode (namens apply). Ist also ein Funktionales Interface. * Ein FunN-Interface enthält nur eine Methode (namens apply). Ist also ein Funktionales Interface.
* @param N - Die Anzahl der Parameter der apply-Methode. Beispiel N = 1 ergibt <code>R apply(T1 par1);</code> * @param N - Die Anzahl der Parameter der apply-Methode. Beispiel N = 1 ergibt <code>R apply(T1 par1);</code>
*/ */
public FunNInterface(int N) { public FunNInterface(int N) {
super("Fun"+N, 0); super("Fun"+N, null, new Modifiers(), FunNInterface.makeParaList(N));
/*
GenericTypeVar gtv; GenericTypeVar gtv;
Vector<Type> paralist = new Vector<>(); Vector<Type> paralist = new Vector<>();
gtv = new GenericTypeVar("R",this, 0); gtv = new GenericTypeVar("R",this, 0);
@ -43,6 +46,16 @@ public class FunNInterface extends Class{
//paralist.add(TypePlaceholder.fresh()); //paralist.add(TypePlaceholder.fresh());
} }
this.set_ParaList(paralist); this.set_ParaList(paralist);
*/
}
private static Vector<String> makeParaList(int n) {
Vector<String> ret = new Vector<>();
ret.add("R");
for(int i = 1; i<=n;i++){
ret.add("T"+i);
}
return ret;
} }
/** /**
@ -54,7 +67,7 @@ public class FunNInterface extends Class{
TypeAssumptions ret = new TypeAssumptions(); TypeAssumptions ret = new TypeAssumptions();
ret.addAssumption(new MethodAssumption(this.getApplyFunction(), this)); ret.addAssumption(new MethodAssumption(this.getApplyFunction(), this));
ret.addClassAssumption(new ClassAssumption(this)); ret.addClassAssumption(new ClassAssumption(this));
for(GenericTypeVar gtv : this.gtvparalist)ret.addGenericVarAssumption(gtv); for(GenericTypeVar gtv : this.getGenericParameter())ret.addGenericVarAssumption(gtv);
return ret; return ret;
} }

View File

@ -15,7 +15,7 @@ public class FunNMethod extends Method{
* *
* @param N - Anzahl der Parameter (Beispiel: Fun2<R, T1, T2>) * @param N - Anzahl der Parameter (Beispiel: Fun2<R, T1, T2>)
*/ */
public FunNMethod(Vector<Type> paralist){ public FunNMethod(Vector<? extends Type> paralist){
super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode
int N = paralist.size(); //In der paraliste ist der erste Parameter der Rückgabetyp int N = paralist.size(); //In der paraliste ist der erste Parameter der Rückgabetyp
this.setType(paralist.firstElement()); this.setType(paralist.firstElement());

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference;
import java.util.Vector; import java.util.Vector;
import de.dhbwstuttgart.logger.TypinferenzLog;
import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -86,7 +87,7 @@ public class OderConstraint{
if(!unify.unify(cons.getConstraintPairs()).isEmpty()){ if(!unify.unify(cons.getConstraintPairs()).isEmpty()){
filteredConstraints.add(cons); filteredConstraints.add(cons);
}else{ }else{
System.out.println("Ausgesondertes Constraint: "+cons); TypinferenzLog.debug("Ausgesondertes Constraint: "+cons);
} }
} }
this.oderConstraintPairs = filteredConstraints; this.oderConstraintPairs = filteredConstraints;

View File

@ -163,7 +163,7 @@ public class TypeAssumptions {
} }
//Ebenso wie die Generischen Variablen: //Ebenso wie die Generischen Variablen:
for(GenericVarAssumption ass : this.genericVarAssumptions){ for(GenericVarAssumption ass : this.genericVarAssumptions){
if(ass.getIdentifier().equals(variableName))return ass.getAssumedType();
} }
//und zuletzt die Felder der Klasse in dessen Namensraum sich dieses AssumptionSet befindet. //und zuletzt die Felder der Klasse in dessen Namensraum sich dieses AssumptionSet befindet.
@ -173,8 +173,8 @@ public class TypeAssumptions {
} }
} }
//Wird keine Assumption gefunden, muss ein Fehler vorliegen: //Wird keine Assumption gefunden, muss ein Fehler vorliegen:
//throw new TypeinferenceException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden"); throw new TypeinferenceException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden", inScope);
return null; //return null;
} }
/** /**
@ -300,7 +300,20 @@ public class TypeAssumptions {
if(match && t instanceof RefType){ if(match && t instanceof RefType){
RefType tr = (RefType)t; RefType tr = (RefType)t;
RefType ret = ass.getAssumedClass().getType(); //Dadurch erhält der RefType den vollen Namen (bsp. java.lang.Integer) RefType ret = ass.getAssumedClass().getType(); //Dadurch erhält der RefType den vollen Namen (bsp. java.lang.Integer)
ret.set_ParaList(tr.getParaList());
//Falls der RefType mit Parametern angegeben wurde, so müssen diese erhalten bleiben:
if(tr.get_ParaList()!=null && tr.getParaList().size()>0){
ret.set_ParaList(tr.getParaList());
}
//Der RefType muss zusätzlich seine Parameter prüfen.
Vector<Type> parameterList = new Vector<>();
if(ret.get_ParaList()!=null)for(Type param : ret.get_ParaList()){
ConstraintType ct = param.TYPE(this, inNode);
parameterList.add(ct.getType());
}
ret.set_ParaList(parameterList);
return new ConstraintType(ret); return new ConstraintType(ret);
} }
} }
@ -374,6 +387,12 @@ public class TypeAssumptions {
return this.classAssumptions; return this.classAssumptions;
} }
public Type checkType(RefType type, SyntaxTreeNode parent) {
ConstraintType t = this.getTypeFor(type, parent); //Richtigkeit des Typnahmensprüfen
type.setName(t.getType().getName()); //Und diesen auf den Typ anwenden
return t.getType();
}
/** /**
* Prüft einen Typ auf das vorhandensein in den BasicAssumptions. * Prüft einen Typ auf das vorhandensein in den BasicAssumptions.
* Dabei werden alle Konstruktoren nach diesem Typ durchsucht. Denn jede Klasse hat einen Konstruktor und der muss in den TypeAssumptions vorhanden sein. * Dabei werden alle Konstruktoren nach diesem Typ durchsucht. Denn jede Klasse hat einen Konstruktor und der muss in den TypeAssumptions vorhanden sein.

View File

@ -74,8 +74,8 @@ public class FC_TTO
public void generateFullyNamedTypes(TypeAssumptions ass) { public void generateFullyNamedTypes(TypeAssumptions ass) {
for(Pair p : this.FC){ for(Pair p : this.FC){
p.TA1 = ass.getTypeFor(p.TA1, null).getType(); p.TA1 = ass.getTypeFor(p.TA1, p.TA1.getParent()).getType();
p.TA2 = ass.getTypeFor(p.TA2, null).getType(); p.TA2 = ass.getTypeFor(p.TA2, p.TA2.getParent()).getType();
} }
} }
} }

View File

@ -10,7 +10,7 @@ public class LambdaTest24 {
@Test @Test
public void run(){ public void run(){
Vector<String> mustContain = new Vector<String>(); Vector<String> mustContain = new Vector<String>();
//mustContain.add("Matrix ret"); mustContain.add("Fun2");
MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain);
} }
} }

View File

@ -4,7 +4,7 @@ import java.util.Vector;
import org.junit.Test; import org.junit.Test;
public class ypedMatrixSimpleTest { public class TypedMatrixSimpleTest {
private static final String TEST_FILE = "TypedMatrixSimpleTest.jav"; private static final String TEST_FILE = "TypedMatrixSimpleTest.jav";
@Test @Test

View File

@ -15,7 +15,7 @@ class Matrix extends Vector<Vector<Integer>> {
Integer j; Integer j;
j = 0; j = 0;
while(j < this.size()) { while(j < this.size()) {
erg; Integer erg;
erg = 0; erg = 0;
Integer k; Integer k;
k = 0; k = 0;