35
36:- module(pldoc_register,
37 [ process_stored_comments/0
38 ]). 39:- use_module(doc_process). 40:- use_module(library(pldoc)). 41:- use_module(library(debug)). 42:- set_prolog_flag(generate_debug_info, false). 43
44pldoc_module(pldoc_modes). 45pldoc_module(pldoc_process).
46pldoc_module(pldoc_wiki).
47pldoc_module(pldoc).
48pldoc_module(lists).
49pldoc_module(apply).
50pldoc_module(pairs).
51
52 55
56:- multifile
57 prolog:comment_hook/3. 58
59:- dynamic
60 mydoc/3. 61
(_, _, _, _) :-
63 current_prolog_flag(pldoc_collecting, false),
64 !.
65do_comment_hook(Comments, TermPos, File, _) :-
66 pldoc_loading,
67 !,
68 assert(mydoc(Comments, TermPos, File)).
69do_comment_hook(Comments, TermPos, File, _Term) :-
70 \+ current_prolog_flag(xref, true),
71 prolog_load_context(module, Module),
72 pldoc_module(Module),
73 !,
74 assert(mydoc(Comments, TermPos, File)).
75do_comment_hook(Comments, TermPos, File, _) :-
76 ( \+ current_prolog_flag(xref, true)
77 -> true
78 ; current_prolog_flag(xref_store_comments, true)
79 ),
80 process_comments(Comments, TermPos, File).
93prolog:(Comments, TermPos, Term) :-
94 source_location(File, _TermLine),
95 setup_call_cleanup(
96 '$push_input_context'(pldoc), 97 do_comment_hook(Comments, TermPos, File, Term),
98 '$pop_input_context').
99
:-
101 forall(retract(mydoc(Comments, TermPos, File)),
102 delayed_process(Comments, TermPos, File)).
103
104delayed_process(Comments, TermPos, File) :-
105 module_property(Module, file(File)),
106 setup_call_cleanup(
107 '$set_source_module'(Old, Module),
108 process_comments(Comments, TermPos, File),
109 '$set_source_module'(_, Old)).
110
111:- multifile prolog:message_action/2. 112
113prolog:message_action(load_file(done(0, _F, _A, _M, _T, _H)), _) :-
114 mydoc(_, _, _),
115 \+ pldoc_loading,
116 debug(pldoc, 'Processing delayed comments', []),
117 process_stored_comments