From 2b33576488baf251ccd8c351fc5f701e2b271008 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 8 Oct 2014 19:00:17 +0200 Subject: [PATCH] Finite Closure ohne Subtypes. checkType statt TYPE --- .../dhbwstuttgart/parser/JavaClassName.java | 1 + src/de/dhbwstuttgart/syntaxtree/Class.java | 34 +++++++---- .../syntaxtree/FormalParameter.java | 3 +- src/de/dhbwstuttgart/syntaxtree/Method.java | 4 +- .../dhbwstuttgart/syntaxtree/SourceFile.java | 56 ++++++++++++------- .../syntaxtree/statement/BoolLiteral.java | 2 +- .../syntaxtree/statement/DoubleLiteral.java | 2 +- .../syntaxtree/statement/IntLiteral.java | 2 +- .../syntaxtree/statement/LocalOrFieldVar.java | 3 +- .../syntaxtree/statement/LocalVarDecl.java | 2 +- .../syntaxtree/statement/NewClass.java | 44 +-------------- .../syntaxtree/statement/Null.java | 2 +- .../syntaxtree/statement/StringLiteral.java | 2 +- .../type/BoundedGenericTypeVar.java | 4 +- .../syntaxtree/type/FreshWildcardType.java | 2 +- .../syntaxtree/type/RefType.java | 19 ++++--- .../dhbwstuttgart/syntaxtree/type/Type.java | 12 ++-- .../syntaxtree/type/WildcardType.java | 3 +- .../typeinference/ConstraintType.java | 2 +- .../typeinference/FunNInterface.java | 19 ++++++- .../typeinference/FunNMethod.java | 2 +- .../typeinference/OderConstraint.java | 3 +- .../assumptions/TypeAssumptions.java | 27 +++++++-- .../typeinference/unify/FC_TTO.java | 4 +- .../TypeInsertTests/LambdaTest24.java | 2 +- ...leTest.java => TypedMatrixSimpleTest.java} | 2 +- .../TypeInsertTests/TypedMatrixTest.jav | 2 +- 27 files changed, 143 insertions(+), 117 deletions(-) rename test/plugindevelopment/TypeInsertTests/{ypedMatrixSimpleTest.java => TypedMatrixSimpleTest.java} (90%) diff --git a/src/de/dhbwstuttgart/parser/JavaClassName.java b/src/de/dhbwstuttgart/parser/JavaClassName.java index dbb87943..31609fe3 100644 --- a/src/de/dhbwstuttgart/parser/JavaClassName.java +++ b/src/de/dhbwstuttgart/parser/JavaClassName.java @@ -17,6 +17,7 @@ public class JavaClassName { private PackageName packageName; public JavaClassName(String name){ + if(name == null)throw new NullPointerException(); String[] names = name.split("[.]"); boolean match = true; if(names.length == 1){ diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index c2a9dc2f..a33f3d76 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -112,7 +112,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit private Block class_block; // ino.end // ino.attribute.paralist.23023.declaration - private Vector paralist = new Vector(); // Parameterliste 'class xy{}' wird gespeichert + //private Vector paralist = new Vector(); // Parameterliste 'class xy{}' wird gespeichert // ino.end // ino.attribute.parahash.23026.declaration private Hashtable parahash = new Hashtable(); // 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){ this(name,mod,offset); - this.superClass = superClass; + if(superClass == null)this.superClass = new Class("Object",-1).getType(); } // ino.method.Class.23044.definition @@ -247,7 +247,15 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } if (vector != null) setSuperInterfaces(vector); if (paralist != null){ - this.set_ParaList(paralist); + //this.set_ParaList(paralist); + Vector 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; @@ -264,7 +272,6 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end - public Vector getFields() { return fielddecl; @@ -308,7 +315,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end - + /* // ino.method.complete_paralist.23062.definition public Vector complete_paralist(boolean ext) // ino.end @@ -327,7 +334,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit return this.paralist; } // ino.end - + */ /** @@ -478,6 +485,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end + /* // ino.method.set_ParaList.23098.definition public void set_ParaList(Vector para) // ino.end @@ -486,13 +494,15 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit this.paralist = para; } // ino.end - + */ + // ino.method.get_ParaList.23101.definition - public Vector get_ParaList() + public Vector get_ParaList() // ino.end // ino.method.get_ParaList.23101.body { - return this.paralist; + //if(this.paralist == null)return new Vector(); + return this.getGenericParameter(); } // ino.end @@ -660,10 +670,10 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit 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 } - 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 } @@ -1193,10 +1203,12 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } if(this.genericClassParameters == null)this.setGenericParameter(new GenericDeclarationList(new Vector(), 0)); + /*//Nicht mehr notwendig, Generische Klassenparameter werden nun immer direkt in die genericClassParameters gespeichert. for(Type t : this.get_ParaList()){ if(t instanceof GenericTypeVar)this.genericClassParameters.add((GenericTypeVar)t); else this.genericClassParameters.add(new GenericTypeVar(t.get_Name(),this,-1)); } + */ for(Type t : this.get_ParaList()){ t.parserPostProcessing(this); } diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index cb726848..47101ad5 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -6,6 +6,7 @@ package de.dhbwstuttgart.syntaxtree; import java.util.Vector; import org.apache.log4j.Logger; + import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.syntaxtree.misc.DeclId; @@ -15,10 +16,10 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.Typeable; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; // ino.class.FormalParameter.23391.declaration public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeInsertable diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index db84fb99..9b0d5bba 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -527,7 +527,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable } //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)&& !(this.returntype instanceof mycompiler.mytype.Void)){//Sonderfall der Methode: Ihr Typ darf Void definiert werden. @@ -540,7 +540,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable //Die Parameter zu den Assumptions hinzufügen: if(this.parameterlist!=null)for(FormalParameter param : this.parameterlist){ - param.setType(param.getType().TYPE(localAss, this).getType()); + param.setType(param.getType().checkTYPE(localAss, this)); /* if(param.getType() instanceof RefType) { diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 623a4ca4..f98cf230 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -305,19 +305,21 @@ public class SourceFile // Menge FC bilden Vector vFC = new Vector(); // Menge FC - TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports); + TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports, false); globalAssumptions.add(this.getPublicFieldAssumptions()); // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen + Vector basicAssumptionsClassVector = new Vector<>(); //die Klassen aus den BasicAssumptions for(ClassAssumption cAss : ass.getClassAssumptions()){ Type t1 = cAss.getAssumedClass().getType(); Type t2 = cAss.getAssumedClass().getSuperClass(); Pair p = new Pair(t1, t2); - System.out.println("FCPair: "+p); - if(! t1.equals(t2)){ - vFC.add(p); //Um FC_TTO darf kein T <. T stehen. + //System.out.println("FCPair: "+p); + if(! t1.equals(t2)){//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{ - 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 ); - FC_TTO fctto = new FC_TTO(vFC, tto,KlassenVektor); + Vector KlassenVektorunImportierteKlassen = new Vector<>(); + KlassenVektorunImportierteKlassen.addAll(basicAssumptionsClassVector); + KlassenVektorunImportierteKlassen.addAll(KlassenVektor); + + FC_TTO fctto = new FC_TTO(vFC, tto, KlassenVektorunImportierteKlassen); return fctto; } - // ino.end public TypeAssumptions getPublicFieldAssumptions(){ TypeAssumptions publicAssumptions = new TypeAssumptions(null); @@ -666,7 +671,7 @@ public class SourceFile } //Assumptions der importierten Klassen sammeln: - TypeAssumptions importAssumptions = this.makeBasicAssumptionsFromJRE(imports); + TypeAssumptions importAssumptions = this.makeBasicAssumptionsFromJRE(imports, true); globalAssumptions.add(importAssumptions); typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions); @@ -1094,8 +1099,13 @@ public class SourceFile return ret; }*/ - // ino.method.makeBasicAssumptionsFromJRE.21409.definition - private TypeAssumptions makeBasicAssumptionsFromJRE(Vector 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 imports, boolean withSubtypes) // ino.end // ino.method.makeBasicAssumptionsFromJRE.21409.body { @@ -1132,26 +1142,30 @@ public class SourceFile String className=x.getName(); //Ermittle die Superklasse: - Class sClass; - sClass = getSuperClassOfJREClass(x, basicAssumptions); + Class sClass = new Class("Object",0); + if(withSubtypes)sClass = getSuperClassOfJREClass(x, basicAssumptions); - Class parentClass = new Class(className, sClass.getType(),mod , 0); - - // Generische Typen erzeugen + // Namen von Generische Typen erzeugen Hashtable jreSpiderRegistry=new Hashtable(); - Vector typeGenPara = new Vector(); + Vector typeGenPara = new Vector(); for(int j=0;j0){ //auskommentiert von Andreas Stadelmeier: //basicAssumptions.addGenericTypeVars(className, typeGenPara); - parentClass.set_ParaList((Vector)typeGenPara);//myCl.set_ParaList((Vector)typeGenPara); + //parentClass.set_ParaList((Vector)typeGenPara);//myCl.set_ParaList((Vector)typeGenPara); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java index 7516e1f2..7bbaf757 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java @@ -126,7 +126,7 @@ public class BoolLiteral extends Literal @Override 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(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java index b8fec59f..55a3d430 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java @@ -162,7 +162,7 @@ public class DoubleLiteral extends Literal @Override 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(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java index 7d9f5c85..d251cd7b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java @@ -160,7 +160,7 @@ public class IntLiteral extends Literal public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); //this.setType(new IntegerType()); - this.set_Type(assumptions.getTypeFor(new RefType("java.lang.Integer",this,-1), this).getType()); + this.set_Type(assumptions.checkType(new RefType("java.lang.Integer",this,-1), this)); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java index 72907149..d773f48c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java @@ -177,7 +177,8 @@ public class LocalOrFieldVar extends Expr //gibt es eine Assumption für den die LocalOrFieldVar-Variablen, dann folgendes ausführen: 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); - this.setType(thisTypeAssumption); + Type thisType = thisTypeAssumption.checkTYPE(assumptions, this); + this.setType(thisType); //ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable())); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index 3da735a1..855f9dde 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -378,7 +378,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable ConstraintsSet ret = new ConstraintsSet(); if((this.getType() instanceof RefType)){ Type replaceType = null; - replaceType = assumptions.getTypeFor((RefType)this.getType(), this).getType(); + replaceType = assumptions.checkType((RefType)this.getType(), this); this.setType(replaceType); } assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird. diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index 8270ab74..d279ebff 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -88,46 +88,6 @@ public class NewClass extends Expr } // ino.end - // ino.method.sc_check.25852.definition - public void sc_check(Vector classname, Hashtable bh, Hashtable ch, boolean ext, Hashtable parach, 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 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 public void set_ArgumentList(ArgumentList al) // 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){ // ret.add(arg.TYPEExpr(assumptions)); //} - - this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),this,0), this).getType()); + Type thisT = assumptions.checkType(new RefType(this.get_Name(),this,0), (SyntaxTreeNode)this); + this.setType(thisT); /* diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Null.java b/src/de/dhbwstuttgart/syntaxtree/statement/Null.java index 66bc356c..a02121ac 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Null.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Null.java @@ -42,7 +42,7 @@ public class Null extends Literal // ino.method.Null.25926.body { super(-1,-1); - this.setType(new Type("__NULL__",this,getOffset())); + //this.setType(new Type("__NULL__",this,getOffset())); } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java index 56fbe6ac..a1ed579f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java @@ -121,7 +121,7 @@ public class StringLiteral extends Literal @Override 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(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java index d75715df..ebe21b0d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java @@ -13,8 +13,6 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; -// ino.end // ino.class.BoundedGenericTypeVar.26464.description type=javadoc /** @@ -93,7 +91,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar if(this.bounds != null){ for(Type ev : this.bounds){ 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 )); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java index 364681db..829f0f40 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java @@ -6,7 +6,7 @@ import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; public class FreshWildcardType extends Type { diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 56060e9c..ba8178dd 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -268,6 +268,7 @@ public class RefType extends Type implements IMatchable // ino.end public void setName( JavaClassName name ){ + if(name == null)throw new NullPointerException(); this.name = name; } @@ -800,16 +801,16 @@ public class RefType extends Type implements IMatchable @Override public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){ - //Der RefType muss zusätzlich seine Parameter prüfen. - Vector parameterList = new Vector<>(); - Vector 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); + //((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; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Type.java b/src/de/dhbwstuttgart/syntaxtree/type/Type.java index 1c178f2b..ef26b1e7 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Type.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Type.java @@ -5,7 +5,6 @@ package de.dhbwstuttgart.syntaxtree.type; import java.util.ArrayList; import java.util.Vector; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; import de.dhbwstuttgart.bytecode.JVMCode; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.parser.JavaClassName; @@ -19,9 +18,9 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; - +//TODO: Die Klasse Type muss abstract werden! // ino.class.Type.26716.declaration -public class Type extends SyntaxTreeNode implements IItemWithOffset +public abstract class Type extends SyntaxTreeNode implements IItemWithOffset // ino.end // ino.class.Type.26716.body { @@ -181,6 +180,7 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset if(obj instanceof Type){ // String name2 = ((Type)obj).printJavaCode(new ResultSet()).toString(); //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); } else{ @@ -200,7 +200,7 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset // ino.end // 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 @@ -317,6 +317,10 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset public Vector getChildren() { return new Vector<>(); } + + public Type checkTYPE(TypeAssumptions ass, SyntaxTreeNode method){ + return this; + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java index 0a28db06..56312b90 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java @@ -3,7 +3,8 @@ package de.dhbwstuttgart.syntaxtree.type; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; 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. diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintType.java b/src/de/dhbwstuttgart/typeinference/ConstraintType.java index f4ff991a..09ccb730 100644 --- a/src/de/dhbwstuttgart/typeinference/ConstraintType.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintType.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference; import de.dhbwstuttgart.syntaxtree.type.*; +import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; public class ConstraintType{ @@ -18,5 +19,4 @@ public class ConstraintType{ public Type getType() { return t; } - } diff --git a/src/de/dhbwstuttgart/typeinference/FunNInterface.java b/src/de/dhbwstuttgart/typeinference/FunNInterface.java index c41c228c..fcc6b452 100644 --- a/src/de/dhbwstuttgart/typeinference/FunNInterface.java +++ b/src/de/dhbwstuttgart/typeinference/FunNInterface.java @@ -4,7 +4,9 @@ import java.util.Vector; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Class; +import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; 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.assumptions.ClassAssumption; @@ -21,14 +23,15 @@ public class FunNInterface extends Class{ //TODO: getType muss einen Typ mit der ParameterListe zurückliefern. - private Vector gtvparalist; + //private Vector gtvparalist; /** * Ein FunN-Interface enthält nur eine Methode (namens apply). Ist also ein Funktionales Interface. * @param N - Die Anzahl der Parameter der apply-Methode. Beispiel N = 1 ergibt R apply(T1 par1); */ public FunNInterface(int N) { - super("Fun"+N, 0); + super("Fun"+N, null, new Modifiers(), FunNInterface.makeParaList(N)); + /* GenericTypeVar gtv; Vector paralist = new Vector<>(); gtv = new GenericTypeVar("R",this, 0); @@ -43,8 +46,18 @@ public class FunNInterface extends Class{ //paralist.add(TypePlaceholder.fresh()); } this.set_ParaList(paralist); + */ } + private static Vector makeParaList(int n) { + Vector ret = new Vector<>(); + ret.add("R"); + for(int i = 1; i<=n;i++){ + ret.add("T"+i); + } + return ret; + } + /** * @return Im Falle von einem FunN-Interface ist dies die apply-Methode */ @@ -54,7 +67,7 @@ public class FunNInterface extends Class{ TypeAssumptions ret = new TypeAssumptions(); ret.addAssumption(new MethodAssumption(this.getApplyFunction(), this)); ret.addClassAssumption(new ClassAssumption(this)); - for(GenericTypeVar gtv : this.gtvparalist)ret.addGenericVarAssumption(gtv); + for(GenericTypeVar gtv : this.getGenericParameter())ret.addGenericVarAssumption(gtv); return ret; } diff --git a/src/de/dhbwstuttgart/typeinference/FunNMethod.java b/src/de/dhbwstuttgart/typeinference/FunNMethod.java index 07b8acf8..cf056020 100644 --- a/src/de/dhbwstuttgart/typeinference/FunNMethod.java +++ b/src/de/dhbwstuttgart/typeinference/FunNMethod.java @@ -15,7 +15,7 @@ public class FunNMethod extends Method{ * * @param N - Anzahl der Parameter (Beispiel: Fun2) */ - public FunNMethod(Vector paralist){ + public FunNMethod(Vector paralist){ super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode int N = paralist.size(); //In der paraliste ist der erste Parameter der Rückgabetyp this.setType(paralist.firstElement()); diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index 47e21a0a..53fd06bb 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference; import java.util.Vector; +import de.dhbwstuttgart.logger.TypinferenzLog; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; @@ -86,7 +87,7 @@ public class OderConstraint{ if(!unify.unify(cons.getConstraintPairs()).isEmpty()){ filteredConstraints.add(cons); }else{ - System.out.println("Ausgesondertes Constraint: "+cons); + TypinferenzLog.debug("Ausgesondertes Constraint: "+cons); } } this.oderConstraintPairs = filteredConstraints; diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 9549e137..0285a545 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -163,7 +163,7 @@ public class TypeAssumptions { } //Ebenso wie die Generischen Variablen: 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. @@ -173,8 +173,8 @@ public class TypeAssumptions { } } //Wird keine Assumption gefunden, muss ein Fehler vorliegen: - //throw new TypeinferenceException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden"); - return null; + throw new TypeinferenceException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden", inScope); + //return null; } /** @@ -300,7 +300,20 @@ public class TypeAssumptions { if(match && t instanceof RefType){ RefType tr = (RefType)t; RefType ret = ass.getAssumedClass().getType(); //Dadurch erhält der RefType den vollen Namen (bsp. java.lang.Integer) - ret.set_ParaList(tr.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 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); } } @@ -374,6 +387,12 @@ public class TypeAssumptions { 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. * Dabei werden alle Konstruktoren nach diesem Typ durchsucht. Denn jede Klasse hat einen Konstruktor und der muss in den TypeAssumptions vorhanden sein. diff --git a/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java b/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java index b1e8fe69..440bbd50 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java +++ b/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java @@ -74,8 +74,8 @@ public class FC_TTO public void generateFullyNamedTypes(TypeAssumptions ass) { for(Pair p : this.FC){ - p.TA1 = ass.getTypeFor(p.TA1, null).getType(); - p.TA2 = ass.getTypeFor(p.TA2, null).getType(); + p.TA1 = ass.getTypeFor(p.TA1, p.TA1.getParent()).getType(); + p.TA2 = ass.getTypeFor(p.TA2, p.TA2.getParent()).getType(); } } } diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest24.java b/test/plugindevelopment/TypeInsertTests/LambdaTest24.java index 59de42e5..b3086da7 100644 --- a/test/plugindevelopment/TypeInsertTests/LambdaTest24.java +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest24.java @@ -10,7 +10,7 @@ public class LambdaTest24 { @Test public void run(){ Vector mustContain = new Vector(); - //mustContain.add("Matrix ret"); + mustContain.add("Fun2"); MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); } } diff --git a/test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java b/test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.java similarity index 90% rename from test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java rename to test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.java index d90e2627..2db27805 100644 --- a/test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java +++ b/test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.java @@ -4,7 +4,7 @@ import java.util.Vector; import org.junit.Test; -public class ypedMatrixSimpleTest { +public class TypedMatrixSimpleTest { private static final String TEST_FILE = "TypedMatrixSimpleTest.jav"; @Test diff --git a/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav b/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav index f2c5c3f5..c9bbd601 100644 --- a/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav +++ b/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav @@ -15,7 +15,7 @@ class Matrix extends Vector> { Integer j; j = 0; while(j < this.size()) { - erg; + Integer erg; erg = 0; Integer k; k = 0;