Tests bereinigen

This commit is contained in:
JanUlrich 2018-07-17 19:51:50 +02:00
parent e9c87f6bf6
commit d0e7ea86ed
104 changed files with 1148 additions and 1606 deletions

19
asp/adaptRules.lp Normal file
View File

@ -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)
.

22
asp/cartesian.lp Normal file
View File

@ -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)).

70
asp/facultyTestInput.lp Normal file
View File

@ -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).

24
asp/fc.lp Normal file
View File

@ -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

125
asp/fc.lp.backup Normal file
View File

@ -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).

44
asp/reduceRules.lp Normal file
View File

@ -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).

1
asp/result.lp Normal file
View File

@ -0,0 +1 @@
:- equals(A, B), equals(A, C), type(B,BN,_), type(C,CN,_), CN != BN.

291
asp/rule5.test Normal file
View File

@ -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).

113
asp/step4.lp Normal file
View File

@ -0,0 +1,113 @@
%Problem hier: Es gibt in der FiniteClosure nun smaller Beziehungen der Art:
%%(Matrix<A> <) Vector<Vector<A>> < List<Vector<A>>
%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

8
asp/step4.test Normal file
View File

@ -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) .

14
asp/subst.lp Normal file
View File

@ -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).

219
asp/testInput.lp Normal file
View File

@ -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).

28
asp/testReduce.lp Normal file
View File

@ -0,0 +1,28 @@
equals(t1, t2). % Map<Object, Integer> =. Map<Integer, Object>
%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.

12
asp/testUnifikation.lp Normal file
View File

@ -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.

23
asp/unifikation.lp Normal file
View File

@ -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).

40
asp/unifikation.lp.backup Normal file
View File

@ -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).

95
asp/vectorTestInput.lp Normal file
View File

@ -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).

View File

@ -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<File> input;
private static final List<File> 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<File> 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<String> 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;
}
}

View File

@ -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<Pair> testSet = new ConstraintSet<>();
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
List<RefTypeOrTPHOrWildcardOrGeneric> 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<Pair> testSet = new ConstraintSet<>();
List<RefTypeOrTPHOrWildcardOrGeneric> 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<Pair> 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<Pair> 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<ClassOrInterface> 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<Pair> 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<Constraint<Pair>> oderCons = new HashSet<>();
Constraint<Pair> cons1 = new Constraint<>();
cons1.add(new Pair(t1, t2, PairOperator.EQUALSDOT));
oderCons.add(cons1);
Constraint<Pair> 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<Pair> 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<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
RefType t3 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Test1"), list1, new NullToken());
Set<Constraint<Pair>> oderCons = new HashSet<>();
Constraint<Pair> cons1 = new Constraint<>();
cons1.add(new Pair(t1, t2, PairOperator.SMALLERDOT));
oderCons.add(cons1);
Constraint<Pair> 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<Pair> testSet = new ConstraintSet<>();
List<RefTypeOrTPHOrWildcardOrGeneric> 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<Constraint<Pair>> oderCons = new HashSet<>();
Constraint<Pair> 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<ClassOrInterface> 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<Pair> toTest, Collection<ClassOrInterface> 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<List<TypePlaceholder>>{
@Override
public List<TypePlaceholder> visit(RefType refType) {
ArrayList<TypePlaceholder> ret = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
ret.addAll(param.acceptTV(this));
}
return ret;
}
@Override
public List<TypePlaceholder> visit(SuperWildcardType superWildcardType) {
return superWildcardType.getInnerType().acceptTV(this);
}
@Override
public List<TypePlaceholder> visit(TypePlaceholder typePlaceholder) {
return Arrays.asList(typePlaceholder);
}
@Override
public List<TypePlaceholder> visit(ExtendsWildcardType extendsWildcardType) {
return extendsWildcardType.getInnerType().acceptTV(this);
}
@Override
public List<TypePlaceholder> visit(GenericRefType genericRefType) {
return new ArrayList<>();
}
}
protected Collection<TypePlaceholder> getInvolvedTPHS(ConstraintSet<Pair> toTest) {
List<TypePlaceholder> 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<ClassOrInterface> getFC() {
Set<ClassOrInterface> 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<A> extends HashMap<A,Map<Integer, A>>{}
private class Test1<A> extends Object{}
private class Test2 extends Object{}
private class MatrixTest extends Vector<Vector<Integer>>{}
}

View File

@ -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<Pair> toTest = new Constraint();
for(int i = 0; i<5;i++){
toTest.add(new Pair(tph, tph, PairOperator.EQUALSDOT));
}
List<ASPStatement> 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<Constraint<Pair>> oderTest = new HashSet<>();
for(int i = 0; i<5;i++){
Constraint<Pair> toTest = new Constraint();
toTest.add(new Pair(tph, tph, PairOperator.EQUALSDOT));
oderTest.add(toTest);
}
this.convertOderConstraint(oderTest);
System.out.println(this.writer.getASPFile());
}
}

