forked from JavaTX/JavaCompilerCore
126 lines
5.1 KiB
Plaintext
126 lines
5.1 KiB
Plaintext
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
%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).
|
|
|