From d0e7ea86ed84086d7507207961acb892e8cd5779 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 17 Jul 2018 19:51:50 +0200 Subject: [PATCH] Tests bereinigen --- asp/adaptRules.lp | 19 ++ asp/cartesian.lp | 22 ++ asp/facultyTestInput.lp | 70 +++++ asp/fc.lp | 24 ++ asp/fc.lp.backup | 125 ++++++++ asp/reduceRules.lp | 44 +++ asp/result.lp | 1 + asp/rule5.test | 291 ++++++++++++++++++ asp/step4.lp | 113 +++++++ asp/step4.test | 8 + asp/subst.lp | 14 + asp/testInput.lp | 219 +++++++++++++ asp/testReduce.lp | 28 ++ asp/testUnifikation.lp | 12 + asp/unifikation.lp | 23 ++ asp/unifikation.lp.backup | 40 +++ asp/vectorTestInput.lp | 95 ++++++ .../sat/asp/ASPUnifyWithoutWildcards.java | 55 ---- test/asp/UnifyWithoutWildcards.java | 217 ------------- .../unifywithoutwildcards/ASPFactoryTest.java | 45 --- test/asp/unifywithoutwildcards/ASPTests.java | 10 - .../JavaTXCompilerASPBenchmark.java | 89 ------ .../JavaTXCompilerASPTest.java | 145 --------- test/astfactory/ASTFactoryTest.java | 34 -- test/bytecode/ATest.java | 8 - test/bytecode/AssignToLit.jav | 30 -- test/bytecode/AssignToLitTest.java | 7 - test/bytecode/DuMethod.jav | 11 - test/bytecode/DuMethodTest.java | 7 - test/bytecode/EmptyMethod.jav | 8 - test/bytecode/Example.jav | 9 - test/bytecode/Exceptions.jav | 3 - test/bytecode/Faculty.jav | 14 - test/bytecode/Faculty2.jav | 10 - test/bytecode/For.jav | 30 -- test/bytecode/ForTest.java | 11 - test/bytecode/Gen.jav | 5 - test/bytecode/Generics.jav | 17 - test/bytecode/Generics2.jav | 6 - test/bytecode/Generics2Test.java | 7 - test/bytecode/GenericsTest.java | 7 - test/bytecode/IfTest.jav | 10 - test/bytecode/Import.jav | 8 - test/bytecode/ImportTest.java | 7 - test/bytecode/Interface1.jav | 3 - test/bytecode/InterfaceTest.java | 7 - test/bytecode/JavaTXCompilerTest.java | 90 ------ test/bytecode/LamAssign.jav | 15 - test/bytecode/LamAssignTest.java | 7 - test/bytecode/LamRunnable.jav | 9 - test/bytecode/Lambda.jav | 18 -- test/bytecode/Lambda2.jav | 32 -- test/bytecode/Lambda3.jav | 23 -- test/bytecode/Methods.jav | 14 - test/bytecode/MethodsTest.java | 7 - test/bytecode/Op.jav | 12 - test/bytecode/OpTest.java | 7 - test/bytecode/OverlaodGen.jav | 11 - test/bytecode/OverlaodGenTest.java | 7 - test/bytecode/RecursiveMeth.jav | 5 - test/bytecode/ReturnMethod.jav | 6 - test/bytecode/TestIfTest.java | 7 - test/bytecode/VoidMeth.jav | 4 - test/parser/AntlrTest.jav | 6 - test/parser/BoundedParameter.jav | 3 - test/parser/CastTest.jav | 8 - test/parser/ExtendsTest.jav | 4 - test/parser/FeatherWeightJava.jav | 11 - test/parser/FieldInitializationTest.jav | 3 - test/parser/FieldVarTest.jav | 5 - test/parser/GeneralParserTest.java | 55 ---- test/parser/GenericFieldVarTest.jav | 3 - test/parser/ImportTest.jav | 4 - test/parser/ImportTest2.jav | 4 - test/parser/ImportTestGeneric.jav | 5 - test/parser/NewTest.jav | 5 - test/parser/OpratorTest.jav | 12 - test/parser/PackageNameTest.jav | 9 - test/parser/StatementsTest.jav | 8 - test/parser/StructuralTypes.jav | 5 - test/parser/WhileTest.jav | 14 - test/typeinference/JavaTXCompilerTest.java | 140 --------- test/visualisation/ToString.java | 5 - testBytecode/Field.java | 6 - testBytecode/Import.java | 8 - testBytecode/Lam1.java | 10 - testBytecode/LamRun.java | 8 - testBytecode/MethFieldVar.java | 38 --- testBytecode/Subclass.java | 6 - testBytecode/SuperTest.java | 14 - testBytecode/Superclass.java | 6 - testBytecode/TestMyTest.java | 11 - testBytecode/generatedBC/.gitignore | 4 - testBytecode/manually/Fac1.java | 6 - testBytecode/manually/Fac2.java | 14 - testBytecode/manually/LamAssign.java | 10 - testBytecode/manually/LamAssignWithM.java | 12 - testBytecode/manually/LamWithAnField.java | 14 - testBytecode/manually/LamWithField.java | 14 - testBytecode/manually/ReturnM1.java | 6 - testBytecode/public | 1 - testBytecode/testF.java | 5 - testBytecode/testTets.java | 5 - testBytecode/testTetsF.java | 5 - 104 files changed, 1148 insertions(+), 1606 deletions(-) create mode 100644 asp/adaptRules.lp create mode 100644 asp/cartesian.lp create mode 100644 asp/facultyTestInput.lp create mode 100644 asp/fc.lp create mode 100644 asp/fc.lp.backup create mode 100644 asp/reduceRules.lp create mode 100644 asp/result.lp create mode 100644 asp/rule5.test create mode 100644 asp/step4.lp create mode 100644 asp/step4.test create mode 100644 asp/subst.lp create mode 100644 asp/testInput.lp create mode 100644 asp/testReduce.lp create mode 100644 asp/testUnifikation.lp create mode 100644 asp/unifikation.lp create mode 100644 asp/unifikation.lp.backup create mode 100644 asp/vectorTestInput.lp delete mode 100644 src/de/dhbwstuttgart/sat/asp/ASPUnifyWithoutWildcards.java delete mode 100644 test/asp/UnifyWithoutWildcards.java delete mode 100644 test/asp/unifywithoutwildcards/ASPFactoryTest.java delete mode 100644 test/asp/unifywithoutwildcards/ASPTests.java delete mode 100644 test/asp/unifywithoutwildcards/JavaTXCompilerASPBenchmark.java delete mode 100644 test/asp/unifywithoutwildcards/JavaTXCompilerASPTest.java delete mode 100644 test/astfactory/ASTFactoryTest.java delete mode 100644 test/bytecode/ATest.java delete mode 100644 test/bytecode/AssignToLit.jav delete mode 100644 test/bytecode/AssignToLitTest.java delete mode 100644 test/bytecode/DuMethod.jav delete mode 100644 test/bytecode/DuMethodTest.java delete mode 100644 test/bytecode/EmptyMethod.jav delete mode 100644 test/bytecode/Example.jav delete mode 100644 test/bytecode/Exceptions.jav delete mode 100644 test/bytecode/Faculty.jav delete mode 100644 test/bytecode/Faculty2.jav delete mode 100644 test/bytecode/For.jav delete mode 100644 test/bytecode/ForTest.java delete mode 100644 test/bytecode/Gen.jav delete mode 100644 test/bytecode/Generics.jav delete mode 100644 test/bytecode/Generics2.jav delete mode 100644 test/bytecode/Generics2Test.java delete mode 100644 test/bytecode/GenericsTest.java delete mode 100644 test/bytecode/IfTest.jav delete mode 100644 test/bytecode/Import.jav delete mode 100644 test/bytecode/ImportTest.java delete mode 100644 test/bytecode/Interface1.jav delete mode 100644 test/bytecode/InterfaceTest.java delete mode 100644 test/bytecode/JavaTXCompilerTest.java delete mode 100644 test/bytecode/LamAssign.jav delete mode 100644 test/bytecode/LamAssignTest.java delete mode 100644 test/bytecode/LamRunnable.jav delete mode 100644 test/bytecode/Lambda.jav delete mode 100644 test/bytecode/Lambda2.jav delete mode 100644 test/bytecode/Lambda3.jav delete mode 100644 test/bytecode/Methods.jav delete mode 100644 test/bytecode/MethodsTest.java delete mode 100644 test/bytecode/Op.jav delete mode 100644 test/bytecode/OpTest.java delete mode 100644 test/bytecode/OverlaodGen.jav delete mode 100644 test/bytecode/OverlaodGenTest.java delete mode 100644 test/bytecode/RecursiveMeth.jav delete mode 100644 test/bytecode/ReturnMethod.jav delete mode 100644 test/bytecode/TestIfTest.java delete mode 100644 test/bytecode/VoidMeth.jav delete mode 100644 test/parser/AntlrTest.jav delete mode 100644 test/parser/BoundedParameter.jav delete mode 100644 test/parser/CastTest.jav delete mode 100644 test/parser/ExtendsTest.jav delete mode 100644 test/parser/FeatherWeightJava.jav delete mode 100644 test/parser/FieldInitializationTest.jav delete mode 100644 test/parser/FieldVarTest.jav delete mode 100644 test/parser/GeneralParserTest.java delete mode 100644 test/parser/GenericFieldVarTest.jav delete mode 100644 test/parser/ImportTest.jav delete mode 100644 test/parser/ImportTest2.jav delete mode 100644 test/parser/ImportTestGeneric.jav delete mode 100644 test/parser/NewTest.jav delete mode 100644 test/parser/OpratorTest.jav delete mode 100644 test/parser/PackageNameTest.jav delete mode 100644 test/parser/StatementsTest.jav delete mode 100644 test/parser/StructuralTypes.jav delete mode 100644 test/parser/WhileTest.jav delete mode 100644 test/typeinference/JavaTXCompilerTest.java delete mode 100644 test/visualisation/ToString.java delete mode 100644 testBytecode/Field.java delete mode 100644 testBytecode/Import.java delete mode 100644 testBytecode/Lam1.java delete mode 100644 testBytecode/LamRun.java delete mode 100644 testBytecode/MethFieldVar.java delete mode 100644 testBytecode/Subclass.java delete mode 100644 testBytecode/SuperTest.java delete mode 100644 testBytecode/Superclass.java delete mode 100644 testBytecode/TestMyTest.java delete mode 100644 testBytecode/generatedBC/.gitignore delete mode 100644 testBytecode/manually/Fac1.java delete mode 100644 testBytecode/manually/Fac2.java delete mode 100644 testBytecode/manually/LamAssign.java delete mode 100644 testBytecode/manually/LamAssignWithM.java delete mode 100644 testBytecode/manually/LamWithAnField.java delete mode 100644 testBytecode/manually/LamWithField.java delete mode 100644 testBytecode/manually/ReturnM1.java delete mode 100644 testBytecode/public delete mode 100644 testBytecode/testF.java delete mode 100644 testBytecode/testTets.java delete mode 100644 testBytecode/testTetsF.java diff --git a/asp/adaptRules.lp b/asp/adaptRules.lp new file mode 100644 index 00000000..2c81b04e --- /dev/null +++ b/asp/adaptRules.lp @@ -0,0 +1,19 @@ +%makeAdapt(smallerDot(CFC, DFC)) :- smallerDot(C, D), type(C, CN, CNP), type(D, DN, DNP), CNP != DNP + %, smaller(CFC, DFC), type(CFC, CN, CNP), type(DFC, DN, DNP), mapRootFC(smaller(CFC, DFC), _, _) + %. + + +type(pointer(smallerDot(C,D)), DN, DNP) +:- smallerDot(C, D), type(C, CN, CNP), type(D, DN, DNP), CNP != DNP + . +smallerDot(pointer(smallerDot(C,D)), D) +:- smallerDot(C, D), type(C, CN, CNP), type(D, DN, DNP), CNP != DNP + . + +param(pointer(smallerDot(C,D)), P, P2) +:- smallerDot(C, D), type(C, CN, CNP), type(D, DN, DNP), CNP != DNP + , smaller(CFC, DFC), type(CFC, CN, CNP), type(DFC, DN, DNP) + , mapRootFC(smaller(CFC, DFC), P1, P2), param(C, P, P1) + . + + diff --git a/asp/cartesian.lp b/asp/cartesian.lp new file mode 100644 index 00000000..8ff9b5e9 --- /dev/null +++ b/asp/cartesian.lp @@ -0,0 +1,22 @@ + +%Mit Hilfe von Quelle: https://www.cs.uni-potsdam.de/~torsten/Papers/asp4ki.pdf + +%Dieser Code generiert das Karthesische Produkt der Constraints des Inputs. +%und Constraints sind einfach weiterhin equals uns smallerDot +%oder constraints: +% oder(pointer, pointer) +%constraints innerhalb des oders müssen eingepackt sein: +% constraint(pointer, eigentlicher Constraint) +% um mehrere constraints als Und-Constraint innerhalb eines Oders zu verbinden kann die list(..) verwendet werden + +%Die eigentliche Oder-Verknüpfung: +cons(Cons1), cons(Cons2) :- oder(C1, C2), constraint(C1, Cons1), constraint(C2, Cons2). + +%Auspacken der constraints: +equals(X,Y) :- cons(equals(X,Y)). +smallerDot(X,Y) :- cons(smallerDot(X,Y)). +oder(X,Y) :- cons(oder(X,Y)). +list(X,Y) :- cons(list(X,Y)). +equals(X,Y) :- list(equals(X,Y), _). +smallerDot(X,Y) :- list(smallerDot(X,Y), _). +list(A,B) :- list(_, list(A,B)). diff --git a/asp/facultyTestInput.lp b/asp/facultyTestInput.lp new file mode 100644 index 00000000..be6044f1 --- /dev/null +++ b/asp/facultyTestInput.lp @@ -0,0 +1,70 @@ +typeVar(cRO). +smaller(cAVP,cAVQ). +type(cAVY,cjava_DOT_lang_DOT_Integer,0). +type(cAVI,cjava_DOT_lang_DOT_Integer,0). +type(cAVD,cjava_DOT_lang_DOT_Comparable,1). +type(cAVH,cjava_DOT_lang_DOT_Comparable,1). +type(cAVJ,cjava_DOT_lang_DOT_Number,0). +typeVar(cT). +equals(cQ,cRO). +smaller(cAVR,cAVS). +param(cAVZ,cYO,1). +param(cAVZ,cYP,2). +type(cAWD,cjava_DOT_lang_DOT_Integer,0). +typeVar(cO). +smaller(cAVN,cAVO). +type(cAWA,cjava_DOT_lang_DOT_Integer,0). +type(cAVF,cjava_DOT_lang_DOT_Object,0). +typeVar(cYA). +type(cAVU,cjava_DOT_lang_DOT_Integer,0). +equals(cN,cAVV). +smaller(cAVB,cAVC). +type(cAVO,cjava_DOT_lang_DOT_Object,0). +type(cAVB,cjava_DOT_io_DOT_Serializable,0). +smallerDot(cT,cM). +typeVar(cL). +smallerDot(cM,cL). +typeVar(cP). +type(cAVQ,cjava_DOT_lang_DOT_Number,0). +type(cAVR,cFaculty,0). +smallerDot(cAWD,cAWE). +typeVar(cYB). +type(cAVE,cjava_DOT_lang_DOT_Integer,0). +type(cAVN,cjava_DOT_lang_DOT_Number,0). +equals(cT,cAVT). +type(cAVV,cFaculty,0). +type(cAVC,cjava_DOT_lang_DOT_Object,0). +type(cAVM,cjava_DOT_lang_DOT_Object,0). +smaller(cAVG,cAVH). +type(cAVL,cjava_DOT_lang_DOT_Object,0). +type(cAWE,cjava_DOT_lang_DOT_Integer,0). +type(cAVG,cjava_DOT_lang_DOT_Integer,0). +param(cAVT,cAVU,2). +typeVar(cYO). +type(cAWB,cjava_DOT_lang_DOT_Integer,0). +type(cAVW,cjava_DOT_lang_DOT_Integer,0). +typeVar(cM). +param(cAVH,cAVI,1). +typeVar(cQ). +type(cAVX,cjava_DOT_lang_DOT_Integer,0). +equals(cYA,cO). +equals(cAWA,cP). +smallerDot(cM,cAVZ). +type(cAVK,cjava_DOT_io_DOT_Serializable,0). +smallerDot(cP,cQ). +smallerDot(cO,cAWB). +param(cAVD,cAVE,1). +smallerDot(cAVY,cYB). +smallerDot(cAVW,cAVX). +smaller(cAVD,cAVF). +smaller(cAVL,cAVM). +type(cAVP,cjava_DOT_lang_DOT_Integer,0). +typeVar(cYP). +typeVar(cN). +type(cAVT,cFun2,2). +param(cAVT,cRO,1). +type(cAVS,cjava_DOT_lang_DOT_Object,0). +type(cAWC,cFaculty,0). +smallerDot(cN,cAWC). +type(cAVZ,cFun2,2). +smaller(cAVJ,cAVK). diff --git a/asp/fc.lp b/asp/fc.lp new file mode 100644 index 00000000..0e2ca20c --- /dev/null +++ b/asp/fc.lp @@ -0,0 +1,24 @@ +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). + +%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/asp/fc.lp.backup b/asp/fc.lp.backup new file mode 100644 index 00000000..bc2b95b2 --- /dev/null +++ b/asp/fc.lp.backup @@ -0,0 +1,125 @@ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Anzahl Wildcards in einem Typ feststellen: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Start, am Ende der Parameterliste: +wildcard(A) :- extendsWildcard(A). +wildcard(A) :- superWildcard(A). +numWildcards(TP, Ende-1, Num) :- param(TP, Param, Ende), + numWildcards(Param, Num), type(TP,_,Ende) + , not wildcard(Param) + . +numWildcards(TP, Ende-1, Num + 1) :- param(TP, Param, Ende), + numWildcards(Param, Num), type(TP,_,Ende) + , wildcard(Param) + . +%Anschließend aufsummieren: +numWildcards(TP, ParamNum-1, NumWC1 + NumWC2 + 1) :- param(TP, Param, ParamNum), + numWildcards(Param, NumWC1), numWildcards(TP,ParamNum, NumWC2) + , wildcard(Param) + . +numWildcards(TP, ParamNum-1, NumWC1 + NumWC2) :- param(TP, Param, ParamNum), + numWildcards(Param, NumWC1), numWildcards(TP,ParamNum, NumWC2) + , not wildcard(Param) + . + +numWildcards(TP, Num) :- numWildcards(TP, 0, Num), param(TP, P, 1), wildcard(P). +numWildcards(TP, Num) :- numWildcards(TP, 0, Num), param(TP, P, 1), not wildcard(P). +numWildcards(TP, 0) :- type(TP, _, 0). +numWildcards(TP, 0) :- typeVar(TP). + +%%%%%%%%%%%%%%%%% +% Greater +%%%%%%%%%%%%%%%% +{ greaterGen(P, A, AFC, BFC) : smaller(AFC, BFC), type(AFC, AN, ANum) } == 1 :- greaterGen(P, A), type(A, AN, ANum) +%, greaterArgGenNum(P, N), N < 100000 +. +%:- greaterGen(A, _, _ , _), numWildcards(A, NW), NW >= 1. +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). +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). + +makeSmallerGenS(Pointer, T) :- smallerArgGen(Pointer, T), extendsWildcard(T). +makeGreaterGenS(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). + diff --git a/asp/reduceRules.lp b/asp/reduceRules.lp new file mode 100644 index 00000000..eb71e6df --- /dev/null +++ b/asp/reduceRules.lp @@ -0,0 +1,44 @@ + +%%%%%%%%%%%%%%%%%%%% +% reduce1 +%%%%%%%%%%%%%%%%%%%% +smallerDotWC(CP, DP) +:- smallerDot(C, D), type(C, CN, NP), type(D, DN, NP) + , type(CFC, CN, NP), type(DFC, DN, NP), smaller(CFC, DFC) + , mapFC(smaller(CFC, DFC), N, N2) + , param(C, CP, N), param(D, DP, N2), N = 1 .. NP + . + + +%%%%%%%%%%%%%%%%%%%% +% reduceExt +%%%%%%%%%%%%%%%%%%%% +%TODO +%smallerDotWC(CP, DP) +%:- smallerDotWC(C, D), type(C, CN, NP), type(D, DN, NP) + %, type(CFC, CN, NP), type(DFC, DN, NP), smaller(CFC, DFC) + %, mapFC(smaller(CFC, DFC), N, N2) + %, param(C, CP, N), param(D, DP, N2), N = 1 .. NP + %. + + +%%%%%%%%%%%%%%%%%%%% +% reduceEq +%%%%%%%%%%%%%%%%%%%% +equals(CP, DP) +:- smallerDot(C, D), type(C, CN, NP), type(D, CN, NP) + , param(C, CP, N), param(D, DP, N), N = 1 .. NP + . + + +%%%%%%%%%%%%%%%%%%%% +% reduce2 +%%%%%%%%%%%%%%%%%%%% +equals(P1, P2) :- equals(C, D), type(C, CN, NP), type(D, CN, NP) + , param(C, P1, N), param(D, P2, N) + . + +%%%%%%%%%%%%%%%%%%%% +% swap +%%%%%%%%%%%%%%%%%%%% +equals(A, B) :- equals(B, A), typeVar(A), not typeVar(B). diff --git a/asp/result.lp b/asp/result.lp new file mode 100644 index 00000000..3d58897e --- /dev/null +++ b/asp/result.lp @@ -0,0 +1 @@ +:- equals(A, B), equals(A, C), type(B,BN,_), type(C,CN,_), CN != BN. \ No newline at end of file diff --git a/asp/rule5.test b/asp/rule5.test new file mode 100644 index 00000000..c5376230 --- /dev/null +++ b/asp/rule5.test @@ -0,0 +1,291 @@ +param(cEPQ,cAEG,1). +param(cEQX,cAEG,1). +param(cEQE,cAEG,1). +typeVar(cBFS). +type(cEON,cjava_DOT_io_DOT_Serializable,0). +constraint(cESK,list(equals(cESN,cM),list(smallerDot(cL,cESM),list(smallerDot(cESL,cQC),null)))). +type(cESM,cjava_DOT_util_DOT_ArrayList,1). +param(cERA,cDKY,1). +param(cEQM,cDKY,1). +type(cEQE,cjava_DOT_util_DOT_List,1). +type(cEQI,cjava_DOT_util_DOT_Collection,1). +type(cEPS,cjava_DOT_util_DOT_AbstractList,1). +param(cEQD,cBFS,1). +type(cEPQ,cjava_DOT_lang_DOT_Iterable,1). +type(cEOM,cjava_DOT_util_DOT_ArrayList,1). +smaller(cEOW,cEOX). +type(cEPV,cjava_DOT_lang_DOT_Object,0). +param(cERQ,cCII,1). +param(cEPY,cDKY,1). +smaller(cEPM,cEPN). +param(cEOQ,cBFS,1). +smaller(cEQC,cEQD). +type(cERM,cjava_DOT_util_DOT_Vector,1). +param(cESJ,cQF,1). +type(cESN,cjava_DOT_lang_DOT_Boolean,0). +smaller(cEPI,cEPJ). +type(cERJ,cjava_DOT_util_DOT_Collection,1). +type(cEQA,cjava_DOT_util_DOT_ArrayList,1). +type(cEOA,cjava_DOT_util_DOT_ArrayList,1). +param(cEOT,cBFS,1). +type(cEOW,cjava_DOT_util_DOT_AbstractCollection,1). +param(cEPC,cCII,1). +type(cEQB,cjava_DOT_util_DOT_AbstractList,1). +param(cENS,cCII,1). +type(cEQS,cjava_DOT_util_DOT_Collection,1). +typeVar(cDKY). +type(cEPU,cjava_DOT_util_DOT_AbstractCollection,1). +smaller(cEQG,cEQH). +type(cEQJ,cjava_DOT_lang_DOT_Object,0). +param(cEQG,cCII,1). +param(cEPN,cCII,1). +param(cESE,cDKY,1). +param(cEQZ,cBFS,1). +type(cERK,cjava_DOT_util_DOT_Vector,1). +smaller(cEPE,cEPF). +type(cEOK,cjava_DOT_util_DOT_ArrayList,1). +typeVar(cQC). +smaller(cERE,cERF). +param(cEOA,cCII,1). +type(cEQQ,cjava_DOT_lang_DOT_Iterable,1). +smaller(cEPA,cEPB). +typeVar(cM). +smaller(cERA,cERB). +type(cEPP,cjava_DOT_lang_DOT_Object,0). +param(cEPS,cCII,1). +param(cENQ,cAEG,1). +param(cEPH,cCII,1). +smaller(cERW,cERX). +type(cEOG,cjava_DOT_util_DOT_Collection,1). +type(cERE,cjava_DOT_io_DOT_Serializable,0). +param(cERG,cDKY,1). +smaller(cERS,cERT). +param(cEOF,cBFS,1). +type(cESA,cjava_DOT_util_DOT_AbstractCollection,1). +param(cERY,cDKY,1). +typeVar(cCII). +type(cEOO,cjava_DOT_util_DOT_Collection,1). +type(cERN,cjava_DOT_lang_DOT_Cloneable,0). +param(cENO,cBFS,1). +typeVar(cAEG). +type(cERB,cjava_DOT_lang_DOT_Object,0). +typeVar(cQD). +param(cEQP,cAEG,1). +param(cEOO,cAEG,1). +type(cESF,cjava_DOT_io_DOT_Serializable,0). +param(cEPE,cBFS,1). +type(cEPG,cjava_DOT_util_DOT_ArrayList,1). +type(cEPD,cjava_DOT_util_DOT_Collection,1). +type(cERC,cjava_DOT_util_DOT_AbstractCollection,1). +type(cERQ,cjava_DOT_util_DOT_ArrayList,1). +type(cENW,cjava_DOT_lang_DOT_Iterable,1). +type(cENQ,cjava_DOT_util_DOT_ArrayList,1). +smaller(cESC,cESD). +type(cEOU,cjava_DOT_util_DOT_List,1). +smaller(cENO,cENP). +smaller(cEOE,cEOF). +smaller(cERO,cERP). +type(cEPH,cjava_DOT_util_DOT_List,1). +smaller(cESE,cESF). +param(cERO,cCII,1). +param(cEOS,cBFS,1). +type(cEQX,cjava_DOT_util_DOT_List,1). +type(cEQR,cjava_DOT_lang_DOT_Object,0). +param(cEQY,cBFS,1). +smaller(cEQW,cEQX). +smaller(cEOC,cEOD). +smaller(cERM,cERN). +param(cEPT,cCII,1). +param(cEQQ,cBFS,1). +param(cERZ,cDKY,1). +type(cENV,cjava_DOT_util_DOT_AbstractCollection,1). +type(cEOZ,cjava_DOT_lang_DOT_Object,0). +param(cEQK,cAEG,1). +type(cEQO,cjava_DOT_util_DOT_AbstractList,1). +type(cEQU,cjava_DOT_util_DOT_Vector,1). +smaller(cEOK,cEOL). +type(cEQW,cjava_DOT_util_DOT_ArrayList,1). +type(cENO,cjava_DOT_util_DOT_ArrayList,1). +type(cERF,cjava_DOT_lang_DOT_Object,0). +param(cEPA,cCII,1). +type(cERV,cjava_DOT_io_DOT_Serializable,0). +smaller(cERG,cERH). +param(cEOU,cCII,1). +param(cENU,cDKY,1). +param(cESM,cQE,1). +param(cEOP,cAEG,1). +param(cEPO,cBFS,1). +param(cEOK,cBFS,1). +constraint(cESG,list(smallerDot(cL,cESJ),list(equals(cESI,cM),list(smallerDot(cESH,cQD),null)))). +type(cEPE,cjava_DOT_util_DOT_ArrayList,1). +param(cEQF,cAEG,1). +smaller(cEPY,cEPZ). +param(cESC,cDKY,1). +param(cENY,cAEG,1). +param(cEOM,cAEG,1). +smaller(cEQO,cEQP). +type(cEOR,cjava_DOT_lang_DOT_Object,0). +type(cESC,cjava_DOT_util_DOT_List,1). +type(cEOP,cjava_DOT_lang_DOT_Iterable,1). +type(cERU,cjava_DOT_util_DOT_ArrayList,1). +type(cERY,cjava_DOT_util_DOT_AbstractCollection,1). +param(cEPL,cAEG,1). +param(cEOX,cAEG,1). +type(cEQK,cjava_DOT_util_DOT_ArrayList,1). +type(cERZ,cjava_DOT_util_DOT_Collection,1). +param(cEQA,cBFS,1). +param(cERI,cDKY,1). +smaller(cEPC,cEPD). +type(cEQT,cjava_DOT_lang_DOT_Iterable,1). +type(cERT,cjava_DOT_lang_DOT_Object,0). +type(cEOY,cjava_DOT_lang_DOT_Cloneable,0). +param(cEQU,cDKY,1). +type(cEPB,cjava_DOT_util_DOT_AbstractCollection,1). +type(cESI,cjava_DOT_lang_DOT_Boolean,0). +smaller(cENU,cENV). +type(cESE,cjava_DOT_util_DOT_Vector,1). +param(cEOG,cCII,1). +type(cEOI,cjava_DOT_util_DOT_List,1). +type(cENU,cjava_DOT_util_DOT_AbstractList,1). +smaller(cERU,cERV). +type(cEPN,cjava_DOT_util_DOT_AbstractList,1). +type(cEQV,cjava_DOT_util_DOT_List,1). +type(cEPA,cjava_DOT_util_DOT_AbstractList,1). +smaller(cEPQ,cEPR). +type(cEQL,cjava_DOT_util_DOT_AbstractList,1). +param(cEQH,cCII,1). +type(cEOL,cjava_DOT_lang_DOT_Cloneable,0). +type(cEQY,cjava_DOT_util_DOT_AbstractList,1). +type(cEOF,cjava_DOT_util_DOT_AbstractCollection,1). +param(cEQT,cBFS,1). +smaller(cEOS,cEOT). +type(cENR,cjava_DOT_lang_DOT_Cloneable,0). +type(cEQD,cjava_DOT_util_DOT_Collection,1). +type(cENZ,cjava_DOT_lang_DOT_Object,0). +param(cEPG,cCII,1). +type(cEQF,cjava_DOT_util_DOT_Collection,1). +type(cEQN,cjava_DOT_util_DOT_List,1). +type(cEQH,cjava_DOT_util_DOT_Collection,1). +smaller(cEOY,cEOZ). +type(cERR,cjava_DOT_lang_DOT_Cloneable,0). +param(cERU,cCII,1). +type(cESB,cjava_DOT_lang_DOT_Object,0). +smaller(cEPO,cEPP). +param(cEPU,cDKY,1). +param(cEQI,cDKY,1). +smaller(cEQE,cEQF). +smaller(cEQA,cEQB). +type(cEPM,cjava_DOT_util_DOT_ArrayList,1). +param(cENW,cCII,1). +param(cEOE,cBFS,1). +type(cEOX,cjava_DOT_util_DOT_Collection,1). +type(cEQG,cjava_DOT_util_DOT_List,1). +param(cERH,cDKY,1). +smaller(cEQI,cEQJ). +param(cEOC,cAEG,1). +type(cEPT,cjava_DOT_util_DOT_List,1). +type(cEOT,cjava_DOT_util_DOT_Collection,1). +type(cERP,cjava_DOT_lang_DOT_Object,0). +type(cERS,cMyVector,0). +type(cESD,cjava_DOT_lang_DOT_Object,0). +type(cEOD,cjava_DOT_util_DOT_RandomAccess,0). +smaller(cEPK,cEPL). +type(cEPK,cjava_DOT_util_DOT_AbstractList,1). +param(cERM,cDKY,1). +smaller(cEPG,cEPH). +type(cEOS,cjava_DOT_util_DOT_AbstractCollection,1). +param(cEQS,cBFS,1). +param(cEQW,cAEG,1). +type(cENY,cjava_DOT_util_DOT_Collection,1). +param(cEPW,cBFS,1). +type(cEOJ,cjava_DOT_lang_DOT_Object,0). +param(cEQC,cBFS,1). +type(cENT,cjava_DOT_lang_DOT_Iterable,1). +param(cERK,cDKY,1). +type(cEPY,cjava_DOT_util_DOT_Vector,1). +type(cEQM,cjava_DOT_util_DOT_AbstractList,1). +smaller(cENW,cENX). +smaller(cEPW,cEPX). +smaller(cEOM,cEON). +smaller(cEQM,cEQN). +smaller(cEPS,cEPT). +type(cENX,cjava_DOT_lang_DOT_Object,0). +smallerDot(cL,cK). +type(cESJ,cjava_DOT_util_DOT_Vector,1). +type(cEQC,cjava_DOT_util_DOT_List,1). +type(cEOB,cjava_DOT_util_DOT_RandomAccess,0). +smaller(cEOU,cEOV). +param(cERC,cAEG,1). +smaller(cEQU,cEQV). +type(cERG,cjava_DOT_util_DOT_Collection,1). +type(cESH,cjava_DOT_lang_DOT_Object,0). +smaller(cEOQ,cEOR). +oder(cESG,cESK). +smaller(cEQQ,cEQR). +param(cEPD,cCII,1). +type(cEPZ,cjava_DOT_util_DOT_AbstractList,1). +param(cEQL,cAEG,1). +type(cEPC,cjava_DOT_util_DOT_AbstractCollection,1). +smaller(cENS,cENT). +param(cESA,cBFS,1). +type(cERA,cjava_DOT_lang_DOT_Iterable,1). +smaller(cEQY,cEQZ). +typeVar(cQE). +type(cEOE,cjava_DOT_util_DOT_AbstractList,1). +type(cESL,cjava_DOT_lang_DOT_Object,0). +type(cERX,cjava_DOT_lang_DOT_Object,0). +type(cENP,cjava_DOT_util_DOT_List,1). +type(cEPI,cjava_DOT_util_DOT_RandomAccess,0). +typeVar(cK). +smaller(cERK,cERL). +type(cERD,cjava_DOT_lang_DOT_Object,0). +type(cERI,cjava_DOT_util_DOT_List,1). +type(cEPJ,cjava_DOT_lang_DOT_Object,0). +smaller(cESA,cESB). +type(cEOC,cjava_DOT_util_DOT_ArrayList,1). +param(cEOW,cAEG,1). +param(cERJ,cDKY,1). +param(cEQB,cBFS,1). +smaller(cEOI,cEOJ). +type(cEPL,cjava_DOT_util_DOT_AbstractCollection,1). +param(cEQO,cAEG,1). +smaller(cERI,cERJ). +typeVar(cQF). +param(cEPK,cAEG,1). +param(cENP,cBFS,1). +type(cERO,cjava_DOT_util_DOT_AbstractCollection,1). +typeVar(cL). +smaller(cEOG,cEOH). +param(cEQV,cDKY,1). +type(cERW,cjava_DOT_lang_DOT_Object,0). +type(cEQZ,cjava_DOT_util_DOT_List,1). +type(cENS,cjava_DOT_util_DOT_Collection,1). +smaller(cENY,cENZ). +param(cEOI,cAEG,1). +smaller(cEOO,cEOP). +smaller(cERY,cERZ). +param(cEPZ,cDKY,1). +param(cEQN,cDKY,1). +smaller(cEQK,cEQL). +type(cEOH,cjava_DOT_lang_DOT_Object,0). +type(cEPF,cjava_DOT_util_DOT_RandomAccess,0). +smaller(cERC,cERD). +type(cEPO,cjava_DOT_util_DOT_List,1). +type(cEPR,cjava_DOT_lang_DOT_Object,0). +type(cEQP,cjava_DOT_util_DOT_List,1). +smaller(cEQS,cEQT). +type(cERL,cjava_DOT_util_DOT_RandomAccess,0). +param(cENT,cCII,1). +type(cEOQ,cjava_DOT_util_DOT_Collection,1). +type(cEPW,cjava_DOT_util_DOT_ArrayList,1). +type(cEPX,cjava_DOT_io_DOT_Serializable,0). +smaller(cEPU,cEPV). +smaller(cEOA,cEOB). +type(cEOV,cjava_DOT_lang_DOT_Object,0). +param(cEPB,cCII,1). +smaller(cENQ,cENR). +param(cEPM,cCII,1). +smaller(cERQ,cERR). +param(cENV,cDKY,1). +type(cERH,cjava_DOT_lang_DOT_Iterable,1). + diff --git a/asp/step4.lp b/asp/step4.lp new file mode 100644 index 00000000..e362b80c --- /dev/null +++ b/asp/step4.lp @@ -0,0 +1,113 @@ +%Problem hier: Es gibt in der FiniteClosure nun smaller Beziehungen der Art: +%%(Matrix <) Vector> < List> +%Mit diesen funktioniert die Unifikation in Schritt 4 des Algorithmus nicht korrekt. +%Lösung: Man könnte es lösen mit: +%typeVarOnly(TP) :- type(TP, _, PN), {notTypeVarOnly(TP, A) : param(TP, A, _), type(A, _, _)} == 0. + +% Die Karthesischen Produkte von Schritt 4 des Unifikationsalgorithmus + +{ makeRule1(A,TP,TPFC, SmallerType) : smaller(SmallerType, TPFC), type(TPFC, TypeName, NumParams) } = 1 +:- smallerDot(A, TP), type(TP, TypeName, NumParams), typeVar(A).%, smaller(_, TPFC), type(TPFC, TypeName, NumParams). + +%:- makeRule1(A, B, C,_), makeRule1(A,B,D,_), D != C. + +%Alle Greater Arg Paralisten des Typen C generieren +greaterArgParaList(pointer(rule1(A, TP)), TPFC) :- makeRule1(A,TP,TPFC,_). + +%Es braucht greaterArg Parameter von allen Parametern des Typs: +greaterArg(pointer(P, Param), Param) :- greaterArgParaList(P, FCType), type(FCType, FCTName, FCTPN), param(FCType, Param, Num), not typeVar(Param). + +%Ein neuer Typ muss angelegt werden: +type(P, FCTName, FCTPN) +:- greaterArgParaList(P, FCType), type(FCType, FCTName, FCTPN). + +param(P, pointer(P, Param), N) +:- greaterArgParaList(P, FCType), type(FCType, FCTName, FCTPN) + , param(FCType, Param, N), not typeVar(Param) + . +%Typvariablen bleiben bestehen. Sie werden durch das unify ausgetauscht +param(P, Param, N) +:- greaterArgParaList(P, FCType), type(FCType, FCTName, FCTPN) + , param(FCType, Param, N), typeVar(Param) + . + + +%Die Unifikation vom AusgangsTyp im Constraint und dem greaterArgList gebildeten Typen +unify(pointer(rule1unify(A,TP)), pointer(rule1(A,TP)), TP) +:- makeRule1(A,TP,TPFC, _). + +%Unify auf den SmallerType anwenden: +type(pointer(rule1unify(A,TP,TPFC,SmallerType)), TN, TNum) +:- makeRule1(A, TP, TPFC, SmallerType), type(SmallerType, TN, TNum). + +{ param(pointer(rule1unify(A,TP,TPFC,SmallerType)), PNew, PN) : unify(pointer(rule1unify(A,TP)), P, PNew)} == 1 +:- makeRule1(A, TP, TPFC, SmallerType), param(SmallerType, P, PN). + +%Am Schluss davon noch das smaller bilden: +smallerGen(pointer(smallerDot(A,TP), SmallerType), pointer(rule1unify(A,TP,TPFC,SmallerType))) +:- makeRule1(A, TP, TPFC, SmallerType), type(TP, TypeName, NumParams) %Die Bedingung für Regel 1 + . + +smallerGen(A) :- list(smallerGen(A),_). +type(A,B,C) :- list(type(A,B,C),_). +list(A,B) :- list(_, list(A,B)). + +smallerGen(A,A) :- smallerGen(A). + +{ equals(A, NewType) : smallerGen(pointer(smallerDot(A,TP), SmallerType), NewType) } == 1 +:- smallerDot(A, TP), type(TP, TypeName, NumParams), typeVar(A) %Das karthesische Produkt + , smaller(SmallerType, TPFC), type(pointer(smallerDot(A,TP), SmallerType), _, _) + . + +%TODO: Typen welche durch Unifikation ersetzt werden auch zu Constraints machen +%%%%%%%%%%%%%%%%%% +% Regel 2 +%%%%%%%%%%%%%%%%% + +%{ makeRule2(A, Theta', TPFC) : smaller(SmallerType, TPFC), type(TPFC, TypeName, NumParams) } == 1 +%:- smallerDotWC(A, Theta'), extendsWildcard(Theta'), typeVar(A). +% +%%Alle Greater Arg Paralisten des Typen C generieren +%greaterArgParaList(pointer(rule2(A, TP)), TPFC) :- makeRule2(A,TP,TPFC,_). +% +%unify(pointer(rule2(A,TP)), TP) +%:- makeRule2(A,TP,TPFC) +%% , type(TP, TypeName, NumParams), typeVar(A), type(TPFC, TypeName, NumParams) + %. +% +%{ list(smallerArgGen(pointer(smallerDot(A,TP), SmallerType), SmallerType), +%list(extendsWildcard(pointer(smallerDot(A,TP), SmallerType)), null)) +%: smaller(SmallerType, TPFC), type(SmallerType, SmallerName, SmallerPNum) } == 1 +%:- makeRule2(A, TP, TPFC) %Die Bedingung für Regel 2 + %. +% +%smallerArgGen(A, B) :- list(smallerArgGen(A, B), _). +%extendsWildcard(A) :- list(extendsWildcard(A), _). + +%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Regel 3 +%%%%%%%%%%%%%%%%%%%%%%%%%%% +smallerArgGen(pointer(smallerDotWC(A, Theta')), Theta') :- smallerDotWC(A, Theta'), superWildcard(Theta'). +equals(A, pointer(smallerDotWC(A, Theta'))) :- smallerDotWC(A, Theta'), superWildcard(Theta'). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Regel 4 +%%%%%%%%%%%%%%%%%%%%%%%%%%% +equals(A, Theta') :- smallerDotWC(A, Theta'), not wildcard(Theta'). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Regel 5 +%%%%%%%%%%%%%%%%%%%%%%%%%%% +greaterGen(pointer(smallerDot(Theta,A)), Theta) :- smallerDot(Theta, A), not wildcard(Theta), not typeVar(Theta), typeVar(A) . +equals(A, pointer(smallerDot(Theta,A))) :- smallerDot(Theta, A), not wildcard(Theta) , not typeVar(Theta), typeVar(A) . + + +%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Regel 6 +%%%%%%%%%%%%%%%%%%%%%%%%%%% +greaterArgGen(pointer(smallerDotWC(Theta,A)), Theta) :- smallerDotWC(Theta, A), extendsWildcard(Theta) . +equals(A, pointer(smallerDot(Theta,A))) :- smallerDotWC(Theta, A), extendsWildcard(Theta) . + +%TODO: Regel 7 diff --git a/asp/step4.test b/asp/step4.test new file mode 100644 index 00000000..77d15cb0 --- /dev/null +++ b/asp/step4.test @@ -0,0 +1,8 @@ + +%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Regel 5 +%%%%%%%%%%%%%%%%%%%%%%%%%%% +greaterGen(pointer(smallerDot(Theta,A)), Theta) :- smallerDot(Theta, A), not wildcard(Theta), not typeVar(Theta), typeVar(A) . +equals(A, pointer(smallerDot(Theta,A))) :- smallerDot(Theta, A), not wildcard(Theta) , not typeVar(Theta), typeVar(A) . + + diff --git a/asp/subst.lp b/asp/subst.lp new file mode 100644 index 00000000..1727eacc --- /dev/null +++ b/asp/subst.lp @@ -0,0 +1,14 @@ +subst(TV,T) :- equals(TV, T), not occurs(TV, T), not typeVar(T), typeVar(TV). + +equals(A, pointer(TP, subst(TV, T))) +:- equals(A, TP), subst(TV, T), not typeVar(TP), occurs(TV, TP). + +type(pointer(TP, subst(TV, T)), Name, Num) +:- type(TP, Name, Num), subst(TV, T), occurs(TV, TP). + +param(pointer(TP, subst(TV, T)), Param, PNum) +:- type(pointer(TP, subst(TV, T)), Name, Num), subst(TV, T), param(TP, Param, PNum), not occurs(TV, Param). + +param(pointer(TP, subst(TV, T)), pointer(Param, subst(TV, T)), PNum) +:- type(pointer(TP, subst(TV, T)), Name, Num), subst(TV, T), param(TP, Param, PNum), occurs(TV, Param). + diff --git a/asp/testInput.lp b/asp/testInput.lp new file mode 100644 index 00000000..92211957 --- /dev/null +++ b/asp/testInput.lp @@ -0,0 +1,219 @@ +typeVar(a). +type(t1, cjava_DOT_util_DOT_Vector, 1). +param(t1, t2, 1). +type(t2, cjava_DOT_util_DOT_Vector, 1). +param(t2, b, 1). +typeVar(b). + +smallerDot(a, t1). + + +typeFC(cBUF,cjava_DOT_util_DOT_Vector,1). +paramFC(cBQX,cAKH,1). +typeFC(cBRW,cjava_DOT_lang_DOT_Object,0). +typeFC(cBRF,cjava_DOT_util_DOT_Vector,1). +typeFC(cBTR,cjava_DOT_util_DOT_Vector,1). +paramFC(cBTZ,cAKH,1). +paramFC(cBUN,cAKH,1). +typeFC(cBRY,cjava_DOT_util_DOT_Vector,1). +paramFC(cBUE,cBUF,1). +paramFC(cBRL,cAKH,1). +smaller(cBSB,cBSE). +paramFC(cBTR,cBTS,1). +smaller(cBQJ,cBQK). +typeFC(cBQP,cjava_DOT_util_DOT_Vector,1). +typeFC(cBUA,cjava_DOT_util_DOT_Collection,1). +typeFC(cBSD,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBUE,cjava_DOT_util_DOT_Collection,1). +typeFC(cBUK,cjava_DOT_util_DOT_Collection,1). +paramFC(cBTJ,cAKH,1). +typeFC(cBRZ,cjava_DOT_lang_DOT_Integer,0). +smaller(cBSF,cBSI). +typeFC(cBRT,cjava_DOT_lang_DOT_Integer,0). +paramFC(cBRX,cBRY,1). +typeFC(cBRJ,cjava_DOT_util_DOT_Vector,1). +paramFC(cBRF,cBRG,1). +typeFC(cBQN,cjava_DOT_lang_DOT_Integer,0). +smaller(cBRL,cBRM). +smaller(cBUH,cBUK). +smaller(cBTR,cBTU). +paramFC(cBUL,cBUM,1). +smaller(cBRH,cBRI). +typeFC(cBTV,cjava_DOT_util_DOT_Vector,1). +typeFC(cBSQ,cjava_DOT_lang_DOT_Object,0). +typeFC(cBUL,cjava_DOT_util_DOT_Vector,1). +typeFC(cBTX,cjava_DOT_lang_DOT_Object,0). +paramFC(cBSN,cAKH,1). +typeFC(cBTE,cjava_DOT_util_DOT_Vector,1). +paramFC(cBUC,cBUD,1). +smaller(cBST,cBSU). +paramFC(cBRI,cAKH,1). +typeFC(cBSR,cjava_DOT_lang_DOT_Iterable,1). +typeFC(cBRC,cjava_DOT_util_DOT_RandomAccess,0). +typeFC(cBTL,cjava_DOT_util_DOT_Collection,1). +typeFC(cBSF,cjava_DOT_util_DOT_AbstractList,1). +typeFC(cBSX,cjava_DOT_util_DOT_AbstractList,1). +paramFC(cBSI,cBSJ,1). +typeFC(cBTH,cjava_DOT_util_DOT_Collection,1). +paramFC(cBSV,cAKH,1). +paramFC(cBQZ,cBRA,1). +paramFC(cBQJ,cAKH,1). +smaller(cBRD,cBRE). +paramFC(cBRO,cBRP,1). +typeFC(cBSI,cjava_DOT_util_DOT_List,1). +typeFC(cBQX,cjava_DOT_util_DOT_Vector,1). +paramFC(cBUI,cBUJ,1). +paramFC(cBQO,cBQP,1). +typeFC(cBTA,cjava_DOT_util_DOT_AbstractCollection,1). +paramFC(cBRJ,cAKH,1). +paramFC(cBTV,cBTW,1). +typeFC(cBUO,cjava_DOT_lang_DOT_Object,0). +typeFC(cBSA,cjava_DOT_lang_DOT_Object,0). +smaller(cBUB,cBUE). +typeFC(cBUD,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBQZ,cjava_DOT_util_DOT_Vector,1). +smaller(cBTL,cBTO). +typeFC(cBTU,cjava_DOT_util_DOT_AbstractList,1). +smaller(cBTZ,cBUA). +typeFC(cBRG,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBSC,cjava_DOT_util_DOT_Vector,1). +typeFC(cBSK,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBST,cjava_DOT_util_DOT_AbstractList,1). +paramFC(cBSY,cBSZ,1). +typeFC(cBTW,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBQW,cjava_DOT_lang_DOT_Integer,0). +smaller(cBSP,cBSQ). +paramFC(cBSG,cBSH,1). +smaller(cBTD,cBTG). +typeFC(cBUG,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBSW,cjava_DOT_lang_DOT_Object,0). +paramFC(cBTD,cBTE,1). +paramFC(cBSX,cBSY,1). +paramFC(cBQM,cBQN,1). +typeFC(cBRH,cjava_DOT_util_DOT_AbstractCollection,1). +smaller(cBSN,cBSO). +paramFC(cBQK,cAKH,1). +typeFC(cBTM,cjava_DOT_util_DOT_Vector,1). +paramFC(cBTU,cBTV,1). +typeFC(cBQM,cjava_DOT_util_DOT_Vector,1). +typeFC(cBRA,cjava_DOT_util_DOT_Vector,1). +smaller(cBSV,cBSW). +typeFC(cBSO,cjava_DOT_lang_DOT_Object,0). +typeFC(cBSZ,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBQL,cjava_DOT_util_DOT_Vector,1). +paramFC(cBSL,cAKH,1). +typeFC(cBRB,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBSY,cjava_DOT_util_DOT_Vector,1). +paramFC(cBUH,cBUI,1). +paramFC(cBTH,cAKH,1). +typeFC(cBTN,cjava_DOT_lang_DOT_Integer,0). +smaller(cBRJ,cBRK). +typeFC(cBRP,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBUH,cjava_DOT_util_DOT_List,1). +paramFC(cBRE,cBRF,1). +typeFC(cBQR,cjava_DOT_util_DOT_Collection,1). +typeFC(cBTY,cjava_DOT_lang_DOT_Object,0). +paramFC(cBQS,cBQT,1). +typeFC(cBTI,cjava_DOT_lang_DOT_Iterable,1). +typeFC(cBUC,cjava_DOT_util_DOT_Vector,1). +paramFC(cBSB,cBSC,1). +typeFC(cBQS,cjava_DOT_util_DOT_Vector,1). +smaller(cBQR,cBQU). +paramFC(cBTE,cBTF,1). +paramFC(cBUB,cBUC,1). +typeFC(cBRO,cjava_DOT_util_DOT_Vector,1). +paramFC(cBST,cAKH,1). +typeFC(cBQO,cjava_DOT_util_DOT_List,1). +typeFC(cBRE,cjava_DOT_util_DOT_Vector,1). +typeFC(cBQY,cjava_DOT_io_DOT_Serializable,0). +typeFC(cBTQ,cjava_DOT_lang_DOT_Object,0). +smaller(cBSX,cBTA). +typeFC(cBRN,cjava_DOT_util_DOT_AbstractCollection,1). +typeVar(cAKH). +paramFC(cBRH,cAKH,1). +paramFC(cBQP,cBQQ,1). +typeFC(cBSE,cjava_DOT_io_DOT_Serializable,0). +smaller(cBTP,cBTQ). +paramFC(cBRN,cBRO,1). +typeFC(cBUI,cjava_DOT_util_DOT_Vector,1). +typeFC(cBRV,cjava_DOT_io_DOT_Serializable,0). +typeFC(cBSJ,cjava_DOT_util_DOT_Vector,1). +typeFC(cBTK,cjava_DOT_util_DOT_RandomAccess,0). +paramFC(cBSJ,cBSK,1). +typeFC(cBQK,cjava_DOT_util_DOT_AbstractList,1). +smaller(cBUN,cBUO). +typeFC(cBUB,cjava_DOT_util_DOT_AbstractCollection,1). +paramFC(cBSR,cAKH,1). +paramFC(cBSC,cBSD,1). +paramFC(cBRA,cBRB,1). +paramFC(cBRM,cAKH,1). +paramFC(cBQR,cBQS,1). +typeFC(cBSM,cjava_DOT_util_DOT_AbstractCollection,1). +smaller(cBTH,cBTI). +paramFC(cBTA,cBTB,1). +smaller(cBQL,cBQO). +typeFC(cBTB,cjava_DOT_util_DOT_Vector,1). +paramFC(cBUF,cBUG,1). +paramFC(cBQL,cBQM,1). +smaller(cBRN,cBRQ). +smaller(cBRR,cBRU). +smaller(cBQX,cBQY). +typeFC(cBRM,cjava_DOT_util_DOT_List,1). +typeFC(cBTZ,cjava_DOT_util_DOT_List,1). +paramFC(cBTL,cBTM,1). +typeFC(cBRI,cjava_DOT_util_DOT_Collection,1). +typeFC(cBRK,cjava_DOT_lang_DOT_Cloneable,0). +typeFC(cBTS,cjava_DOT_util_DOT_Vector,1). +typeFC(cBUN,cjava_DOT_util_DOT_Collection,1). +paramFC(cBRR,cBRS,1). +smaller(cBQZ,cBRC). +smaller(cBRV,cBRW). +smaller(cBSL,cBSM). +typeFC(cBSB,cjava_DOT_util_DOT_Vector,1). +typeFC(cBSN,cjava_DOT_util_DOT_AbstractCollection,1). +typeFC(cBTF,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBTG,cjava_DOT_lang_DOT_Object,0). +paramFC(cBTI,cAKH,1). +typeFC(cBSH,cjava_DOT_lang_DOT_Integer,0). +paramFC(cBTM,cBTN,1). +paramFC(cBSM,cAKH,1). +typeFC(cBTD,cjava_DOT_util_DOT_List,1). +typeFC(cBTJ,cjava_DOT_util_DOT_Vector,1). +typeFC(cBQJ,cjava_DOT_util_DOT_Vector,1). +typeFC(cBQU,cjava_DOT_lang_DOT_Iterable,1). +paramFC(cBSF,cBSG,1). +typeFC(cBTC,cjava_DOT_lang_DOT_Integer,0). +paramFC(cBQU,cBQV,1). +typeFC(cBTT,cjava_DOT_lang_DOT_Integer,0). +paramFC(cBUK,cBUL,1). +paramFC(cBUA,cAKH,1). +typeFC(cBUM,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBQT,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBSL,cjava_DOT_util_DOT_AbstractList,1). +smaller(cBSR,cBSS). +typeFC(cBUJ,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBQQ,cjava_DOT_lang_DOT_Integer,0). +typeFC(cBRD,casp_DOT_UnifyWithoutWildcards_DOLLAR_MatrixTest,0). +paramFC(cBSU,cAKH,1). +typeFC(cBSU,cjava_DOT_util_DOT_List,1). +typeFC(cBTP,cjava_DOT_util_DOT_RandomAccess,0). +typeFC(cBRQ,cjava_DOT_lang_DOT_Object,0). +typeFC(cBRX,cjava_DOT_lang_DOT_Iterable,1). +typeFC(cBQV,cjava_DOT_util_DOT_Vector,1). +typeFC(cBSG,cjava_DOT_util_DOT_Vector,1). +paramFC(cBRY,cBRZ,1). +typeFC(cBSV,cjava_DOT_util_DOT_List,1). +smaller(cBRX,cBSA). +typeFC(cBRS,cjava_DOT_util_DOT_Vector,1). +typeFC(cBRL,cjava_DOT_util_DOT_Vector,1). +typeFC(cBRR,cjava_DOT_util_DOT_Vector,1). +smaller(cBTJ,cBTK). +typeFC(cBRU,cjava_DOT_lang_DOT_Cloneable,0). +paramFC(cBRS,cBRT,1). +paramFC(cBTB,cBTC,1). +paramFC(cBTS,cBTT,1). +typeFC(cBSP,cjava_DOT_lang_DOT_Cloneable,0). +smaller(cBTX,cBTY). +paramFC(cBQV,cBQW,1). +typeFC(cBSS,cjava_DOT_lang_DOT_Object,0). +typeFC(cBTO,cjava_DOT_lang_DOT_Object,0). diff --git a/asp/testReduce.lp b/asp/testReduce.lp new file mode 100644 index 00000000..7b782b42 --- /dev/null +++ b/asp/testReduce.lp @@ -0,0 +1,28 @@ +equals(t1, t2). % Map =. Map +%smallerDot(t2, t1). + +type(t1, cMap, 2). +type(t2, cMap, 2). +%type(t2, cHashMap, 2). +param(t1, t3, 1). +param(t1, t4, 2). +param(t2, t6, 1). +param(t2, t5, 2). + +type(t3, cObject, 0). +type(t5, cInteger, 0). +typeVar(t4). +typeVar(t6). + +type(tfc1, cMap, 2). +type(tfc2, cHashMap, 2). +param(tfc1, gA, 1). +param(tfc1, gB, 2). +param(tfc2, gB, 1). +param(tfc2, gA, 2). +typeVar(gA). +typeVar(gB). +smaller(tfc2, tfc1). +smaller(tfc1, tfc1). + +#show equals/2. diff --git a/asp/testUnifikation.lp b/asp/testUnifikation.lp new file mode 100644 index 00000000..ca985320 --- /dev/null +++ b/asp/testUnifikation.lp @@ -0,0 +1,12 @@ +type(t1, cjava_DOT_util_DOT_Vector, 1). +param(t1, t2, 1). +type(t2, cjava_DOT_util_DOT_Vector, 1). +param(t2, b, 1). +typeVar(b). +type(t3, cjava_DOT_util_DOT_Vector, 1). +param(t3, a, 1). +typeVar(a). + +unify(p, t1, t3). + +#show unify/3. diff --git a/asp/unifikation.lp b/asp/unifikation.lp new file mode 100644 index 00000000..8fa41a0c --- /dev/null +++ b/asp/unifikation.lp @@ -0,0 +1,23 @@ + +%reduce: +unify(Pointer, Param1, Param2) + :- unify(Pointer, T1, T2), type(T1, TName, Num), type(T2, TName, Num) + , param(T1, Param1, PNum), param(T2, Param2, PNum) + . + +%Ich lasse das Subst hier aus. Vector Beispiel funktioniert womöglich auch ohne + +%swap: +unify(Pointer, B, A) :- unify(Pointer, A, B). + +%Subst neu implementieren. +%Subst muss von hinten nach vorne durchgehen. +%Mit occurs kann man prüfen, welche unify(P, A, B) ausgetauscht werden müssen + +%Diese Fälle dürfen nicht auftreten: +%TODO (möglicherweise braucht man sie nicht; Die Unifikation geht hier nie schief) + +%Occurs Regeln: +occurs(A, A) :- typeVar(A). +occurs(A, T) :- type(T, _,_), param(T, B, _), occurs(A, B). + diff --git a/asp/unifikation.lp.backup b/asp/unifikation.lp.backup new file mode 100644 index 00000000..245258a4 --- /dev/null +++ b/asp/unifikation.lp.backup @@ -0,0 +1,40 @@ + +%reduce: +unify(Pointer, Param1, Param2) + :- unify(Pointer, T1, T2), type(T1, TName, Num), type(T2, TName, Num) + , param(T1, Param1, PNum), param(T2, Param2, PNum) + . + +%swap: +unify(Pointer, B, A) :- unify(Pointer, A, B). + +%subst: +%Neuen Typ erstellen, in diesem werden dann die TPHs ersetzt: +type(pointer(unify(Pointer, A, B, E)), Name, Num) +:- unify(Pointer, A, B), typeVar(A), not occurs(A, B), type(E, Name, Num) + ,param(E, Param, _), occurs(A, Param), Param != A. + +param(pointer(unify(Pointer, A, B, E)), pointer(unify(Pointer, A, B, Param)), ParamNum) +:- unify(Pointer, A, B), typeVar(A), not occurs(A, B), type(E, Name, Num) + ,param(E, Param, ParamNum), occurs(A, Param), Param != A. + +param(pointer(unify(Pointer, A, B, E)), B, ParamNum) +:- unify(Pointer, A, B), typeVar(A), not occurs(A, B), type(E, Name, Num) + ,param(E, A, ParamNum). + +param(pointer(unify(Pointer, A, B, E)), Param, ParamNum) +:- unify(Pointer, A, B), typeVar(A), not occurs(A, B), type(E, Name, Num) + ,param(E, Param, ParamNum), not occurs(A, Param). + + +%Subst neu implementieren. +%Subst muss von hinten nach vorne durchgehen. +%Mit occurs kann man prüfen, welche unify(P, A, B) ausgetauscht werden müssen + +%Diese Fälle dürfen nicht auftreten: +%TODO (möglicherweise braucht man sie nicht; Die Unifikation geht hier nie schief) + +%Occurs Regeln: +occurs(A, A) :- typeVar(A). +occurs(A, T) :- type(T, _,_), param(T, B, _), occurs(A, B). + diff --git a/asp/vectorTestInput.lp b/asp/vectorTestInput.lp new file mode 100644 index 00000000..5f5cf40f --- /dev/null +++ b/asp/vectorTestInput.lp @@ -0,0 +1,95 @@ + +%#show smallerGen/2. +%#show smallerGen/4. + +typeVar(cZW). +smallerDot(cN,cK). +smaller(cBHW,cBHX). +param(cBHW,cZW,1). +type(cBHO,cjava_DOT_util_DOT_Vector,1). +smaller(cBIM,cBIN). +type(cBIQ,cjava_DOT_util_DOT_AbstractList,1). +type(cBIB,cjava_DOT_lang_DOT_Object,0). +type(cBIC,cjava_DOT_util_DOT_List,1). +type(cBHN,cjava_DOT_lang_DOT_Object,0). +param(cBHS,cZW,1). +param(cBHT,cZW,1). +param(cBHU,cZW,1). +param(cBHV,cZW,1). +smaller(cBHY,cBHZ). +type(cBIA,cjava_DOT_lang_DOT_Cloneable,0). +type(cBIV,cjava_DOT_lang_DOT_Object,0). +typeVar(cK). +smaller(cBHU,cBHV). +smallerDot(cL,cBIY). +type(cBIM,cjava_DOT_lang_DOT_Object,0). +smaller(cBIK,cBIL). +type(cBIL,cjava_DOT_lang_DOT_Object,0). +type(cBIE,cjava_DOT_util_DOT_Vector,1). +type(cBII,cjava_DOT_util_DOT_AbstractCollection,1). +param(cBIY,cLL,1). +type(cBHZ,cjava_DOT_lang_DOT_Object,0). +typeVar(cLL). +type(cBIR,cjava_DOT_util_DOT_List,1). +param(cBID,cZW,1). +type(cBHY,cMyVector,0). +smaller(cBII,cBIJ). +param(cBIF,cZW,1). +type(cBIG,cjava_DOT_util_DOT_Collection,1). +type(cBHT,cjava_DOT_util_DOT_AbstractCollection,1). +type(cBIT,cjava_DOT_util_DOT_AbstractList,1). +param(cBHQ,cZW,1). +smaller(cBIE,cBIF). +typeVar(cL). +param(cBHO,cZW,1). +type(cBHM,cjava_DOT_io_DOT_Serializable,0). +type(cBIK,cjava_DOT_util_DOT_RandomAccess,0). +type(cBIJ,cjava_DOT_lang_DOT_Object,0). +type(cBIO,cjava_DOT_util_DOT_AbstractCollection,1). +type(cBIZ,cjava_DOT_lang_DOT_Integer,0). +type(cBHX,cjava_DOT_lang_DOT_Object,0). +type(cBIS,cjava_DOT_util_DOT_Vector,1). +smaller(cBIG,cBIH). +param(cBIW,cZW,1). +smaller(cBIW,cBIX). +smaller(cBHM,cBHN). +smaller(cBIC,cBID). +type(cBHP,cjava_DOT_util_DOT_RandomAccess,0). +param(cBIS,cZW,1). +param(cBIQ,cZW,1). +param(cBIU,cZW,1). +param(cBIR,cZW,1). +param(cBIT,cZW,1). +smaller(cBHO,cBHP). +param(cBIP,cZW,1). +type(cBIH,cjava_DOT_lang_DOT_Object,0). +typeVar(cM). +type(cBIU,cjava_DOT_lang_DOT_Iterable,1). +type(cBHR,cjava_DOT_lang_DOT_Cloneable,0). +type(cBIF,cjava_DOT_util_DOT_List,1). +smaller(cBIU,cBIV). +type(cBHV,cjava_DOT_lang_DOT_Iterable,1). +smaller(cBIA,cBIB). +equals(cLL,cN). +type(cBIP,cjava_DOT_util_DOT_Collection,1). +type(cBHS,cjava_DOT_util_DOT_AbstractList,1). +type(cBIN,cjava_DOT_lang_DOT_Object,0). +smaller(cBHS,cBHT). +param(cBIE,cZW,1). +smaller(cBIS,cBIT). +param(cBIC,cZW,1). +param(cBIG,cZW,1). +param(cBII,cZW,1). +type(cBID,cjava_DOT_util_DOT_Collection,1). +param(cBIO,cZW,1). +type(cBIW,cjava_DOT_util_DOT_Vector,1). +smallerDot(cM,cBIZ). +smaller(cBIO,cBIP). +type(cBIY,cjava_DOT_util_DOT_Vector,1). +typeVar(cN). +type(cBHW,cjava_DOT_util_DOT_List,1). +type(cBHU,cjava_DOT_util_DOT_Collection,1). +type(cBIX,cjava_DOT_io_DOT_Serializable,0). +smaller(cBHQ,cBHR). +smaller(cBIQ,cBIR). +type(cBHQ,cjava_DOT_util_DOT_Vector,1). diff --git a/src/de/dhbwstuttgart/sat/asp/ASPUnifyWithoutWildcards.java b/src/de/dhbwstuttgart/sat/asp/ASPUnifyWithoutWildcards.java deleted file mode 100644 index 392670ae..00000000 --- a/src/de/dhbwstuttgart/sat/asp/ASPUnifyWithoutWildcards.java +++ /dev/null @@ -1,55 +0,0 @@ -package de.dhbwstuttgart.sat.asp; - - -import org.apache.commons.io.IOUtils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class ASPUnifyWithoutWildcards { - private final List input; - private static final List programFiles = new ArrayList<>(); - static{ - programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/basis.lp")); - programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/finiteclosure.lp")); - programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/subst.lp")); - programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/reduce.lp")); - programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/unify.lp")); - programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/result.lp")); - programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/adapt.lp")); - programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/cartesian.lp")); - } - - public ASPUnifyWithoutWildcards(List inputFiles){ - this.input = inputFiles; - } - - /* - TODO: Clingo per Java Wrapper https://stackoverflow.com/questions/3356200/using-java-to-wrap-over-c - */ - public String runClingo() throws IOException, InterruptedException { - String pathToClingo = - "/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/clingo-5.2.1-linux-x86_64/clingo"; - List commands = new ArrayList<>(); - commands.add(pathToClingo); - //commands.add("--outf=2"); //use JSON-Output - commands.add("--outf=1"); //use Text-Output - commands.add("-n 0"); //Compute all models - for(File file : input){ - commands.add(file.getPath()); - } - commands.addAll(programFiles.stream().map(f->f.getPath()).collect(Collectors.toList())); - - Process clingo = new ProcessBuilder( commands.toArray(new String[0])).start(); - InputStream output = clingo.getInputStream(); - clingo.waitFor(); - String result = IOUtils.toString(output, StandardCharsets.UTF_8); - return result; - } -} diff --git a/test/asp/UnifyWithoutWildcards.java b/test/asp/UnifyWithoutWildcards.java deleted file mode 100644 index 75cc1cce..00000000 --- a/test/asp/UnifyWithoutWildcards.java +++ /dev/null @@ -1,217 +0,0 @@ -package asp; - -import de.dhbwstuttgart.parser.NullToken; -import de.dhbwstuttgart.parser.scope.JavaClassName; -import de.dhbwstuttgart.sat.asp.ASPUnifyWithoutWildcards; -import de.dhbwstuttgart.sat.asp.parser.ASPParser; -import de.dhbwstuttgart.sat.asp.writer.ASPFactory; -import de.dhbwstuttgart.syntaxtree.ClassOrInterface; -import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; -import de.dhbwstuttgart.syntaxtree.type.*; -import de.dhbwstuttgart.typeinference.constraints.Constraint; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.constraints.Pair; -import de.dhbwstuttgart.typeinference.result.ResolvedType; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import de.dhbwstuttgart.typeinference.unify.model.PairOperator; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.*; - -public class UnifyWithoutWildcards { - - public static final String tempDirectory = "/tmp/"; - - @Test - public void adapt() throws InterruptedException, IOException, ClassNotFoundException { - ConstraintSet testSet = new ConstraintSet<>(); - List list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken())); - List list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken())); - RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), list1, new NullToken()); - RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken()); - testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); - ResultSet resultSet = run(testSet, getFC()); - //System.out.println(ResultSetPrinter.print(resultSet)); - assert resultSet.results.size() > 0; - ResolvedType rsType = resultSet.resolveType(list2.get(1)); - assert ((RefType)rsType.resolvedType).getName().equals("java.util.Map"); - } - - @Test - public void adaptNewParaListTest1() throws InterruptedException, IOException, ClassNotFoundException { - ConstraintSet testSet = new ConstraintSet<>(); - List list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken())); - RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Test1"), list1, new NullToken()); - RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken()); - testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); - ResultSet resultSet = run(testSet, getFC()); - //System.out.println(ResultSetPrinter.print(resultSet)); - assert resultSet.results.size() == 0; //Hier gibt es keine Lösung. - //TODO: Kann in zukünfigen Fällen eine Lösung geben - } - - @Test - public void step1() throws InterruptedException, IOException, ClassNotFoundException { - ConstraintSet testSet = new ConstraintSet<>(); - TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken()); - RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken()); - testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); - ResultSet resultSet = run(testSet, getFC()); - System.out.println(resultSet.results.size()); - } - - @Test - public void failTest() throws InterruptedException, IOException, ClassNotFoundException { - ConstraintSet testSet = new ConstraintSet<>(); - TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken()); - RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken()); - RefType t3 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Test2"), new ArrayList<>(), new NullToken()); - testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT)); - testSet.addUndConstraint(new Pair(t1, t3, PairOperator.SMALLERDOT)); - Set fc = new HashSet<>(); - fc.add(ASTFactory.createClass(Test2.class)); - ResultSet resultSet = run(testSet, fc); - assert resultSet.results.size()==1; - } - - @Test - public void oderConstraintTest() throws InterruptedException, IOException, ClassNotFoundException { - ConstraintSet testSet = new ConstraintSet<>(); - TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken()); - RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken()); - RefType t3 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Test2"), new ArrayList<>(), new NullToken()); - Set> oderCons = new HashSet<>(); - Constraint cons1 = new Constraint<>(); - cons1.add(new Pair(t1, t2, PairOperator.EQUALSDOT)); - oderCons.add(cons1); - Constraint cons2 = new Constraint<>(); - cons2.add(new Pair(t1, t3, PairOperator.EQUALSDOT)); - oderCons.add(cons2); - testSet.addOderConstraint(oderCons); - ResultSet resultSet = run(testSet, getFC()); - assert resultSet.results.size() == 1; - } - - @Test - public void oderConstraints() throws InterruptedException, IOException, ClassNotFoundException { - ConstraintSet testSet = new ConstraintSet<>(); - for(int i = 0; i<1; i++){ - TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken()); - RefType t2 = new RefType(new JavaClassName("java.lang.Object"), new ArrayList<>(), new NullToken()); - List list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken())); - RefType t3 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Test1"), list1, new NullToken()); - Set> oderCons = new HashSet<>(); - Constraint cons1 = new Constraint<>(); - cons1.add(new Pair(t1, t2, PairOperator.SMALLERDOT)); - oderCons.add(cons1); - Constraint cons2 = new Constraint<>(); - cons2.add(new Pair(t1, t3, PairOperator.SMALLERDOT)); - oderCons.add(cons2); - testSet.addOderConstraint(oderCons); - } - ResultSet resultSet = run(testSet, getFC()); - assert resultSet.results.size() == 1; - } - - @Test - public void martinTest() throws InterruptedException, IOException, ClassNotFoundException { - ConstraintSet testSet = new ConstraintSet<>(); - List list1 = - Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken())); - TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken()); - RefType t2 = new RefType(new JavaClassName("java.util.Map"), list1, new NullToken()); - RefType t3 = new RefType(new JavaClassName("java.util.Map"), list1, new NullToken()); - Set> oderCons = new HashSet<>(); - Constraint cons1 = new Constraint<>(); - cons1.add(new Pair(t2, t3, PairOperator.EQUALSDOT)); - oderCons.add(cons1); - testSet.addOderConstraint(oderCons); - ResultSet resultSet = run(testSet, getFC()); - assert resultSet.results.size() > 0; - } - - @Test - public void fc() throws ClassNotFoundException { - Collection fc = new ArrayList<>(); - fc.add(ASTFactory.createClass(MatrixTest.class)); - fc.add(ASTFactory.createClass(Vector.class)); - String content = ""; - content = ASPFactory.generateASP(new ConstraintSet<>(), fc); - System.out.println(content); - } - - public ResultSet run(ConstraintSet toTest, Collection fc) throws IOException, InterruptedException, ClassNotFoundException { - String content = ""; - content = ASPFactory.generateASP(toTest, fc); - System.out.println(content); - PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); - writer.println(content); - writer.close(); - ASPUnifyWithoutWildcards clingo = new ASPUnifyWithoutWildcards(Arrays.asList(new File(tempDirectory + "test.lp"))); - String result = clingo.runClingo(); - System.out.println(result); - ResultSet resultSet = ASPParser.parse(result, getInvolvedTPHS(toTest)); - return resultSet; - } - - private static class TPHExtractor implements TypeVisitor>{ - @Override - public List visit(RefType refType) { - ArrayList ret = new ArrayList<>(); - for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){ - ret.addAll(param.acceptTV(this)); - } - return ret; - } - - @Override - public List visit(SuperWildcardType superWildcardType) { - return superWildcardType.getInnerType().acceptTV(this); - } - - @Override - public List visit(TypePlaceholder typePlaceholder) { - return Arrays.asList(typePlaceholder); - } - - @Override - public List visit(ExtendsWildcardType extendsWildcardType) { - return extendsWildcardType.getInnerType().acceptTV(this); - } - - @Override - public List visit(GenericRefType genericRefType) { - return new ArrayList<>(); - } - } - - protected Collection getInvolvedTPHS(ConstraintSet toTest) { - List ret = new ArrayList<>(); - toTest.map((Pair p)-> { - ret.addAll(p.TA1.acceptTV(new TPHExtractor())); - ret.addAll(p.TA2.acceptTV(new TPHExtractor())); - return p; - }); - return ret; - } - - private Collection getFC() { - Set ret = new HashSet<>(); - ret.add(ASTFactory.createClass(Matrix.class)); - ret.add(ASTFactory.createClass(Test1.class)); - ret.add(ASTFactory.createClass(Map.class)); - //ret.add(ASTFactory.createObjectClass()); - //ret.add(ASTFactory.createClass(java.util.List.class)); - return ret; - } - private class Matrix extends HashMap>{} - - private class Test1 extends Object{} - - private class Test2 extends Object{} - - private class MatrixTest extends Vector>{} -} diff --git a/test/asp/unifywithoutwildcards/ASPFactoryTest.java b/test/asp/unifywithoutwildcards/ASPFactoryTest.java deleted file mode 100644 index 16cd150f..00000000 --- a/test/asp/unifywithoutwildcards/ASPFactoryTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package asp.unifywithoutwildcards; - -import de.dhbwstuttgart.parser.NullToken; -import de.dhbwstuttgart.sat.asp.writer.ASPFactory; -import de.dhbwstuttgart.sat.asp.writer.ASPStatement; -import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.constraints.Constraint; -import de.dhbwstuttgart.typeinference.constraints.Pair; -import de.dhbwstuttgart.typeinference.unify.model.PairOperator; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class ASPFactoryTest extends ASPFactory { - @Test - public void undConstraintTest(){ - TypePlaceholder tph = TypePlaceholder.fresh(new NullToken()); - Constraint toTest = new Constraint(); - for(int i = 0; i<5;i++){ - toTest.add(new Pair(tph, tph, PairOperator.EQUALSDOT)); - } - List undCons = new ArrayList<>(); - for(Pair p : toTest){ - undCons.add(generatePairStmt(p)); - } - ASPStatement ret = convertListToUndConstraint(undCons); - System.out.println(ret.getASP()); - } - - @Test - public void oderConstraintTest(){ - TypePlaceholder tph = TypePlaceholder.fresh(new NullToken()); - Set> oderTest = new HashSet<>(); - for(int i = 0; i<5;i++){ - Constraint toTest = new Constraint(); - toTest.add(new Pair(tph, tph, PairOperator.EQUALSDOT)); - oderTest.add(toTest); - } - this.convertOderConstraint(oderTest); - System.out.println(this.writer.getASPFile()); - } -} diff --git a/test/asp/unifywithoutwildcards/ASPTests.java b/test/asp/unifywithoutwildcards/ASPTests.java deleted file mode 100644 index 80e7bb78..00000000 --- a/test/asp/unifywithoutwildcards/ASPTests.java +++ /dev/null @@ -1,10 +0,0 @@ -package asp.unifywithoutwildcards; - -import org.junit.Test; - -public class ASPTests { - @Test - public void test(){ - - } -} diff --git a/test/asp/unifywithoutwildcards/JavaTXCompilerASPBenchmark.java b/test/asp/unifywithoutwildcards/JavaTXCompilerASPBenchmark.java deleted file mode 100644 index d1396f0a..00000000 --- a/test/asp/unifywithoutwildcards/JavaTXCompilerASPBenchmark.java +++ /dev/null @@ -1,89 +0,0 @@ -package asp.unifywithoutwildcards; - -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.ClassOrInterface; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.constraints.Pair; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.*; - -public class JavaTXCompilerASPBenchmark { - - public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; - - @Test - public void vector() throws IOException, ClassNotFoundException, InterruptedException { - //execute(new File(rootDirectory+"Vector.jav")); - List> benchmarkUnifyResults = new ArrayList<>(); - for(int numAdds = 1; numAdds <= 15; numAdds++){ - - String tmpFile = "/tmp/vector.jav"; - PrintWriter writer = new PrintWriter(tmpFile, "UTF-8"); - writer.println("import java.util.ArrayList;"); - writer.println("import java.util.Vector;"); - writer.println("import java.lang.Object;"); - writer.println("class MyVector{"); - writer.println("id(x){"); - writer.println("Object i;"); - for(int i = 0; i< numAdds; i++) - writer.println("x.add(i);"); - writer.println("return x;"); - writer.println("}}"); - writer.close(); - - List results = new ArrayList<>(); - List resultsTotal = new ArrayList<>(); - for(int i = 0; i < 20 ; i++){ - Date d1 = new Date(); - JavaTXCompiler compiler = new JavaTXCompiler(new File(tmpFile)); - - Date du1 = new Date(); - compiler.aspTypeInference(); - Date du2 = new Date(); - - Date d2 = new Date(); - if(i > 4){ - long milliseconds = (du2.getTime()-du1.getTime()); - results.add(milliseconds); - milliseconds = (d2.getTime()-d1.getTime()); - resultsTotal.add(milliseconds); - } - } - benchmarkUnifyResults.add(results); - } - - for(int y = 0; y < benchmarkUnifyResults.get(0).size(); y++){ - for(int x = 0; x < benchmarkUnifyResults.size(); x++){ - long value = benchmarkUnifyResults.get(x).get(y); - System.out.print(value + " "); - } - System.out.println(); - } - - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } - -} - diff --git a/test/asp/unifywithoutwildcards/JavaTXCompilerASPTest.java b/test/asp/unifywithoutwildcards/JavaTXCompilerASPTest.java deleted file mode 100644 index 72742517..00000000 --- a/test/asp/unifywithoutwildcards/JavaTXCompilerASPTest.java +++ /dev/null @@ -1,145 +0,0 @@ -package asp.unifywithoutwildcards; - -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class JavaTXCompilerASPTest { - - public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; - - @Test - public void finiteClosure() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"fc.jav")); - } - @Test - public void lambda() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Lambda.jav")); - } - @Test - public void lambda2() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Lambda2.jav")); - } - @Test - public void lambda3() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Lambda3.jav")); - } - @Test - public void mathStruc() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"mathStruc.jav")); - } - @Test - public void generics() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Generics.jav")); - } - @Test - public void genericsMethodCall() throws IOException, ClassNotFoundException, InterruptedException { - TestResultSet result = execute(new File(rootDirectory+"MethodCallGenerics.jav")); - //TODO: Hier sollte der Rückgabetyp der Methode String sein - } - @Test - public void faculty() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Faculty.jav")); - } - @Test - public void facultyTyped() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"FacultyTyped.jav")); - } - @Test - public void matrix() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Matrix.jav")); - } - @Test - public void matrixTest() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"MatrixTest.jav")); - } - @Test - public void packageTests() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Package.jav")); - } - @Test - public void vector() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Vector.jav")); - } - @Test - public void lambdaRunnable() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"LambdaRunnable.jav")); - } - @Test - public void expressions() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"Expressions.jav")); - } - @Test - public void addLong() throws IOException, ClassNotFoundException, InterruptedException { - execute(new File(rootDirectory+"AddLong.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InterruptedException { - //filesToTest.add(new File(rootDirectory+"fc.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda3.jav")); - //filesToTest.add(new File(rootDirectory+"Vector.jav")); - //filesToTest.add(new File(rootDirectory+"Generics.jav")); - //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); - //filesToTest.add(new File(rootDirectory+"Matrix.jav")); - //filesToTest.add(new File(rootDirectory+"Import.jav")); - // //filesToTest.add(new File(rootDirectory+"Faculty.jav")); - // //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); - // //filesToTest.add(new File(rootDirectory+"test.jav")); - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - - List results = compiler.aspTypeInference(); - - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - System.out.println(ResultSetPrinter.print(results.get(0))); - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } - -} - diff --git a/test/astfactory/ASTFactoryTest.java b/test/astfactory/ASTFactoryTest.java deleted file mode 100644 index 6285cf0a..00000000 --- a/test/astfactory/ASTFactoryTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package astfactory; - -//import javafx.collections.ObservableList; -import de.dhbwstuttgart.syntaxtree.ClassOrInterface; -import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; -import de.dhbwstuttgart.syntaxtree.type.GenericRefType; -import org.junit.Test; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.util.Arrays; -import java.util.HashMap; - -import static org.junit.Assert.*; - -public class ASTFactoryTest extends HashMap{ - @Test - public void test(){ - System.out.println((this.getClass().getGenericSuperclass())); - Type[] arguments = ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments(); - System.out.println(Arrays.toString(arguments)); - System.out.println(((TypeVariable)arguments[1]).getGenericDeclaration()); - } - - public static class GenericFieldTest{ - public G testField; - } - @Test - public void genericFieldTest(){ - ClassOrInterface test = ASTFactory.createClass(GenericFieldTest.class); - assertTrue(test.getFieldDecl().get(0).getType() instanceof GenericRefType); - } -} \ No newline at end of file diff --git a/test/bytecode/ATest.java b/test/bytecode/ATest.java deleted file mode 100644 index 14dbacbf..00000000 --- a/test/bytecode/ATest.java +++ /dev/null @@ -1,8 +0,0 @@ -package bytecode; - -public class ATest extends JavaTXCompilerTest { - public ATest() { - fileName = "Example"; - } - -} diff --git a/test/bytecode/AssignToLit.jav b/test/bytecode/AssignToLit.jav deleted file mode 100644 index 873828ed..00000000 --- a/test/bytecode/AssignToLit.jav +++ /dev/null @@ -1,30 +0,0 @@ -import java.lang.Integer; -import java.lang.Boolean; -import java.lang.String; -import java.lang.Byte; -import java.lang.Short; -import java.lang.Long; -import java.lang.Float; -import java.lang.Double; -import java.lang.Character; - -class AssignToLit { - void m(){ -// String s = "Test"; -// Boolean b = false; -// Byte byte1 = 5; -// Byte byte2 = 55; -// Short short1 = 5; -// Short short2 = 55; -// Integer int1 = 5; -// Integer int2 = 8888888; -// Long long1 = 1; -// Long long2 = 5; -// Long long3 = 89989898; -// Float float1 = 1; -// Float float2 = 55; -// Double d1 = 1; -// Double d2 = 55; - Character c = 'A'; - } -} \ No newline at end of file diff --git a/test/bytecode/AssignToLitTest.java b/test/bytecode/AssignToLitTest.java deleted file mode 100644 index dc5d397b..00000000 --- a/test/bytecode/AssignToLitTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class AssignToLitTest extends JavaTXCompilerTest { - public AssignToLitTest() { - this.fileName = "AssignToLit"; - } -} diff --git a/test/bytecode/DuMethod.jav b/test/bytecode/DuMethod.jav deleted file mode 100644 index 3898a7ba..00000000 --- a/test/bytecode/DuMethod.jav +++ /dev/null @@ -1,11 +0,0 @@ -public class DuMethod{ - - method(a){ - return a+a; - } - - method(a){ - return a; - } - -} \ No newline at end of file diff --git a/test/bytecode/DuMethodTest.java b/test/bytecode/DuMethodTest.java deleted file mode 100644 index a4c8a226..00000000 --- a/test/bytecode/DuMethodTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class DuMethodTest extends JavaTXCompilerTest{ - public DuMethodTest() { - this.fileName = "DuMethod"; - } -} diff --git a/test/bytecode/EmptyMethod.jav b/test/bytecode/EmptyMethod.jav deleted file mode 100644 index 961989df..00000000 --- a/test/bytecode/EmptyMethod.jav +++ /dev/null @@ -1,8 +0,0 @@ -public class EmptyMethod{ - - public void m1(){ - System.out.println("test"); - } - - public void m2(){} -} diff --git a/test/bytecode/Example.jav b/test/bytecode/Example.jav deleted file mode 100644 index b7455a3f..00000000 --- a/test/bytecode/Example.jav +++ /dev/null @@ -1,9 +0,0 @@ -import java.lang.String; - -public class Example { - - public m() { - String x = "X"; - return x; - } -} \ No newline at end of file diff --git a/test/bytecode/Exceptions.jav b/test/bytecode/Exceptions.jav deleted file mode 100644 index 9903511c..00000000 --- a/test/bytecode/Exceptions.jav +++ /dev/null @@ -1,3 +0,0 @@ -public class Exceptions { -// m(Integer i) throws -} \ No newline at end of file diff --git a/test/bytecode/Faculty.jav b/test/bytecode/Faculty.jav deleted file mode 100644 index 5742d720..00000000 --- a/test/bytecode/Faculty.jav +++ /dev/null @@ -1,14 +0,0 @@ -class Faculty { - - Integer mul(Integer x, Integer y) { - return x; - } - - m () { - - var fact = (Integer x) -> { - return mul(x, x); - }; - return fact; - } -} diff --git a/test/bytecode/Faculty2.jav b/test/bytecode/Faculty2.jav deleted file mode 100644 index 828f06f5..00000000 --- a/test/bytecode/Faculty2.jav +++ /dev/null @@ -1,10 +0,0 @@ -class Faculty2 { - - m () { - - var fact = (Integer x) -> { - return x; - }; - return fact; - } -} \ No newline at end of file diff --git a/test/bytecode/For.jav b/test/bytecode/For.jav deleted file mode 100644 index c4bd6677..00000000 --- a/test/bytecode/For.jav +++ /dev/null @@ -1,30 +0,0 @@ -import java.lang.Integer; -import java.lang.Boolean; - -class For{ - Integer m(Integer x){ - var c = x + 2; -// Boolean b = true; -// c = 5; -// c++; -// ++c; -// c--; -// --c; -// while(x<2){ -// x = x +1; -// b = false; -// } - return c; -// for(int i = 0;i<10;i++) { -// x = x + 5; -// } - } - -// m2(Integer x){ -// if(x<2) { -// return 1; -// }else { -// return 2; -// } -// } -} \ No newline at end of file diff --git a/test/bytecode/ForTest.java b/test/bytecode/ForTest.java deleted file mode 100644 index c95138d3..00000000 --- a/test/bytecode/ForTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package bytecode; - -import org.objectweb.asm.Opcodes; - -public class ForTest extends JavaTXCompilerTest { - - public ForTest() { - this.fileName = "For"; - } - -} diff --git a/test/bytecode/Gen.jav b/test/bytecode/Gen.jav deleted file mode 100644 index 1f873919..00000000 --- a/test/bytecode/Gen.jav +++ /dev/null @@ -1,5 +0,0 @@ -public class Gen{ - Vector m(Vector v){ - return v; - } -} \ No newline at end of file diff --git a/test/bytecode/Generics.jav b/test/bytecode/Generics.jav deleted file mode 100644 index bb7b2af5..00000000 --- a/test/bytecode/Generics.jav +++ /dev/null @@ -1,17 +0,0 @@ - -class Generics { - Generics(B b){ - } - B mt1(B b){ - return mt1(b); - } -} - - -/* -Problem: -auto test = new List(); -auto test2 = new List(); -... //code, welcher möglicherweise test und test2 vertauscht -test.add("hallo"); -*/ \ No newline at end of file diff --git a/test/bytecode/Generics2.jav b/test/bytecode/Generics2.jav deleted file mode 100644 index 52d5caa2..00000000 --- a/test/bytecode/Generics2.jav +++ /dev/null @@ -1,6 +0,0 @@ -class Generics2{ - B m1(B b){ - return b; - } - -} \ No newline at end of file diff --git a/test/bytecode/Generics2Test.java b/test/bytecode/Generics2Test.java deleted file mode 100644 index 26e52665..00000000 --- a/test/bytecode/Generics2Test.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class Generics2Test extends JavaTXCompilerTest{ - public Generics2Test() { - this.fileName = "Generics2"; - } -} diff --git a/test/bytecode/GenericsTest.java b/test/bytecode/GenericsTest.java deleted file mode 100644 index cca16129..00000000 --- a/test/bytecode/GenericsTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class GenericsTest extends JavaTXCompilerTest { - public GenericsTest() { - this.fileName = "Generics"; - } -} diff --git a/test/bytecode/IfTest.jav b/test/bytecode/IfTest.jav deleted file mode 100644 index 806e2157..00000000 --- a/test/bytecode/IfTest.jav +++ /dev/null @@ -1,10 +0,0 @@ -public class IfTest{ - Integer m1(Boolean b) { - Integer i; - if(b) { - return i; - } - - return i; - } -} \ No newline at end of file diff --git a/test/bytecode/Import.jav b/test/bytecode/Import.jav deleted file mode 100644 index c658568f..00000000 --- a/test/bytecode/Import.jav +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.Vector; - -class Import { - void methode(){ - Vector v = new Vector<>(); - v.add("X"); - } -} \ No newline at end of file diff --git a/test/bytecode/ImportTest.java b/test/bytecode/ImportTest.java deleted file mode 100644 index b7244e15..00000000 --- a/test/bytecode/ImportTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class ImportTest extends JavaTXCompilerTest{ - public ImportTest() { - this.fileName = "Import"; - } -} diff --git a/test/bytecode/Interface1.jav b/test/bytecode/Interface1.jav deleted file mode 100644 index b741819c..00000000 --- a/test/bytecode/Interface1.jav +++ /dev/null @@ -1,3 +0,0 @@ -public interface Interface1{ - public void test(); -} \ No newline at end of file diff --git a/test/bytecode/InterfaceTest.java b/test/bytecode/InterfaceTest.java deleted file mode 100644 index ed378127..00000000 --- a/test/bytecode/InterfaceTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class InterfaceTest extends JavaTXCompilerTest{ - public InterfaceTest() { - this.fileName = "Interface1"; - } -} diff --git a/test/bytecode/JavaTXCompilerTest.java b/test/bytecode/JavaTXCompilerTest.java deleted file mode 100644 index 623fc96e..00000000 --- a/test/bytecode/JavaTXCompilerTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package bytecode; - -import de.dhbwstuttgart.bytecode.BytecodeGen; -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.typeinference.result.ResultPair; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import org.junit.Test; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import static org.junit.Assert.*; - -public class JavaTXCompilerTest { - - private static final String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - private static final List filesToTest = new ArrayList<>(); - - protected String fileName = ""; - - @Test - public void test() throws IOException, java.lang.ClassNotFoundException { - System.out.println(rootDirectory); - filesToTest.add(new File(rootDirectory+fileName+".jav")); - System.out.println(rootDirectory+fileName+".jav"); - JavaTXCompiler compiler = new JavaTXCompiler(filesToTest); - for(File f : filesToTest){ - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - List typeinferenceResult = compiler.typeInference(); - HashMap bytecode = this.getBytecode(compiler.sourceFiles.get(f), typeinferenceResult.get(0)); - -// for(ResultPair ep : typeinferenceResult.get(0).results) { -// System.out.println(ep.getLeft() + " ->" + ep.getRight()); -// } - - String name; - int pos = f.getName().lastIndexOf("."); - if(pos != -1) { - name = f.getName().substring(0, pos); - } - this.writeClassFile(bytecode); - } - - } - - - public HashMap getBytecode(SourceFile sf, ResultSet resultSet) { - HashMap classFiles = new HashMap<>(); - BytecodeGen bytecodeGen = new BytecodeGen(classFiles,resultSet); - bytecodeGen.visit(sf); - return bytecodeGen.getClassFiles(); - } - - public void writeClassFile(HashMap classFiles) { - FileOutputStream output; - for(String name : classFiles.keySet()) { - byte[] bytecode = classFiles.get(name); - try { - System.out.println("generating "+name+ ".class file ..."); - output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class")); - output.write(bytecode); - output.close(); - System.out.println(name+".class file generated"); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } - -} \ No newline at end of file diff --git a/test/bytecode/LamAssign.jav b/test/bytecode/LamAssign.jav deleted file mode 100644 index 82bb31b1..00000000 --- a/test/bytecode/LamAssign.jav +++ /dev/null @@ -1,15 +0,0 @@ -import java.lang.Integer; - -class LamAssign { - - m () { - var lam1 = (Integer x) -> { - return x; - }; - return lam1; - } -} - -interface Fun1{ - public A apply(B b); -} \ No newline at end of file diff --git a/test/bytecode/LamAssignTest.java b/test/bytecode/LamAssignTest.java deleted file mode 100644 index 3442c1d1..00000000 --- a/test/bytecode/LamAssignTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class LamAssignTest extends JavaTXCompilerTest{ - public LamAssignTest() { - this.fileName = "LamAssign"; - } -} diff --git a/test/bytecode/LamRunnable.jav b/test/bytecode/LamRunnable.jav deleted file mode 100644 index 451858f2..00000000 --- a/test/bytecode/LamRunnable.jav +++ /dev/null @@ -1,9 +0,0 @@ -public class LamRunnable{ - - public LamRunnable(){ - - Runnable lam = () -> {System.out.println("lambda");}; - lam.run(); - } -} - \ No newline at end of file diff --git a/test/bytecode/Lambda.jav b/test/bytecode/Lambda.jav deleted file mode 100644 index 378eb4d3..00000000 --- a/test/bytecode/Lambda.jav +++ /dev/null @@ -1,18 +0,0 @@ -class Lambda{ - -methode(){ - return ((f) -> f); -} -} -/* -interface Fun0{ - A apply(); -} - -interface Fun1{ - A apply(B b); -} -*/ -interface Fun2{ - A apply(B b, C c); -} \ No newline at end of file diff --git a/test/bytecode/Lambda2.jav b/test/bytecode/Lambda2.jav deleted file mode 100644 index fbcdaf55..00000000 --- a/test/bytecode/Lambda2.jav +++ /dev/null @@ -1,32 +0,0 @@ - -public class Lambda2 -{ - public static void main(List args){ - var listOfStrings = new List(); - var listOfObjects; - listOfObjects = map(listOfStrings, (a) -> a); -} - -public map(a , b){ - b.apply(a); - return a; -} - -/* -public static List map(List input, Function func) { - List output; - output = new List(); - output.add(func.apply(input.get())); - return output; -} -*/ -} - -class List{ - A get(); - void add(A); -} - -class Function{ - B apply(A a); -} \ No newline at end of file diff --git a/test/bytecode/Lambda3.jav b/test/bytecode/Lambda3.jav deleted file mode 100644 index 9c4e960c..00000000 --- a/test/bytecode/Lambda3.jav +++ /dev/null @@ -1,23 +0,0 @@ - -public class Lambda2 -{ - /* - public static List map(List input, - Function func){ - input.add(func.apply(input.get())); - } - */ - public map(input,func){ - input.add(func.apply(input.get())); - return map(new List(), func); - } -} - -class List{ - A get(); - void add(A); -} - -class Function{ - B apply(A a); -} \ No newline at end of file diff --git a/test/bytecode/Methods.jav b/test/bytecode/Methods.jav deleted file mode 100644 index 3c46739d..00000000 --- a/test/bytecode/Methods.jav +++ /dev/null @@ -1,14 +0,0 @@ -import java.lang.Integer; - -class Methods { - - m(a,b){ - var c=a+b; - return c; - } - - method2(x){ - Integer i = this.m(x,2); - return i; - } -} \ No newline at end of file diff --git a/test/bytecode/MethodsTest.java b/test/bytecode/MethodsTest.java deleted file mode 100644 index 11195b71..00000000 --- a/test/bytecode/MethodsTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class MethodsTest extends JavaTXCompilerTest { - public MethodsTest() { - this.fileName = "Methods"; - } -} diff --git a/test/bytecode/Op.jav b/test/bytecode/Op.jav deleted file mode 100644 index 9c05b0a2..00000000 --- a/test/bytecode/Op.jav +++ /dev/null @@ -1,12 +0,0 @@ -import java.lang.Integer; - -class Op { - m(Integer a, Integer b) { - Integer c = a+b; -// d = a-b; -// e = a*b; -// f = a/b; - - return c; - } -} \ No newline at end of file diff --git a/test/bytecode/OpTest.java b/test/bytecode/OpTest.java deleted file mode 100644 index cd8fee06..00000000 --- a/test/bytecode/OpTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class OpTest extends JavaTXCompilerTest { - public OpTest() { - this.fileName = "Op"; - } -} diff --git a/test/bytecode/OverlaodGen.jav b/test/bytecode/OverlaodGen.jav deleted file mode 100644 index d5946496..00000000 --- a/test/bytecode/OverlaodGen.jav +++ /dev/null @@ -1,11 +0,0 @@ -import java.util.Vector; - -class OverlaodGen { - void method(Vector v) { -// Integer i = v.get(0); - } - - void method(Vector v) { -// String s = v.get(0); - } -} \ No newline at end of file diff --git a/test/bytecode/OverlaodGenTest.java b/test/bytecode/OverlaodGenTest.java deleted file mode 100644 index 72bde4f9..00000000 --- a/test/bytecode/OverlaodGenTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class OverlaodGenTest extends JavaTXCompilerTest { - public OverlaodGenTest() { - this.fileName = "OverlaodGen"; - } -} diff --git a/test/bytecode/RecursiveMeth.jav b/test/bytecode/RecursiveMeth.jav deleted file mode 100644 index be35a43c..00000000 --- a/test/bytecode/RecursiveMeth.jav +++ /dev/null @@ -1,5 +0,0 @@ -public class RecursiveMeth{ - public Integer test(){ - return this.test(); - } -} \ No newline at end of file diff --git a/test/bytecode/ReturnMethod.jav b/test/bytecode/ReturnMethod.jav deleted file mode 100644 index 38386d0d..00000000 --- a/test/bytecode/ReturnMethod.jav +++ /dev/null @@ -1,6 +0,0 @@ -class ReturnMethod{ - Integer r; - Integer mul(Integer x, Integer y) { - return r; - } -} \ No newline at end of file diff --git a/test/bytecode/TestIfTest.java b/test/bytecode/TestIfTest.java deleted file mode 100644 index 804a0616..00000000 --- a/test/bytecode/TestIfTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package bytecode; - -public class TestIfTest extends JavaTXCompilerTest{ - public TestIfTest() { - this.fileName = "IfTest"; - } -} diff --git a/test/bytecode/VoidMeth.jav b/test/bytecode/VoidMeth.jav deleted file mode 100644 index 6b3ab212..00000000 --- a/test/bytecode/VoidMeth.jav +++ /dev/null @@ -1,4 +0,0 @@ -public class VoidMeth{ - public void test(){ - } -} \ No newline at end of file diff --git a/test/parser/AntlrTest.jav b/test/parser/AntlrTest.jav deleted file mode 100644 index 31ab067d..00000000 --- a/test/parser/AntlrTest.jav +++ /dev/null @@ -1,6 +0,0 @@ -class Test{ -method(){ - if(true)i++; - if(true)i--; - else i++; -}} \ No newline at end of file diff --git a/test/parser/BoundedParameter.jav b/test/parser/BoundedParameter.jav deleted file mode 100644 index 6d7518a9..00000000 --- a/test/parser/BoundedParameter.jav +++ /dev/null @@ -1,3 +0,0 @@ -class Matrix{ - String op = "String"; -} diff --git a/test/parser/CastTest.jav b/test/parser/CastTest.jav deleted file mode 100644 index 86ca7519..00000000 --- a/test/parser/CastTest.jav +++ /dev/null @@ -1,8 +0,0 @@ - -class CastTest{ -void methode(){ - Object a; - String b; - a = (Object) b; -} -} \ No newline at end of file diff --git a/test/parser/ExtendsTest.jav b/test/parser/ExtendsTest.jav deleted file mode 100644 index 9103f463..00000000 --- a/test/parser/ExtendsTest.jav +++ /dev/null @@ -1,4 +0,0 @@ -class C1 extends Object -{ - m(para) { return para; } -} \ No newline at end of file diff --git a/test/parser/FeatherWeightJava.jav b/test/parser/FeatherWeightJava.jav deleted file mode 100644 index e607b12a..00000000 --- a/test/parser/FeatherWeightJava.jav +++ /dev/null @@ -1,11 +0,0 @@ - -class FeatherWeightJava { - mt4(a,b,c) { return a.add(b).sub(c) ; } - - mt1(a) {return a; } - - mt2(a) {return a.f; } - - mt3(a) {return a.add(); } -} - diff --git a/test/parser/FieldInitializationTest.jav b/test/parser/FieldInitializationTest.jav deleted file mode 100644 index f7818cc3..00000000 --- a/test/parser/FieldInitializationTest.jav +++ /dev/null @@ -1,3 +0,0 @@ -class FieldInitializationTest{ - var var = "hallo"; -} \ No newline at end of file diff --git a/test/parser/FieldVarTest.jav b/test/parser/FieldVarTest.jav deleted file mode 100644 index 6e897824..00000000 --- a/test/parser/FieldVarTest.jav +++ /dev/null @@ -1,5 +0,0 @@ -package test; - -class Test{ -Typ a; -} \ No newline at end of file diff --git a/test/parser/GeneralParserTest.java b/test/parser/GeneralParserTest.java deleted file mode 100644 index 4e7d9868..00000000 --- a/test/parser/GeneralParserTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package parser; - -import static org.junit.Assert.*; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.parser.JavaTXParser; - -import org.junit.Test; - - -/** - * Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. - * Der dabei erstellte Syntaxbaum wird nicht kontrolliert. - * @author janulrich - * - */ -public class GeneralParserTest{ - private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/"; - - @Test - public void run(){ - - - List filenames = new ArrayList(); - /* - filenames.add("NewTest.jav"); - filenames.add("FieldInitializationTest.jav"); - filenames.add("ImportTest.jav"); - filenames.add("CastTest.jav"); - filenames.add("StatementsTest.jav"); - //filenames.add("Methods.jav"); - filenames.add("ImportTestGeneric.jav"); - filenames.add("CastTest.jav"); - //filenames.add("BoundedParameter.jav"); - //filenames.add("GenericFieldVarTest.jav"); - filenames.add("FieldVarTest.jav"); - filenames.add("StructuralTypes.jav"); - */ -// filenames.add("ExtendsTest.jav"); - filenames.add("PackageNameTest.jav"); - try{ - new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList())); - }catch(Exception exc){ - exc.printStackTrace(); - fail(); - } - assertTrue("Tests durchlaufen",filenames.size()>0); - } - -} diff --git a/test/parser/GenericFieldVarTest.jav b/test/parser/GenericFieldVarTest.jav deleted file mode 100644 index a47b41eb..00000000 --- a/test/parser/GenericFieldVarTest.jav +++ /dev/null @@ -1,3 +0,0 @@ -class Test{ - A var; -} diff --git a/test/parser/ImportTest.jav b/test/parser/ImportTest.jav deleted file mode 100644 index 2de55cee..00000000 --- a/test/parser/ImportTest.jav +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.*; - -class ImportTest{ -} \ No newline at end of file diff --git a/test/parser/ImportTest2.jav b/test/parser/ImportTest2.jav deleted file mode 100644 index 3492e31c..00000000 --- a/test/parser/ImportTest2.jav +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.ArrayList; - -class ImportTest{ -} \ No newline at end of file diff --git a/test/parser/ImportTestGeneric.jav b/test/parser/ImportTestGeneric.jav deleted file mode 100644 index 094f4c5e..00000000 --- a/test/parser/ImportTestGeneric.jav +++ /dev/null @@ -1,5 +0,0 @@ -import java.util.List; - -class ImportTest{ - List test; -} \ No newline at end of file diff --git a/test/parser/NewTest.jav b/test/parser/NewTest.jav deleted file mode 100644 index 992a2e8d..00000000 --- a/test/parser/NewTest.jav +++ /dev/null @@ -1,5 +0,0 @@ - -class NewTest { -main() { return new NewTest<>().mt(new NewTest(1) , new NewTest(2) , new -NewTest(3)); } -} \ No newline at end of file diff --git a/test/parser/OpratorTest.jav b/test/parser/OpratorTest.jav deleted file mode 100644 index 2764adf4..00000000 --- a/test/parser/OpratorTest.jav +++ /dev/null @@ -1,12 +0,0 @@ -import java.lang.Integer; - -class OpratorTest { - m(Integer a, Integer b) { - c = a+b; -// d = a-b; -// e = a*b; -// f = a/b; - - return c; - } -} \ No newline at end of file diff --git a/test/parser/PackageNameTest.jav b/test/parser/PackageNameTest.jav deleted file mode 100644 index 58ec1b57..00000000 --- a/test/parser/PackageNameTest.jav +++ /dev/null @@ -1,9 +0,0 @@ - -import java.lang.Comparable; - -class PackageNameTest{ -java.lang.Integer test(a){return a;} - -Comparable test2(a){return a;} - -} \ No newline at end of file diff --git a/test/parser/StatementsTest.jav b/test/parser/StatementsTest.jav deleted file mode 100644 index 891dff12..00000000 --- a/test/parser/StatementsTest.jav +++ /dev/null @@ -1,8 +0,0 @@ -class Statements{ - -public void methodeTest(){ - methodeTest(); - return null; -} - -} diff --git a/test/parser/StructuralTypes.jav b/test/parser/StructuralTypes.jav deleted file mode 100644 index b3c210c8..00000000 --- a/test/parser/StructuralTypes.jav +++ /dev/null @@ -1,5 +0,0 @@ - -class A { - mt(x, y, z) { return x.sub(y).add(z); } -} - diff --git a/test/parser/WhileTest.jav b/test/parser/WhileTest.jav deleted file mode 100644 index 2ce192bd..00000000 --- a/test/parser/WhileTest.jav +++ /dev/null @@ -1,14 +0,0 @@ -class WhileTest{ - void methode(){ - Boolean test; - do{ - test=test; - }while(test); - - - while(test){ - test = test; - } - return; - } -} \ No newline at end of file diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java deleted file mode 100644 index ba004cb5..00000000 --- a/test/typeinference/JavaTXCompilerTest.java +++ /dev/null @@ -1,140 +0,0 @@ -package typeinference; - -import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; -import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; -import de.dhbwstuttgart.typedeployment.TypeInsert; -import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.result.ResultSet; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class JavaTXCompilerTest { - - public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; - - @Test - public void finiteClosure() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"fc.jav")); - } - @Test - public void lambda() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Lambda.jav")); - } - @Test - public void lambda2() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Lambda2.jav")); - } - @Test - public void lambda3() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Lambda3.jav")); - } - @Test - public void mathStruc() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"mathStruc.jav")); - } - @Test - public void generics() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Generics.jav")); - } - @Test - public void genericsMethodCall() throws IOException, ClassNotFoundException { - TestResultSet result = execute(new File(rootDirectory+"MethodCallGenerics.jav")); - //TODO: Hier sollte der Rückgabetyp der Methode String sein - } - @Test - public void faculty() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Faculty.jav")); - } - @Test - public void facultyTyped() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"FacultyTyped.jav")); - } - @Test - public void matrix() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Matrix.jav")); - } - @Test - public void packageTests() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Package.jav")); - } - @Test - public void vector() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Vector.jav")); - } - @Test - public void lambdaRunnable() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"LambdaRunnable.jav")); - } - @Test - public void expressions() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Expressions.jav")); - } - @Test - public void addLong() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"AddLong.jav")); - } - - private static class TestResultSet{ - - } - - public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { - //filesToTest.add(new File(rootDirectory+"fc.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); - //filesToTest.add(new File(rootDirectory+"Lambda3.jav")); - //filesToTest.add(new File(rootDirectory+"Vector.jav")); - //filesToTest.add(new File(rootDirectory+"Generics.jav")); - //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); - //filesToTest.add(new File(rootDirectory+"Matrix.jav")); - //filesToTest.add(new File(rootDirectory+"Import.jav")); - // //filesToTest.add(new File(rootDirectory+"Faculty.jav")); - // //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); - // //filesToTest.add(new File(rootDirectory+"test.jav")); - JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - - List results = compiler.typeInference(); - - for(File f : compiler.sourceFiles.keySet()){ - SourceFile sf = compiler.sourceFiles.get(f); - System.out.println(ASTTypePrinter.print(sf)); - System.out.println(ASTPrinter.print(sf)); - //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen - assert results.size()>0; - Set insertedTypes = new HashSet<>(); - for(ResultSet resultSet : results){ - Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); - assert result.size()>0; - String content = readFile(f.getPath(), StandardCharsets.UTF_8); - for(TypeInsert tip : result){ - insertedTypes.add(tip.insert(content)); - } - } - for(String s : insertedTypes){ - System.out.println(s); - } - } - return new TestResultSet(); - } - - static String readFile(String path, Charset encoding) - throws IOException - { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } - -} - diff --git a/test/visualisation/ToString.java b/test/visualisation/ToString.java deleted file mode 100644 index 00b8ddea..00000000 --- a/test/visualisation/ToString.java +++ /dev/null @@ -1,5 +0,0 @@ -package visualisation; - -public class ToString { - -} diff --git a/testBytecode/Field.java b/testBytecode/Field.java deleted file mode 100644 index 50002082..00000000 --- a/testBytecode/Field.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Field{ - public void m(){ - MethFieldVar mF = new MethFieldVar(); - mF.s1 = "Field S1"; - } -} diff --git a/testBytecode/Import.java b/testBytecode/Import.java deleted file mode 100644 index f3519acb..00000000 --- a/testBytecode/Import.java +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.Vector; - -class Import { - void methode(){ - Vector v = new Vector(); - v.add(v); - } -} diff --git a/testBytecode/Lam1.java b/testBytecode/Lam1.java deleted file mode 100644 index 142feed2..00000000 --- a/testBytecode/Lam1.java +++ /dev/null @@ -1,10 +0,0 @@ -import java.util.function.Function; -public class Lam1{ - public Lam1() { - Function fun = (x) -> x+"1"; - fun.apply("2"); - - Runnable lam = () -> System.out.println("lambda"); - lam.run(); - } -} diff --git a/testBytecode/LamRun.java b/testBytecode/LamRun.java deleted file mode 100644 index fdaf0852..00000000 --- a/testBytecode/LamRun.java +++ /dev/null @@ -1,8 +0,0 @@ -public class LamRun{ - - public void mRun(){ - - Runnable lam = () -> System.out.println("lambda"); - lam.run(); - } -} diff --git a/testBytecode/MethFieldVar.java b/testBytecode/MethFieldVar.java deleted file mode 100644 index 74086a01..00000000 --- a/testBytecode/MethFieldVar.java +++ /dev/null @@ -1,38 +0,0 @@ -public class MethFieldVar{ - String s1;// = ""; - String s2; - -/* public void meth(Integer i, String j, Boolean b){ - //String local = "a"; - //int localL = local.length(); - //int l = s.length(); - String s = null; - //s = ""; - //return s.length();//l+localL; - } -*/ - public void mm(){ -// return "mm"; - } - public void m2(){ - System.out.println(""); - // Math.abs(1); - // String lV = "local"; - // s1 = "1"; - // s1.concat("2"); - s2 = s1; - - mm(); - - Clazz i = new Clazz(); - - Runnable lam = ()->{ - String test = ""; - String b = "b"; - test = b; - System.out.println(test); - }; - } -} - -class Clazz{} diff --git a/testBytecode/Subclass.java b/testBytecode/Subclass.java deleted file mode 100644 index 3e8b5853..00000000 --- a/testBytecode/Subclass.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Subclass extends Superclass { - - public void printMethod() { - super.printMethod(); - } -} diff --git a/testBytecode/SuperTest.java b/testBytecode/SuperTest.java deleted file mode 100644 index 1b6ac268..00000000 --- a/testBytecode/SuperTest.java +++ /dev/null @@ -1,14 +0,0 @@ -public class Superclass { - - public void printMethod() { - System.out.println("Printed in Superclass."); - } -} - -public class Subclass extends Superclass { - - public void printMethod() { - super.printMethod(); - - } -} diff --git a/testBytecode/Superclass.java b/testBytecode/Superclass.java deleted file mode 100644 index d58089de..00000000 --- a/testBytecode/Superclass.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Superclass { - - public void printMethod() { - System.out.println("Printed in Superclass."); - } -} diff --git a/testBytecode/TestMyTest.java b/testBytecode/TestMyTest.java deleted file mode 100644 index e1305f76..00000000 --- a/testBytecode/TestMyTest.java +++ /dev/null @@ -1,11 +0,0 @@ -class TestMyTest{ -public static void main(String[] a){ - //test1 - //new TestClass(); - //test if statement - //new TestIf(new Boolean(true)); - // test lambda - //new TestClass(); - new LamRun(); -} -} diff --git a/testBytecode/generatedBC/.gitignore b/testBytecode/generatedBC/.gitignore deleted file mode 100644 index 5e7d2734..00000000 --- a/testBytecode/generatedBC/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/testBytecode/manually/Fac1.java b/testBytecode/manually/Fac1.java deleted file mode 100644 index e36ad3ae..00000000 --- a/testBytecode/manually/Fac1.java +++ /dev/null @@ -1,6 +0,0 @@ -class Fuc1{ - - Integer mul(Integer x, Integer y) { - return x; - } -} diff --git a/testBytecode/manually/Fac2.java b/testBytecode/manually/Fac2.java deleted file mode 100644 index dbf307b8..00000000 --- a/testBytecode/manually/Fac2.java +++ /dev/null @@ -1,14 +0,0 @@ -import java.util.function.Function; -class Fac2 { - - Integer mul(Integer x, Integer y) { - return x; - } - - Function m () { - Function fact = (Integer x) -> { - return mul(x, x); - }; - return fact; - } -} diff --git a/testBytecode/manually/LamAssign.java b/testBytecode/manually/LamAssign.java deleted file mode 100644 index 8d45a641..00000000 --- a/testBytecode/manually/LamAssign.java +++ /dev/null @@ -1,10 +0,0 @@ -import java.util.function.Function; -class LamAssign { - - Function m () { - Function lam1 = (Integer x) -> { - return x; - }; - return lam1; - } -} diff --git a/testBytecode/manually/LamAssignWithM.java b/testBytecode/manually/LamAssignWithM.java deleted file mode 100644 index 61077d27..00000000 --- a/testBytecode/manually/LamAssignWithM.java +++ /dev/null @@ -1,12 +0,0 @@ -import java.util.function.Function; -class LamAssignWithM { - Integer mul(Integer x, Integer y) { - return x; - } - Function m () { - Function lam1 = (Integer x) -> { - return mul(x,x); - }; - return lam1; - } -} diff --git a/testBytecode/manually/LamWithAnField.java b/testBytecode/manually/LamWithAnField.java deleted file mode 100644 index ae6da4fc..00000000 --- a/testBytecode/manually/LamWithAnField.java +++ /dev/null @@ -1,14 +0,0 @@ -import java.util.function.Function; -class LamWithAnField { - Integer mul(Integer x, Integer y) { - return x; - } - LamWithField temp= new LamWithField(); - Function m () { - Function lam1 = (Integer x) -> { - return temp.res*x; - }; - return lam1; - } -} - diff --git a/testBytecode/manually/LamWithField.java b/testBytecode/manually/LamWithField.java deleted file mode 100644 index dacdca8b..00000000 --- a/testBytecode/manually/LamWithField.java +++ /dev/null @@ -1,14 +0,0 @@ -import java.util.function.Function; -class LamWithField { - Integer mul(Integer x, Integer y) { - return x; - } - Integer res = new Integer(5); - Function m () { - Function lam1 = (Integer x) -> { - return res*x; - }; - return lam1; - } -} - diff --git a/testBytecode/manually/ReturnM1.java b/testBytecode/manually/ReturnM1.java deleted file mode 100644 index 3f89147d..00000000 --- a/testBytecode/manually/ReturnM1.java +++ /dev/null @@ -1,6 +0,0 @@ -class ReturnM1{ - Integer r; - Integer mul(Integer x, Integer y) { - return r; - } -} diff --git a/testBytecode/public b/testBytecode/public deleted file mode 100644 index 8b137891..00000000 --- a/testBytecode/public +++ /dev/null @@ -1 +0,0 @@ - diff --git a/testBytecode/testF.java b/testBytecode/testF.java deleted file mode 100644 index fa4a50b7..00000000 --- a/testBytecode/testF.java +++ /dev/null @@ -1,5 +0,0 @@ -public class testTets(){ - public static void main(String[] args){ - new tetsF(); - } -} diff --git a/testBytecode/testTets.java b/testBytecode/testTets.java deleted file mode 100644 index 4f95cbc0..00000000 --- a/testBytecode/testTets.java +++ /dev/null @@ -1,5 +0,0 @@ -public class testTets{ - public static void main(String[] args){ - new TetsF(); - } -} diff --git a/testBytecode/testTetsF.java b/testBytecode/testTetsF.java deleted file mode 100644 index fa4a50b7..00000000 --- a/testBytecode/testTetsF.java +++ /dev/null @@ -1,5 +0,0 @@ -public class testTets(){ - public static void main(String[] args){ - new tetsF(); - } -}