fix operator error checking (Ulrich #192)
This commit is contained in:
parent
ff6bd1dda0
commit
da0aee0f57
129
pl/utils.yap
129
pl/utils.yap
@ -19,34 +19,37 @@
|
|||||||
'$check_op'(P,T,V,op(P,T,V)),
|
'$check_op'(P,T,V,op(P,T,V)),
|
||||||
'$op'(P, T, V).
|
'$op'(P, T, V).
|
||||||
|
|
||||||
|
% just check the operator declarations for correctness.
|
||||||
|
'$check_op'(P,T,Op,G) :-
|
||||||
|
( var(P) ; var(T); var(Op)), !,
|
||||||
|
'$do_error'(instantiation_error,G).
|
||||||
|
'$check_op'(P,_,_,G) :-
|
||||||
|
\+ integer(P), !,
|
||||||
|
'$do_error'(type_error(integer,P),G).
|
||||||
|
'$check_op'(P,_,_,G) :-
|
||||||
|
P < 0, !,
|
||||||
|
'$do_error'(domain_error(operator_priority,P),G).
|
||||||
|
'$check_op'(P,_,_,G) :-
|
||||||
|
P > 1200, !,
|
||||||
|
'$do_error'(domain_error(operator_priority,P),G).
|
||||||
|
'$check_op'(_,T,_,G) :-
|
||||||
|
\+ atom(T), !,
|
||||||
|
'$do_error'(type_error(atom,P),G).
|
||||||
|
'$check_op'(_,T,_,G) :-
|
||||||
|
\+ '$associativity'(T), !,
|
||||||
|
'$do_error'(domain_error(operator_specifier,T),G).
|
||||||
'$check_op'(P,T,V,G) :-
|
'$check_op'(P,T,V,G) :-
|
||||||
(
|
'$check_module_for_op'(V, G, NV),
|
||||||
var(P) ->
|
'$check_top_op'(P, T, NV, G).
|
||||||
'$do_error'(instantiation_error,G)
|
|
||||||
;
|
'$check_top_op'(_, _, [], _).
|
||||||
var(T) ->
|
'$check_top_op'(P, T, Op.NV, G) :- !,
|
||||||
'$do_error'(instantiation_error,G)
|
'$check_ops'(P, T, Op.NV, G).
|
||||||
;
|
'$check_top_op'(P, T, V, G) :-
|
||||||
var(V) ->
|
atom(V), !,
|
||||||
'$do_error'(instantiation_error,G)
|
'$check_op_name'(P, T, V, G).
|
||||||
;
|
'$check_top_op'(P, T, V, G) :-
|
||||||
\+ integer(P) ->
|
'$do_error'(type_error(atom,V),G).
|
||||||
'$do_error'(type_error(integer,P),G)
|
|
||||||
;
|
|
||||||
\+ atom(T) ->
|
|
||||||
'$do_error'(type_error(atom,T),G)
|
|
||||||
;
|
|
||||||
P < 0 ->
|
|
||||||
'$do_error'(domain_error(operator_priority,P),G)
|
|
||||||
;
|
|
||||||
P > 1200 ->
|
|
||||||
'$do_error'(domain_error(operator_priority,P),G)
|
|
||||||
;
|
|
||||||
\+ '$associativity'(T) ->
|
|
||||||
'$do_error'(domain_error(operator_specifier,T),G)
|
|
||||||
;
|
|
||||||
'$check_op_name'(V,G)
|
|
||||||
).
|
|
||||||
|
|
||||||
'$associativity'(xfx).
|
'$associativity'(xfx).
|
||||||
'$associativity'(xfy).
|
'$associativity'(xfy).
|
||||||
@ -57,17 +60,43 @@
|
|||||||
'$associativity'(fx).
|
'$associativity'(fx).
|
||||||
'$associativity'(fy).
|
'$associativity'(fy).
|
||||||
|
|
||||||
'$check_op_name'(V,G) :-
|
'$check_module_for_op'(MOp, G, _) :-
|
||||||
|
var(MOp), !,
|
||||||
|
'$do_error'(instantiation_error,G).
|
||||||
|
'$check_module_for_op'(M:V, G, _) :-
|
||||||
|
var(M), !,
|
||||||
|
'$do_error'(instantiation_error,G).
|
||||||
|
'$check_module_for_op'(M:V, G, NV) :-
|
||||||
|
atom(M), !,
|
||||||
|
'$check_module_for_op'(V, G, NV).
|
||||||
|
'$check_module_for_op'(M:V, G, _) :- !,
|
||||||
|
'$do_error'(type_error(atom,P),G).
|
||||||
|
'$check_module_for_op'(V, G, V).
|
||||||
|
|
||||||
|
'$check_ops'(P, T, [], G) :- !.
|
||||||
|
'$check_ops'(P, T, Op.NV, G) :- !,
|
||||||
|
(
|
||||||
|
var(NV)
|
||||||
|
->
|
||||||
|
'$do_error'(instantiation_error,G)
|
||||||
|
;
|
||||||
|
'$check_module_for_op'(Op, G, NOp),
|
||||||
|
'$check_op_name'(P, T, NOp, G),
|
||||||
|
'$check_ops'(P, T, NV, G)
|
||||||
|
).
|
||||||
|
'$check_ops'(P, T, Ops, G) :-
|
||||||
|
'$do_error'(type_error(list,Ops),G).
|
||||||
|
|
||||||
|
'$check_op_name'(_,_,V,G) :-
|
||||||
var(V), !,
|
var(V), !,
|
||||||
'$do_error'(instantiation_error,G).
|
'$do_error'(instantiation_error,G).
|
||||||
'$check_op_name'(',',G) :- !,
|
'$check_op_name'(_,_,',',G) :- !,
|
||||||
'$do_error'(permission_error(modify,operator,','),G).
|
'$do_error'(permission_error(modify,operator,','),G).
|
||||||
'$check_op_name'('[]',G) :- !,
|
'$check_op_name'(_,_,'[]',G) :- !,
|
||||||
'$do_error'(permission_error(create,operator,'[]'),G).
|
'$do_error'(permispsion_error(create,operator,'[]'),G).
|
||||||
'$check_op_name'('{}',G) :- !,
|
'$check_op_name'(_,_,'{}',G) :- !,
|
||||||
'$do_error'(permission_error(create,operator,'{}'),G).
|
'$do_error'(permission_error(create,operator,'{}'),G).
|
||||||
'$check_op_name'('|',G) :- !,
|
'$check_op_name'(P,T,'|',G) :- !,
|
||||||
G = op(P, T, _),
|
|
||||||
(
|
(
|
||||||
integer(P),
|
integer(P),
|
||||||
P < 1001
|
P < 1001
|
||||||
@ -75,35 +104,13 @@
|
|||||||
Fix \== xfx, Fix \== xfy, Fix \== yfx, Fix \== yfy
|
Fix \== xfx, Fix \== xfy, Fix \== yfx, Fix \== yfy
|
||||||
),
|
),
|
||||||
'$do_error'(permission_error(create,operator,'|'),G).
|
'$do_error'(permission_error(create,operator,'|'),G).
|
||||||
'$check_op_name'(V,_) :-
|
'$check_op_name'(_,_,V,_) :-
|
||||||
atom(V), !.
|
atom(V), !.
|
||||||
'$check_op_name'(M:A, G) :-
|
'$check_op_name'(_,_,A,G) :-
|
||||||
(
|
'$do_error'(type_error(atom,A),G).
|
||||||
var(M) ->
|
|
||||||
'$do_error'(instantiation_error,G)
|
|
||||||
;
|
|
||||||
var(A) ->
|
|
||||||
'$do_error'(instantiation_error,G)
|
|
||||||
;
|
|
||||||
atom(M) ->
|
|
||||||
'$check_op_name'(A, G)
|
|
||||||
;
|
|
||||||
'$do_error'(instantiation_error,G)
|
|
||||||
).
|
|
||||||
'$check_op_name'([A|As], G) :-
|
|
||||||
'$check_op_name'(A, G),
|
|
||||||
'$check_op_names'(As, G).
|
|
||||||
|
|
||||||
'$check_op_names'([], _).
|
'$op'(P, T, ML) :-
|
||||||
'$check_op_names'([A|As], G) :-
|
strip_module(ML, M, [A|As]), !,
|
||||||
'$check_op_name'(A, G),
|
|
||||||
'$check_op_names'(As, G).
|
|
||||||
|
|
||||||
|
|
||||||
'$op'(P, T, M:[A|As]) :- !,
|
|
||||||
'$current_module'(M),
|
|
||||||
'$opl'(P, T, M, [A|As]).
|
|
||||||
'$op'(P, T, [A|As]) :- !,
|
|
||||||
'$opl'(P, T, M, [A|As]).
|
'$opl'(P, T, M, [A|As]).
|
||||||
'$op'(P, T, A) :-
|
'$op'(P, T, A) :-
|
||||||
'$op2'(P,T,A).
|
'$op2'(P,T,A).
|
||||||
|
Reference in New Issue
Block a user