1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
/* Part of XPCE --- The SWI-Prolog GUI toolkit
Author: Jan Wielemaker and Anjo Anjewierden
E-mail: jan@swi.psy.uva.nl
WWW: http://www.swi.psy.uva.nl/projects/xpce/
Copyright (c) 1999-2011, University of Amsterdam
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
:- module(pce_portray, []).
:- use_module(pce_boot(pce_principal)).
:- multifile
user:portray/1,
user:prolog_list_goal/1,
user:prolog_predicate_name/2,
user:prolog_clause_name/2.
:- dynamic
user:portray/1.
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
XPCE portray rules. These rules print object references indicating their
class-name and the goal to the implementation of methods more readable
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
user:portray(Obj) :-
Obj = @Ref,
object(Obj),
!,
( send(Obj, '_instance_of', var)
-> get(Obj, '_value', Value),
format('@~w(= ~p)', [Ref, Value])
; get(Obj, '_class_name', CN),
format('@~w/~w', [Ref, CN])
).
user:portray(pce_principal:send_implementation(Id, Args, Receiver)) :-
object(Receiver),
!,
method_from_id(Id, (Class->_Method)),
format('Send-method on ~p: ~w->~p', [Receiver, Class, Args]).
user:portray(pce_principal:get_implementation(Id, Args, Receiver, RVal)) :-
object(Receiver),
!,
method_from_id(Id, <-(Class, _Method)),
format('Get-method on ~p: ~w<-~p --> ~p',
[Receiver, Class, Args, RVal]).
% user:prolog_list_goal(:Goal)
%
% Called from the SWI-Prolog debugger 'L' command to show the
% relevant sourcecode given the current Goal.
user:prolog_list_goal(pce_principal:send_implementation(Id, _Args, _Ref)) :-
!,
( Head = pce_principal:send_implementation(Id, Args, Ref),
method_from_id(Id, ->(Class, Sel)),
clause(Head, Body)
-> format('~N~n% XPCE Method ~w->~w:~n~n', [Class, Sel]),
portray_clause(((Ref->Args) :- Body)),
nl
; format('No XPCE method implementation for id=~p~n', [Id])
).
user:prolog_list_goal(pce_principal:get_implementation(Id, _Args, _Ref, _Rval)) :-
!,
( Head = pce_principal:get_implementation(Id, Args, Ref, Rval),
method_from_id(Id, <-(Class, Sel)),
clause(Head, Body)
-> format('~N~n% XPCE Method ~w<-~w:~n~n', [Class, Sel]),
portray_clause(((Rval = <-(Ref,Args)) :- Body)),
nl
; format('No XPCE method implementation for id=~p~n', [Id])
).
%! user:prolog_predicate_name(:Goal, -Name:atom) is semidet.
%
% Hook used by the Prolog graphical tracer to display the frames
% in the stack.
user:prolog_predicate_name(pce_principal:send_implementation(Id0, _, _),
Id) :-
method_from_id(Id0, SG),
atom_from_method(SG, Id).
user:prolog_predicate_name(pce_principal:get_implementation(Id0, _, _, _),
Id) :-
method_from_id(Id0, SG),
atom_from_method(SG, Id).
%! user:prolog_clause_name(+ClauseRef, -Name)
%
% Translate the reference to a method-clause into the corresponding
% method.
user:prolog_clause_name(Ref, Name) :-
clause(Head, _, Ref),
user:prolog_predicate_name(Head, Name).
/*******************************
* UTIL *
*******************************/
% Get the type, class and selector from a method identifier.
% Should we cache this info for proper performance on the tracer?
method_from_id(Id, Method) :-
compound(Id),
!,
arg(1, Id, Id2),
method_from_id(Id2, Method).
method_from_id(Id, ->(Class, Selector)) :-
pce_principal:pce_lazy_send_method(Selector, Class, Binder),
arg(1, Binder, Id),
!.
method_from_id(Id, <-(Class, Selector)) :-
pce_principal:pce_lazy_get_method(Selector, Class, Binder),
arg(1, Binder, Id).
atom_from_method(->(Class, Selector), Atom) :-
atomic_list_concat([Class, (->), Selector], Atom).
atom_from_method(<-(Class, Selector), Atom) :-
atomic_list_concat([Class, (<-), Selector], Atom).
|