-
Notifications
You must be signed in to change notification settings - Fork 0
/
compilation.pl
49 lines (43 loc) · 1.97 KB
/
compilation.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% COMPILATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
check_for_multiple_arities :-
setof(FileName-Pred:Arities,
multiple_arity_predicate(FileName, Pred, Arities),
MultipleArityPredicates),
!,
nl,
warn_multiple_arity_predicates(MultipleArityPredicates),
nl.
check_for_multiple_arities.
multiple_arity_predicate(AbsoluteFileName, PredicateName, Arities) :-
gen_pred_name(PredicateName, AbsoluteFileName, Predicate),
functor(Predicate, PredicateName, _Arity),
setof(Term, gen_pred_with_known_functor(PredicateName, AbsoluteFileName, Term), PredList),
map_preds_to_arities(PredList, MultipleArities),
sort(MultipleArities, Arities),
Arities = [_,_|_].
gen_pred_name(PredicateName, FileName, SkeletalSpecification) :-
source_file(SkeletalSpecification, FileName),
functor(SkeletalSpecification, PredicateName, _).
gen_pred_name(PredicateName, FileName, SkeletalSpecification) :-
source_file(_Module:SkeletalSpecification, FileName),
functor(SkeletalSpecification, PredicateName, _).
gen_pred_with_known_functor(PredicateName, FileName, SkeletalSpecification) :-
current_predicate(PredicateName, SkeletalSpecification),
source_file(SkeletalSpecification, FileName).
gen_pred_with_known_functor(PredicateName, FileName, SkeletalSpecification) :-
current_predicate(PredicateName, _Module:SkeletalSpecification),
source_file(_Module:SkeletalSpecification, FileName).
map_preds_to_arities([], []).
map_preds_to_arities([Pred1|RestPreds], [Arity1|RestArities]) :-
functor(Pred1, _Functor, Arity1),
map_preds_to_arities(RestPreds, RestArities).
warn_multiple_arity_predicates([]).
warn_multiple_arity_predicates([FileName-Pred:ArityList|Rest]) :-
( sub_atom(specialist, FileName) ->
basename(FileName, BaseName),
format(user_output, '~N~q/~w in ~w~n', [Pred, ArityList, BaseName])
; true
),
warn_multiple_arity_predicates(Rest).