View File

@ -1,10 +0,0 @@
package asp.unifywithoutwildcards;
import org.junit.Test;
public class ASPTests {
@Test
public void test(){
}
}

View File

@ -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<List<Long>> 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<Long> results = new ArrayList<>();
List<Long> 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);
}
}

View File

@ -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<ResultSet> 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<ResultSet> 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<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> 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);
}
}

View File

@ -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<A> extends HashMap<String, A>{
@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<G>{
public G testField;
}
@Test
public void genericFieldTest(){
ClassOrInterface test = ASTFactory.createClass(GenericFieldTest.class);
assertTrue(test.getFieldDecl().get(0).getType() instanceof GenericRefType);
}
}

View File

@ -1,8 +0,0 @@
package bytecode;
public class ATest extends JavaTXCompilerTest {
public ATest() {
fileName = "Example";
}
}

View File

@ -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';
}
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class AssignToLitTest extends JavaTXCompilerTest {
public AssignToLitTest() {
this.fileName = "AssignToLit";
}
}

View File

@ -1,11 +0,0 @@
public class DuMethod{
method(a){
return a+a;
}
method(a){
return a;
}
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class DuMethodTest extends JavaTXCompilerTest{
public DuMethodTest() {
this.fileName = "DuMethod";
}
}

View File

@ -1,8 +0,0 @@
public class EmptyMethod{
public void m1(){
System.out.println("test");
}
public void m2(){}
}

View File

@ -1,9 +0,0 @@
import java.lang.String;
public class Example {
public m() {
String x = "X";
return x;
}
}

View File

@ -1,3 +0,0 @@
public class Exceptions {
// m(Integer i) throws
}

View File

@ -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;
}
}

View File

@ -1,10 +0,0 @@
class Faculty2 {
m () {
var fact = (Integer x) -> {
return x;
};
return fact;
}
}

View File

@ -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;
// }
// }
}

View File

@ -1,11 +0,0 @@
package bytecode;
import org.objectweb.asm.Opcodes;
public class ForTest extends JavaTXCompilerTest {
public ForTest() {
this.fileName = "For";
}
}

View File

@ -1,5 +0,0 @@
public class Gen{
Vector<Integer> m(Vector<Integer> v){
return v;
}
}

View File

@ -1,17 +0,0 @@
class Generics<B> {
Generics(B b){
}
B mt1(B b){
return mt1(b);
}
}
/*
Problem:
auto test = new List<String>();
auto test2 = new List<Integer>();
... //code, welcher möglicherweise test und test2 vertauscht
test.add("hallo");
*/

View File

