| 1 | % (c) 2009-2024 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
| 2 | % Heinrich Heine Universitaet Duesseldorf | |
| 3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
| 4 | ||
| 5 | % term_expansion/6 hook for the debugging_calls module | |
| 6 | % this file should only be used by the debugging_calls module | |
| 7 | ||
| 8 | :- use_module(module_information,[module_info/3]). | |
| 9 | ||
| 10 | :- module_info(debugging_calls_te,group,infrastructure). | |
| 11 | :- module_info(debugging_calls_te,description,'This sub-module contains the term-expansing code of the debugging call module, to remove ~~ calls'). | |
| 12 | ||
| 13 | :- dynamic current_context/2. | |
| 14 | current_context(none,none). | |
| 15 | ||
| 16 | assert_layout(File,Layout,NewPos) :- | |
| 17 | print('Layout:'),print(Layout),nl, | |
| 18 | retractall(current_context(_,_)), | |
| 19 | (Layout = [NewPos|_] -> true ; NewPos = none), | |
| 20 | assertz(current_context(File,NewPos)). | |
| 21 | ||
| 22 | logte(_Term,Layout) :- | |
| 23 | prolog_load_context(file,File), | |
| 24 | current_context(Before,OldPos), | |
| 25 | assert_layout(File,Layout,NewPos), | |
| 26 | ( File=Before -> | |
| 27 | true | |
| 28 | ; | |
| 29 | print('### start: '), | |
| 30 | print(File),print('/'),print(NewPos), | |
| 31 | print(', was: '), | |
| 32 | print(Before),print('/'),print(OldPos),nl). | |
| 33 | ||
| 34 | ||
| 35 | expand((:- meta_predicate '~~'(_X)),_Layout1,_Term2,_Layout2) :- !, | |
| 36 | %print(not_removing_in_meta_predicate('~~'(_X))),nl, | |
| 37 | fail. | |
| 38 | expand((:- use_module(library(Lib))),Layout1,Term2,Layout2) :- | |
| 39 | library_to_patch(Lib,PatchedLib), | |
| 40 | (prolog_load_context(module,CurModule) -> true ; CurModule=user), | |
| 41 | \+ ignore_patches_in_module(CurModule), | |
| 42 | !, | |
| 43 | Layout2 = Layout1, | |
| 44 | format('Patching use_module(library(~w)) in ~w to ~w~n',[Lib,CurModule,PatchedLib]), | |
| 45 | Term2 = (:- use_module(PatchedLib)). | |
| 46 | expand((:- use_module(library(Lib),Preds)),Layout1,Term2,Layout2) :- | |
| 47 | library_to_patch(Lib,PatchedLib), | |
| 48 | Preds \= [], % so that there is a way to bypass the term expander | |
| 49 | current_module(CurModule), | |
| 50 | (prolog_load_context(module,CurModule) -> true ; CurModule=user), | |
| 51 | \+ ignore_patches_in_module(CurModule), | |
| 52 | !, | |
| 53 | Layout2 = Layout1, | |
| 54 | format('Patching use_module(library(~w),~w) in ~w to ~w~n',[Lib,Preds,CurModule,PatchedLib]), | |
| 55 | Term2 = (:- use_module(PatchedLib,Preds)). | |
| 56 | expand(Term1,Layout1,Term2,Layout2) :- | |
| 57 | % removes terms like ~~ pp_mnf,... | |
| 58 | debugging_calls:remove_debugging_calls(Layout1,Term1,Layout2,Term2). | |
| 59 | ||
| 60 | % patch libraries for plspec | |
| 61 | :- load_files(library(system), [when(compile_time), imports([environ/2])]). | |
| 62 | :- if(environ(plspec_patch_libraries,true)). | |
| 63 | library_to_patch(ordsets,library_plspec(ordsetsp)). | |
| 64 | library_to_patch(avl,library_plspec(avlp)). | |
| 65 | library_to_patch(lists,library_plspec(listsp)). | |
| 66 | :- endif. | |
| 67 | library_to_patch('~~'(X),library(X)). | |
| 68 | ||
| 69 | ignore_patches_in_module(X) :- var(X),!. | |
| 70 | ignore_patches_in_module(plspec). | |
| 71 | ignore_patches_in_module(plspec_core). | |
| 72 | ignore_patches_in_module(plspec_logger). | |
| 73 | ignore_patches_in_module(prettyprinter). | |
| 74 | ignore_patches_in_module(validator). | |
| 75 | ||
| 76 | ignore_patches_in_module(debugging_calls). | |
| 77 | ignore_patches_in_module(pathes). | |
| 78 | ignore_patches_in_module(module_information). | |
| 79 | ||
| 80 | ignore_patches_in_module('$restore'). | |
| 81 | ignore_patches_in_module('$save'). | |
| 82 | ignore_patches_in_module(alignments). | |
| 83 | ignore_patches_in_module(avl). | |
| 84 | ignore_patches_in_module(clpfd). | |
| 85 | ignore_patches_in_module(chr). | |
| 86 | ignore_patches_in_module(codesio). | |
| 87 | ignore_patches_in_module(file_systems). | |
| 88 | ignore_patches_in_module(ordsets). | |
| 89 | ignore_patches_in_module(lists). | |
| 90 | ignore_patches_in_module(prolog). | |
| 91 | ignore_patches_in_module(structs). | |
| 92 | ignore_patches_in_module(system). | |
| 93 | ignore_patches_in_module(terms). | |
| 94 | ignore_patches_in_module(types). | |
| 95 | ignore_patches_in_module('SU_messages'). | |
| 96 | ||
| 97 | :- if((environ(prob_debug_flag,true) ; environ(plspec_patch_libraries,true))). | |
| 98 | :- multifile user:term_expansion/6. | |
| 99 | user:term_expansion(Term1, Layout1, Ids, Term2, Layout2, [rm_debug_calls|Ids]) :- | |
| 100 | nonvar(Term1), nonmember(rm_debug_calls,Ids), | |
| 101 | expand(Term1,Layout1,Term2,Layout2). | |
| 102 | :- endif. | |
| 103 | ||
| 104 | ||
| 105 |