YAP 7.1.0
checker.yap
1/*************************************************************************
2* *
3* YAP Prolog *
4* *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: checker.yap *
12* comments: style checker for Prolog *
13* *
14* Last rev: $Date: 2008-03-31 22:56:22 $,$Author: vsc $ *
15* *
16*************************************************************************/
17
18:- system_module( style_checker, [no_style_check/1,
19 style_check/1], ['$check_term'/5,
20 '$sv_warning'/2,
21 '$syntax_check_discontiguous'/2,
22 '$syntax_check_multiple'/2,
23 '$syntax_check_single_var'/2]).
24
25%% @{
26
27/**
28
29@defgroup YAPStyleChecker YAP Style Checker
30 @ingroup YAPCompilerSettings
31
32YAP implements a style-checker thay currently verifies whether:
33
341 named variables occur once in a clause.
35
362 clauses from dofferent predicates are mixed together.
37
383 clauses for the same predicate occur in different files.
39
40One can declare a predicate to be discontiguous (see the
41discontiguous/1 declaration) and/or multifile/1.
42
43*/
44
45/*
46@pred style_check(+ _X_)
47
48Turns on style checking according to the attribute specified by _X_,
49which must be one of the following:
50
51 + single_var
52 Checks single occurrences of named variables in a clause.
53
54 + discontiguous
55 Checks non-contiguous clauses for the same predicate in a file.
56
57 + multiple
58 Checks the presence of clauses for the same predicate in more than one
59 file when the predicate has not been declared as `multifile`
60
61 + all
62 Performs style checking for all the cases mentioned above.
63
64
65By default, style checking is disabled in YAP unless we are in
66`sicstus` or `iso` language mode.
67
68The style_check/1 built-in is now deprecated. Please use
69`set_prolog_flag/1` instead.
70
71 **/
72%
73% A Small style checker for YAP
74
75style_check(V) :- var(V), var, var.
76/*style_check(V) :-
77 \+atom(V),
78 \+ is_list(V),
79 V \= + _,
80 V \= - _, !,
81 '$do_error'( type_error('+|-|?(Flag)', V), style_check(V) ).
82 */
83
84style_check(-single_var) :-
85 set_prolog_flag( single_var_warnings, false ).
86style_check(single_var) :-
87 set_prolog_flag( single_var_warnings, true ).
88style_check(singleton) :-
89 set_prolog_flag( single_var_warnings, true ).
90style_check(-singleton) :-
91 set_prolog_flag( single_var_warnings, false ).
92style_check(discontiguous) :-
93 set_prolog_flag( discontiguous_warnings, true ).
94style_check(-discontiguous) :-
95 set_prolog_flag( discontiguous_warnings, false ).
96style_check(multiple) :-
97 set_prolog_flag( redefine_warnings, true ).
98style_check(-multiple) :-
99 set_prolog_flag( redefine_warnings, false ).
100style_check(all) :-
101 style_check([single_var, multiple, discontiguous]).
102style_check(no_effect).
103style_check(+no_effect) .
104style_check(-no_effect).
105style_check(var_branches).
106style_check(+var_branches) :-
107 '$style_checker'( [ var_branches ] ).
108style_check(-var_branches) :-
109 '$style_checker'( [ -var_branches ] ).
110style_check(atom).
111style_check(+atom) :-
112 '$style_checker'( [ atom ] ).
113style_check(-atom) :-
114 '$style_checker'( [ -atom ] ).
115style_check(charset) :-
116 '$style_checker'( [ charset ] ).
117style_check(+charset) :-
118 '$style_checker'( [ charset ] ).
119style_check(-charset) :-
120 '$style_checker'( [ -charset ] ).
121style_check('?'(Info) ) :-
122 L = [ singleton, discontiguous, multiple ],
123 ( lists:member(Style, L ) -> Info = +Style ; Info = -Style ).
124style_check([]).
125style_check([H|T]) :- style_check(H), style_check(T).
126
127/** @pred no_style_check(+ _X_)
128
129Turns off style checking according to the attribute specified by
130 _X_, which have the same meaning as in style_check/1.
131
132The no_style_check/1 built-in is now deprecated. Please use
133`set_prolog_flag/1` instead.
134
135**/
136no_style_check(V) :- var(V), var, var.
137no_style_check(all) :-
138 '$style_checker'( [ -singleton, -discontiguous, -multiple ] ).
139no_style_check(-single_var) :-
140 '$style_checker'( [ -singleton ] ).
141no_style_check(-singleton) :-
142 '$style_checker'( [ -singleton ] ).
143no_style_check(-discontiguous) :-
144 '$style_checker'( [ -discontiguous ] ).
145no_style_check(-multiple) :-
146 '$style_checker'( [ -multiple ] ).
149
150/** @pred discontiguous(+ _G_) is iso
151 Avoid warnings from the sytax checker.
152
153Declare that the predicate _G_ or list of predicates are discontiguous
154procedures, that is, clauses for discontigous procedures may be
155separated by clauses from other procedures.
156
157*/
158
159discontiguous(P) :- '$discontiguous'(P).
160
161:- op(1150, fx, [multifile,discontiguous]).
162
163
164/*
165@}
166*/
167
no_style_check(+ X)
op(+ P,+ T,+ A)
set_prolog_flag(+ Flag,+ Value)
var( T)
member(?Element, ?Set) is true when Set is a list, and Element occurs in it