From 0d3514cbd860dbffa9c5462d24c46eceaae28fe5 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 24 Aug 2018 13:55:53 +0200 Subject: [PATCH] backup --- asp/fc.lp | 114 +++++++++++++++++++++++++---- test/asp/withWildcards/TestFC.java | 42 +++++++++++ 2 files changed, 142 insertions(+), 14 deletions(-) create mode 100644 test/asp/withWildcards/TestFC.java diff --git a/asp/fc.lp b/asp/fc.lp index 0e2ca20c..5a7289ed 100644 --- a/asp/fc.lp +++ b/asp/fc.lp @@ -1,24 +1,110 @@ -newType(P, A) :- smallerGen(P, A). -newType(P, A) :- greaterGen(P, A). -newType(P, A) :- greaterArgGen(P, A). -newType(P, A) :- smallerArgGen(P, A). - -typeVar(P) :- newType(P, A), typeVar(A). -type(P, AN, ANum) :- newType(P, A), type(A, AN, ANum). -param(P, AN, ANum) :- newType(P, A), param(A, AN, ANum). wildcard(A) :- extendsWildcard(A). wildcard(A) :- superWildcard(A). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Anzahl der Wildcards ist 1 +% Mehr benötigt man nicht verschachtelt +% Dadurch ist numWildcards unnötig, man ändert einfach die grArg auf Wildcards +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +type(P, TN, TNum) :- makeSameGen(P, T), type(T, TN, TNum). +param(P, TN, TNum) :- makeSameGen(P, T), param(T, TN, TNum). +superWildcard(P) :- makeSameGen(P, T), superWildcard(T). +extendsWildcard(P) :- makeSameGen(P, T), extendsWildcard(T). + +%%%%%%%%%%%%%%%%% +% Greater +%%%%%%%%%%%%%%%% +{ greaterGen(P, A, AFC, BFC) : smaller(AFC, BFC), type(AFC, AN, ANum) } == 1 :- greaterGen(P, A), type(A, AN, ANum) +. + +type(P, BN, BNum) :- greaterGen(P, A, _, B), type(B, BN, BNum). +%Bei den Parametern gibt es zwei Fälle: +%% Die TPHs müssen gemapt werden, die anderen übernommen +greaterArgGen(pointer(P, Param), Param) :- greaterGen(P, A, Afc, B), param(A, Param, PNum), mapFC(smaller(Afc, B), PNum, _). +greaterArgGen(pointer(P, Param), Param) :- greaterGen(P, A, _, B), param(B, Param, PNum), type(B, _, _). +param(P, pointer(P, Param), PNum) :- greaterGen(P, A, _, B), param(B, Param, PNum) + , type(Param, _, _) + . +param(P, pointer(P, Param), PNum2) :- greaterGen(P, A, Afc, B), param(A, Param, PNum) + , mapFC(smaller(Afc,B), PNum, PNum2) + . + +%TypeVars bleiben einfach TypeVars: +typeVar(Pointer) :- greaterArgGen(Pointer, T), typeVar(T). + +%makeGreaterGen(Pointer, T) :- greaterArgGen(Pointer, T), extendsWildcard(T). +%makeSmallerGen(Pointer, T) :- greaterArgGen(Pointer, T), superWildcard(T). +makeSameGen(Pointer, T) :- greaterArgGen(Pointer, T), extendsWildcard(T). +makeSameGen(Pointer, T) :- greaterArgGen(Pointer, T), superWildcard(T). +makeSmallerGenG(Pointer, T), +makeGreaterGenG(Pointer, T), +makeSameGenG(Pointer, T) +:- greaterArgGen(Pointer, T), not extendsWildcard(T), not superWildcard(T), type(T, N, Num). + +greaterGen(P, T) :- makeGreaterGenG(P, T). +extendsWildcard(P) :- makeGreaterGenG(P, T). + +smallerGen(P, T) :- makeGreaterGenG(P, T). +superWildcard(P) :- makeSmallerGenG(P, T). + +{ greaterGen(P, T, TFC, TFC) : smaller(TFC, _), type(TFC, TN, TNum) } == 1 :- makeSameGenG(P, T), type(T, TN, TNum). + +greaterArgGenNum(P, 0) :- greaterArgGen(P, _), type(P, _ ,_). +greaterArgGenNum(pointer(P, P2), Num + 1) :- greaterArgGen(pointer(P, P2),_), greaterArgGenNum(P, Num). + + +%%%%%%%%%%%%%%%%% +% smaller +%%%%%%%%%%%%%%%% +{ smallerGen(P, A, AFC, BFC) : smaller(BFC, AFC), type(AFC, AN, ANum) } == 1 :- smallerGen(P, A), type(A, AN, ANum) +. +{ type(P, BN, BNum) : type(B,BN,BNum) } == 1 :- smallerGen(P, A, _, B). +%Bei den Parametern gibt es drei Fälle: +%% Die TPHs müssen gemapt werden, die anderen übernommen +smallerArgGen(pointer(P, Param), Param) :- smallerGen(P, A, Afc, B), param(A, Param, PNum), mapFC(smaller(B, Afc), _, PNum). +param(P, pointer(P, Param), PNum2) :- smallerGen(P, A, Afc, B), param(A, Param, PNum) + , mapFC(smaller(B,Afc), PNum2, PNum) + . + +%Neue Parameter können hinzu kommen: TODO +%smallerArgGen(pointer(P, Param), Param) :- smallerGen(P, A, _, B), param(B, Param, PNum). +%param(P, pointer(P, Param), PNum) :- greaterGen(P, A, _, B), param(B, Param, PNum) +% %, type(Param, _, _) %Es ist egal ob es ein Typparameter oder eine TypeVar ist. smallerArgGen macht das richtige +% . + +%Es können voraussetzungen hinzukommen: +equals(Param, PA) :- smallerGen(P, A, Afc, B), param(Afc, Param, PNum), type(Param, _, _), param(A, PA, PNum). + +%TypeVars bleiben einfach TypeVars: +typeVar(Pointer) :- smallerArgGen(Pointer, T), typeVar(T). + +makeSameGen(Pointer, T) :- smallerArgGen(Pointer, T), extendsWildcard(T). +makeSameGen(Pointer, T) :- smallerArgGen(Pointer, T), superWildcard(T). +makeSmallerGenS(Pointer, T), +makeGreaterGenS(Pointer, T), +makeSameGenS(Pointer, T) +:- smallerArgGen(Pointer, T), not extendsWildcard(T), not superWildcard(T), type(T, N, Num). + +greaterGen(P, T) :- makeGreaterGenS(P, T). +extendsWildcard(P) :- makeGreaterGenS(P, T). + +smallerGen(P, T) :- makeSmallerGenS(P, T). +superWildcard(P) :- makeSmallerGenS(P, T). + +{ smallerGen(P, T, TFC, TFC) : smaller(TFC, _), type(TFC, TN, TNum) } == 1 :- makeSameGenS(P, T), type(T, TN, TNum). + + +%%% +% Grundlegende Regeln +%%% +smaller(A, A) :- smaller(A, _). +smaller(B, B) :- smaller(_, B). +%smaller(A, A) :- type(A). %Alle Typen erben von sich selber. Hätte komische Nebeneffekte + %Mapping: mapFC(smaller(A,B), Num, Num2) :- smaller(A,B), param(A, P, Num), typeVar(P), param(B, P, Num2). hasTypeInParameterList(A) :- type(A, _, _), param(A, P, _), type(P, _, _). mapRootFC(smaller(A,B), Num, Num2) :- smaller(A, B), not hasTypeInParameterList(A), param(A, P, Num), typeVar(P), param(B, P, Num2). -%%% -% Grundlegende Regeln -%%% -%smaller(A, A) :- smaller(A, _). -%smaller(B, B) :- smaller(_, B). -%smaller(A, A) :- type(A). %Alle Typen erben von sich selber. Hätte komische Nebeneffekte diff --git a/test/asp/withWildcards/TestFC.java b/test/asp/withWildcards/TestFC.java new file mode 100644 index 00000000..f7ba1b1d --- /dev/null +++ b/test/asp/withWildcards/TestFC.java @@ -0,0 +1,42 @@ +package asp.withWildcards; + +import de.dhbwstuttgart.sat.asp.Clingo; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + +public class TestFC { + public static final String tempDirectory = "/tmp/"; + + @Test + public void testInteger() throws InterruptedException, IOException, ClassNotFoundException { + Collection fc = new ArrayList<>(); + fc.add(ASTFactory.createClass(Integer.class)); + System.out.println(run(fc)); + //TODO Hier noch Constraint Integer <. a anfügen + } + + public String run(Collection fc) throws IOException, InterruptedException, ClassNotFoundException { + String content = ""; + //this.convertFC(fc); + + //content = writer.getASPFile(); + + PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); + writer.println(content); + writer.close(); + Clingo clingo = new Clingo( + Arrays.asList(new File(tempDirectory + "test.lp"), + new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/finiteClosure/fc.pl"))); + String result = clingo.runClingo(); + + return result; + } +}