forked from JavaTX/JavaCompilerCore
111 lines
4.6 KiB
Plaintext
111 lines
4.6 KiB
Plaintext
|
|
wildcard(A) :- extendsWildcard(A).
|
|
wildcard(A) :- superWildcard(A).
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
%Anzahl der Wildcards ist 1
|
|
% Mehr benötigt man nicht verschachtelt
|
|
% Dadurch ist numWildcards unnötig, man ändert einfach die grArg auf Wildcards
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
type(P, TN, TNum) :- makeSameGen(P, T), type(T, TN, TNum).
|
|
param(P, TN, TNum) :- makeSameGen(P, T), param(T, TN, TNum).
|
|
superWildcard(P) :- makeSameGen(P, T), superWildcard(T).
|
|
extendsWildcard(P) :- makeSameGen(P, T), extendsWildcard(T).
|
|
|
|
%%%%%%%%%%%%%%%%%
|
|
% Greater
|
|
%%%%%%%%%%%%%%%%
|
|
{ greaterGen(P, A, AFC, BFC) : smaller(AFC, BFC), type(AFC, AN, ANum) } == 1 :- greaterGen(P, A), type(A, AN, ANum)
|
|
.
|
|
|
|
type(P, BN, BNum) :- greaterGen(P, A, _, B), type(B, BN, BNum).
|
|
%Bei den Parametern gibt es zwei Fälle:
|
|
%% Die TPHs müssen gemapt werden, die anderen übernommen
|
|
greaterArgGen(pointer(P, Param), Param) :- greaterGen(P, A, Afc, B), param(A, Param, PNum), mapFC(smaller(Afc, B), PNum, _).
|
|
greaterArgGen(pointer(P, Param), Param) :- greaterGen(P, A, _, B), param(B, Param, PNum), type(B, _, _).
|
|
param(P, pointer(P, Param), PNum) :- greaterGen(P, A, _, B), param(B, Param, PNum)
|
|
, type(Param, _, _)
|
|
.
|
|
param(P, pointer(P, Param), PNum2) :- greaterGen(P, A, Afc, B), param(A, Param, PNum)
|
|
, mapFC(smaller(Afc,B), PNum, PNum2)
|
|
.
|
|
|
|
%TypeVars bleiben einfach TypeVars:
|
|
typeVar(Pointer) :- greaterArgGen(Pointer, T), typeVar(T).
|
|
|
|
%makeGreaterGen(Pointer, T) :- greaterArgGen(Pointer, T), extendsWildcard(T).
|
|
%makeSmallerGen(Pointer, T) :- greaterArgGen(Pointer, T), superWildcard(T).
|
|
makeSameGen(Pointer, T) :- greaterArgGen(Pointer, T), extendsWildcard(T).
|
|
makeSameGen(Pointer, T) :- greaterArgGen(Pointer, T), superWildcard(T).
|
|
makeSmallerGenG(Pointer, T),
|
|
makeGreaterGenG(Pointer, T),
|
|
makeSameGenG(Pointer, T)
|
|
:- greaterArgGen(Pointer, T), not extendsWildcard(T), not superWildcard(T), type(T, N, Num).
|
|
|
|
greaterGen(P, T) :- makeGreaterGenG(P, T).
|
|
extendsWildcard(P) :- makeGreaterGenG(P, T).
|
|
|
|
smallerGen(P, T) :- makeGreaterGenG(P, T).
|
|
superWildcard(P) :- makeSmallerGenG(P, T).
|
|
|
|
{ greaterGen(P, T, TFC, TFC) : smaller(TFC, _), type(TFC, TN, TNum) } == 1 :- makeSameGenG(P, T), type(T, TN, TNum).
|
|
|
|
greaterArgGenNum(P, 0) :- greaterArgGen(P, _), type(P, _ ,_).
|
|
greaterArgGenNum(pointer(P, P2), Num + 1) :- greaterArgGen(pointer(P, P2),_), greaterArgGenNum(P, Num).
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%
|
|
% smaller
|
|
%%%%%%%%%%%%%%%%
|
|
{ smallerGen(P, A, AFC, BFC) : smaller(BFC, AFC), type(AFC, AN, ANum) } == 1 :- smallerGen(P, A), type(A, AN, ANum)
|
|
.
|
|
{ type(P, BN, BNum) : type(B,BN,BNum) } == 1 :- smallerGen(P, A, _, B).
|
|
%Bei den Parametern gibt es drei Fälle:
|
|
%% Die TPHs müssen gemapt werden, die anderen übernommen
|
|
smallerArgGen(pointer(P, Param), Param) :- smallerGen(P, A, Afc, B), param(A, Param, PNum), mapFC(smaller(B, Afc), _, PNum).
|
|
param(P, pointer(P, Param), PNum2) :- smallerGen(P, A, Afc, B), param(A, Param, PNum)
|
|
, mapFC(smaller(B,Afc), PNum2, PNum)
|
|
.
|
|
|
|
%Neue Parameter können hinzu kommen: TODO
|
|
%smallerArgGen(pointer(P, Param), Param) :- smallerGen(P, A, _, B), param(B, Param, PNum).
|
|
%param(P, pointer(P, Param), PNum) :- greaterGen(P, A, _, B), param(B, Param, PNum)
|
|
% %, type(Param, _, _) %Es ist egal ob es ein Typparameter oder eine TypeVar ist. smallerArgGen macht das richtige
|
|
% .
|
|
|
|
%Es können voraussetzungen hinzukommen:
|
|
equals(Param, PA) :- smallerGen(P, A, Afc, B), param(Afc, Param, PNum), type(Param, _, _), param(A, PA, PNum).
|
|
|
|
%TypeVars bleiben einfach TypeVars:
|
|
typeVar(Pointer) :- smallerArgGen(Pointer, T), typeVar(T).
|
|
|
|
makeSameGen(Pointer, T) :- smallerArgGen(Pointer, T), extendsWildcard(T).
|
|
makeSameGen(Pointer, T) :- smallerArgGen(Pointer, T), superWildcard(T).
|
|
makeSmallerGenS(Pointer, T),
|
|
makeGreaterGenS(Pointer, T),
|
|
makeSameGenS(Pointer, T)
|
|
:- smallerArgGen(Pointer, T), not extendsWildcard(T), not superWildcard(T), type(T, N, Num).
|
|
|
|
greaterGen(P, T) :- makeGreaterGenS(P, T).
|
|
extendsWildcard(P) :- makeGreaterGenS(P, T).
|
|
|
|
smallerGen(P, T) :- makeSmallerGenS(P, T).
|
|
superWildcard(P) :- makeSmallerGenS(P, T).
|
|
|
|
{ smallerGen(P, T, TFC, TFC) : smaller(TFC, _), type(TFC, TN, TNum) } == 1 :- makeSameGenS(P, T), type(T, TN, TNum).
|
|
|
|
|
|
%%%
|
|
% Grundlegende Regeln
|
|
%%%
|
|
smaller(A, A) :- smaller(A, _).
|
|
smaller(B, B) :- smaller(_, B).
|
|
%smaller(A, A) :- type(A). %Alle Typen erben von sich selber. Hätte komische Nebeneffekte
|
|
|
|
%Mapping:
|
|
mapFC(smaller(A,B), Num, Num2) :- smaller(A,B), param(A, P, Num), typeVar(P), param(B, P, Num2).
|
|
|
|
hasTypeInParameterList(A) :- type(A, _, _), param(A, P, _), type(P, _, _).
|
|
mapRootFC(smaller(A,B), Num, Num2) :- smaller(A, B), not hasTypeInParameterList(A), param(A, P, Num), typeVar(P), param(B, P, Num2).
|
|
|