ConstuctorAssumption angefügt

This commit is contained in:
JanUlrich 2014-03-18 20:18:57 +01:00
parent 9d361072e3
commit d4b9ea9a73
27 changed files with 144 additions and 152 deletions

View File

@ -42,9 +42,10 @@ import org.apache.log4j.xml.DOMConfigurator;
import com.sun.corba.se.spi.orbutil.fsm.Guard.Result; import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
import com.sun.org.apache.xerces.internal.impl.xs.identity.Field; import com.sun.org.apache.xerces.internal.impl.xs.identity.Field;
import typinferenz.TypinferenzException;
// ino.end // ino.end
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.ParserException;
import typinferenz.exceptions.TypinferenzException;
@ -752,8 +753,8 @@ public class MyCompiler implements MyCompilerAPI
try { try {
srcFile = (SourceFile) parser.yyparse( scanner ); srcFile = (SourceFile) parser.yyparse( scanner );
} catch (IOException | yyException e) { } catch (IOException | yyException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
if(e instanceof yyException)throw new ParserException((yyException)e);
} }
////////////////////////////////////// //////////////////////////////////////
// Postprocessing: // Postprocessing:
@ -786,7 +787,6 @@ public class MyCompiler implements MyCompilerAPI
} }
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
@ -812,7 +812,6 @@ public class MyCompiler implements MyCompilerAPI
reader.close(); reader.close();
gesamterSrc += fileData.toString() + "\n"; // Alle Dateien nacheinander hintereinander anhängen... gesamterSrc += fileData.toString() + "\n"; // Alle Dateien nacheinander hintereinander anhängen...
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
throw new TypinferenzException("Die übergebenen Dateien konnten nicht zum Parsen eingelesen werden."); throw new TypinferenzException("Die übergebenen Dateien konnten nicht zum Parsen eingelesen werden.");
} }

View File

@ -43,9 +43,9 @@ import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
import typinferenz.ConstraintsSet; import typinferenz.ConstraintsSet;
import typinferenz.FunN; import typinferenz.FunN;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.TypinferenzException;
import typinferenz.UndConstraint; import typinferenz.UndConstraint;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
@ -741,7 +741,7 @@ public class SourceFile
TypeAssumptions basics; TypeAssumptions basics;
basics = this.makeBasicAssumptions(); //TODO: Diese Funktion ändern, dass nur noch TypeAssumptions zurückgegeben werden. Diese sind wichtig, da hier die Standard-Library von Java als Assumptions generiert wird. basics = this.makeBasicAssumptions();
//A.addElement(basics); //auskommentiert von Andreas Stadelmeier //A.addElement(basics); //auskommentiert von Andreas Stadelmeier
@ -1376,7 +1376,9 @@ public class SourceFile
return foo; return foo;
*/ */
return new TypeAssumptions(null); //TODO: Diese TypeAssumptions mit basic-Assumptions füllen TypeAssumptions ret = new TypeAssumptions();
return ret; //TODO: Diese TypeAssumptions mit basic-Assumptions füllen
} }
// ino.end // ino.end
@ -1515,7 +1517,6 @@ public class SourceFile
@Override @Override
public SyntaxTreeNode getParent() { public SyntaxTreeNode getParent() {
// TODO Auto-generated method stub
return null; return null;
} }

View File

