Show
Ignore:
Timestamp:
04/21/08 09:25:05 (6 months ago)
Author:
pmoura
Message:

Added support for checking arithmetic expressions for calls to non-portable function calls when using the "portability" compiler flag.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4196 r4213  
    205205:- dynamic('$lgt_pp_calls_pred_'/4).            % '$lgt_pp_calls_pred_'(Functor, Arity, TFunctor, TArity) 
    206206:- dynamic('$lgt_non_portable_call_'/2).        % '$lgt_non_portable_call_'(Functor, Arity) 
     207:- dynamic('$lgt_non_portable_function_'/2).    % '$lgt_non_portable_function_'(Functor, Arity) 
    207208 
    208209:- dynamic('$lgt_pp_defs_nt_'/2).               % '$lgt_pp_defs_nt_'(Functor, Arity) 
     
    47524753    retractall('$lgt_pp_calls_pred_'(_, _, _, _)), 
    47534754    retractall('$lgt_non_portable_call_'(_, _)), 
     4755    retractall('$lgt_non_portable_function_'(_, _)), 
    47544756    retractall('$lgt_pp_defs_nt_'(_, _)), 
    47554757    retractall('$lgt_pp_calls_nt_'(_, _)), 
     
    71987200 
    71997201 
     7202% arithmetic predicates (portability checks) 
     7203 
     7204'$lgt_tr_body'(_ is Exp, _, _, _) :- 
     7205    '$lgt_check_non_portable_functions'(Exp), 
     7206    fail. 
     7207'$lgt_tr_body'(Exp1 =:= Exp2, _, _, _) :- 
     7208    '$lgt_check_non_portable_functions'(Exp1), 
     7209    '$lgt_check_non_portable_functions'(Exp2), 
     7210    fail. 
     7211'$lgt_tr_body'(Exp1 =\= Exp2, _, _, _) :- 
     7212    '$lgt_check_non_portable_functions'(Exp1), 
     7213    '$lgt_check_non_portable_functions'(Exp2), 
     7214    fail. 
     7215'$lgt_tr_body'(Exp1 < Exp2, _, _, _) :- 
     7216    '$lgt_check_non_portable_functions'(Exp1), 
     7217    '$lgt_check_non_portable_functions'(Exp2), 
     7218    fail. 
     7219'$lgt_tr_body'(Exp1 =< Exp2, _, _, _) :- 
     7220    '$lgt_check_non_portable_functions'(Exp1), 
     7221    '$lgt_check_non_portable_functions'(Exp2), 
     7222    fail. 
     7223'$lgt_tr_body'(Exp1 > Exp2, _, _, _) :- 
     7224    '$lgt_check_non_portable_functions'(Exp1), 
     7225    '$lgt_check_non_portable_functions'(Exp2), 
     7226    fail. 
     7227'$lgt_tr_body'(Exp1 >= Exp2, _, _, _) :- 
     7228    '$lgt_check_non_portable_functions'(Exp1), 
     7229    '$lgt_check_non_portable_functions'(Exp2), 
     7230    fail. 
     7231 
     7232 
    72007233% Logtalk and Prolog built-in (meta-)predicates 
    72017234 
     
    75537586 
    75547587'$lgt_compiler_db_pred_ind_chk'(_). 
     7588 
     7589 
     7590 
     7591% '$lgt_check_non_portable_functions'(@term) 
     7592% 
     7593% checks an arithmetic expression for calls to non-standard Prolog functions 
     7594 
     7595 
     7596'$lgt_check_non_portable_functions'(Exp) :- 
     7597    var(Exp), 
     7598    !. 
     7599 
     7600'$lgt_check_non_portable_functions'(Exp) :- 
     7601    number(Exp), 
     7602    !. 
     7603 
     7604'$lgt_check_non_portable_functions'(Exp) :- 
     7605    '$lgt_iso_spec_function'(Exp), 
     7606    !, 
     7607    Exp =.. [_| Exps], 
     7608    '$lgt_check_non_portable_function_args'(Exps). 
     7609 
     7610'$lgt_check_non_portable_functions'(Exp) :- 
     7611    functor(Exp, Functor, Arity), 
     7612    (   '$lgt_non_portable_function_'(Functor, Arity) -> 
     7613        true 
     7614    ;   assertz('$lgt_non_portable_function_'(Functor, Arity)) 
     7615    ), 
     7616    Exp =.. [_| Exps], 
     7617    '$lgt_check_non_portable_function_args'(Exps). 
     7618 
     7619 
     7620'$lgt_check_non_portable_function_args'([]). 
     7621 
     7622'$lgt_check_non_portable_function_args'([Exp| Exps]) :- 
     7623    '$lgt_check_non_portable_functions'(Exp), 
     7624    '$lgt_check_non_portable_function_args'(Exps). 
    75557625 
    75567626 
     
    86098679        '$lgt_report_misspelt_calls', 
    86108680        '$lgt_report_non_portable_calls', 
     8681        '$lgt_report_non_portable_functions', 
    86118682        '$lgt_report_unknown_entities' 
    86128683    ;   true 
     
    1015310224    functor(Pred, Functor, Arity), 
    1015410225    \+ '$lgt_pp_redefined_built_in_'(Pred, _, _, _, _). 
     10226 
     10227 
     10228 
     10229% report non-portable arithmetic function calls in the body of object and category predicates 
     10230 
     10231'$lgt_report_non_portable_functions' :- 
     10232    '$lgt_compiler_flag'(portability, warning), 
     10233    setof(Functor/Arity, '$lgt_non_portable_function_'(Functor, Arity), Functions), 
     10234    '$lgt_inc_compile_warnings_counter', 
     10235    nl, 
     10236    (   Functions = [_] -> 
     10237        write('  WARNING!  Call to non-standard Prolog built-in arithmetic function: ') 
     10238    ;   write('  WARNING!  Calls to non-standard Prolog built-in arithmetic functions: ') 
     10239    ), 
     10240    '$lgt_writeq_list'(Functions), 
     10241    !. 
     10242 
     10243'$lgt_report_non_portable_functions'. 
    1015510244 
    1015610245 
     
    1270612795'$lgt_iso_spec_pred'(halt). 
    1270712796'$lgt_iso_spec_pred'(halt(_)). 
     12797 
     12798 
     12799 
     12800 
     12801%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
     12802% 
     12803%  table of ISO specified arithmetic functions 
     12804% 
     12805%  (used for portability checking) 
     12806% 
     12807%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
     12808 
     12809 
     12810 
     12811'$lgt_iso_spec_function'('-'(_)). 
     12812'$lgt_iso_spec_function'('+'(_, _)). 
     12813'$lgt_iso_spec_function'('-'(_, _)). 
     12814'$lgt_iso_spec_function'('*'(_, _)). 
     12815'$lgt_iso_spec_function'('/'(_, _)). 
     12816'$lgt_iso_spec_function'('//'(_, _)). 
     12817'$lgt_iso_spec_function'(rem(_, _)). 
     12818'$lgt_iso_spec_function'(mod(_, _)). 
     12819'$lgt_iso_spec_function'('/\\'(_, _)). 
     12820'$lgt_iso_spec_function'('\\/'(_, _)). 
     12821'$lgt_iso_spec_function'('\\'(_, _)). 
     12822'$lgt_iso_spec_function'('<<'(_, _)). 
     12823'$lgt_iso_spec_function'('>>'(_, _)). 
     12824'$lgt_iso_spec_function'('**'(_, _)). 
     12825 
     12826'$lgt_iso_spec_function'(abs(_)). 
     12827'$lgt_iso_spec_function'(sign(_)). 
     12828'$lgt_iso_spec_function'(sqrt(_)). 
     12829'$lgt_iso_spec_function'(atan(_)). 
     12830'$lgt_iso_spec_function'(cos(_)). 
     12831'$lgt_iso_spec_function'(sin(_)). 
     12832'$lgt_iso_spec_function'(exp(_)). 
     12833'$lgt_iso_spec_function'(log(_)). 
     12834'$lgt_iso_spec_function'(float(_)). 
     12835'$lgt_iso_spec_function'(ceiling(_)). 
     12836'$lgt_iso_spec_function'(floor(_)). 
     12837'$lgt_iso_spec_function'(round(_)). 
     12838'$lgt_iso_spec_function'(truncate(_)). 
     12839'$lgt_iso_spec_function'(float_fractional_part(_)). 
     12840'$lgt_iso_spec_function'(float_integer_part(_)). 
    1270812841 
    1270912842