View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (C): 2014, VU University Amsterdam
    7
    8    This program is free software; you can redistribute it and/or
    9    modify it under the terms of the GNU General Public License
   10    as published by the Free Software Foundation; either version 2
   11    of the License, or (at your option) any later version.
   12
   13    This program is distributed in the hope that it will be useful,
   14    but WITHOUT ANY WARRANTY; without even the implied warranty of
   15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16    GNU General Public License for more details.
   17
   18    You should have received a copy of the GNU General Public
   19    License along with this library; if not, write to the Free Software
   20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21
   22    As a special exception, if you link this library with other files,
   23    compiled with a Free Software compiler, to produce an executable, this
   24    library does not by itself cause the resulting executable to be covered
   25    by the GNU General Public License. This exception does not however
   26    invalidate any other reasons why the executable file might be covered by
   27    the GNU General Public License.
   28*/
   29
   30:- module(object_support,
   31	  [ object_label/2,		% +Object:compound
   32					% -Label:atom
   33	    object_id/2			% ?Object:compound
   34					% ?Id:atom
   35	  ]).

Object support

*/

   41:- use_module(wiki).   42
   43:- dynamic
   44	object_id_cache/2.
 object_id(+Object:compound, -Id:atom) is det
object_id(-Object:compound, +Id:atom) is semidet
True when Id is a (hash) id for Object.
   51object_id(Object, Id) :-
   52	object_id_cache(Object, Id), !.
   53object_id(Object, Id) :-
   54	ground(Object),
   55	variant_sha1(Object, Id),
   56	assertz(object_id_cache(Object, Id)).
 object_label(+Object:compound, -Label:atom) is det
True when Label is a label for Object.
   63object_label(Name/Arity, Label) :- !,
   64	format(atom(Label), 'predicate ~w/~w', [Name, Arity]).
   65object_label(Name//Arity, Label) :- !,
   66	format(atom(Label), 'non-terminal ~w/~w', [Name, Arity]).
   67object_label(M:Name/Arity, Label) :- !,
   68	format(atom(Label), 'predicate ~w:~w/~w', [M, Name, Arity]).
   69object_label(M:Name//Arity, Label) :- !,
   70	format(atom(Label), 'non-terminal ~w:~w//~w', [M, Name, Arity]).
   71object_label(f(Name/Arity), Label) :- !,
   72	format(atom(Label), 'function ~w/~w', [Name, Arity]).
   73object_label(c(Function), Label) :- !,
   74	format(atom(Label), 'C API function ~w()', [Function]).
   75object_label(Module:module(_Title), Label) :-
   76	module_property(Module, file(File)), !,
   77	file_base_name(File, Base),
   78	format(atom(Label), 'module ~w', [Base]).
   79object_label(section(ID), Label) :-
   80	prolog:doc_object_summary(section(_Level, _No, ID, _File),_,_,Title), !,
   81	format(atom(Label), 'Section "~w"', [Title]).
   82object_label(wiki(Location), Label) :-
   83	wiki_page_title(Location, Title),
   84	format(atom(Label), 'Wiki page "~w"', [Title]).
   85object_label(Obj, Label) :-
   86	term_to_atom(Obj, Label)