View source with raw comments or as raw
    1/*  Part of XPCE --- The SWI-Prolog GUI toolkit
    2
    3    Author:        Jan Wielemaker and Anjo Anjewierden
    4    E-mail:        jan@swi.psy.uva.nl
    5    WWW:           http://www.swi.psy.uva.nl/projects/xpce/
    6    Copyright (c)  1999-2013, University of Amsterdam
    7    All rights reserved.
    8
    9    Redistribution and use in source and binary forms, with or without
   10    modification, are permitted provided that the following conditions
   11    are met:
   12
   13    1. Redistributions of source code must retain the above copyright
   14       notice, this list of conditions and the following disclaimer.
   15
   16    2. Redistributions in binary form must reproduce the above copyright
   17       notice, this list of conditions and the following disclaimer in
   18       the documentation and/or other materials provided with the
   19       distribution.
   20
   21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32    POSSIBILITY OF SUCH DAMAGE.
   33*/
   34
   35:- module(pce_goal_expansion, []).   36:- use_module(pce_realise).   37:- use_module(pce_boot(pce_expansion), [pce_compiling/1]).   38:- use_module(pce_boot(pce_principal)).   39:- require([ pce_error/1
   40           , append/3
   41           ]).   42
   43expandable(send, A)       :- A >= 2.
   44expandable(get, A)        :- A >= 3.
   45expandable(send_super, A) :- A >= 2.
   46expandable(get_super, A)  :- A >= 3.
   47expandable(pce_catch_error, 2).
   48
   49%       Convert old send/get into new format.
   50
   51expand(OldSend, Send) :-
   52    compound(OldSend),
   53    OldSend =.. [ send, R, Sel | Args ],
   54    atom(Sel),
   55    Args \== [],
   56    !,
   57    Msg =.. [Sel|Args],
   58    Send = send(R, Msg).
   59expand(OldGet, Get) :-
   60    compound(OldGet),
   61    OldGet =.. [ get, R, Sel | AllArgs ],
   62    atom(Sel),
   63    append(Args, [Result], AllArgs),
   64    Args \== [],
   65    !,
   66    Msg =.. [Sel|Args],
   67    Get = get(R, Msg, Result).
   68
   69%       Deal with send-super
   70
   71expand(send(R, Msg), send_class(R, Super, SuperMsg)) :-
   72    compound(Msg),
   73    Msg =.. [send_super, Selector | Args],
   74    !,
   75    selector(Selector),
   76    current_super_class(send_super, Super),
   77    SuperMsg =.. [Selector|Args].
   78expand(get(R, Msg, Answer), get_class(R, Super, SuperMsg, Answer)) :-
   79    compound(Msg),
   80    Msg =.. [get_super, Selector | Args],
   81    !,
   82    selector(Selector),
   83    current_super_class(get_super, Super),
   84    SuperMsg =.. [Selector|Args].
   85expand(send_super(R, Msg), send_class(R, Super, Msg)) :-
   86    !,
   87    current_super_class(send_super, Super).
   88expand(get_super(R, Msg, V), get_class(R, Super, Msg, V)) :-
   89    !,
   90    current_super_class(get_super, Super).
   91expand(SendSuperN, send_class(R, Super, Msg)) :-
   92    compound(SendSuperN),
   93    SendSuperN =.. [send_super, R, Sel | Args],
   94    selector(Sel),
   95    Msg =.. [Sel|Args],
   96    current_super_class(send_super, Super).
   97expand(GetSuperN, get_class(R, Super, Msg, Answer)) :-
   98    compound(GetSuperN),
   99    GetSuperN =.. [get_super, R, Sel | AllArgs],
  100    selector(Sel),
  101    append(Args, [Answer], AllArgs),
  102    Msg =.. [Sel|Args],
  103    current_super_class(get_super, Super).
  104expand(pce_catch_error(E,G), pce_catch_error(E, EG)) :-
  105    expand_goal(G, EG).
  106
  107selector(Sel) :-
  108    atom(Sel),
  109    !.
  110selector(Sel) :-
  111    pce_error(error(type_error(selector, Sel), _)),
  112    fail.
 current_super_class(-Super)
Return the name of the super-class of the currently compiling class.
  119current_super_class(_, Super) :-
  120    pce_compiling(Class),
  121    super_class(Class, Super),
  122    !.
  123current_super_class(Op, _) :-
  124    pce_error(context_error(Op, nosuper, goal)),
  125    fail.
 super_class(+ClassName, -SuperClassName)
Deternine the super-class of a class. Try to avoid realising the class to improve compilation and save-state performance. First clause deals with the most common case, where we want to have the super-class of the currently compiling class.
  134super_class(Class, Super) :-
  135    pce_expansion:attribute(Class, super, Super),
  136    !.
  137super_class(Class, Super) :-
  138    pce_prolog_class(Class, Super),
  139    !.
  140super_class(Class, Super) :-
  141    get(@classes, member, Class, ClassObject),
  142    get(ClassObject, super_class_name, Super).
  143
  144
  145                 /*******************************
  146                 *        REGISTER HOOK         *
  147                 *******************************/
  148
  149pce_ifhostproperty(prolog(sicstus),
  150(   user:goal_expansion(Goal, _Context, ExpandedGoal) :-
  151        compound(Goal),
  152        functor(Goal, Name, Arity),
  153        expandable(Name, Arity),
  154        expand(Goal, ExpandedGoal)
  155),
  156(   system:goal_expansion(Goal, ExpandedGoal) :-
  157        compound(Goal),
  158        compound_name_arity(Goal, Name, Arity),
  159        expandable(Name, Arity),
  160        expand(Goal, ExpandedGoal)
  161))