| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | /************************************************************************* | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | *	 YAP Prolog 							 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | *	Yap Prolog was developed at NCCUP - Universidade do Porto	 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997	 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | ************************************************************************** | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | * File:		checker.yap						 * | 
					
						
							| 
									
										
										
										
											2004-03-19 11:35:42 +00:00
										 |  |  | * comments:	style checker for Prolog				 * | 
					
						
							|  |  |  | *									 * | 
					
						
							| 
									
										
										
										
											2008-03-31 22:56:22 +00:00
										 |  |  | * Last rev:     $Date: 2008-03-31 22:56:22 $,$Author: vsc $						 * | 
					
						
							| 
									
										
										
										
											2004-06-29 19:04:46 +00:00
										 |  |  | * $Log: not supported by cvs2svn $ | 
					
						
							| 
									
										
										
										
											2008-03-31 22:56:22 +00:00
										 |  |  | * Revision 1.23  2007/11/26 23:43:09  vsc | 
					
						
							|  |  |  | * fixes to support threads and assert correctly, even if inefficiently. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  | * Revision 1.22  2006/11/17 12:10:46  vsc | 
					
						
							|  |  |  | * style_checker was failing on DCGs | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-11-17 12:10:46 +00:00
										 |  |  | * Revision 1.21  2006/03/24 16:26:31  vsc | 
					
						
							|  |  |  | * code review | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-03-24 16:26:31 +00:00
										 |  |  | * Revision 1.20  2005/11/05 23:56:10  vsc | 
					
						
							|  |  |  | * should have meta-predicate definitions for calls, | 
					
						
							|  |  |  | *   multifile and discontiguous. | 
					
						
							|  |  |  | * have discontiguous as a builtin, not just as a | 
					
						
							|  |  |  | *   declaration. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-11-05 23:56:10 +00:00
										 |  |  | * Revision 1.19  2005/10/28 17:38:50  vsc | 
					
						
							|  |  |  | * sveral updates | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-10-28 17:38:50 +00:00
										 |  |  | * Revision 1.18  2005/04/20 20:06:11  vsc | 
					
						
							|  |  |  | * try to improve error handling and warnings from within consults. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-04-20 20:06:26 +00:00
										 |  |  | * Revision 1.17  2005/04/20 04:08:20  vsc | 
					
						
							|  |  |  | * fix warnings | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-04-20 04:08:20 +00:00
										 |  |  | * Revision 1.16  2005/01/13 05:47:27  vsc | 
					
						
							|  |  |  | * lgamma broke arithmetic optimisation | 
					
						
							|  |  |  | * integer_y has type y | 
					
						
							|  |  |  | * pass original source to checker (and maybe even use option in parser) | 
					
						
							|  |  |  | * use warning mechanism for checker messages. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-01-13 05:47:27 +00:00
										 |  |  | * Revision 1.15  2004/06/29 19:12:01  vsc | 
					
						
							|  |  |  | * fix checker messages | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-06-29 19:12:01 +00:00
										 |  |  | * Revision 1.14  2004/06/29 19:04:46  vsc | 
					
						
							|  |  |  | * fix multithreaded version | 
					
						
							|  |  |  | * include new version of Ricardo's profiler | 
					
						
							|  |  |  | * new predicat atomic_concat | 
					
						
							|  |  |  | * allow multithreaded-debugging | 
					
						
							|  |  |  | * small fixes | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-06-29 19:04:46 +00:00
										 |  |  | * Revision 1.13  2004/03/19 11:35:42  vsc | 
					
						
							|  |  |  | * trim_trail for default machine | 
					
						
							|  |  |  | * be more aggressive about try-retry-trust chains. | 
					
						
							|  |  |  | *    - handle cases where block starts with a wait | 
					
						
							|  |  |  | *    - don't use _killed instructions, just let the thing rot by itself. | 
					
						
							|  |  |  | *                                                                  * | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | *									 * | 
					
						
							|  |  |  | *************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-23 21:39:32 +01:00
										 |  |  | :- system_module( style_checker, [no_style_check/1, | 
					
						
							| 
									
										
										
										
											2014-04-09 12:39:29 +01:00
										 |  |  |         style_check/1], ['$check_term'/5, | 
					
						
							|  |  |  |         '$sv_warning'/2, | 
					
						
							|  |  |  |         '$syntax_check_discontiguous'/2, | 
					
						
							|  |  |  |         '$syntax_check_multiple'/2, | 
					
						
							|  |  |  |         '$syntax_check_single_var'/2]). | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 23:58:23 +00:00
										 |  |  | %% @{ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-26 19:14:15 -05:00
										 |  |  | /** | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @defgroup   YAPStyle Checker | 
					
						
							|  |  |  |     @ingroup  YAPCompilerSettings | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-13 00:53:56 -05:00
										 |  |  | YAP implements a style-checker thay currently verifies whether: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 1 named variables occur once in a clause. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 2 clauses from dofferent predicates are mixed together. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 3 clauses for the same predicate occur in different files. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | One can declare a predicate to be discontiguous (see the | 
					
						
							|  |  |  | discontiguous/1 declaration) and/or multifile/1. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							| 
									
										
										
										
											2014-07-26 19:14:15 -05:00
										 |  |  | @pred style_check(+ _X_) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Turns on style checking according to the attribute specified by  _X_, | 
					
						
							|  |  |  | which must be one of the following: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     + single_var | 
					
						
							|  |  |  |       Checks single occurrences of named variables in a clause. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     + discontiguous | 
					
						
							|  |  |  |       Checks non-contiguous clauses for the same predicate in a file. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     + multiple | 
					
						
							|  |  |  |       Checks the presence of clauses for the same predicate in more than one | 
					
						
							|  |  |  |       file when the predicate has not been declared as `multifile` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     + all | 
					
						
							|  |  |  |       Performs style checking for all the cases mentioned above. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | By default, style checking is disabled in YAP unless we are in | 
					
						
							|  |  |  | `sicstus` or `iso` language mode. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The style_check/1 built-in is now deprecated. Please use | 
					
						
							|  |  |  | `set_prolog_flag/1` instead. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 23:58:23 +00:00
										 |  |  |   **/ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | % | 
					
						
							|  |  |  | % A Small style checker for YAP | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 08:26:31 +01:00
										 |  |  | :- op(1150, fx, [multifile,discontiguous]). | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | style_check(V) :- var(V), !, fail. | 
					
						
							| 
									
										
										
										
											2014-04-23 21:39:32 +01:00
										 |  |  | style_check(V) :- | 
					
						
							|  |  |  | 	style_check_(V), !. | 
					
						
							|  |  |  | style_check(V) :- | 
					
						
							|  |  |  | 	\+atom(V), \+ list(V), V \= + _, V \= + _, !, | 
					
						
							|  |  |  | 	'$do_error'( type_error('+|-|?(Flag)', V), style_check(V) ). | 
					
						
							|  |  |  | style_check(V) :- | 
					
						
							|  |  |  | 	\+atom(V), \+ list(V), V \= + _, V \= + _, !, | 
					
						
							| 
									
										
										
										
											2014-10-07 01:35:41 +01:00
										 |  |  | 	'$do_error'( domain_error(style_name, V), style_check(V) ). | 
					
						
							| 
									
										
										
										
											2014-04-23 21:39:32 +01:00
										 |  |  | 	 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | style_check_(all) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ singleton, discontiguous, multiple ] ). | 
					
						
							|  |  |  | style_check_(single_var) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ singleton ] ). | 
					
						
							|  |  |  | style_check_(singleton) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ singleton ] ). | 
					
						
							|  |  |  | style_check_(+single_var) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ singleton ] ). | 
					
						
							|  |  |  | style_check_(+singleton) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ singleton ] ). | 
					
						
							|  |  |  | style_check_(-single_var) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ -singleton ] ). | 
					
						
							|  |  |  | style_check_(-singleton) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ -singleton ] ). | 
					
						
							|  |  |  | style_check_(discontiguous) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ discontiguous ] ). | 
					
						
							|  |  |  | style_check_(+discontiguous) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ discontiguous ] ). | 
					
						
							|  |  |  | style_check_(-discontiguous) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ -discontiguous ] ). | 
					
						
							|  |  |  | style_check_(multiple) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  multiple ] ). | 
					
						
							|  |  |  | style_check_(+multiple) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  multiple ] ). | 
					
						
							|  |  |  | style_check_(-multiple) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  -multiple ] ). | 
					
						
							|  |  |  | style_check_(no_effect) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  no_effect ] ). | 
					
						
							|  |  |  | style_check_(+no_effect) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  no_effect ] ). | 
					
						
							|  |  |  | style_check_(-no_effect) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  -no_effect ] ). | 
					
						
							|  |  |  | style_check_(var_branches) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  var_branches ] ). | 
					
						
							|  |  |  | style_check_(+var_branches) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  var_branches ] ). | 
					
						
							|  |  |  | style_check_(-var_branches) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  -var_branches ] ). | 
					
						
							|  |  |  | style_check_(atom) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  atom ] ). | 
					
						
							|  |  |  | style_check_(+atom) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  atom ] ). | 
					
						
							|  |  |  | style_check_(-atom) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  -atom ] ). | 
					
						
							|  |  |  | style_check_(charset) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  charset ] ). | 
					
						
							|  |  |  | style_check_(+charset) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  charset ] ). | 
					
						
							|  |  |  | style_check_(-charset) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  -charset ] ). | 
					
						
							|  |  |  | style_check_('?'(Info) ) :- | 
					
						
							| 
									
										
										
										
											2014-10-07 01:35:41 +01:00
										 |  |  | 	L =  [ singleton, discontiguous, multiple ], | 
					
						
							| 
									
										
										
										
											2014-04-23 21:39:32 +01:00
										 |  |  | 	( lists:member(Style, L ) -> Info = +Style ; Info = -Style ). | 
					
						
							|  |  |  | style_check_([]). | 
					
						
							|  |  |  | style_check_([H|T]) :- style_check(H), style_check(T). | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-13 00:53:56 -05:00
										 |  |  | /** @pred no_style_check(+ _X_) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Turns off style checking according to the attribute specified by | 
					
						
							|  |  |  |  _X_, which have the same meaning as in style_check/1. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The no_style_check/1 built-in is now deprecated. Please use  | 
					
						
							|  |  |  | `set_prolog_flag/1` instead. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | **/ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | no_style_check(V) :- var(V), !, fail. | 
					
						
							| 
									
										
										
										
											2013-02-04 11:22:42 -06:00
										 |  |  | no_style_check(all) :- | 
					
						
							| 
									
										
										
										
											2014-04-23 21:39:32 +01:00
										 |  |  | 	'$style_checker'( [ -singleton, -discontiguous, -multiple ] ). | 
					
						
							|  |  |  | no_style_check(-single_var) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ -singleton ] ). | 
					
						
							|  |  |  | no_style_check(-singleton) :- | 
					
						
							|  |  |  | 	'$style_checker'( [ -singleton ] ). | 
					
						
							|  |  |  | no_style_check(-discontiguous) :- | 
					
						
							| 
									
										
										
										
											2014-08-04 09:45:30 -05:00
										 |  |  | 	'$style_checker'( [ -discontiguous ] ). | 
					
						
							| 
									
										
										
										
											2014-04-23 21:39:32 +01:00
										 |  |  | no_style_check(-multiple) :- | 
					
						
							|  |  |  | 	'$style_checker'( [  -multiple ] ). | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | no_style_check([]). | 
					
						
							|  |  |  | no_style_check([H|T]) :- no_style_check(H), no_style_check(T). | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-26 19:14:15 -05:00
										 |  |  | /** @pred discontiguous(+ _G_) is iso | 
					
						
							|  |  |  |     Avoid warnings from the sytax checker. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Declare that the predicate _G_ or list of predicates are discontiguous | 
					
						
							|  |  |  | procedures, that is, clauses for discontigous procedures may be | 
					
						
							|  |  |  | separated by clauses from other procedures. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  | @} | 
					
						
							|  |  |  | */ |