home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / plbin.zip / pl / library / check.pl < prev    next >
Text File  |  1992-05-26  |  3KB  |  116 lines

  1. /*  check.pl,v 1.1.1.1 1992/05/26 11:51:35 jan Exp
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: Simple program consistency check predicates
  7. */
  8.  
  9. :- module(check,
  10.     [ check/0            % run all checks
  11.         , list_undefined/0        % list undefined predicates
  12.     , list_autoload/0        % list predicates that need autoloading
  13.     , list_redefined/0        % list redefinitions
  14.     ]).
  15.  
  16. :- style_check(+dollar).        % lock these predicates
  17.  
  18. %    check
  19. %    run all consistency checks of this module
  20.  
  21. check :-
  22.     format('PASS 1: Scanning for undefined predicates ...~n'),
  23.     list_undefined,
  24.     format('~nPASS 2: Scanning for redefined system and global predicates ...~n'),
  25.     list_redefined,
  26.     format('~nPASS 3: Scanning for predicates that need autoloading ...~n'),
  27.     list_autoload.
  28.  
  29. %    list_undefined
  30. %    List predicates names refered to  in  a  clause  body,  but  not
  31. %    defined.  This forms a "Quick and Dirty" alternative for a cross
  32. %    referencing tool (which I need to write someday).
  33.  
  34. list_undefined :-
  35.     $style_check(Old, Old), 
  36.     style_check(+dollar), 
  37.     list_undefined_, 
  38.     $style_check(_, Old).
  39.  
  40. list_undefined_ :-
  41.     predicate_property(Module:Head, undefined), 
  42.     \+ predicate_property(Module:Head, imported_from(_)), 
  43.     functor(Head, Functor, Arity), 
  44.     \+ $in_library(Functor, Arity),
  45.     write_undefined(Module:Functor/Arity), 
  46.     fail.
  47. list_undefined_.
  48.  
  49. write_undefined(user:Name/Arity) :- !, 
  50.     format('~w/~w~n', [Name, Arity]).
  51. write_undefined(Module:Name/Arity) :-
  52.     format('~w:~w/~w~n', [Module, Name, Arity]).
  53.  
  54. %    list_autoload/0
  55. %    Show predicates that need be linked via the autoload mechanism
  56.  
  57. list_autoload :-
  58.     $style_check(Old, Old), 
  59.     style_check(+dollar), 
  60.     please(autoload, OldAutoLoad, off),
  61.     list_autoload_, 
  62.     please(autoload, _, OldAutoLoad),
  63.     $style_check(_, Old).
  64.     
  65. list_autoload_ :-
  66.     predicate_property(Module:Head, undefined), 
  67.     \+ predicate_property(Module:Head, imported_from(_)), 
  68.     functor(Head, Functor, Arity), 
  69.     $in_library(Functor, Arity),
  70.     show_library(Module, Functor, Arity), 
  71.     fail.
  72. list_autoload_.
  73.  
  74. show_library(Module, Name, Arity) :-
  75.     $find_library(Module, Name, Arity, _LoadModule, Library),
  76.     (   Module == user
  77.     ->  format('~w/~w~t~30|~w~n', [Name, Arity, Library])
  78.     ;   format('~w:~w/~w~t~30|~w~n', [Module, Name, Arity, Library])
  79.     ).
  80.  
  81. %    list_redefined/0
  82. %    Show redefined system predicates
  83.  
  84. list_redefined :-
  85.     $style_check(Old, Old), 
  86.     style_check(+dollar), 
  87.     list_redefined_, 
  88.     $style_check(_, Old).
  89.     
  90. list_redefined_ :-
  91.     current_module(Module),
  92.     Module \== system,
  93.     current_predicate(_, Module:Head),
  94.     \+ predicate_property(Module:Head, imported_from(_)),
  95.     (   $default_module(Module, Super, Super),
  96.         $c_current_predicate(_, Super:Head),
  97.         $syspreds:$defined_predicate(Super:Head),
  98.         \+ predicate_property(Super:Head, (dynamic)),
  99.         \+ predicate_property(Super:Head, imported_from(Module)),
  100.         functor(Head, Functor, Arity)
  101.     ->  show_redefined(Module, Super, Functor, Arity)
  102.     ),
  103.     fail.
  104. list_redefined_.
  105.  
  106. show_redefined(user, system, F, A) :- !,
  107.     format('system predicate ~w/~w has been redefined globally.~n',
  108.                                 [F, A]).
  109. show_redefined(M, system, F, A) :-
  110.     format('system predicate ~w/~w has been redefined in module ~w.~n',
  111.                                 [F, A, M]).
  112. show_redefined(M, user, F, A) :- !,
  113.     format('global predicate ~w/~w has been redefined in module ~w.~n',
  114.                                 [F, A, M]).
  115.  
  116.