@ -1,6 +0,0 @@
class Generics2<B extends String>{
<B extends Integer> B m1(B b){
return b;
}
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class Generics2Test extends JavaTXCompilerTest{
public Generics2Test() {
this.fileName = "Generics2";
}
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class GenericsTest extends JavaTXCompilerTest {
public GenericsTest() {
this.fileName = "Generics";
}
}

View File

@ -1,10 +0,0 @@
public class IfTest{
Integer m1(Boolean b) {
Integer i;
if(b) {
return i;
}
return i;
}
}

View File

@ -1,8 +0,0 @@
import java.util.Vector;
class Import {
void methode(){
Vector v = new Vector<>();
v.add("X");
}
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class ImportTest extends JavaTXCompilerTest{
public ImportTest() {
this.fileName = "Import";
}
}

View File

@ -1,3 +0,0 @@
public interface Interface1{
public void test();
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class InterfaceTest extends JavaTXCompilerTest{
public InterfaceTest() {
this.fileName = "Interface1";
}
}

View File

@ -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<File> 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<ResultSet> typeinferenceResult = compiler.typeInference();
HashMap<String,byte[]> 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<String,byte[]> getBytecode(SourceFile sf, ResultSet resultSet) {
HashMap<String,byte[]> classFiles = new HashMap<>();
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,resultSet);
bytecodeGen.visit(sf);
return bytecodeGen.getClassFiles();
}
public void writeClassFile(HashMap<String,byte[]> 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);
}
}

View File

@ -1,15 +0,0 @@
import java.lang.Integer;
class LamAssign {
m () {
var lam1 = (Integer x) -> {
return x;
};
return lam1;
}
}
interface Fun1<A,B>{
public A apply(B b);
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class LamAssignTest extends JavaTXCompilerTest{
public LamAssignTest() {
this.fileName = "LamAssign";
}
}

View File

@ -1,9 +0,0 @@
public class LamRunnable{
public LamRunnable(){
Runnable lam = () -> {System.out.println("lambda");};
lam.run();
}
}

View File

@ -1,18 +0,0 @@
class Lambda{
methode(){
return ((f) -> f);
}
}
/*
interface Fun0<A>{
A apply();
}
interface Fun1<A,B>{
A apply(B b);
}
*/
interface Fun2<A,B,C>{
A apply(B b, C c);
}

View File

@ -1,32 +0,0 @@
public class Lambda2
{
public static void main(List<String> args){
var listOfStrings = new List<String>();
var listOfObjects;
listOfObjects = map(listOfStrings, (a) -> a);
}
public map(a , b){
b.apply(a);
return a;
}
/*
public static <I,O> List<O> map(List<I> input, Function<I,O> func) {
List<O> output;
output = new List<O>();
output.add(func.apply(input.get()));
return output;
}
*/
}
class List<A>{
A get();
void add(A);
}
class Function<A,B>{
B apply(A a);
}

View File

@ -1,23 +0,0 @@
public class Lambda2
{
/*
public static <A> List<A> map(List<? extends A> input,
Function<? super A, ? extends A> func){
input.add(func.apply(input.get()));
}
*/
public map(input,func){
input.add(func.apply(input.get()));
return map(new List<String>(), func);
}
}
class List<A>{
A get();
void add(A);
}
class Function<A,B>{
B apply(A a);
}

View File

@ -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;
}
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class MethodsTest extends JavaTXCompilerTest {
public MethodsTest() {
this.fileName = "Methods";
}
}

View File

@ -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;
}
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class OpTest extends JavaTXCompilerTest {
public OpTest() {
this.fileName = "Op";
}
}

View File

@ -1,11 +0,0 @@
import java.util.Vector;
class OverlaodGen {
void method(Vector<Integer> v) {
// Integer i = v.get(0);
}
void method(Vector<String> v) {
// String s = v.get(0);
}
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class OverlaodGenTest extends JavaTXCompilerTest {
public OverlaodGenTest() {
this.fileName = "OverlaodGen";
}
}

View File

@ -1,5 +0,0 @@
public class RecursiveMeth{
public Integer test(){
return this.test();
}
}

View File

@ -1,6 +0,0 @@
class ReturnMethod{
Integer r;
Integer mul(Integer x, Integer y) {
return r;
}
}

View File

@ -1,7 +0,0 @@
package bytecode;
public class TestIfTest extends JavaTXCompilerTest{
public TestIfTest() {
this.fileName = "IfTest";
}
}

View File

@ -1,4 +0,0 @@
public class VoidMeth{
public void test(){
}
}

View File

@ -1,6 +0,0 @@
class Test{
method(){
if(true)i++;
if(true)i--;
else i++;
}}

View File

@ -1,3 +0,0 @@
class Matrix{
<A extends B, C extends B> String op = "String";
}

View File

@ -1,8 +0,0 @@
class CastTest{
void methode(){
Object a;
String b;
a = (Object) b;
}
}

View File

@ -1,4 +0,0 @@
class C1 extends Object
{
m(para) { return para; }
}

View File

@ -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(); }
}

View File

@ -1,3 +0,0 @@
class FieldInitializationTest{
var var = "hallo";
}

View File

@ -1,5 +0,0 @@
package test;
class Test<Typ>{
Typ a;
}

View File

