forked from JavaTX/JavaCompilerCore
FunNInterface N = 1-6 zu den BasicAssumptions hinzugefügt
This commit is contained in:
parent
69af867293
commit
b6e2d75174
@ -44,8 +44,11 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
|
||||
import typinferenz.ConstraintsSet;
|
||||
import typinferenz.FunN;
|
||||
import typinferenz.FunNInterface;
|
||||
import typinferenz.FunNMethod;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.UndConstraint;
|
||||
import typinferenz.assumptions.MethodAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
|
||||
@ -1389,6 +1392,14 @@ public class SourceFile
|
||||
*/
|
||||
TypeAssumptions ret = new TypeAssumptions();
|
||||
|
||||
//Basic Assumptions für die FunN Interfaces:
|
||||
//TODO: Hier mehr als Fun1-Fun5 implementieren
|
||||
for(int i = 0; i<6; i++){
|
||||
FunNInterface funN = new FunNInterface(i);
|
||||
ret.add(funN.getPublicFieldAssumptions());
|
||||
}
|
||||
|
||||
|
||||
return ret; //TODO: Diese TypeAssumptions mit basic-Assumptions füllen
|
||||
}
|
||||
// ino.end
|
||||
|
@ -477,7 +477,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
|
||||
// ino.end
|
||||
|
||||
// ino.method.get_ParaList.23101.definition
|
||||
public Vector get_ParaList()
|
||||
public Vector<Type> get_ParaList()
|
||||
// ino.end
|
||||
// ino.method.get_ParaList.23101.body
|
||||
{
|
||||
|
@ -465,7 +465,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
// ino.end
|
||||
// ino.method.toString.23605.body
|
||||
{
|
||||
return this.getType() + " " + block.toString();
|
||||
return this.getType() + " " +( (block!=null)?block.toString():"");
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
@ -2,17 +2,52 @@ package typinferenz;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.assumptions.MethodAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import mycompiler.mytype.*;
|
||||
import mycompiler.myclass.Class;
|
||||
import mycompiler.mytype.TypePlaceholder;
|
||||
|
||||
|
||||
/**
|
||||
* Stellt das Interface FunN dar.
|
||||
* @author janulrich
|
||||
*
|
||||
*/
|
||||
public class FunNInterface extends Class{
|
||||
//TODO: Diese Klasse sollte eigentlich von Interface erben
|
||||
//TODO: getType muss einen Typ mit der ParameterListe zurückliefern.
|
||||
/**
|
||||
* Ein FunN-Interface enthält nur eine Methode (namens apply). Ist also ein Funktionales Interface.
|
||||
* @param N - Die Anzahl der Parameter der apply-Methode. Beispiel N = 1 ergibt <code>R apply(T1 par1);</code>
|
||||
*/
|
||||
public FunNInterface(int N) {
|
||||
super("Fun"+N);
|
||||
Vector<Type> paralist = new Vector<Type>();
|
||||
paralist.add(new GenericTypeVar("R",0));
|
||||
for(int i = 1; i<=N;i++){
|
||||
paralist.add(new GenericTypeVar("T"+i,0));
|
||||
}
|
||||
this.set_ParaList(paralist);
|
||||
}
|
||||
|
||||
public FunNInterface(Vector<Type> parameter) {
|
||||
super("Fun"+parameter.size());
|
||||
this.set_ParaList(parameter);
|
||||
/**
|
||||
* @return Im Falle von einem FunN-Interface ist dies die apply-Methode
|
||||
*/
|
||||
@Override
|
||||
public TypeAssumptions getPublicFieldAssumptions() {
|
||||
//return super.getPublicFieldAssumptions();
|
||||
TypeAssumptions ret = new TypeAssumptions();
|
||||
ret.addMethodAssumption(new MethodAssumption(this.getApplyFunction(), this));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt die nach Definition des Typinferenzalgorithmus von Martin Plümicke, in jedem FunN-Interface enthaltene apply-Methode
|
||||
* @return
|
||||
*/
|
||||
private FunNMethod getApplyFunction(){
|
||||
return new FunNMethod(this.get_ParaList());
|
||||
//return new FunNMethod(this.get_ParaList().size()-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package typinferenz;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.mytype.*;
|
||||
import mycompiler.myclass.*;
|
||||
import mycompiler.mytype.TypePlaceholder;
|
||||
|
||||
@ -10,13 +11,32 @@ public class FunNMethod extends Method{
|
||||
*
|
||||
* @param N - Anzahl der Parameter (Beispiel: Fun2<R, T1, T2>)
|
||||
*/
|
||||
public FunNMethod(Vector<Type> 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());
|
||||
this.set_DeclId(new DeclId("apply"));
|
||||
ParameterList pl = new ParameterList();
|
||||
Vector<FormalParameter> fpList = new Vector<FormalParameter>();
|
||||
for(int i = 1;i<N;i++){ //Alle verbleibenden Elemente in der übergebenen paralist durchgehen.
|
||||
DeclId paramName = new DeclId("T"+i);
|
||||
FormalParameter parameter = new FormalParameter(paramName);
|
||||
//parameter.setType(TypePlaceholder.fresh(parameter));
|
||||
parameter.setType(paralist.get(i));
|
||||
//parameter.set_DeclId(paramName);
|
||||
fpList.add(parameter);
|
||||
}
|
||||
pl.formalparameter = fpList;
|
||||
this.parameterlist = pl;
|
||||
}
|
||||
|
||||
public FunNMethod(int N){
|
||||
super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
this.set_DeclId(new DeclId("Fun"+N));
|
||||
this.set_DeclId(new DeclId("apply"));
|
||||
ParameterList pl = new ParameterList();
|
||||
Vector<FormalParameter> fpList = new Vector<FormalParameter>();
|
||||
for(int i = 0;i<N;i++){
|
||||
for(int i = 1;i<=N;i++){ //Alle verbleibenden Elemente in der übergebenen paralist durchgehen.
|
||||
DeclId paramName = new DeclId("T"+i);
|
||||
FormalParameter parameter = new FormalParameter(paramName);
|
||||
parameter.setType(TypePlaceholder.fresh(parameter));
|
||||
|
@ -23,6 +23,10 @@ public class FieldAssumption extends Assumption {
|
||||
return this.field.getIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "FieldAssumption: "+this.field.getType()+" "+this.getIdentifier();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -146,12 +146,13 @@ public class TypeAssumptions {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Dieser Teil mit der Generierung von FunN-Methoden kann raus, da die FunNInterfaces sich in den Basic-Assumptions befinden sollten.
|
||||
//Falls es sich um die apply-Methode eines FunN-Interface handelt:
|
||||
if(methodName.equals("apply")){ //Ein Workaround für den Typinferenzalgorithmus TODO: Das hier rausnehmen.
|
||||
//if(methodName.equals("apply")){ //Ein Workaround für den Typinferenzalgorithmus TODO: Das hier rausnehmen.
|
||||
//CMethodTypeAssumption funNAssumption = new FunN(parameterCount).toCMethodTypeAssumption();
|
||||
MethodAssumption funNAssumption = new MethodAssumption(new FunNMethod(parameterCount), new FunNInterface(parameter));
|
||||
ret.add(funNAssumption);
|
||||
}
|
||||
// MethodAssumption funNAssumption = new MethodAssumption(new FunNMethod(parameterCount), new FunNInterface(parameter));
|
||||
// ret.add(funNAssumption);
|
||||
//}
|
||||
if(ret.size()==0)throw new TypinferenzException("Eine Methode "+methodName+" ist in den Assumptions nicht vorhanden");
|
||||
return ret;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
5
test/plugindevelopment/TypeInsertTests/LambdaTest3.jav
Normal file
5
test/plugindevelopment/TypeInsertTests/LambdaTest3.jav
Normal file
@ -0,0 +1,5 @@
|
||||
class LambdaTest{
|
||||
var;
|
||||
Fun0<String> op = () -> {return var;};
|
||||
|
||||
}
|
18
test/plugindevelopment/TypeInsertTests/LambdaTest3.java
Normal file
18
test/plugindevelopment/TypeInsertTests/LambdaTest3.java
Normal file
@ -0,0 +1,18 @@
|
||||
package plugindevelopment.TypeInsertTests;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class LambdaTest3 {
|
||||
|
||||
private static final String TEST_FILE = "LambdaTest3.jav";
|
||||
|
||||
@Test
|
||||
public void run(){
|
||||
Vector<String> mustContain = new Vector<String>();
|
||||
mustContain.add("String var");
|
||||
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ import mycompiler.myparser.JavaParser.yyException;
|
||||
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
|
||||
import typinferenz.TypeInsertSet;
|
||||
|
||||
public class MultipleTypesInsertTester {
|
||||
public class MultipleTypesInsertTester extends TypeInsertTester{
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/TypeInsertTests/";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user