1/* Part of XPCE --- The SWI-Prolog GUI toolkit 2 3 Author: Jan Wielemaker and Anjo Anjewierden 4 E-mail: J.Wielemaker@vu.nl 5 WWW: http://www.swi-prolog.org/projects/xpce/ 6 Copyright (c) 2003-2013, University of Amsterdam 7 VU University Amsterdam 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions 12 are met: 13 14 1. Redistributions of source code must retain the above copyright 15 notice, this list of conditions and the following disclaimer. 16 17 2. Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in 19 the documentation and/or other materials provided with the 20 distribution. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 POSSIBILITY OF SUCH DAMAGE. 34*/ 35 36:- module(pce_prolog_xref, 37 [ xref_source/1, % +Source 38 xref_source/2, % +Source, +Options 39 xref_called/3, % ?Source, ?Callable, ?By 40 xref_defined/3, % ?Source. ?Callable, -How 41 xref_definition_line/2, % +How, -Line 42 xref_exported/2, % ?Source, ?Callable 43 xref_module/2, % ?Source, ?Module 44 xref_op/2, % ?Source, ?Op 45 xref_clean/1, % +Source 46 xref_current_source/1, % ?Source 47 xref_done/2, % +Source, -Time 48 xref_built_in/1, % ?Callable 49 xref_source_file/3, % +Spec, -Path, +Source 50 xref_source_file/4, % +Spec, -Path, +Source, +Options 51 xref_public_list/4, % +Path, -Export, +Src 52 xref_meta/2, % +Goal, -Called 53 xref_hook/1, % ?Callable 54 % XPCE class references 55 xref_used_class/2, % ?Source, ?ClassName 56 xref_defined_class/3 % ?Source, ?ClassName, -How 57 ]). 58:- use_module(library(pce)). 59:- use_module(library(prolog_xref)). 60 61:- multifile 62 prolog:xref_source_identifier/2, % +Source, -Id 63 prolog:xref_source_directory/2, % +Source, -Dir 64 prolog:xref_open_source/2. % +SourceId, -Stream
71prologxref_source_identifier(Object, Ref) :- 72 object(Object), 73 !, 74 Object = @Ref. 75prologxref_source_identifier(Ref, Ref) :- 76 integer(Ref), 77 !.
83prologxref_source_directory(SourceId, Dir) :-
84 integer(SourceId),
85 Obj = @SourceId,
86 object(Obj),
87 catch(get(Obj?file, absolute_path, Path), _, fail),
88 file_directory_name(Path, Dir).
94prologxref_open_source(SourceId, Stream) :-
95 integer(SourceId),
96 Obj = @SourceId,
97 object(Obj),
98 pce_open(Obj, read, Stream),
99 ( catch(get(Obj?file, absolute_path, Path), _, fail)
100 -> set_stream(Stream, file_name(Path))
101 ; true
102 )