From ccc16fd22b5f4d740069c10968fd8d1cb273448f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 7 Mar 2018 13:09:47 +0100 Subject: [PATCH] modified: ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java 1. Version mit compare von UnifyPairs --- .../dhbwstuttgart/typeinference/unify/RuleSet.java | 5 ++++- .../typeinference/unify/TypeUnifyTask.java | 7 ++++--- .../typeinference/unify/interfaces/IRuleSet.java | 4 ++++ .../typeinference/unify/model/FiniteClosure.java | 3 +++ .../unify/model/OrderingUnifyPair.java | 13 +++---------- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index d74ef01f..660ab38c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -699,6 +699,8 @@ public class RuleSet implements IRuleSet{ return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC)); } + /* PL 2018-03-06 auskommentiert sind mutmaßlich falsch + * vgl. JAVA_BSP/Wildcard6.java @Override public Optional reduceWildcardLowUp(UnifyPair pair) { if(pair.getPairOp() != PairOperator.SMALLERDOTWC) @@ -725,6 +727,7 @@ public class RuleSet implements IRuleSet{ return Optional.of(new UnifyPair(((SuperType) lhsType).getSuperedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.EQUALSDOT)); } + @Override public Optional reduceWildcardLeft(UnifyPair pair) { if(pair.getPairOp() != PairOperator.SMALLERDOTWC) @@ -741,7 +744,7 @@ public class RuleSet implements IRuleSet{ return Optional.empty(); } - + */ @Override public Optional> reduceFunN(UnifyPair pair) { if((pair.getPairOp() != PairOperator.SMALLERDOT) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 091f7aef..3a0dab30 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -403,9 +403,10 @@ public class TypeUnifyTask extends RecursiveTask>> { opt = opt.isPresent() ? opt : rules.reduceWildcardLowRight(pair); opt = opt.isPresent() ? opt : rules.reduceWildcardUp(pair); opt = opt.isPresent() ? opt : rules.reduceWildcardUpRight(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardLowUp(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardUpLow(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardLeft(pair); + //PL 2018-03-06 auskommentiert muesste falsch sein vgl. JAVA_BSP/Wildcard6.java + //opt = opt.isPresent() ? opt : rules.reduceWildcardLowUp(pair); + //opt = opt.isPresent() ? opt : rules.reduceWildcardUpLow(pair); + //opt = opt.isPresent() ? opt : rules.reduceWildcardLeft(pair); // Reduce TPH opt = opt.isPresent() ? opt : rules.reduceTph(pair); diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java index 62c9649f..a2b647c6 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java @@ -27,9 +27,13 @@ public interface IRuleSet { public Optional reduceWildcardLowRight(UnifyPair pair); public Optional reduceWildcardUp(UnifyPair pair); public Optional reduceWildcardUpRight(UnifyPair pair); + + /* + * vgl. JAVA_BSP/Wildcard6.java public Optional reduceWildcardLowUp(UnifyPair pair); public Optional reduceWildcardUpLow(UnifyPair pair); public Optional reduceWildcardLeft(UnifyPair pair); + */ /* * Additional Rules which replace cases of the cartesian product diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index c7e197c3..2e4e7bc3 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -439,6 +439,9 @@ public class FiniteClosure extends Ordering implements IFiniteClosure } public int compare (UnifyType left, UnifyType right, PairOperator pairop) { + if ((left instanceof ExtendsType && right instanceof ReferenceType) + || (right instanceof ExtendsType && left instanceof ReferenceType)) + System.out.println(""); UnifyPair up = new UnifyPair(left, right, pairop); TypeUnifyTask unifyTask = new TypeUnifyTask(); HashSet hs = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index a95a790f..be561934 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -114,20 +114,13 @@ public class OrderingUnifyPair extends Ordering> { } //Fall 1 und 4 if (lefteq.size() == 1 && righteq.size() == 1 && (leftlewc.size() > 0 || rightlewc.size() > 0)) { - //TODO 2018-03-02: hier muessen mehree =. eingefuegt werden und alle weiteren Faelle pruefen UnifyPair lseq = lefteq.iterator().next(); UnifyPair rseq = righteq.iterator().next(); - /*Set lsle = left.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) - .collect(Collectors.toCollection(HashSet::new)); - Set rsle = right.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) - .collect(Collectors.toCollection(HashSet::new)); - */ Pair> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType()); Unifier uni = new Unifier(); int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); - if (lseq.equals(rseq) || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey(); + if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName()) + || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey(); else { Set lsleuni = leftlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); Set rsleuni = rightlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); @@ -148,7 +141,7 @@ public class OrderingUnifyPair extends Ordering> { si = lslewcstr.map(x -> compare(x, hm.get(x.getRhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); } if (!si.isPresent()) return 0; - else if (si.get() == int_Unifier.getKey()) return int_Unifier.getKey(); else return 0; + else return si.get(); } }