Changeset 4516 for trunk/compiler

Show
Ignore:
Timestamp:
10/18/08 13:28:14 (3 months ago)
Author:
pmoura
Message:

Cleanup code that reports singleton variables.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4514 r4516  
    46524652    '$lgt_report_singletons'(Singletons, Term, Input), 
    46534653    '$lgt_tr_term'(Term, Input, Output), 
    4654     read_term(Input, Next, [singletons(NSingletons)]), 
    4655     '$lgt_tr_file'(Next, NSingletons, Input, Output). 
     4654    read_term(Input, Next, [singletons(NextSingletons)]), 
     4655    '$lgt_tr_file'(Next, NextSingletons, Input, Output). 
    46564656 
    46574657 
     
    46754675% reports the singleton variables found while compiling an entity term 
    46764676 
    4677 '$lgt_report_singletons'(TSingletons, Term, Input) :- 
    4678     '$lgt_filter_dont_care_vars'(TSingletons, FSingletons), 
    4679     '$lgt_singleton_var_names'(FSingletons, Names), 
    4680     '$lgt_report_singletons_aux'(Names, Term, Input). 
    4681  
    4682  
    4683 '$lgt_report_singletons_aux'([], _, _) :- 
    4684     !.  % cut needed to prevent problems with compilers with broken read_term/3 
    4685  
    4686 '$lgt_report_singletons_aux'([Name| Names], Term, Stream) :- 
     4677'$lgt_report_singletons'(Singletons, Term, Input) :- 
    46874678    (   '$lgt_compiler_flag'(singletons, warning), 
    46884679        '$lgt_compiler_flag'(report, on) -> 
    4689         '$lgt_inc_compile_warnings_counter', 
    4690         (   '$lgt_pp_entity'(_, _, _, _, _) -> 
    4691             nl 
    4692         ; true 
    4693         ), 
    4694         (   Names == [] -> 
    4695             write('        WARNING!  Singleton variable ') 
    4696         ;   write('        WARNING!  Singleton variables ') 
    4697         ), 
    4698         'lgt_report_singletons_term'(Term), 
    4699         '$lgt_write_list'([Name| Names]), 
    4700         nl, '$lgt_report_compiler_error_line_number'(Stream), 
    4701         (   '$lgt_pp_entity'(_, _, _, _, _) -> 
    4702             true 
    4703         ;   nl 
    4704         ) 
     4680        '$lgt_filter_singletons'(Singletons, Names), 
     4681        '$lgt_report_singleton_names'(Names, Term, Input) 
    47054682    ;   true 
     4683    ). 
     4684 
     4685 
     4686'$lgt_report_singleton_names'([], _, _) :- 
     4687    !.  % cut needed to prevent problems with compilers with broken read_term/3 implementations 
     4688 
     4689'$lgt_report_singleton_names'([Name| Names], Term, Stream) :- 
     4690    '$lgt_inc_compile_warnings_counter', 
     4691    (   '$lgt_pp_entity'(_, _, _, _, _) -> 
     4692        nl 
     4693    ; true 
     4694    ), 
     4695    (   Names == [] -> 
     4696        write('        WARNING!  Singleton variable ') 
     4697    ;   write('        WARNING!  Singleton variables ') 
     4698    ), 
     4699    'lgt_report_singletons_term'(Term), 
     4700    '$lgt_write_list'([Name| Names]), 
     4701    nl, '$lgt_report_compiler_error_line_number'(Stream), 
     4702    (   '$lgt_pp_entity'(_, _, _, _, _) -> 
     4703        true 
     4704    ;   nl 
    47064705    ). 
    47074706 
     
    47434742 
    47444743 
    4745 % '$lgt_singleton_var_names'(@list, -list) 
    4746 % 
    4747 % colects singleton variable names into a list 
     4744% '$lgt_filter_singletons'(+list, -list) 
     4745% 
     4746% filter variables whose name start with an underscore from a singletons list if  
     4747% the corresponding compiler flag sets their interpretation to don't care variables 
     4748 
     4749'$lgt_filter_singletons'(List, Result) :- 
     4750    (   '$lgt_compiler_flag'(underscore_variables, dont_care) -> 
     4751        '$lgt_filter_dont_care_vars'(List, Result) 
     4752    ;   '$lgt_singleton_var_names'(List, Result) 
     4753    ). 
     4754 
    47484755 
    47494756'$lgt_singleton_var_names'([], []). 
     
    47534760 
    47544761 
    4755  
    4756 % '$lgt_filter_dont_care_vars'(+list, -list) 
    4757 % 
    4758 % filter variables whose name start with an underscore from a singletons list if  
    4759 % the corresponding compiler flag sets their interpretation to don't care variables 
    4760  
    4761 '$lgt_filter_dont_care_vars'(List, Result) :- 
    4762     (   '$lgt_compiler_flag'(underscore_variables, dont_care) -> 
    4763         '$lgt_filter_dont_care_vars'(List, [], Result) 
    4764     ;   List = Result 
    4765     ). 
    4766  
    4767  
    4768 '$lgt_filter_dont_care_vars'([], Result, Result) :- 
    4769     !.  % cut needed to prevent problems with compilers with broken read_term/3 
    4770  
    4771 '$lgt_filter_dont_care_vars'([Atom = Var| List], Sofar, Result) :- 
    4772     (   atom_concat('_', _, Atom) -> 
    4773         '$lgt_filter_dont_care_vars'(List, Sofar, Result) 
    4774     ;   '$lgt_filter_dont_care_vars'(List, [Atom = Var| Sofar], Result) 
     4762'$lgt_filter_dont_care_vars'([], []). 
     4763 
     4764'$lgt_filter_dont_care_vars'([Name = _| Singletons], Names) :- 
     4765    (   atom_concat('_', _, Name) -> 
     4766        '$lgt_filter_dont_care_vars'(Singletons, Names) 
     4767    ;   Names = [Name| Rest], 
     4768        '$lgt_filter_dont_care_vars'(Singletons, Rest) 
    47754769    ). 
    47764770