@ -2,7 +2,7 @@ package mycompiler;
import java.util.Vector; import java.util.Vector;
import typinferenz.TypinferenzException; import typinferenz.exceptions.TypinferenzException;
import mycompiler.myclass.Class; import mycompiler.myclass.Class;
public abstract class SyntaxTreeNode { public abstract class SyntaxTreeNode {

View File

@ -57,15 +57,16 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException; import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.ConstraintsSet; import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult; import typinferenz.JavaCodeResult;
import typinferenz.OderConstraint; import typinferenz.OderConstraint;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.TypinferenzException;
import typinferenz.UndConstraint; import typinferenz.UndConstraint;
import typinferenz.FunN; import typinferenz.FunN;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
@ -1156,11 +1157,6 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
JavaCodeResult classBodyCode = new JavaCodeResult(); JavaCodeResult classBodyCode = new JavaCodeResult();
if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" "); if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" ");
if(superclassid == null || superclassid.get_Name().size()<1){
int superclassidOffset = superclassid == null ? 0 : superclassid.getOffset();
superclassid = new UsedId("Object", superclassidOffset);
}
classBodyCode.attach(this.name + " extends ").attach(superclassid.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach("\n"); classBodyCode.attach(this.name + " extends ").attach(superclassid.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach("\n");
@ -1262,6 +1258,12 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
public void parserPostProcessing(SyntaxTreeNode parent) { public void parserPostProcessing(SyntaxTreeNode parent) {
super.parserPostProcessing(parent); super.parserPostProcessing(parent);
//Wenn keine Superklasse, dann erbt die Klasse zwangsweise von Object:
if(superclassid == null || superclassid.get_Name().size()<1){
int superclassidOffset = superclassid == null ? 0 : superclassid.getOffset();
superclassid = new UsedId("Object", superclassidOffset);
}
//Alle Methoden auf Konstruktoren durchsuchen und diese umwandeln: //Alle Methoden auf Konstruktoren durchsuchen und diese umwandeln:
Vector<Field> tempFields = new Vector<Field>(); Vector<Field> tempFields = new Vector<Field>();
for(Field f : this.getFields()){ for(Field f : this.getFields()){

View File

@ -15,8 +15,10 @@ import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult; import typinferenz.JavaCodeResult;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.SingleConstraint; import typinferenz.SingleConstraint;
import typinferenz.TypinferenzException; import typinferenz.assumptions.ConstructorAssumption;
import typinferenz.assumptions.MethodAssumption;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
public class Constructor extends Method { public class Constructor extends Method {
private Method methode; private Method methode;
@ -238,10 +240,17 @@ public class Constructor extends Method {
@Override @Override
public TypeAssumptions createTypeAssumptions(Class classmember) { public TypeAssumptions createTypeAssumptions(Class classmember) {
Class parentClass = this.getParentClass();
return this.methode.createTypeAssumptions(classmember); TypeAssumptions ret = new TypeAssumptions();
ret.addConstructorAssumption(new ConstructorAssumption(this, parentClass));
return ret;
} }
@Override
public SyntaxTreeNode getParent(){
return this.methode.getParent();
}
@Override @Override
public void parserPostProcessing(SyntaxTreeNode parent) { public void parserPostProcessing(SyntaxTreeNode parent) {

View File

@ -7,9 +7,9 @@ import typinferenz.JavaCodeResult;
import typinferenz.OderConstraint; import typinferenz.OderConstraint;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.SingleConstraint; import typinferenz.SingleConstraint;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.FieldAssumption; import typinferenz.assumptions.FieldAssumption;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.SyntaxTreeNode; import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile; import mycompiler.mybytecode.ClassFile;
import mycompiler.myexception.JVMCodeException; import mycompiler.myexception.JVMCodeException;
@ -75,7 +75,7 @@ public class FieldDeclaration extends Field{
////////////////////////////// //////////////////////////////
TypeAssumptions assumptions = new TypeAssumptions(); TypeAssumptions assumptions = new TypeAssumptions();
/* /*
* TODO: Der Feld-Assumption muss ein TPH als Typ hinzugefügt werden, falls er Typlos initialisiert wurde. Dies kann auch der Type-Algorithmus der Inst/FieldVar - Klasse machen. * Der Feld-Assumption muss ein TPH als Typ hinzugefügt werden, falls er Typlos initialisiert wurde. Dies kann auch der Type-Algorithmus der Inst/FieldVar - Klasse machen.
* Wird das Feld mit einem Typ initialisiert so muss dieser auch in die Assumptions. * Wird das Feld mit einem Typ initialisiert so muss dieser auch in die Assumptions.
*/ */
if(this.getType() == null)throw new TypinferenzException("Der Typ eines Feldes darf nicht null sein"); if(this.getType() == null)throw new TypinferenzException("Der Typ eines Feldes darf nicht null sein");

View File

@ -22,12 +22,13 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException; import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.JavaCodeResult; import typinferenz.JavaCodeResult;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.Typeable; import typinferenz.Typeable;
import typinferenz.TypeInsertable; import typinferenz.TypeInsertable;
import typinferenz.TypinferenzException; import typinferenz.exceptions.TypinferenzException;
// ino.class.FormalParameter.23391.declaration // ino.class.FormalParameter.23391.declaration
public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementListener, Typeable, TypeInsertable public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementListener, Typeable, TypeInsertable

View File

@ -563,7 +563,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
@Override @Override
public JavaCodeResult printJavaCode(ResultSet resultSet) { public JavaCodeResult printJavaCode(ResultSet resultSet) {
JavaCodeResult ret = new JavaCodeResult(); JavaCodeResult ret = new JavaCodeResult();
ret.attach(this.getType().printJavaCode(resultSet)).attach(" ").attach(this.get_Method_Name()).attach("()\n"); //TODO: hier müssen auch noch die Parameter ausgegeben werden! ret.attach(this.getType().printJavaCode(resultSet)).attach(" ").attach(this.get_Method_Name()).attach("(").attach(this.getParameterList().printJavaCode(resultSet)).attach(")\n");
ret.attach(this.block.printJavaCode(resultSet)); ret.attach(this.block.printJavaCode(resultSet));
return ret; return ret;

View File

@ -7,7 +7,7 @@ import java.util.Vector;
import typinferenz.JavaCodeResult; import typinferenz.JavaCodeResult;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.TypinferenzException; import typinferenz.exceptions.TypinferenzException;
import mycompiler.IItemWithOffset; import mycompiler.IItemWithOffset;
import mycompiler.mybytecode.JVMCode; import mycompiler.mybytecode.JVMCode;
import mycompiler.mytype.Type; import mycompiler.mytype.Type;

View File

@ -32,14 +32,15 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException; import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.JavaCodeResult; import typinferenz.JavaCodeResult;
import typinferenz.SingleConstraint; import typinferenz.SingleConstraint;
import typinferenz.ConstraintsSet; import typinferenz.ConstraintsSet;
import typinferenz.FreshTypeVariable; import typinferenz.FreshTypeVariable;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;

View File

@ -10,9 +10,9 @@ import typinferenz.FreshTypeVariable;
import typinferenz.FunN; import typinferenz.FunN;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.Typeable; import typinferenz.Typeable;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.ParameterAssumption; import typinferenz.assumptions.ParameterAssumption;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.SyntaxTreeNode; import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile; import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute; import mycompiler.mybytecode.CodeAttribute;
@ -124,7 +124,7 @@ public class LambdaExpression extends Expr{
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet(); ConstraintsSet ret = new ConstraintsSet();
//Die Assumptions für die Parameter der LambdaExpression //Die Assumptions für die Parameter der LambdaExpression
TypeAssumptions ArgumentAssumptions = new TypeAssumptions(assumptions.getThisValue().getName()); TypeAssumptions ArgumentAssumptions = new TypeAssumptions(this.getParentClass().getName());
Vector<Type> paramTypes = new Vector<Type>(); Vector<Type> paramTypes = new Vector<Type>();
for(FormalParameter param : params.formalparameter){ for(FormalParameter param : params.formalparameter){

View File

@ -664,7 +664,6 @@ public class MethodCall extends Expr
*/ */
@Override @Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
//TODO hier muss unterschieden werden zwischen einem Konstruktor und einer Methode.
//Hier der Ablauf für einen Methodenaufruf: //Hier der Ablauf für einen Methodenaufruf:
ConstraintsSet ret = new ConstraintsSet(); ConstraintsSet ret = new ConstraintsSet();
//Der Return-Type des MEthodenaufrufs ist zunächst unbekannt: //Der Return-Type des MEthodenaufrufs ist zunächst unbekannt:

View File

@ -170,7 +170,8 @@ public class This extends Expr
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet(); ConstraintsSet ret = new ConstraintsSet();
//this.set_Type(new); //this.set_Type(new);
this.setType(assumptions.getThisValue());//Die Assumption für this als TypeVariable setzen. //this.setType(assumptions.getThisValue());//Die Assumption für this als TypeVariable setzen.
this.setType(new RefType(this.getParentClass().getName(),0));
return ret; return ret;
} }

View File

@ -15,8 +15,8 @@ import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout; import org.apache.log4j.PatternLayout;
import org.apache.log4j.SimpleLayout; import org.apache.log4j.SimpleLayout;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.MyCompiler; import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI; import mycompiler.MyCompilerAPI;
import mycompiler.mytype.Type; import mycompiler.mytype.Type;

View File

@ -11,8 +11,8 @@ import typinferenz.ConstraintsSet;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint; import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet; import typinferenz.TypeInsertSet;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.Pair; import mycompiler.mytype.Pair;
import mycompiler.mytype.RefType; import mycompiler.mytype.RefType;

View File

@ -59,8 +59,8 @@ public class OderConstraint{
@Override @Override
public String toString(){ public String toString(){
String ret = "["; String ret = "[";
for(Pair p : this.getConstraintPairs()){ for(UndConstraint p : this.getUndConstraints()){
ret += p.toString()+ ", "; ret += p.toString()+ "| ";
} }
return ret+"]"; return ret+"]";
} }

View File

@ -2,6 +2,7 @@ package typinferenz;
import java.util.Vector; import java.util.Vector;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.mytype.Pair; import mycompiler.mytype.Pair;
import mycompiler.mytype.RefType; import mycompiler.mytype.RefType;
import mycompiler.mytype.Type; import mycompiler.mytype.Type;

View File

@ -27,9 +27,15 @@ public class UndConstraint extends OderConstraint {
return ret; return ret;
} }
@Override
public String toString(){ public String toString(){
String ret = super.toString(); //String ret = super.toString();
return ret.replace(',', '|'); //return ret.replace('|', ',');
String ret = "[";
for(Pair p : this.getConstraintPairs()){
ret += p.toString()+ ", ";
}
return ret+"]";
} }
} }

View File

@ -5,7 +5,7 @@ import java.util.Vector;
import sun.reflect.generics.reflectiveObjects.NotImplementedException; import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.FunN; import typinferenz.FunN;
import typinferenz.TypinferenzException; import typinferenz.exceptions.TypinferenzException;
import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.RefType; import mycompiler.mytype.RefType;
import mycompiler.mytype.Type; import mycompiler.mytype.Type;
@ -155,6 +155,7 @@ public class CopyOfTypeAssumptions implements Iterable<CTypeAssumption> {
} }
//TODO: Dann die lokalen Variablen //TODO: Dann die lokalen Variablen
// ... (noch nicht implementiert) // ... (noch nicht implementiert)
//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.
for(CTypeAssumption ass : this.getInstVarAssumptions()){ for(CTypeAssumption ass : this.getInstVarAssumptions()){
if(ass.getIdentifier().equals(variableName))return ass.getAssumedType(); if(ass.getIdentifier().equals(variableName))return ass.getAssumedType();

View File

@ -1,14 +1,16 @@
package typinferenz.assumptions; package typinferenz.assumptions;
import java.util.Iterator; import java.util.Iterator;
import mycompiler.myclass.Class; import mycompiler.myclass.Class;
import java.util.Vector; import java.util.Vector;
import sun.reflect.generics.reflectiveObjects.NotImplementedException; import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.FunN; import typinferenz.FunN;
import typinferenz.FunNInterface; import typinferenz.FunNInterface;
import typinferenz.FunNMethod; import typinferenz.FunNMethod;
import typinferenz.TypinferenzException; import typinferenz.exceptions.TypinferenzException;
import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.RefType; import mycompiler.mytype.RefType;
import mycompiler.mytype.Type; import mycompiler.mytype.Type;
@ -46,6 +48,7 @@ public class TypeAssumptions {
private Vector<MethodAssumption> methodAssumptions = new Vector<MethodAssumption>(); private Vector<MethodAssumption> methodAssumptions = new Vector<MethodAssumption>();
private Vector<ConstructorAssumption> constructorAssumptions = new Vector<ConstructorAssumption>();
private Vector<FieldAssumption> fieldAssumptions = new Vector<FieldAssumption>(); private Vector<FieldAssumption> fieldAssumptions = new Vector<FieldAssumption>();
private Vector<LocalVarAssumption> localVarAssumptions = new Vector<LocalVarAssumption>(); private Vector<LocalVarAssumption> localVarAssumptions = new Vector<LocalVarAssumption>();
private Vector<ParameterAssumption> parameterAssumptions = new Vector<ParameterAssumption>(); private Vector<ParameterAssumption> parameterAssumptions = new Vector<ParameterAssumption>();
@ -67,7 +70,12 @@ public class TypeAssumptions {
public void addMethodAssumption(MethodAssumption mAss){ public void addMethodAssumption(MethodAssumption mAss){
this.methodAssumptions.add(mAss); this.methodAssumptions.add(mAss);
} }
public void addConstructorAssumption(
ConstructorAssumption constructorAssumption) {
this.constructorAssumptions.add(constructorAssumption);
}
public void addFieldAssumption(FieldAssumption ass){ public void addFieldAssumption(FieldAssumption ass){
this.fieldAssumptions.add(ass); this.fieldAssumptions.add(ass);
} }
@ -87,10 +95,11 @@ public class TypeAssumptions {
*/ */
public Vector<FieldAssumption> getFieldVars(String withName){ public Vector<FieldAssumption> getFieldVars(String withName){
//TODO: Implementieren //TODO: Implementieren
return null; return new Vector<FieldAssumption>();
} }
public Type getTypeOfFieldVar(String withName, Class inClass){ public Type getTypeOfFieldVar(String withName, Class inClass){
//TODO: Implementieren
return null; return null;
} }
@ -100,7 +109,8 @@ public class TypeAssumptions {
* @return * @return
*/ */
public Vector<MethodAssumption> getMethods(String withName){ public Vector<MethodAssumption> getMethods(String withName){
return null; //TODO: Implementieren
return new Vector<MethodAssumption>();
} }
/** /**
@ -109,6 +119,7 @@ public class TypeAssumptions {
* @return * @return
*/ */
public Type getTypeOfLocalVar(String withName){ public Type getTypeOfLocalVar(String withName){
//TODO: Implementieren
return null; return null;
} }
@ -243,9 +254,13 @@ public class TypeAssumptions {
return ret; return ret;
} }
public Type getThisValue() { @Deprecated
public Type getThisValue2() {
if(thisClassName == null)throw new TypinferenzException("Kein Wert für this vorhanden, in diesem Kontext");
return new RefType(thisClassName, 0); return new RefType(thisClassName, 0);
} }
} }

View File

@ -1,4 +1,4 @@
package typinferenz; package typinferenz.exceptions;
/** /**
* Eine RuntimeException, welche bei einem Fehler während des Typinferenzalgorithmus ausgelöst wird. * Eine RuntimeException, welche bei einem Fehler während des Typinferenzalgorithmus ausgelöst wird.

View File

@ -8,7 +8,8 @@ import java.util.Vector;
import mycompiler.MyCompiler; import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI; import mycompiler.MyCompilerAPI;
import mycompiler.mytypereconstruction.TypeinferenceResultSet; import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import typinferenz.TypinferenzException; import typinferenz.exceptions.TypinferenzException;
import java.util.*; import java.util.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;

View File

@ -2,7 +2,7 @@ class OverloadingTest{
var; var;
public Object clone(){ public clone(){
return this; return this;
} }
@ -14,7 +14,7 @@ class OverloadingTest{
class OverloadingTest2{ class OverloadingTest2{
public Object clone(){ public clone(){
return this; return this;
} }

View File

@ -1,123 +1,36 @@
Class DEBUG [Typeinference] Erstellte Assumptions: this: MatrixMethod Assumptions: Class DEBUG [Typeinference] Erstellte Assumptions: this: ThisTestMethod Assumptions:
[MethodAssumption: Matrix null { []] []
FieldVar Assumptions: FieldVar Assumptions:
[typinferenz.assumptions.FieldAssumption@15502c5e] [typinferenz.assumptions.FieldAssumption@6d657803]
LocalVar Assumptions: LocalVar Assumptions:
[] []
Parameter Assumptions: Parameter Assumptions:
[] []
Block DEBUG [Typeinference] Prozessing statement: null Return null (( [ f, ]) -> null { [null Return null (f.apply( [ null (this(null)), m, ]))])
Block DEBUG [Typeinference] Prozessing statement: null Return null (f.apply( [ null (this(null)), m, ]))
Block DEBUG [Typeinference] Prozessing statement: TPH K Return TPH G (f: TPH E.apply( [ Matrix (this(null)), m: TPH C, ]))
Block DEBUG [Typeinference] Prozessing statement: TPH L Return TPH F (( [ TPH E f, ]) -> TPH K { [TPH K Return TPH G (f: TPH E.apply( [ Matrix (this(null)), m: TPH C, ]))])
Class DEBUG [Typeinference] Erstellte Constraints: TPH A < TPH A Class DEBUG [Typeinference] Erstellte Constraints: TPH A < TPH A
[(TPH H <. TPH G), (Matrix <. TPH I), (TPH C <. TPH J), (TPH E <. FunN), ] ThisTest < TPH A
TPH G < TPH K
Fun1< TPH K, TPH E > < TPH F
TPH F < TPH L
Fun1< TPH L, TPH C > < TPH D
TPH D < TPH A
SourceFile DEBUG [Typeinference] Karthesisches Produkt der Constraints: [[(TPH A <. TPH A), (TPH H <. TPH G), (Matrix <. TPH I), (TPH C <. TPH J), (TPH E <. FunN), (TPH G <. TPH K), (Fun1< TPH K, TPH E > <. TPH F), (TPH F <. TPH L), (Fun1< TPH L, TPH C > <. TPH D), (TPH D <. TPH A)]] SourceFile DEBUG [Typeinference] Karthesisches Produkt der Constraints: [[(TPH A <. TPH A), (ThisTest <. TPH A)]]
SourceFile DEBUG [Typeinference] Unifiziertes Ergebnis: [[(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Matrix), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< ? super GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? super Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? super Matrix >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)]] SourceFile DEBUG [Typeinference] Unifiziertes Ergebnis: [[(TPH A = ThisTest)], [(TPH A = Object)]]
SourceFile DEBUG [Typeinference] SourceFile DEBUG [Typeinference]
JavaFiles: JavaFiles:
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Matrix), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)] SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH A = ThisTest)]
SourceFile DEBUG [Typeinference] class <K, C>Matrix extends Vector<Vector<Integer>> SourceFile DEBUG [Typeinference] class ThisTest extends Object
{ {
Fun1<Fun1<K, FunN>, C> op = (C m) -> { ThisTest thisVar = this;
return (FunN f) -> { ThisTest ThisTest()
return f.apply(this, m);;
};
};
Matrix Matrix()
{ {
} }
} }
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)] SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH A = Object)]
SourceFile DEBUG [Typeinference] class <K, C>Matrix extends Vector<Vector<Integer>> SourceFile DEBUG [Typeinference] class ThisTest extends Object
{ {
Fun1<Fun1<K, FunN>, C> op = (C m) -> { Object thisVar = this;
return (FunN f) -> { ThisTest ThisTest()
return f.apply(this, m);;
};
};
Matrix Matrix()
{
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)]
SourceFile DEBUG [Typeinference] class <K, C>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<K, FunN>, C> op = (C m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
};
Matrix Matrix()
{
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)]
SourceFile DEBUG [Typeinference] class <K, C>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<K, FunN>, C> op = (C m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
};
Matrix Matrix()
{
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< ? super GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)]
SourceFile DEBUG [Typeinference] class <K, C>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<K, FunN>, C> op = (C m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
};
Matrix Matrix()
{
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? super Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)]
SourceFile DEBUG [Typeinference] class <K, C>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<K, FunN>, C> op = (C m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
};
Matrix Matrix()
{
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? super Matrix >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)]
SourceFile DEBUG [Typeinference] class <K, C>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<K, FunN>, C> op = (C m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
};
Matrix Matrix()
{ {
} }
} }

View File

@ -7,9 +7,6 @@ import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption;
import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption;
/*TODO:
*/
public class TestAbstractInferenceTest extends AbstractInferenceTestOLD_2 { public class TestAbstractInferenceTest extends AbstractInferenceTestOLD_2 {
private final static String TESTEDCLASSNAME="TestAbstractInferenceTest"; private final static String TESTEDCLASSNAME="TestAbstractInferenceTest";

View File

@ -1,5 +1,50 @@
package plugindevelopment; package plugindevelopment;
public class OverloadingInsertTest { import java.io.File;
import java.io.IOException;
import java.util.Vector;
import junit.framework.TestCase;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.myparser.JavaParser.yyException;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import org.junit.Test;
import typinferenz.TypeInsertSet;
public class OverloadingInsertTest {
private static final String TEST_FILE = "OverloadingInsertTest.jav";
@Test
public void run(){
this.test(this.TEST_FILE);
}
public static void test(String sourceFileToInfere){
String inferedSource = "";
MyCompilerAPI compiler = MyCompiler.getAPI();
try {
compiler.parse(new File(TypeInsertTester.rootDirectory + sourceFileToInfere));
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
//TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
for(TypeinferenceResultSet result : results){
Vector<TypeInsertSet> points = result.getTypeInsertionPoints();
TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
for(TypeInsertSet point : points){
TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0);
if(point.points.size()>0){
inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(TypeInsertTester.rootDirectory + sourceFileToInfere));
System.out.println(inferedSource);
}
}
}
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
} }

View File

@ -39,7 +39,7 @@ public class TypeInsertTester{
inferencelog.addAppender(logAppender); //Bei den Tests wird der Log auch in System.out geschrieben. inferencelog.addAppender(logAppender); //Bei den Tests wird der Log auch in System.out geschrieben.
} }
} }
private static final String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/"; static final String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/";
public static void test(String sourceFileToInfere, String solutionFile){ public static void test(String sourceFileToInfere, String solutionFile){
String inferedSource = ""; String inferedSource = "";
@ -47,7 +47,7 @@ public class TypeInsertTester{
try { try {
compiler.parse(new File(rootDirectory + sourceFileToInfere)); compiler.parse(new File(rootDirectory + sourceFileToInfere));
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction(); Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben", results.size()==1); TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
for(TypeinferenceResultSet result : results){ for(TypeinferenceResultSet result : results){
Vector<TypeInsertSet> points = result.getTypeInsertionPoints(); Vector<TypeInsertSet> points = result.getTypeInsertionPoints();
TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0); TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
@ -68,7 +68,7 @@ public class TypeInsertTester{
} }
//Source: https://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file //Source: https://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file
private static String getFileContent(String path)throws IOException static String getFileContent(String path)throws IOException
{ {
byte[] encoded = Files.readAllBytes(Paths.get(path)); byte[] encoded = Files.readAllBytes(Paths.get(path));
return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString(); return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString();