Compare commits
2 Commits
929392b7d4
...
a9d836ce25
Author | SHA1 | Date | |
---|---|---|---|
|
a9d836ce25 | ||
|
fd8a66dd59 |
@ -327,74 +327,6 @@ public class JavaTXCompiler {
|
|||||||
logFile.write(ASTTypePrinter.print(f));
|
logFile.write(ASTTypePrinter.print(f));
|
||||||
}
|
}
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
|
||||||
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist().stream().filter(z -> z.getType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}, (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
})).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
});
|
|
||||||
|
|
||||||
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist().stream().filter(z -> z.getType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}, (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
})).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
});
|
|
||||||
|
|
||||||
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
|
||||||
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
|
||||||
|
|
||||||
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}).get();
|
|
||||||
|
|
||||||
Set<String> fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}).get();
|
|
||||||
|
|
||||||
returnTypeVarNames.addAll(fieldTypeVarNames);
|
|
||||||
|
|
||||||
unifyCons = unifyCons.map(x -> {
|
|
||||||
// Hier muss ueberlegt werden, ob
|
|
||||||
// 1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
|
|
||||||
// mit disableWildcardtable() werden.
|
|
||||||
// 2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
|
|
||||||
// in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
|
|
||||||
// PL 2018-04-23
|
|
||||||
if ((x.getLhsType() instanceof PlaceholderType)) {
|
|
||||||
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getLhsType()).setVariance((byte) 1);
|
|
||||||
((PlaceholderType) x.getLhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getLhsType()).setVariance((byte) -1);
|
|
||||||
((PlaceholderType) x.getLhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((x.getRhsType() instanceof PlaceholderType)) {
|
|
||||||
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getRhsType()).setVariance((byte) 1);
|
|
||||||
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getRhsType()).setVariance((byte) -1);
|
|
||||||
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return x;// HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE
|
|
||||||
// JEWEILS ANDERE SEITE
|
|
||||||
});
|
|
||||||
Set<PlaceholderType> varianceTPHold;
|
Set<PlaceholderType> varianceTPHold;
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
@ -461,85 +393,6 @@ public class JavaTXCompiler {
|
|||||||
logFile.write(ASTTypePrinter.print(sf));
|
logFile.write(ASTTypePrinter.print(sf));
|
||||||
System.out.println(ASTTypePrinter.print(sf));
|
System.out.println(ASTTypePrinter.print(sf));
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
|
||||||
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist().stream().filter(z -> z.getType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}, (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
})).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
});
|
|
||||||
|
|
||||||
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist().stream().filter(z -> z.getType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}, (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
})).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
});
|
|
||||||
|
|
||||||
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
|
||||||
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
|
||||||
|
|
||||||
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}).get();
|
|
||||||
|
|
||||||
Set<String> fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}).get();
|
|
||||||
|
|
||||||
returnTypeVarNames.addAll(fieldTypeVarNames);
|
|
||||||
|
|
||||||
unifyCons = unifyCons.map(x -> {
|
|
||||||
// Hier muss ueberlegt werden, ob
|
|
||||||
// 1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
|
|
||||||
// mit disableWildcardtable() werden.
|
|
||||||
// 2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
|
|
||||||
// in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
|
|
||||||
// PL 2018-04-23
|
|
||||||
if ((x.getLhsType() instanceof PlaceholderType)) {
|
|
||||||
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getLhsType()).setVariance((byte) 1);
|
|
||||||
((PlaceholderType) x.getLhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getLhsType()).setVariance((byte) -1);
|
|
||||||
((PlaceholderType) x.getLhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((x.getRhsType() instanceof PlaceholderType)) {
|
|
||||||
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getRhsType()).setVariance((byte) 1);
|
|
||||||
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getRhsType()).setVariance((byte) -1);
|
|
||||||
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return x;// HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE
|
|
||||||
// JEWEILS ANDERE SEITE
|
|
||||||
});
|
|
||||||
|
|
||||||
// PL 2020-02-05 alle Oder-Constraints Receiver und Parameter werden auf
|
|
||||||
// variance 1 gesetzt
|
|
||||||
// Es wird davon ausgegangen, dass in OderConstraints in Bedingungen für
|
|
||||||
// Parameter die Typen der Argumente links stehen
|
|
||||||
// und die Typen der Rückgabewerte immer rechts stehen
|
|
||||||
|
|
||||||
/*
|
|
||||||
* unifyCons.getOderConstraints().forEach(z -> z.forEach(y -> y.forEach(x -> { if ((x.getLhsType() instanceof PlaceholderType) && x.getPairOp().compareTo(PairOperator.SMALLERDOT) == 0) { ((PlaceholderType) x.getLhsType()).setVariance((byte)1); } else if ((x.getRhsType() instanceof PlaceholderType) && x.getPairOp().compareTo(PairOperator.EQUALSDOT) == 0) { ((PlaceholderType) x.getRhsType()).setVariance((byte)-1); } })));
|
|
||||||
*/
|
|
||||||
|
|
||||||
System.out.println("Unify nach Oder-Constraints-Anpassung:" + unifyCons.toString());
|
System.out.println("Unify nach Oder-Constraints-Anpassung:" + unifyCons.toString());
|
||||||
Set<PlaceholderType> varianceTPHold;
|
Set<PlaceholderType> varianceTPHold;
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
|
@ -125,7 +125,7 @@ public class StatementGenerator {
|
|||||||
this.superClass = superType;
|
this.superClass = superType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParameterList convert(Java17Parser.FormalParameterListContext formalParameterListContext) {
|
public ParameterList convert(Java17Parser.FormalParameterListContext formalParameterListContext, boolean methodparameters) {
|
||||||
List<Pattern> ret = new ArrayList<>();
|
List<Pattern> ret = new ArrayList<>();
|
||||||
List<Java17Parser.FormalParameterContext> fps = new ArrayList<>();
|
List<Java17Parser.FormalParameterContext> fps = new ArrayList<>();
|
||||||
if (Objects.isNull(formalParameterListContext))
|
if (Objects.isNull(formalParameterListContext))
|
||||||
@ -147,7 +147,9 @@ public class StatementGenerator {
|
|||||||
if (fp.typeType() != null) {
|
if (fp.typeType() != null) {
|
||||||
type = TypeGenerator.convert(fp.typeType(), reg, generics);
|
type = TypeGenerator.convert(fp.typeType(), reg, generics);
|
||||||
} else {
|
} else {
|
||||||
type = TypePlaceholder.fresh(fp.getStart());
|
type = methodparameters?
|
||||||
|
TypePlaceholder.fresh(fp.getStart(), 1, false)
|
||||||
|
: TypePlaceholder.fresh(fp.getStart());
|
||||||
}
|
}
|
||||||
ret.add(new FormalParameter(paramName, type, fp.getStart()));
|
ret.add(new FormalParameter(paramName, type, fp.getStart()));
|
||||||
localVars.put(paramName, type);
|
localVars.put(paramName, type);
|
||||||
@ -1102,7 +1104,7 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
params = new ParameterList(parameterList, lambdaParams.getStart());
|
params = new ParameterList(parameterList, lambdaParams.getStart());
|
||||||
} else if (lambdaParams.formalParameterList() != null) {
|
} else if (lambdaParams.formalParameterList() != null) {
|
||||||
params = convert(lambdaParams.formalParameterList());
|
params = convert(lambdaParams.formalParameterList(), false);
|
||||||
// }else if( lambdaParams.inferredFormalParameterList != null){
|
// }else if( lambdaParams.inferredFormalParameterList != null){
|
||||||
} else if (!Objects.isNull(lambdaParams.lambdaLVTIList())) {
|
} else if (!Objects.isNull(lambdaParams.lambdaLVTIList())) {
|
||||||
List<Pattern> parameterList = new ArrayList<>();
|
List<Pattern> parameterList = new ArrayList<>();
|
||||||
|
@ -435,7 +435,7 @@ public class SyntaxTreeGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
StatementGenerator stmtgen = new StatementGenerator(superClass, compiler, reg, generics, fields, new HashMap<>());
|
StatementGenerator stmtgen = new StatementGenerator(superClass, compiler, reg, generics, fields, new HashMap<>());
|
||||||
ParameterList paramlist = stmtgen.convert(bodydeclaration.formalParameters().formalParameterList());
|
ParameterList paramlist = stmtgen.convert(bodydeclaration.formalParameters().formalParameterList(), true);
|
||||||
MethodBodyContext body = bodydeclaration.methodBody();
|
MethodBodyContext body = bodydeclaration.methodBody();
|
||||||
Block block = null;
|
Block block = null;
|
||||||
if (!(body instanceof EmptymethodContext)) {
|
if (!(body instanceof EmptymethodContext)) {
|
||||||
@ -532,7 +532,7 @@ public class SyntaxTreeGenerator {
|
|||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric retType;
|
RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||||
if (Objects.isNull(header.refType())) {
|
if (Objects.isNull(header.refType())) {
|
||||||
retType = TypePlaceholder.fresh(header.getStart());
|
retType = TypePlaceholder.fresh(header.getStart(), -1, false);
|
||||||
} else {
|
} else {
|
||||||
if (header.refType() instanceof RefType2Context reftype) {
|
if (header.refType() instanceof RefType2Context reftype) {
|
||||||
retType = TypeGenerator.convert(reftype.typeType(), reg, generics);
|
retType = TypeGenerator.convert(reftype.typeType(), reg, generics);
|
||||||
@ -541,7 +541,7 @@ public class SyntaxTreeGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
StatementGenerator stmtgen = new StatementGenerator(superClass, compiler, reg, localgenerics, fields, new HashMap<>());
|
StatementGenerator stmtgen = new StatementGenerator(superClass, compiler, reg, localgenerics, fields, new HashMap<>());
|
||||||
ParameterList paramlist = stmtgen.convert(header.formalParameters().formalParameterList());
|
ParameterList paramlist = stmtgen.convert(header.formalParameters().formalParameterList(), true);
|
||||||
MethodBodyContext body = methoddeclaration.methodBody();
|
MethodBodyContext body = methoddeclaration.methodBody();
|
||||||
Block block = null;
|
Block block = null;
|
||||||
if (body instanceof EmptymethodContext emptymethod) {
|
if (body instanceof EmptymethodContext emptymethod) {
|
||||||
@ -581,7 +581,7 @@ public class SyntaxTreeGenerator {
|
|||||||
}
|
}
|
||||||
RefTypeOrTPHOrWildcardOrGeneric retType = TypeGenerator.convertTypeName(name, constructordeclaration.getStart(), reg, localgenerics);
|
RefTypeOrTPHOrWildcardOrGeneric retType = TypeGenerator.convertTypeName(name, constructordeclaration.getStart(), reg, localgenerics);
|
||||||
StatementGenerator stmtgen = new StatementGenerator(superClass, compiler, reg, localgenerics, fields, new HashMap<>());
|
StatementGenerator stmtgen = new StatementGenerator(superClass, compiler, reg, localgenerics, fields, new HashMap<>());
|
||||||
ParameterList paramlist = stmtgen.convert(constructordeclaration.formalParameters().formalParameterList());
|
ParameterList paramlist = stmtgen.convert(constructordeclaration.formalParameters().formalParameterList(), true);
|
||||||
Block block = prepareBlock(stmtgen.convert(constructordeclaration.constructorBody, true), superClass);
|
Block block = prepareBlock(stmtgen.convert(constructordeclaration.constructorBody, true), superClass);
|
||||||
return new Constructor(modifiers, name, retType, paramlist, block, gtvDeclarations, constructordeclaration.getStart());
|
return new Constructor(modifiers, name, retType, paramlist, block, gtvDeclarations, constructordeclaration.getStart());
|
||||||
}
|
}
|
||||||
@ -594,7 +594,7 @@ public class SyntaxTreeGenerator {
|
|||||||
} else {
|
} else {
|
||||||
// PL 2019-12-06: variableDeclaratorList() eingefuegt, um als Token nicht die
|
// PL 2019-12-06: variableDeclaratorList() eingefuegt, um als Token nicht die
|
||||||
// Modifier zu bekommen
|
// Modifier zu bekommen
|
||||||
fieldType = TypePlaceholder.fresh(fieldDeclContext.variableDeclarators().getStart());
|
fieldType = TypePlaceholder.fresh(fieldDeclContext.variableDeclarators().getStart(), -1, false);
|
||||||
}
|
}
|
||||||
for (Java17Parser.VariableDeclaratorContext varDecl : fieldDeclContext.variableDeclarators().variableDeclarator()) {
|
for (Java17Parser.VariableDeclaratorContext varDecl : fieldDeclContext.variableDeclarators().variableDeclarator()) {
|
||||||
String fieldName = varDecl.variableDeclaratorId().getText();
|
String fieldName = varDecl.variableDeclaratorId().getText();
|
||||||
|
@ -129,9 +129,10 @@ public class UnifyTypeFactory {
|
|||||||
if (tph.getName().equals("AFR")) {
|
if (tph.getName().equals("AFR")) {
|
||||||
System.out.println("XXX"+innerType);
|
System.out.println("XXX"+innerType);
|
||||||
}
|
}
|
||||||
PlaceholderType ntph = new PlaceholderType(tph.getName());
|
PlaceholderType ntph = new PlaceholderType(tph.getName(), tph.getVariance());
|
||||||
ntph.setVariance(tph.getVariance());
|
ntph.setVariance(tph.getVariance());
|
||||||
ntph.setOrCons(tph.getOrCons());
|
ntph.setOrCons(tph.getOrCons());
|
||||||
|
ntph.setWildcardtable(tph.getWildcardtable());
|
||||||
int in = PLACEHOLDERS.indexOf(ntph);
|
int in = PLACEHOLDERS.indexOf(ntph);
|
||||||
if (in == -1) {
|
if (in == -1) {
|
||||||
PLACEHOLDERS.add(ntph);
|
PLACEHOLDERS.add(ntph);
|
||||||
|
@ -21,10 +21,18 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wird im Generate Generics Teil nach der Rueckumwandlung nach dem Unify genutzt
|
* variance shows the variance of the pair
|
||||||
|
* 1: contravariant
|
||||||
|
* -1 covariant
|
||||||
|
* 0 invariant
|
||||||
*/
|
*/
|
||||||
private int variance = 0;
|
private int variance = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* isWildcardable gibt an, ob ein Wildcardtyp dem PlaceholderType zugeordnet werden darf
|
||||||
|
*/
|
||||||
|
private boolean wildcardable = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fuer Oder-Constraints:
|
* Fuer Oder-Constraints:
|
||||||
* orCons = 1: Receiver
|
* orCons = 1: Receiver
|
||||||
@ -39,10 +47,12 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
* Factory-Methode <code>fresh()</code> erzeugt.
|
* Factory-Methode <code>fresh()</code> erzeugt.
|
||||||
* <br>Author: J�rg B�uerle
|
* <br>Author: J�rg B�uerle
|
||||||
*/
|
*/
|
||||||
private TypePlaceholder(String name, Token offset)
|
private TypePlaceholder(String name, Token offset, int variance, boolean wildcardable)
|
||||||
{
|
{
|
||||||
super(offset);
|
super(offset);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.variance = variance;
|
||||||
|
this.wildcardable = wildcardable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -53,11 +63,15 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static TypePlaceholder fresh(Token position){
|
public static TypePlaceholder fresh(Token position){
|
||||||
return new TypePlaceholder(NameGenerator.makeNewName(), position);
|
return new TypePlaceholder(NameGenerator.makeNewName(), position, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TypePlaceholder fresh(Token position, int variance, boolean wildcardable){
|
||||||
|
return new TypePlaceholder(NameGenerator.makeNewName(), position, variance, wildcardable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric of(String name) {
|
public static RefTypeOrTPHOrWildcardOrGeneric of(String name) {
|
||||||
return new TypePlaceholder(name, new NullToken());
|
return new TypePlaceholder(name, new NullToken(),0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -120,4 +134,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
public byte getOrCons() {
|
public byte getOrCons() {
|
||||||
return orCons;
|
return orCons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Boolean getWildcardtable() {
|
||||||
|
return wildcardable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -822,9 +822,9 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
public void visit(Switch switchStmt) {
|
public void visit(Switch switchStmt) {
|
||||||
switchStack.push(switchStmt);
|
switchStack.push(switchStmt);
|
||||||
|
|
||||||
//if(switchStmt.getSwitch().getType() instanceof TypePlaceholder){
|
if(switchStmt.getSwitch().getType() instanceof TypePlaceholder){
|
||||||
// ((TypePlaceholder) switchStmt.getSwitch().getType()).setVariance(1);
|
((TypePlaceholder) switchStmt.getSwitch().getType()).setVariance(-1);
|
||||||
//}
|
}
|
||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric caseExpressionType = null;
|
RefTypeOrTPHOrWildcardOrGeneric caseExpressionType = null;
|
||||||
for (var child : switchStmt.getBlocks()) {
|
for (var child : switchStmt.getBlocks()) {
|
||||||
|
@ -53,8 +53,8 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* variance shows the variance of the pair
|
* variance shows the variance of the pair
|
||||||
* -1: contravariant
|
* 1: contravariant
|
||||||
* 1 covariant
|
* -1 covariant
|
||||||
* 0 invariant
|
* 0 invariant
|
||||||
* PL 2018-03-21
|
* PL 2018-03-21
|
||||||
*/
|
*/
|
||||||
@ -77,6 +77,14 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
IsGenerated = false; // This type is user generated
|
IsGenerated = false; // This type is user generated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public PlaceholderType(String name, int variance) {
|
||||||
|
super(name, new TypeParams());
|
||||||
|
EXISTING_PLACEHOLDERS.add(name); // Add to list of existing placeholder names
|
||||||
|
IsGenerated = false; // This type is user generated
|
||||||
|
this.variance = variance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new placeholdertype
|
* Creates a new placeholdertype
|
||||||
* @param isGenerated true if this placeholder is auto-generated, false if it is user-generated.
|
* @param isGenerated true if this placeholder is auto-generated, false if it is user-generated.
|
||||||
|
@ -721,7 +721,7 @@ public class TestComplete {
|
|||||||
var list2 = listCtor.newInstance("D", listCtor.newInstance("E", elemCtor.newInstance("F")));
|
var list2 = listCtor.newInstance("D", listCtor.newInstance("E", elemCtor.newInstance("F")));
|
||||||
|
|
||||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
var appendMethod = clazz.getDeclaredMethod("append", Object.class, listClass);
|
var appendMethod = clazz.getDeclaredMethod("append", linkedElemClass, listClass);
|
||||||
|
|
||||||
var res = appendMethod.invoke(instance, list2, list1);
|
var res = appendMethod.invoke(instance, list2, list1);
|
||||||
var expected = listCtor.newInstance("D", listCtor.newInstance("E", listCtor.newInstance("F", listCtor.newInstance("A", listCtor.newInstance("B", elemCtor.newInstance("C"))))));
|
var expected = listCtor.newInstance("D", listCtor.newInstance("E", listCtor.newInstance("F", listCtor.newInstance("A", listCtor.newInstance("B", elemCtor.newInstance("C"))))));
|
||||||
|
Loading…
Reference in New Issue
Block a user