From 64ec7989b477185e6291e20ae7805bec98250e66 Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Tue, 31 Jan 2023 15:39:12 +0100 Subject: [PATCH] Continue with eliminating inner type variables --- .../target/generate/ASTToTargetAST.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index 14a3c7d53..43e11469f 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -568,6 +568,8 @@ public class ASTToTargetAST { } void eliminateInnerTypeVariables(Set referenced, Set> input) { + // Remove type variables that are part of a relation A < B < C where B is not in referenced + // Add new pair A < C var oldInput = new HashSet<>(input); for (var pair : oldInput) { if (pair instanceof PairTPHsmallerTPH ptph && !referenced.contains(ptph.left)) { @@ -581,6 +583,21 @@ public class ASTToTargetAST { } } } + + // Remove lone type variables, A = RefType where A is in no relation X < A or A < X and A is not in referenced + oldInput = new HashSet<>(input); + outer: + for (var pair : oldInput) { + if (pair instanceof PairTPHequalRefTypeOrWildcardType ptph) { + if (!referenced.contains(ptph.left)) { + for (var pair2 : oldInput) { + if (pair != pair2 && (pair2.getLeft().equals(ptph.left) || pair2.getRight().equals(ptph.left))) + continue outer; + } + input.remove(pair); + } + } + } } void eliminateCycles(Set> input) {