debug_argument(SpecDef,Position,Arg) :-
spec_indirection(SpecDef,SpecRHS),
debug_argument(SpecRHS,Position,Arg).
debug_argument(one_of(List),Position,Arg) :- !,
include(prettyprinter:spec_top_level_match(Arg),List,Matches),
(Matches==[]
-> get_functor(Arg,FA,NA),
log(error,'Value at ~w with functor ~w/~w does not match any case of ~w.',[Position,FA,NA,List])
; Matches = [OneMatch]
-> debug_argument(OneMatch,Position,Arg)
; fail).
debug_argument(compound(Spec),Position,Arg) :- !, functor(Spec,F,N),
get_functor(Arg,FA,NA),
( F=FA,N=NA
-> Spec =.. [F|Specs], Arg =.. [F|Args],
l_debug_arguments(Specs,F/N,1,Args)
; log(error,'Value at ~w with functor ~w/~w does not match functor ~w/~w of ~w.',[Position,FA,NA,F,N,Spec])
).
debug_argument(list(Spec),Position,Arg) :- !,
( Arg = [] -> fail
; Arg = [H|T] ->
(debug_argument(Spec,Position,H) -> true
; debug_argument(list(Spec),list(Position),T)
)
; get_functor(Arg,FA,NA),
log(error,'Value at ~w with functor ~w/~w ist not a list.',[Position,FA,NA])
).
debug_argument(atom(X),Position,Arg) :- !,
Arg \== X,
get_functor(Arg,FA,NA),
log(error,'Value at ~w with functor ~w/~w does not match atom ~w.',[Position,FA,NA,X]).
debug_argument(ground,Position,Arg) :- !,
term_variables(Arg,Vars), Vars \==[],
get_functor(Arg,FA,NA),
log(error,'Value at ~w with functor ~w/~w does have variables ~w and is not ground.',[Position,FA,NA,Vars]).
debug_argument(Basic,Position,Arg) :- basic_type(Basic), !,
\+ valid(Basic, Arg),
get_functor(Arg,FA,NA),
log(error,'Value at ~w with functor ~w/~w ist not ~w.',[Position,FA,NA,Basic]).