Changeset 4526 for trunk/compiler

Show
Ignore:
Timestamp:
10/21/08 09:08:54 (3 months ago)
Author:
pmoura
Message:

Allow a complementing category to define an alias for a predicate of the complemented object.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4525 r4526  
    100100:- dynamic('$lgt_extends_protocol_'/3). 
    101101                                                 
    102 :- multifile('$lgt_complemented_object_'/4).    % '$lgt_complemented_object_'(Obj, Ctg, Dcl, Def) 
    103 :- dynamic('$lgt_complemented_object_'/4). 
     102:- multifile('$lgt_complemented_object_'/5).    % '$lgt_complemented_object_'(Obj, Ctg, Dcl, Def, Rnm) 
     103:- dynamic('$lgt_complemented_object_'/5). 
    104104 
    105105 
     
    216216:- dynamic('$lgt_pp_extended_protocol_'/4).     % '$lgt_pp_extended_protocol_'(Ptc, Prefix, Dcl, Scope) 
    217217:- dynamic('$lgt_pp_extended_category_'/5).     % '$lgt_pp_extended_category_'(Ctg, Prefix, Dcl, Def, Scope) 
     218:- dynamic('$lgt_pp_complemented_object_'/1).   % '$lgt_pp_complemented_object_'(Obj) 
    218219 
    219220:- dynamic('$lgt_pp_file_init_'/1).             % '$lgt_pp_file_init_'(Goal)     
     
    10781079 
    10791080complements_object(Category, Object) :- 
    1080     '$lgt_complemented_object_'(Object, Category, _, _). 
     1081    '$lgt_complemented_object_'(Object, Category, _, _, _). 
    10811082 
    10821083 
     
    24082409            % object doesn't supports dynamic declaration of new predicates: 
    24092410            throw(error(permission_error(modify, object_protocol, Pred), Goal, Sender)) 
    2410         ;   '$lgt_assert_ddcl_clause'(DDcl, Pred, DclScope), 
     2411        ;   functor(Pred, Functor, Arity), 
     2412            functor(DPred, Functor, Arity), 
     2413            Clause =.. [DDcl, DPred, DclScope], 
     2414            assertz(Clause), 
    24112415            (Scope, Type, Meta) = (DclScope, (dynamic), no) 
    24122416        ) 
     
    33273331% lookup predicate declarations in any category that complements the given object 
    33283332 
    3329 '$lgt_complemented_object'(This, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Ctn) :- 
    3330     '$lgt_complemented_object_'(This, _, Dcl, _), 
    3331     call_with_args(Dcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Ctn). 
     3333'$lgt_complemented_object'(This, ThisDcl, Alias, Scope, Compilation, Meta, NonTerminal, Synchronized, SCtn, TCtn) :- 
     3334    '$lgt_complemented_object_'(This, _, Dcl, _, Rnm), 
     3335    (   call_with_args(Dcl, Alias, Scope, Compilation, Meta, NonTerminal, Synchronized, TCtn), 
     3336        SCtn = This 
     3337    ;   call_with_args(Rnm, This, Pred, Alias), 
     3338        Pred \= Alias, 
     3339        call_with_args(ThisDcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, SCtn, TCtn) 
     3340    ). 
    33323341 
    33333342 
     
    33353344% lookup predicate definitions in any category that complements the given object 
    33363345 
    3337 '$lgt_complemented_object'(Pred, Sender, This, Self, Call, Ctn) :- 
    3338     '$lgt_complemented_object_'(This, _, _, Def), 
    3339     call_with_args(Def, Pred, Sender, This, Self, Call, Ctn). 
     3346'$lgt_complemented_object'(ThisDef, Alias, Sender, This, Self, Call, Ctn) :- 
     3347    '$lgt_complemented_object_'(This, _, _, Def, Rnm), 
     3348    (   call_with_args(Def, Alias, Sender, This, Self, Call, Ctn) 
     3349    ;   call_with_args(Rnm, This, Pred, Alias), 
     3350        Pred \= Alias, 
     3351        call_with_args(ThisDef, Pred, Sender, This, Self, Call, Ctn) 
     3352    ).   
    33403353 
    33413354 
     
    42814294    retractall('$lgt_extends_object_'(Entity, _, _)), 
    42824295    retractall('$lgt_extends_category_'(Entity, _, _)), 
    4283     retractall('$lgt_complemented_object_'(_, Entity, _, _)), 
     4296    retractall('$lgt_complemented_object_'(_, Entity, _, _, _)), 
    42844297    retractall('$lgt_debugging_'(Entity)). 
    42854298 
     
    49574970    retractall('$lgt_pp_extended_protocol_'(_, _, _, _)), 
    49584971    retractall('$lgt_pp_extended_category_'(_, _, _, _, _)), 
     4972    retractall('$lgt_pp_complemented_object_'(_)), 
    49594973    retractall('$lgt_pp_uses_'(_)), 
    49604974    retractall('$lgt_pp_uses_'(_, _, _)), 
     
    57325746    ;   '$lgt_pp_instantiated_class_'(Entity, _, _, _, _, _, _, _, _, _) 
    57335747    ;   '$lgt_pp_specialized_class_'(Entity, _, _, _, _, _, _, _, _, _) 
     5748    ;   '$lgt_pp_complemented_object_'(Entity) 
    57345749    ), 
    57355750    !, 
     
    90579072 
    90589073'$lgt_tr_complements_category'(Objs, Ctg) :- 
    9059     '$lgt_pp_category_'(Ctg, _, Dcl, Def, _, _) -> 
    9060     '$lgt_tr_complements_category'(Objs, Ctg, Dcl, Def). 
    9061  
    9062  
    9063 '$lgt_tr_complements_category'([], _, _, _). 
    9064  
    9065 '$lgt_tr_complements_category'([Obj| _], _, _, _) :- 
     9074    '$lgt_pp_category_'(Ctg, _, Dcl, Def, Rnm, _) -> 
     9075    '$lgt_tr_complements_category'(Objs, Ctg, Dcl, Def, Rnm). 
     9076 
     9077 
     9078'$lgt_tr_complements_category'([], _, _, _, _). 
     9079 
     9080'$lgt_tr_complements_category'([Obj| _], _, _, _, _) :- 
    90669081    var(Obj), 
    90679082    throw(instantiation_error). 
    90689083 
    9069 '$lgt_tr_complements_category'([Obj| Objs], Ctg, Dcl, Def) :- 
     9084'$lgt_tr_complements_category'([Obj| Objs], Ctg, Dcl, Def, Rnm) :- 
    90709085    (   callable(Obj) -> 
    90719086        assertz('$lgt_pp_referenced_object_'(Obj)), 
    9072         assertz('$lgt_pp_rclause_'('$lgt_complemented_object_'(Obj, Ctg, Dcl, Def))), 
    9073         '$lgt_tr_complements_category'(Objs, Ctg, Dcl, Def) 
     9087        assertz('$lgt_pp_complemented_object_'(Obj)), 
     9088        assertz('$lgt_pp_rclause_'('$lgt_complemented_object_'(Obj, Ctg, Dcl, Def, Rnm))), 
     9089        '$lgt_tr_complements_category'(Objs, Ctg, Dcl, Def, Rnm) 
    90749090    ;   throw(type_error(object_identifier, Obj)) 
    90759091    ). 
     
    93399355        '$lgt_clean_lookup_caches'(Head) 
    93409356    ). 
    9341  
    9342  
    9343  
    9344 % '$lgt_assert_ddcl_clause'(+atom, +term, +term) 
    9345 % 
    9346 % asserts a dynamic predicate declaration 
    9347  
    9348 '$lgt_assert_ddcl_clause'(DDcl, Pred, Scope) :- 
    9349     functor(Pred, Functor, Arity), 
    9350     functor(DPred, Functor, Arity), 
    9351     Clause =.. [DDcl, DPred, Scope], 
    9352     assertz(Clause). 
    93539357 
    93549358 
     
    98609864    (   '$lgt_compiler_flag'(complements, on) -> 
    98619865        '$lgt_pp_object_'(Obj, _, ODcl, _, _, _, _, _, _, _, _) -> 
    9862         Head =.. [ODcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Obj, Ctn], 
    9863         Lookup = '$lgt_complemented_object'(Obj, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Ctn), 
     9866        Head =.. [ODcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, SCtn, TCtn], 
     9867        Lookup = '$lgt_complemented_object'(Obj, ODcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, SCtn, TCtn), 
    98649868        assertz('$lgt_pp_dcl_'((Head:-Lookup))) 
    98659869    ;   true 
     
    99399943        '$lgt_pp_object_'(Obj, _, _, ODef, _, _, _, _, _, _, _) -> 
    99409944        Head =.. [ODef, Pred, Sender, Obj, Self, Call, Ctn], 
    9941         Lookup = '$lgt_complemented_object'(Pred, Sender, Obj, Self, Call, Ctn), 
     9945        Lookup = '$lgt_complemented_object'(ODef, Pred, Sender, Obj, Self, Call, Ctn), 
    99429946        assertz('$lgt_pp_fdef_'((Head:-Lookup))) 
    99439947    ;   true 
     
    1012110125    (   '$lgt_compiler_flag'(complements, on) -> 
    1012210126        '$lgt_pp_object_'(Obj, _, _, _, _, OIDcl, _, _, _, _, _) -> 
    10123         Head =.. [OIDcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Obj, Ctn], 
    10124         Lookup = '$lgt_complemented_object'(Obj, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, Ctn), 
     10127        Head =.. [OIDcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, SCtn, TCtn], 
     10128        Lookup = '$lgt_complemented_object'(Obj, OIDcl, Pred, Scope, Compilation, Meta, NonTerminal, Synchronized, SCtn, TCtn), 
    1012510129        assertz('$lgt_pp_dcl_'((Head:-Lookup))) 
    1012610130    ;   true 
     
    1020110205        '$lgt_pp_object_'(Obj, _, _, ODef, _, _, _, _, _, _, _) -> 
    1020210206        Head =.. [ODef, Pred, Sender, Obj, Self, Call, Ctn], 
    10203         Lookup = '$lgt_complemented_object'(Pred, Sender, Obj, Self, Call, Ctn), 
     10207        Lookup = '$lgt_complemented_object'(ODef, Pred, Sender, Obj, Self, Call, Ctn), 
    1020410208        assertz('$lgt_pp_fdef_'((Head:-Lookup))) 
    1020510209    ;   true 
     
    1026710271        '$lgt_pp_object_'(Obj, _, _, _, _, _, OIDef, _, _, _, _) -> 
    1026810272        Head =.. [OIDef, Pred, Sender, Obj, Self, Call, Ctn], 
    10269         Lookup = '$lgt_complemented_object'(Pred, Sender, Obj, Self, Call, Ctn), 
     10273        Lookup = '$lgt_complemented_object'(OIDef, Pred, Sender, Obj, Self, Call, Ctn), 
    1027010274        assertz('$lgt_pp_fdef_'((Head:-Lookup))) 
    1027110275    ;   true 
     
    1083110835        '$lgt_write_runtime_clauses'(Stream, '$lgt_extends_object_'/3), 
    1083210836        '$lgt_write_runtime_clauses'(Stream, '$lgt_extends_protocol_'/3), 
    10833         '$lgt_write_runtime_clauses'(Stream, '$lgt_complemented_object_'/4), 
     10837        '$lgt_write_runtime_clauses'(Stream, '$lgt_complemented_object_'/5), 
    1083410838        '$lgt_write_runtime_clauses'(Stream, '$lgt_debugging_'/1) 
    1083510839    ;   true