@ -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<String> filenames = new ArrayList<String>();
/*
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);
}
}

View File

@ -1,3 +0,0 @@
class Test{
<A> A var;
}

View File

@ -1,4 +0,0 @@
import java.util.*;
class ImportTest{
}

View File

@ -1,4 +0,0 @@
import java.util.ArrayList;
class ImportTest{
}

View File

@ -1,5 +0,0 @@
import java.util.List;
class ImportTest{
List<ImportTest> test;
}

View File

@ -1,5 +0,0 @@
class NewTest {
main() { return new NewTest<>().mt(new NewTest(1) , new NewTest(2) , new
NewTest(3)); }
}

View File

@ -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;
}
}

View File

@ -1,9 +0,0 @@
import java.lang.Comparable;
class PackageNameTest{
java.lang.Integer test(a){return a;}
Comparable<Integer> test2(a){return a;}
}

View File

@ -1,8 +0,0 @@
class Statements{
public void methodeTest(){
methodeTest();
return null;
}
}

View File

@ -1,5 +0,0 @@
class A {
mt(x, y, z) { return x.sub(y).add(z); }
}

View File

@ -1,14 +0,0 @@
class WhileTest{
void methode(){
Boolean test;
do{
test=test;
}while(test);
while(test){
test = test;
}
return;
}
}

View File

@ -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<ResultSet> 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<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> 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);
}
}

View File

@ -1,5 +0,0 @@
package visualisation;
public class ToString {
}

View File

@ -1,6 +0,0 @@
public class Field{
public void m(){
MethFieldVar mF = new MethFieldVar();
mF.s1 = "Field S1";
}
}

View File

@ -1,8 +0,0 @@
import java.util.Vector;
class Import {
void methode(){
Vector v = new Vector();
v.add(v);
}
}

View File

@ -1,10 +0,0 @@
import java.util.function.Function;
public class Lam1{
public Lam1() {
Function<String,String> fun = (x) -> x+"1";
fun.apply("2");
Runnable lam = () -> System.out.println("lambda");
lam.run();
}
}

View File

@ -1,8 +0,0 @@
public class LamRun{
public void mRun(){
Runnable lam = () -> System.out.println("lambda");
lam.run();
}
}

View File

@ -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{}

View File

@ -1,6 +0,0 @@
public class Subclass extends Superclass {
public void printMethod() {
super.printMethod();
}
}

View File

@ -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();
}
}

View File

@ -1,6 +0,0 @@
public class Superclass {
public void printMethod() {
System.out.println("Printed in Superclass.");
}
}

View File

@ -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();
}
}

View File

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View File

@ -1,6 +0,0 @@
class Fuc1{
Integer mul(Integer x, Integer y) {
return x;
}
}

View File

@ -1,14 +0,0 @@
import java.util.function.Function;
class Fac2 {
Integer mul(Integer x, Integer y) {
return x;
}
Function<Integer,Integer> m () {
Function<Integer,Integer> fact = (Integer x) -> {
return mul(x, x);
};
return fact;
}
}

View File

@ -1,10 +0,0 @@
import java.util.function.Function;
class LamAssign {
Function<Integer,Integer> m () {
Function<Integer,Integer> lam1 = (Integer x) -> {
return x;
};
return lam1;
}
}

View File

@ -1,12 +0,0 @@
import java.util.function.Function;
class LamAssignWithM {
Integer mul(Integer x, Integer y) {
return x;
}
Function<Integer,Integer> m () {
Function<Integer,Integer> lam1 = (Integer x) -> {
return mul(x,x);
};
return lam1;
}
}

View File

@ -1,14 +0,0 @@
import java.util.function.Function;
class LamWithAnField {
Integer mul(Integer x, Integer y) {
return x;
}
LamWithField temp= new LamWithField();
Function<Integer,Integer> m () {
Function<Integer,Integer> lam1 = (Integer x) -> {
return temp.res*x;
};
return lam1;
}
}

View File

@ -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<Integer,Integer> m () {
Function<Integer,Integer> lam1 = (Integer x) -> {
return res*x;
};
return lam1;
}
}

View File

@ -1,6 +0,0 @@
class ReturnM1{
Integer r;
Integer mul(Integer x, Integer y) {
return r;
}
}

Some files were not shown because too many files have changed in this diff Show More