Consider nested type variables for signature (usage)

This commit is contained in:
Victorious3 2023-01-24 16:24:24 +01:00
parent a9f69ead5c
commit dabe7f269c

View File

@ -72,6 +72,10 @@ public class ASTToTargetAST {
} else if (type instanceof RefType refType) {
for (var t : refType.getParaList())
result.addAll(findTypeVariables(t));
} else if (type instanceof ExtendsWildcardType wildcardType) {
result.addAll(findTypeVariables(wildcardType.getInnerType()));
} else if (type instanceof SuperWildcardType wildcardType) {
result.addAll(findTypeVariables(wildcardType.getInnerType()));
}
return result;
}
@ -126,7 +130,6 @@ public class ASTToTargetAST {
HashSet<TypePlaceholder> typeVariables = new HashSet<>();
HashSet<TypePlaceholder> typeVariablesOfFields = new HashSet<>();
HashSet<TypePlaceholder> typeVariablesOfLocals = new HashSet<>();
for (var field : owner.getFieldDecl()) {
typeVariablesOfFields.addAll(findTypeVariables(field.getType()));
@ -140,9 +143,7 @@ public class ASTToTargetAST {
method.block.accept(new TracingStatementVisitor() {
@Override
public void visit(LocalVarDecl localVarDecl) {
var tphs = findTypeVariables(localVarDecl.getType());
typeVariablesOfLocals.addAll(tphs);
typeVariables.addAll(tphs);
typeVariables.addAll(findTypeVariables(localVarDecl.getType()));
}
@Override
@ -463,13 +464,12 @@ public class ASTToTargetAST {
usedTPHsOfMethods.put(method, typeVariables);
// For eliminating inner type variables we need to figure out which ones are actually used
// TODO Maybe don't do this twice?
var typeVariablesOfSignature = new HashSet<TypePlaceholder>();
for (var param : method.getParameterList().getFormalparalist()) {
if (param.getType() instanceof TypePlaceholder tph)
typeVariablesOfSignature.add(equality.getOrDefault(tph, tph));
typeVariablesOfSignature.addAll(findTypeVariables(param.getType()));
}
if (method.getReturnType() instanceof TypePlaceholder tph)
typeVariablesOfSignature.add(equality.getOrDefault(tph, tph));
typeVariablesOfSignature.addAll(findTypeVariables(method.getReturnType()));
eliminateInnerTypeVariables(typeVariablesOfSignature, result);
System.out.println(method.name + ": " + result);