forked from JavaTX/JavaCompilerCore
modified: src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
FunN$$ eingefuegt modified: src/de/dhbwstuttgart/syntaxtree/type/FunN.java modified: src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java modified: src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java modified: src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java Methodcall einige Bugs sowohl beim apply als uch bei allen anderen gefixt. modified: test/javFiles/Lambda.jav
This commit is contained in:
parent
11649b39d3
commit
2eb7a63480
@ -208,7 +208,7 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(FunNType t, Map<String,TypePlaceholder> tphs) {
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(FunNType t, Map<String,TypePlaceholder> tphs) {
|
||||||
RefType ret = new RefType(new JavaClassName(t.getName()), convert(t.getTypeParams(), tphs), new NullToken());
|
RefType ret = new RefType(new JavaClassName(t.getName()+"$$"), convert(t.getTypeParams(), tphs), new NullToken());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class FunN extends RefType {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public FunN(List<RefTypeOrTPHOrWildcardOrGeneric> params) {
|
public FunN(List<RefTypeOrTPHOrWildcardOrGeneric> params) {
|
||||||
super(new JavaClassName("Fun"+params.size()), params, new NullToken());
|
super(new JavaClassName("Fun"+(params.size())), params, new NullToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,32 +8,36 @@ import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FunNClass extends ClassOrInterface {
|
public class FunNClass extends ClassOrInterface {
|
||||||
public FunNClass(List<RefTypeOrTPHOrWildcardOrGeneric> funNParams) {
|
public FunNClass(List<GenericRefType> funNParams) {
|
||||||
super(0, new JavaClassName("Fun"+(funNParams.size()-1)), new ArrayList<>(),
|
super(0, new JavaClassName("Fun"+(funNParams.size())), new ArrayList<>(),
|
||||||
createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams),
|
createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams),
|
||||||
ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken());
|
ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GenericDeclarationList createGenerics(List<RefTypeOrTPHOrWildcardOrGeneric> funNParams) {
|
private static GenericDeclarationList createGenerics(List<GenericRefType> funNParams) {
|
||||||
|
//PL 2018-06-22: so geaendert, dass generierte Generics den Namen der funParams entsprechen.
|
||||||
List<GenericTypeVar> generics = new ArrayList<>();
|
List<GenericTypeVar> generics = new ArrayList<>();
|
||||||
for(RefTypeOrTPHOrWildcardOrGeneric param : funNParams){
|
for(GenericRefType param : funNParams){
|
||||||
generics.add(new GenericTypeVar(NameGenerator.makeNewName(),
|
generics.add(new GenericTypeVar(param.getParsedName(),//NameGenerator.makeNewName(),
|
||||||
new ArrayList<>(), new NullToken(), new NullToken()));
|
new ArrayList<>(), new NullToken(), new NullToken()));
|
||||||
}
|
}
|
||||||
return new GenericDeclarationList(generics, new NullToken());
|
return new GenericDeclarationList(generics, new NullToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Method> createMethods(List<RefTypeOrTPHOrWildcardOrGeneric> funNParams) {
|
private static List<Method> createMethods(List<GenericRefType> funNParams) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,10 @@ import java.util.List;
|
|||||||
public class MethodAssumption extends Assumption{
|
public class MethodAssumption extends Assumption{
|
||||||
private ClassOrInterface receiver;
|
private ClassOrInterface receiver;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params;
|
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||||
|
|
||||||
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
|
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
|
||||||
super(scope);
|
super(scope);
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
this.retType = retType;
|
this.retType = retType;
|
||||||
@ -38,7 +38,9 @@ public class MethodAssumption extends Assumption{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
|
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
|
||||||
if(retType instanceof GenericRefType)return resolver.resolve(retType);
|
if(retType instanceof GenericRefType) {
|
||||||
|
return resolver.resolve(retType);
|
||||||
|
}
|
||||||
return retType;
|
return retType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.parser.NullToken;
|
|||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||||
@ -451,11 +452,14 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
List<MethodAssumption> ret = new ArrayList<>();
|
List<MethodAssumption> ret = new ArrayList<>();
|
||||||
//TODO: apply Methoden wieder anfügen. Diese könnten möglicherweise auch in den Assumptions auftauchen (überdenken)
|
//TODO: apply Methoden wieder anfügen. Diese könnten möglicherweise auch in den Assumptions auftauchen (überdenken)
|
||||||
if(name.equals("apply")){
|
if(name.equals("apply")){
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
List<GenericRefType> funNParams = new ArrayList<>();
|
||||||
for(int i = 0; i< numArgs + 1 ; i++){
|
for(int i = 0; i< numArgs + 1 ; i++){
|
||||||
funNParams.add(TypePlaceholder.fresh(new NullToken()));
|
//funNParams.add(TypePlaceholder.fresh(new NullToken()));
|
||||||
|
funNParams.add(new GenericRefType(NameGenerator.makeNewName(),
|
||||||
|
new NullToken()));
|
||||||
}
|
}
|
||||||
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(0), funNParams.subList(1, funNParams.size()),
|
funNParams.get(funNParams.size()-1);
|
||||||
|
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(funNParams.size()-1), funNParams.subList(0, funNParams.size()-1),
|
||||||
new TypeScope() {
|
new TypeScope() {
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||||
@ -498,7 +502,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
*/
|
*/
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
for(FormalParameter fp : parameterList.getFormalparalist()){
|
for(FormalParameter fp : parameterList.getFormalparalist()){
|
||||||
params.add(info.checkGTV(fp.getType()));
|
params.add(fp.getType()); //info.checkGTV(fp.getType())); //PL 2018-06-22 GTV sollen in Argumenten erhalten bleiben
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Number;
|
import java.lang.Number;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
public class Lambda {
|
public class Lambda {
|
||||||
|
|
||||||
m () {
|
m () {
|
||||||
|
var v;
|
||||||
|
v.addElement(3);
|
||||||
|
v.elementAt(1);
|
||||||
var lam1 = (x) -> {
|
var lam1 = (x) -> {
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user