1 % (c) 2016-2026 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 :- module(meta_interface,[command_description/3, command_call/4,
6 command_unavailable/2,
7 command_arguments/2, command_optional_arguments/4,
8 command_category/2,
9 command_preferences_category/2,
10 command_additional_info/2,
11 get_command_preferences/2,
12 call_command/5,
13 is_dot_command/1, is_dot_command/6,
14 call_dot_command/2, call_dot_command/3,
15 is_dot_command_for_expr/1, call_dot_command_for_expr/3, call_dot_command_for_expr/4,
16 call_dot_command_with_engine/4, call_dot_command_with_engine_for_expr/5,
17 is_plantuml_command/1, is_plantuml_command/6,
18 call_plantuml_command/2, call_plantuml_command/3,
19 is_plantuml_command_for_expr/1,
20 call_plantuml_command_for_expr/3, call_plantuml_command_for_expr/4,
21 is_table_command/6, is_table_command/1, is_table_command_for_expr/1,
22 write_table_to_csv_file/2, write_table_to_csv_file/3, write_table_to_text_file/2]).
23
24 :- use_module(probsrc(module_information)).
25 :- module_info(group,visualization).
26 :- module_info(description,'This module provides access and description to a variety of Prolog commands.').
27
28 % the table command can be called from probcli via -csv
29 % e.g., probcli M.mch -csv wd_pos user_output
30
31 :- use_module(probsrc(error_manager)).
32 :- use_module(probsrc(debug)).
33 :- use_module(probsrc(tools_strings),[ajoin/2]).
34 :- use_module(probsrc(preferences),[get_preference/2, get_computed_preference/2]).
35 :- use_module(probsrc(specfile),[
36 b_or_z_mode/0, eventb_mode/0, csp_mode/0,
37 %csp_with_bz_mode/0,
38 get_specification_description/2, spec_file_has_been_successfully_loaded/0]).
39 :- use_module(probsrc(state_space), [current_state_corresponds_to_fully_setup_b_machine/0, current_state_corresponds_to_setup_constants_b_machine/0]).
40
41 :- use_module(probsrc(bmachine),[b_machine_has_constants_or_properties/0, b_machine_has_assertions/0,
42 b_machine_has_constants/0, b_machine_has_variables/0,
43 b_machine_has_operations/0]).
44
45 % dot command with no arguments
46 is_dot_command(Command) :- command_category(Command,dot), command_arguments(Command,[dotfile]).
47 call_dot_command(Command,File) :- call_dot_command(Command,File,[]).
48 call_dot_command(Command,File,OptionalArgs) :- %print(cmd(Command,File,OptionalArgs)),nl,
49 call_command(dot,Command,[dotfile],[File],OptionalArgs).
50
51 % dot command with expr argument
52 is_dot_command_for_expr(Command) :-
53 command_category(Command,dot), command_arguments(Command,[expression_atom,dotfile]).
54 call_dot_command_for_expr(Command,Expr,File) :-
55 call_dot_command_for_expr(Command,Expr,File,[]).
56 call_dot_command_for_expr(Command,Expr,File,OptionalArgs) :- % print(cmd(Command,Expr,File,OptionalArgs)),nl,
57 call_command(dot,Command,[expression_atom,dotfile],[Expr,File],OptionalArgs).
58
59 % plantuml command with no arguments
60 is_plantuml_command(Command) :- command_category(Command,plantuml), command_arguments(Command,[plantumlfile]).
61 call_plantuml_command(Command,File) :- call_plantuml_command(Command,File,[]).
62 call_plantuml_command(Command,File,OptionalArgs) :-
63 plantuml_filename_extension_can_be_converted(File,Ext,UmlFile),
64 !, % we can convert a plantuml file to this format
65 call_plantuml_command(Command,UmlFile,OptionalArgs),
66 gen_plantuml_output([UmlFile],Ext,File).
67 call_plantuml_command(Command,File,OptionalArgs) :-
68 split_filename(File,FileRoot,Ext),
69 (Ext \= puml
70 -> add_warning(get_puml_output,'Unsupported file extension for PlantUML output, create .puml file: ',Ext),
71 ajoin([FileRoot,'.puml'],PumlFile)
72 ; PumlFile = File),
73 call_command(plantuml,Command,[plantumlfile],[PumlFile],OptionalArgs).
74
75 % plantuml command with expr argument
76 is_plantuml_command_for_expr(Command) :-
77 command_category(Command,plantuml), command_arguments(Command,[expression_atom,plantumlfile]).
78 call_plantuml_command_for_expr(Command,Expr,File) :-
79 plantuml_filename_extension_can_be_converted(File,Ext,UmlFile),
80 !, % we can convert a plantuml file to this format
81 call_plantuml_command_for_expr(Command,Expr,File,[]),
82 gen_plantuml_output([UmlFile],Ext,File).
83 call_plantuml_command_for_expr(Command,Expr,File,OptionalArgs) :-
84 call_command(plantuml,Command,[expression_atom,plantumlfile],[Expr,File],OptionalArgs).
85
86
87 :- use_module(probsrc(tools_commands),[gen_dot_output/4, gen_plantuml_output/3, valid_dot_output_format/1, valid_plantuml_output_format/1]).
88 :- use_module(probsrc(tools),[split_filename/3]).
89 :- use_module(probsrc(tools_strings),[ajoin/2]).
90
91 % call dot_command and dot engine if necessary
92 call_dot_command_with_engine(Command,File,OptionalArgs,DotEngine) :-
93 dot_filename_extension_can_be_converted(File,Ext,DotFile),
94 !, % we can convert a dot file to this format
95 call_dot_command(Command,DotFile,OptionalArgs),
96 % DotEngine = default, sfdp, circo, ...
97 gen_dot_output(DotFile,DotEngine,Ext,File).
98 call_dot_command_with_engine(Command,File,OptionalArgs,_) :-
99 call_dot_command(Command,File,OptionalArgs).
100
101 % call dot_command and dot engine if necessary
102 call_dot_command_with_engine_for_expr(Command,Expr,File,OptionalArgs,DotEngine) :-
103 dot_filename_extension_can_be_converted(File,Ext,DotFile),
104 !, % we can convert a dot file to this format
105 call_dot_command_for_expr(Command,Expr,DotFile,OptionalArgs),
106 gen_dot_output(DotFile,DotEngine,Ext,File).
107 call_dot_command_with_engine_for_expr(Command,Expr,File,OptionalArgs,_) :-
108 call_dot_command_for_expr(Command,Expr,File,OptionalArgs).
109
110 dot_filename_extension_can_be_converted(File,Ext,DotFile) :-
111 split_filename(File,FileRoot,Ext), Ext \= dot,
112 valid_dot_output_format(Ext),!, % we can convert a dot file to this format
113 ajoin([FileRoot,'.dot'],DotFile). % TODO: we could generate a temp file in /tmp
114
115 plantuml_filename_extension_can_be_converted(File,Ext,DotFile) :-
116 split_filename(File,FileRoot,Ext), Ext \= puml,
117 valid_plantuml_output_format(Ext),!, % we can convert a plantuml file to this format
118 ajoin([FileRoot,'.puml'],DotFile). % TODO: we could generate a temp file in /tmp
119
120 % TODO: maybe automatically call dot -Tpdf <F.dot >F.pdf for pdf, svg or similar file endings
121
122 % dot commands with no or with extra arguments:
123 % find out which dot commands are available and what arguments and preferences they take:
124 is_dot_command(Command,Name,Description,NumberOfFormulaArgs,Preferences,AdditionalInfo) :-
125 command_description(Command,Name,Description), % move forward to ensure ordering of found commands is same as in file
126 (is_dot_command(Command),NumberOfFormulaArgs=0 ;
127 is_dot_command_for_expr(Command),NumberOfFormulaArgs=1),
128 get_command_preferences(Command, Preferences),
129 findall(Info, command_additional_info(Command, Info), AdditionalInfo).
130
131 % find out which plantuml commands are available and what arguments and preferences they take:
132 is_plantuml_command(Command,Name,Description,NumberOfFormulaArgs,Preferences,AdditionalInfo) :-
133 command_description(Command,Name,Description), % move forward to ensure ordering of found commands is same as in file
134 (is_plantuml_command(Command),NumberOfFormulaArgs=0 ;
135 is_plantuml_command_for_expr(Command),NumberOfFormulaArgs=1),
136 get_command_preferences(Command, Preferences),
137 findall(Info, command_additional_info(Command, Info), AdditionalInfo).
138
139 :- use_module(library(lists)).
140 % table commands (return as last argument list of lists)
141 is_table_command(Command,Name,Description,NumberOfFormulaArgs,Preferences,AdditionalInfo) :-
142 command_category(Command,table),
143 command_arguments(Command,Args), last(Args,table_result),
144 length(Args,Len), NumberOfFormulaArgs is Len - 1,
145 command_description(Command,Name,Description),
146 get_command_preferences(Command, Preferences),
147 findall(Info, command_additional_info(Command, Info), AdditionalInfo).
148
149 is_table_command(Command) :-
150 is_table_command(Command,_,_,0,_,_).
151 is_table_command_for_expr(Command) :-
152 command_category(Command,table), command_arguments(Command,[expression_atom,table_result]).
153
154
155 % ---------------------------------------
156
157 :- use_module(probsrc(tools_io),[safe_intelligent_open_file/3]).
158 % write result of a table command to a CSV file, user_output prints to console w/o CSV seperators
159
160
161 write_table_to_csv_file(CSVFile,Table) :-
162 write_table_to_csv_file(CSVFile,[],Table).
163
164 write_table_to_text_file(TextFile,Table) :-
165 write_table_to_csv_file(TextFile,[text_output],Table).
166
167 write_table_to_csv_file(CSVFile,Opts,Table) :-
168 (CSVFile=user_output ;
169 member(text_output,Opts)),
170 !, % use textual output on user_output
171 Options = [csv_separator(' '),no_quoting|Opts],
172 safe_intelligent_open_file(CSVFile,write,Stream),
173 call_cleanup(write_table_to_csv_stream(Stream,Options,Table), close(Stream)).
174 write_table_to_csv_file(CSVFile,Options,Table) :-
175 safe_intelligent_open_file(CSVFile,write,Stream),
176 call_cleanup(write_table_to_csv_stream(Stream,Options,Table), close(Stream)).
177
178
179 % write result of a table command to a CSV stream
180 write_table_to_csv_stream(Stream,Options,list(L)) :- !,
181 write_table_to_csv_stream(Stream,Options,L).
182 write_table_to_csv_stream(_Stream,_,[]) :- !.
183 write_table_to_csv_stream(Stream,Options,[H|T]) :- !, write_row(H,Options,Stream), nl(Stream),
184 write_table_to_csv_stream(Stream,Options,T).
185 write_table_to_csv_stream(Stream,Options,Other) :- write(Stream,Other),nl(Stream),
186 add_internal_error('Table is not a list: ',write_table_to_csv_stream(Stream,Options,Other)).
187
188 write_row([],_,_) :- !.
189 write_row(list(L),Options,Stream) :- !, write_row(L,Options,Stream).
190 write_row([H],Options,Stream) :- !, write_value(H,Options,Stream).
191 write_row([H|T],Options,Stream) :- !, write_value(H,Options,Stream), write_sep(Options,Stream),
192 write_row(T,Options,Stream).
193 write_row(Other,Options,Stream) :- write(Stream,Other),nl(Stream),
194 add_internal_error('Table row is not a list: ',write_table_to_csv_stream(Stream,Options,Other)).
195
196 ?write_sep(Options,Stream) :- member(csv_separator(Sep),Options), !, write(Stream,Sep).
197 write_sep(_,Stream) :- write(Stream,',').
198
199 write_value(Nr,_,Stream) :- number(Nr), !, write(Stream,Nr).
200 ?write_value(Val,Options,Stream) :- member(no_quoting,Options), !, write(Stream,Val).
201 write_value(Atom,_,Stream) :- atom(Atom), atom_codes(Atom,AC),!,
202 csv_escape_codes(AC,EC),
203 format(Stream,'"~s"',[EC]). % quote for CSV
204 write_value(Other,_,Stream) :- format(Stream,'"~w"',[Other]).
205
206 csv_escape_codes([],[]).
207 csv_escape_codes([0'" | T],R) :- !,
208 R=[0'", 0'" |ET], % quotes in a CSV record must be preceded by another quote
209 csv_escape_codes(T,ET).
210 csv_escape_codes([H|T],[H|ET]) :- csv_escape_codes(T,ET).
211
212 % ---------------------------------------
213
214 % call a command described in this module
215 call_command(Category,Command,FormalArgs,ActualArgs,OptionalArgs) :-
216 command_category(Command,Category),
217 command_arguments(Command,FormalArgs), % to do: more flexible matching of args ?
218 !,
219 (command_unavailable(Command,Msg)
220 -> ajoin(['Command ', Command, ' not available: '],Msg1),
221 add_error(meta_interface,Msg1,Msg),
222 fail
223 ; setup_optional_args(Command,OptionalArgs,OptArgValueList),
224 (command_call(Command,ActualArgs,OptArgValueList,Call)
225 -> debug_println(4,command_call(Call)),
226 ? call(Call)
227 ; command_call(Command,ArgsExpected,_,_),length(ArgsExpected,Exp),length(ActualArgs,Form) %, Exp \= Form
228 ->
229 ajoin(['Command ', Command, ' expects ', Exp, ' arguments, but obtained ',Form,'!'],Msg1),
230 add_internal_error(Msg1,command_call(Command,ActualArgs,OptArgValueList,_)),
231 fail
232 ; add_internal_error('Cannot construct command call: ',command_call(Command,ActualArgs,OptArgValueList,_)),
233 fail
234 )
235 ).
236 call_command(Category,Command,FormalArgs,_ActualArgs,_OptArgs) :- command_category(Command,Category),
237 !,
238 add_error(meta_interface,'Argument mis-match when calling command: ',Command:FormalArgs),fail.
239 call_command(Category,Command,_,_,_) :- command_category(Command,_OtherCategory),!,
240 add_error(meta_interface,'Command belongs to other category: ',Category:Command),fail.
241 call_command(Category,Command,_,_,_) :-
242 add_error(meta_interface,'Unknown command: ',Category:Command),fail.
243
244
245 setup_optional_args(Command,OptionalArgs,OptArgValueList) :-
246 command_optional_arguments(Command,Names,_Types,DefaultValues),!,
247 setup_opt_args_aux(Names,DefaultValues,OptionalArgs,Command,OptArgValueList).
248 setup_optional_args(_,[],Res) :- !, Res=[].
249 setup_optional_args(Cmd,Opt,Res) :- add_internal_error('Illegal optional arguments: ',setup_optional_args(Cmd,Opt,Res)),
250 Res=[].
251
252 :- use_module(library(lists),[select/3]).
253
254 setup_opt_args_aux([],[],OptArgs,Command,Res) :-
255 (OptArgs = [] -> true ; add_internal_error('Too many optional arguments: ',Command:OptArgs)),
256 Res = [].
257 setup_opt_args_aux([Name|NT],[Default|DT],OptArgs,Command,Res) :-
258 (select('='(Name,Value),OptArgs,OA2)
259 -> Res = [Value|RT], setup_opt_args_aux(NT,DT,OA2,Command,RT)
260 ; Res = [Default|RT], setup_opt_args_aux(NT,DT,OptArgs,Command,RT)
261 ).
262
263
264 % TO DO: provide automatic conversion ? expression_atom -> expression_codes -> typed_expression ?
265
266 :- use_module(probsrc(preferences),[virtual_preference_category/2]).
267 % get all preferences for a command
268 get_command_preferences(Command,Preferences) :-
269 findall(Pref, (command_preferences_category(Command,PrefCat),
270 virtual_preference_category(Pref,PrefCat)), Preferences).
271
272 % --------------------
273 % COMMAND DESCRIPTIONS
274 % --------------------
275
276 :- discontiguous command_description/3, command_call/4,
277 command_unavailable/2, command_arguments/2,
278 command_optional_arguments/4,
279 command_category/2, command_preferences_category/2,
280 command_additional_info/2.
281
282 :- use_module(probsrc(b_machine_hierarchy),[write_dot_event_hierarchy_to_file/1,write_dot_variable_hierarchy_to_file/1,
283 write_dot_hierarchy_to_file/1]).
284
285 command_description(machine_hierarchy,'Machine Hierarchy','Shows the machine hierarchy of a B model').
286 command_call(machine_hierarchy,[File],[],b_machine_hierarchy:write_dot_hierarchy_to_file(File)).
287 command_unavailable(machine_hierarchy,Txt) :- command_unavailable(b_mode,Txt).
288 command_arguments(machine_hierarchy,[dotfile]).
289 command_category(machine_hierarchy,dot).
290 command_preferences_category(machine_hierarchy,dot_machine_hierarchy).
291 command_additional_info(machine_hierarchy,group(machine_info)).
292
293 command_description(operations,'Operation Call Graph','Shows the call graph of a classical B model').
294 command_call(operations,[File],[],b_machine_hierarchy:write_dot_op_hierarchy_to_file(File)).
295 command_unavailable(operations,'only available for B or Z models with OPERATIONS') :-
296 (\+ (b_or_z_mode,b_machine_has_operations) ; eventb_mode).
297 command_arguments(operations,[dotfile]).
298 command_category(operations,dot).
299 command_preferences_category(operations,dot_graph_generator).
300 command_additional_info(operations,group(machine_info)).
301
302 command_description(event_hierarchy,'Event Hierarchy','Shows the event hierarchy of an Event-B model').
303 command_call(event_hierarchy,[File],[],b_machine_hierarchy:write_dot_event_hierarchy_to_file(File)).
304 command_unavailable(event_hierarchy,'only available for Event-B models with events') :-
305 \+ (eventb_mode, b_machine_has_operations).
306 command_arguments(event_hierarchy,[dotfile]).
307 command_category(event_hierarchy,dot).
308 command_preferences_category(event_hierarchy,dot_event_hierarchy).
309 command_additional_info(event_hierarchy,group(machine_info)).
310
311 command_description(variable_hierarchy,'Variable Refinement Hierarchy','Shows variables within the refinement hierarchy of an Event-B model').
312 command_call(variable_hierarchy,[File],[],b_machine_hierarchy:write_dot_variable_hierarchy_to_file(File)).
313 command_unavailable(variable_hierarchy,'only available for Event-B models with variables') :-
314 \+ (eventb_mode, b_machine_has_variables).
315 command_arguments(variable_hierarchy,[dotfile]).
316 command_category(variable_hierarchy,dot).
317 command_preferences_category(variable_hierarchy,dot_variable_hierarchy).
318 command_additional_info(variable_hierarchy,group(machine_info)).
319
320
321 :- use_module(dotsrc(visualize_graph),[tcltk_print_states_for_dot/2]).
322 command_description(state_space,'State Space','Show state space').
323 command_call(state_space,[File],[ColourTransitions],visualize_graph:tcltk_print_states_for_dot(File,ColourTransitions)).
324 command_unavailable(state_space,'only available when model successfully loaded') :- \+ spec_file_has_been_successfully_loaded.
325 command_arguments(state_space,[dotfile]).
326 command_optional_arguments(state_space,[colouring],[atom],[no_colour_for_transitions]).
327 command_category(state_space,dot).
328 command_preferences_category(state_space,dot_state_space).
329 command_additional_info(state_space,group(state_space_visualisation)).
330
331 command_description(state_space_sfdp,'State Space (Fast)','Show state space (faster layout with less information and more overlaps)').
332 command_call(state_space_sfdp,[File],[ColourTransitions],visualize_graph:tcltk_print_states_for_dot_sfdp(File,ColourTransitions)).
333 command_unavailable(state_space_sfdp,'only available when model successfully loaded') :- \+ spec_file_has_been_successfully_loaded.
334 command_arguments(state_space_sfdp,[dotfile]).
335 command_optional_arguments(state_space_sfdp,[colouring],[atom],[no_colour_for_transitions]).
336 command_category(state_space_sfdp,dot).
337 command_preferences_category(state_space_sfdp,dot_state_space). % TODO: maybe remove those that are fixed and have no effect
338 command_additional_info(state_space_sfdp,preferred_dot_type(sfdp)). % sfdp preferred
339 command_additional_info(state_space_sfdp,extra_arguments(['-Goverlap=scale'])). % other option is prism
340 command_additional_info(state_space_sfdp,group(state_space_visualisation)).
341
342 :- use_module(dotsrc(visualize_graph),[tcltk_print_current_state_for_dot/1]).
343 command_description(current_state,'Current State in State Space','Show current state and successors in state space').
344 command_call(current_state,[File],[],visualize_graph:tcltk_print_current_state_for_dot(File)).
345 command_unavailable(current_state,'only available when model successfully loaded') :- \+ spec_file_has_been_successfully_loaded.
346 command_arguments(current_state,[dotfile]).
347 command_category(current_state,dot).
348 command_preferences_category(current_state,dot_cur_state_in_state_space).
349 command_additional_info(current_state,group(state_space_visualisation)).
350
351 :- use_module(dotsrc(visualize_graph),[tcltk_print_history_to_current_state_for_dot/1]).
352 command_description(history,'Trace to Current State','Show a trace leading to current state').
353 % in ProB2-UI the Tcl/Tk history is not the ProB2 history !!!
354 command_call(history,[File],[],visualize_graph:tcltk_print_history_to_current_state_for_dot(File)).
355 command_unavailable(history,'only available when model successfully loaded') :- \+ spec_file_has_been_successfully_loaded.
356 command_arguments(history,[dotfile]).
357 command_category(history,dot).
358 command_preferences_category(history,dot_state_space).
359 command_additional_info(history,group(state_visualisation)). % was trace_visualisation
360
361 %:- use_module(dotsrc(visualize_graph),[tcltk_print_history_to_current_state_with_neighbors_for_dot/1]).
362 %command_description(history_with_neighbours,'History of States (with Neighbours for last State)','Show history with neighbours leading to current state').
363 %command_call(history_with_neighbours,[File],[],visualize_graph:tcltk_print_history_to_current_state_with_neighbors_for_dot(File)).
364 %command_unavailable(history_with_neighbours,'only available when model successfully loaded') :- \+ spec_file_has_been_successfully_loaded.
365 %command_arguments(history_with_neighbours,[dotfile]).
366 %command_category(history_with_neighbours,dot).
367 %command_preferences_category(history_with_neighbours,dot_state_space).
368
369 :- use_module(dotsrc(state_space_reduction),[write_transition_diagram_for_expr_to_dotfile/2,
370 write_signature_merge_to_dotfile/2]).
371 command_description(signature_merge,'Signature Merge',
372 'Show signature-merged reduced state space (i.e., merge states which have same set of enabled events/operations)').
373 command_call(signature_merge,[File],[IgnoredEvents],state_space_reduction:write_signature_merge_to_dotfile(IgnoredEvents,File)).
374 command_unavailable(signature_merge,'only available when model successfully loaded') :- \+ spec_file_has_been_successfully_loaded.
375 command_arguments(signature_merge,[dotfile]).
376 command_optional_arguments(signature_merge,[ignored_events],[list(operations)],[[]]).
377 command_category(signature_merge,dot).
378 command_preferences_category(signature_merge,dot_graph_generator).
379 command_additional_info(signature_merge,group(state_space_visualisation)).
380
381
382 :- use_module(dotsrc(reduce_graph_state_space),[print_dot_for_dfa_from_nfa/1]).
383 command_description(dfa_merge,'DFA Merge','Show state space as deterministic automaton (DFA)').
384 command_call(dfa_merge,[File],[],reduce_graph_state_space:print_dot_for_dfa_from_nfa(File)).
385 command_unavailable(dfa_merge,'only available when model successfully loaded') :-
386 \+ spec_file_has_been_successfully_loaded.
387 command_arguments(dfa_merge,[dotfile]).
388 command_category(dfa_merge,dot).
389 command_additional_info(dfa_merge,group(state_space_visualisation)).
390
391 :- use_module(dotsrc(state_space_reduction),[write_transition_diagram_for_expr_to_dotfile/2]).
392 command_description(transition_diagram,'State Space Expression Projection...','Project state space onto expression values and show transition diagram').
393 command_call(transition_diagram,[Expression,File],[],
394 state_space_reduction:write_transition_diagram_for_expr_to_dotfile(Expression,File)).
395 command_unavailable(transition_diagram,Txt) :- command_unavailable(b_mode,Txt).
396 command_arguments(transition_diagram,[expression_atom,dotfile]). % also accepts expression_raw_ast
397 command_category(transition_diagram,dot).
398 command_preferences_category(transition_diagram,dot_projection).
399 command_additional_info(transition_diagram,group(state_space_visualisation)).
400
401 :- use_module(probporsrc(dot_graphs_static_analysis), [tcltk_create_dependence_graph/1, tcltk_create_enable_graph/1]).
402 command_description(enable_graph,'Event Enable Graph',
403 'Show enabling graph (i.e., which event/operation can enable/disable which other event/operation)').
404 command_call(enable_graph,[File],[],dot_graphs_static_analysis:tcltk_create_enable_graph(File)).
405 command_unavailable(enable_graph,Txt) :- command_unavailable(operations_events,Txt).
406 command_arguments(enable_graph,[dotfile]).
407 command_category(enable_graph,dot).
408 command_preferences_category(enable_graph,dot_enable_graph).
409 command_additional_info(enable_graph,group(data_flow_info)).
410
411 :- use_module(dotsrc(state_as_dot_graph),[print_cstate_graph/1]).
412 command_description(state_as_graph,'Current State as Graph',
413 'Show values of variables in current state as one graph').
414 command_call(state_as_graph,[File],[],state_as_dot_graph:print_cstate_graph(File)).
415 %command_call(state_as_graph,[File],[],visualize_graph:tcltk_print_current_state_as_graph_for_dot(File)).
416 command_unavailable(state_as_graph,'only available for B,Z or Event-B models after constant setup or initialisation') :- \+ current_state_corresponds_to_setup_constants_b_machine.
417 command_arguments(state_as_graph,[dotfile]).
418 command_category(state_as_graph,dot).
419 command_preferences_category(state_as_graph,state_as_graph).
420 % we could use tcltk_print_current_state_as_graph_for_dot
421 command_additional_info(state_as_graph,group(state_visualisation)).
422
423 :- use_module(dotsrc(state_custom_dot_graph),
424 [tcltk_generate_state_custom_dot_graph/1,state_custom_dot_graph_available/0]).
425
426 command_description(custom_graph,'Customized Current State as Graph',
427 'Show values in current state as a graph using CUSTOM_GRAPH definition').
428 command_call(custom_graph,[File],[],state_custom_dot_graph:tcltk_generate_state_custom_dot_graph(File)).
429 command_unavailable(custom_graph,'only available when CUSTOM_GRAPH or CUSTOM_GRAPH_NODES and CUSTOM_GRAPH_EDGES are defined in the DEFINITIONS of a B machine') :-
430 ? \+ state_custom_dot_graph_available.
431 command_unavailable(custom_graph,'only available for initialised B,Z or Event-B models') :-
432 ? state_custom_dot_graph_available,
433 \+ current_state_corresponds_to_fully_setup_b_machine.
434 command_arguments(custom_graph,[dotfile]). % also accepts expression_raw_ast
435 command_category(custom_graph,dot).
436 command_preferences_category(custom_graph,dot_graph_generator).
437 command_additional_info(custom_graph,group(state_visualisation)).
438
439 :- use_module(rulesdslsrc(rule_validation), [generate_dependency_graph/1]).
440 :- use_module(probsrc(specfile), [animation_minor_mode/1]).
441 command_description(rule_dependency_graph,'Rule Dependency Graph',
442 'Show dependencies of rules and computations of a rules machine').
443 command_call(rule_dependency_graph,[File],[],generate_dependency_graph(File)).
444 command_unavailable(rule_dependency_graph,'only available for rules machines (.rmch)') :-
445 \+ animation_minor_mode(rules_dsl).
446 command_unavailable(rule_dependency_graph,'only available for initialised rules machine') :-
447 animation_minor_mode(rules_dsl),
448 \+ current_state_corresponds_to_fully_setup_b_machine.
449 command_arguments(rule_dependency_graph,[dotfile]).
450 command_category(rule_dependency_graph,dot).
451 command_preferences_category(rule_dependency_graph,rule_dependency_graph).
452 command_preferences_category(rule_dependency_graph,dot_graph_generator).
453 command_additional_info(rule_dependency_graph,group(state_visualisation)).
454
455 :- use_module(seqproversrc(sequent_prover_exports), [export_proof_for_current_state/2]).
456 command_description(proof_tree_graph,'Proof Tree','Show sequent prover trace as proof tree.').
457 command_call(proof_tree_graph,[File],[],export_proof_for_current_state(dot,File)).
458 command_unavailable(proof_tree_graph,'only available in sequent prover mode (for .pl PO files)') :-
459 \+ animation_minor_mode(sequent_prover).
460 command_arguments(proof_tree_graph,[dotfile]).
461 command_category(proof_tree_graph,dot).
462 command_preferences_category(proof_tree_graph,dot_graph_generator).
463 command_additional_info(proof_tree_graph,group(trace_visualisation)).
464
465 % from tcltk_interface.pl:
466 command_description(expr_as_graph,'(Relational) Expression as Graph...',
467 'Show (relational) expression value as a graph (use tuples for multiple graphs)'). % see decompose_expression_for_dot
468 command_call(expr_as_graph,[Expression,File],[],tcltk_interface:tcltk_show_expression_as_dot(Expression,File)).
469 command_unavailable(expr_as_graph,Txt) :- command_unavailable(b_mode,Txt).
470 command_arguments(expr_as_graph,[expression_atom,dotfile]). % also accepts expression_raw_ast
471 command_category(expr_as_graph,dot).
472 command_preferences_category(expr_as_graph,state_as_graph).
473 command_additional_info(expr_as_graph,group(formula_visualisation)).
474
475
476 command_description(formula_tree,'Custom Predicate/Expression Formula Tree...',
477 'Show predicate/expressions and sub-formulas as a tree').
478 command_call(formula_tree,[Expression,File],[],tcltk_interface:generate_dot_from_formula(Expression,File)).
479 command_unavailable(formula_tree,Txt) :- command_unavailable(b_mode,Txt).
480 command_arguments(formula_tree,[expression_atom,dotfile]). % is actually predicate_atom, also accepts expression_raw_ast
481 command_category(formula_tree,dot).
482 command_preferences_category(formula_tree,dot_formula_tree).
483 command_additional_info(formula_tree,group(formula_visualisation)).
484
485 command_description(invariant,'Invariant Formula Tree','Show invariant as a formula tree').
486 command_call(invariant,[File],[],tcltk_interface:generate_dot_from_invariant(File)).
487 command_unavailable(invariant,'only available for initialised B,Z or Event-B models') :- \+ current_state_corresponds_to_fully_setup_b_machine.
488 command_arguments(invariant,[dotfile]).
489 command_category(invariant,dot).
490 command_preferences_category(invariant,dot_formula_tree).
491 command_additional_info(invariant,group(formula_visualisation)).
492
493 command_description(properties,Name,Desc) :-
494 (eventb_mode
495 -> Name = 'Axioms Formula Tree', Desc = 'Show asioms as a formula tree'
496 ; Name = 'Properties Formula Tree', Desc = 'Show properties as a formula tree').
497 command_call(properties,[File],[],tcltk_interface:generate_dot_from_properties(File)).
498 %command_unavailable(properties,'only available for initialised B,Z or Event-B models') :- \+ b_or_z_mode. % for non-initialised machines an existential quantifier is added
499 command_unavailable(properties,'only available for B,Z or Event-B models with PROPERTIES after constant setup or initialisation') :-
500 \+ (current_state_corresponds_to_setup_constants_b_machine,b_machine_has_constants_or_properties).
501 command_arguments(properties,[dotfile]).
502 command_category(properties,dot).
503 command_preferences_category(properties,dot_formula_tree).
504 command_additional_info(properties,group(formula_visualisation)).
505
506 command_description(assertions,Name,Desc) :-
507 (eventb_mode
508 -> Name = 'Theorems Formula Tree', Desc = 'Show theorems as a formula tree'
509 ; Name = 'Assertions Formula Tree', Desc = 'Show assertions as a formula tree').
510 command_call(assertions,[File],[],tcltk_interface:generate_dot_from_assertions(File)).
511 %command_unavailable(assertions,'only available for initialised B,Z or Event-B models') :- \+ b_or_z_mode. % for non-initialised machines an existential quantifier is added
512 command_unavailable(assertions,'only available for B,Z or Event-B models with ASSERTIONS after constant setup or initialisation') :-
513 \+ (current_state_corresponds_to_setup_constants_b_machine, b_machine_has_assertions).
514 command_arguments(assertions,[dotfile]).
515 command_category(assertions,dot).
516 command_preferences_category(assertions,dot_formula_tree).
517 command_additional_info(assertions,group(formula_visualisation)).
518
519 command_description(deadlock,'Deadlock Formula Tree',
520 'Show deadlocking status (i.e., guards of all operations/events) in current state as a formula tree').
521 command_call(deadlock,[File],[],tcltk_interface:generate_dot_from_deadlock_po(File)).
522 command_unavailable(deadlock,Msg) :-
523 command_unavailable(operations_events,Msg) .
524 command_unavailable(deadlock,'only available for initialised models') :-
525 \+ (current_state_corresponds_to_fully_setup_b_machine).
526 command_arguments(deadlock,[dotfile]).
527 command_category(deadlock,dot).
528 command_preferences_category(deadlock,dot_formula_tree).
529 command_additional_info(deadlock,group(formula_visualisation)).
530
531 :- use_module(probsrc(bmachine),[b_get_machine_goal/1]).
532 command_description(goal,'Goal Formula Tree','Show GOAL as a formula tree').
533 command_call(goal,[File],[],tcltk_interface:generate_dot_from_goal(File)).
534 command_unavailable(goal,'only available for initialised B,Z or Event-B models with a GOAL DEFINITION') :-
535 (\+ b_or_z_mode ; \+ b_get_machine_goal(_)).
536 command_arguments(goal,[dotfile]).
537 command_category(goal,dot).
538 command_preferences_category(goal,dot_formula_tree).
539 command_additional_info(goal,group(formula_visualisation)).
540
541 command_description(dependence_graph,'Event Dependence Graph',
542 'Show dependency graph of events/operations (i.e., which events are not commutative and influence the effect of other ones)').
543 % difference to enable graph : not whether we have enabling/disabling but influence on effect
544 command_call(dependence_graph,[File],[],dot_graphs_static_analysis:tcltk_create_dependence_graph(File)).
545 command_unavailable(dependence_graph,Txt) :- command_unavailable(operations_events,Txt).
546 command_arguments(dependence_graph,[dotfile]).
547 command_category(dependence_graph,dot).
548 command_preferences_category(dependence_graph,dot_enable_graph).
549 command_additional_info(dependence_graph,group(data_flow_info)).
550
551 command_description(variable_modification_graph,'Variable Read/Write Graph',Msg) :-
552 (eventb_mode
553 -> Msg = 'Show variable modification by events and reading in guards'
554 ; Msg = 'Show variable modification by operations and reading in guards').
555 command_call(variable_modification_graph,[File],[],b_read_write_info:tcltk_dot_variable_modification_analysis(File)).
556 command_unavailable(variable_modification_graph,Txt) :- command_unavailable(variables,Txt).
557 command_arguments(variable_modification_graph,[dotfile]).
558 command_category(variable_modification_graph,dot).
559 command_preferences_category(variable_modification_graph,dot_variable_modification).
560 command_additional_info(variable_modification_graph,group(data_flow_info)).
561
562 :- use_module(dotsrc(visualize_graph),[tcltk_print_definitions_as_graph_for_dot/1]).
563 command_description(definitions,'Definitions Graph','Show dependency graph of DEFINITIONS').
564 command_call(definitions,[File],[],visualize_graph:tcltk_print_definitions_as_graph_for_dot(File)).
565 command_unavailable(definitions,'only available for B or Z models') :- (b_or_z_mode -> eventb_mode ; true).
566 command_arguments(definitions,[dotfile]).
567 command_category(definitions,dot).
568 command_preferences_category(definitions,dot_definitions).
569 command_additional_info(definitions,group(debug_info)).
570
571 :- use_module(dotsrc(visualize_graph),[tcltk_print_predicate_dependency_as_graph_for_dot/2]).
572 command_description(predicate_dependency,'Predicate Dependency Graph...','Show dependency graph of conjuncts of a predicate').
573 command_call(predicate_dependency,[Pred,File],[],visualize_graph:tcltk_print_predicate_dependency_as_graph_for_dot(Pred,File)).
574 command_unavailable(predicate_dependency,Txt) :- command_unavailable(b_mode,Txt).
575 command_arguments(predicate_dependency,[expression_atom,dotfile]). % also accepts expression_raw_ast
576 command_category(predicate_dependency,dot).
577 command_additional_info(predicate_dependency,group(debug_info)).
578
579 command_description(last_error,'Last State Error Formula Tree','Try and visualise last state error source as a formula tree').
580 command_call(last_error,[File],[],tcltk_interface:generate_dot_from_last_span_predicate(File)).
581 command_unavailable(last_error,'only available when (state) error occured') :-
582 \+ tcltk_interface:can_generate_dot_from_last_state_error.
583 command_arguments(last_error,[dotfile]).
584 command_category(last_error,dot).
585 command_additional_info(last_error,group(formula_visualisation)).
586
587 command_description(last_mcts_tree,'MCTS Game Tree','Show two levels of last MCTS (Monte Carlo Tree Search) game tree').
588 command_call(last_mcts_tree,[File],[],mcts_game_play:tcltk_gen_last_mcts_tree(2,File)).
589 command_unavailable(last_mcts_tree,'only available when GAME_OVER, ... definitions generated') :- \+ mcts_game_play:mcts_auto_play_available.
590 command_unavailable(last_mcts_tree,'only available after a game move has been computed by MCTS') :- mcts_game_play:mcts_auto_play_available, \+ mcts_game_play:mcts_tree_available.
591 command_arguments(last_mcts_tree,[dotfile]).
592 command_category(last_mcts_tree,dot).
593 command_additional_info(last_mcts_tree,group(formula_visualisation)).
594
595
596 command_description(b2sat_vig_graph,'B2SAT CNF Variable Incidence Graph','Show Variable Incidence Graph of B2SAT CNF and last model found').
597 command_call(b2sat_vig_graph,[File],[],b2sat:generate_cnf_vig_graph(File)).
598 command_unavailable(b2sat_vig_graph,'only available when SOLVER_FOR_PROPERTIES is "sat"') :- \+ get_preference(use_solver_on_load,sat).
599 command_unavailable(b2sat_vig_graph,'only available when path_to_intermediate_output is set') :- \+ b2sat:cnf_vig_graph_available.
600 command_arguments(b2sat_vig_graph,[dotfile]).
601 command_category(b2sat_vig_graph,dot).
602 command_additional_info(b2sat_vig_graph,group(debug_info)).
603
604
605 command_description(find_value_graph,'Find Value (Exact)...','Find exact value inside variables and constants and show matches as graph').
606 command_call(find_value_graph,[Value,File],[],tcltk_interface:tcltk_find_value_as_graph(Value,[exact],File)).
607 command_unavailable(find_value_graph,'only available for initialised B,Z or Event-B models') :-
608 \+ current_state_corresponds_to_setup_constants_b_machine.
609 command_arguments(find_value_graph,[expression_atom,dotfile]).
610 command_category(find_value_graph,dot).
611 command_additional_info(find_value_graph,group(formula_visualisation)).
612
613 %command_description(constants_profile_graph,'ProB Constants Profile Graph','Show constants computed by equations and order of computation').
614 %command_call(constants_profile_graph,[File],[],runtime_profiler:tcltk_dot_constants_profile_info(File)).
615 %command_unavailable(constants_profile_graph,Txt) :- command_unavailable(prob_constants_profile_info,Txt).
616 %command_arguments(constants_profile_graph,[dotfile]).
617 %command_category(constants_profile_graph,dot).
618 %%command_preferences_category(constants_profile_graph,...).
619 %command_additional_info(constants_profile_graph,group(debug_info)).
620
621 % -----------------------------------------
622
623 % PLANTUML COMMANDS:
624
625 :- use_module(dotsrc(uml_generator),[write_uml_sequence_chart/1]).
626 command_description(uml_sequence_chart,'UML Sequence Chart','Visualise the current trace as a UML sequence chart.').
627 command_call(uml_sequence_chart,[File],[],write_uml_sequence_chart(File)).
628 command_unavailable(uml_sequence_chart,'only available when model successfully loaded') :- \+ spec_file_has_been_successfully_loaded.
629 %command_unavailable(uml_sequence_chart,'only available when SEQUENCE_CHART definitions are defined in the DEFINITIONS of a B machine') :-
630 % \+ bmachine:b_definition_prefixed(expression,'SEQUENCE_CHART',_,_,_). % no such def exists
631 command_arguments(uml_sequence_chart,[plantumlfile]).
632 command_category(uml_sequence_chart,plantuml).
633 command_additional_info(uml_sequence_chart,group(trace_visualisation)).
634
635
636 % -----------------------------------------
637
638 % TABLE COMMANDS:
639
640
641 command_description(machine_statistics,'Machine Statistics','Show statistics for main machine/specification').
642 command_call(machine_statistics,[Result],[],meta_interface:meta_get_machine_stats(Result)).
643 command_unavailable(machine_statistics,Txt) :- command_unavailable(b_mode,Txt).
644 command_arguments(machine_statistics,[table_result]).
645 command_category(machine_statistics,table).
646 command_additional_info(machine_statistics,group(machine_info)).
647
648 :- use_module(probsrc(bmachine),[b_machine_statistics/2]).
649 :- public meta_get_machine_stats/1.
650 meta_get_machine_stats(list([list(['Key','Nr'])|L])) :- findall(list([Key,Nr]),b_machine_statistics(Key,Nr),L).
651
652 command_description(expr_as_table,'Expression Table...','Show expression value as a table').
653 command_call(expr_as_table,[Expression,Result],[],tcltk_interface:tcltk_eval_as_table(Expression,Result)).
654 command_unavailable(expr_as_table,Txt) :- command_unavailable(b_mode,Txt).
655 command_arguments(expr_as_table,[expression_atom,table_result]). % also accepts expression_raw_ast
656 command_category(expr_as_table,table).
657 command_additional_info(expr_as_table,group(formula_visualisation)).
658
659 :- use_module(probsrc(tcltk_interface),[tcltk_operations_covered_info/3]).
660
661 command_description(quick_operation_coverage,'Operation Coverage','Show which operations are covered in current state space').
662 command_call(quick_operation_coverage,[Result],[],tcltk_interface:tcltk_operations_covered_info(Result,_,quick)).
663 command_unavailable(quick_operation_coverage,'only available for B,Z, Event-B with OPERATIONS, or CSP models') :-
664 \+ (b_or_z_mode, b_machine_has_operations), \+ csp_mode.
665 command_arguments(quick_operation_coverage,[table_result]). % also accepts expression_raw_ast
666 command_category(quick_operation_coverage,table).
667 command_additional_info(quick_operation_coverage,group(coverage_info)).
668
669 command_description(precise_operation_coverage,'Operation Coverage and Feasibility','Show which feasible operations are covered (possible means operation is in principle feasible given invariant)').
670 command_call(precise_operation_coverage,[Result],[],tcltk_interface:tcltk_operations_covered_info(Result,_,precise)).
671 command_unavailable(precise_operation_coverage,Txt) :- command_unavailable(operations_events,Txt).
672 command_arguments(precise_operation_coverage,[table_result]). % also accepts expression_raw_ast
673 command_category(precise_operation_coverage,table).
674 command_additional_info(precise_operation_coverage,group(coverage_info)).
675
676 :- use_module(probsrc(preferences),[get_prob_application_type/1]).
677 % not really useful for ProB2: already in Statistics View when more details shown, but useful for ProB for Rodin:
678 % rodin
679 command_description(operation_coverage_stats,'Operation Coverage Statistics','Show operation coverage statistics') :-
680 get_prob_application_type(rodin).
681 command_call(operation_coverage_stats,[Result],[],coverage_statistics:tcltk_compute_coverage(Result)) :-
682 get_prob_application_type(rodin).
683 command_arguments(operation_coverage_stats,[table_result]) :-
684 get_prob_application_type(rodin).
685 command_category(operation_coverage_stats,table) :-
686 get_prob_application_type(rodin).
687 :- use_module(extrasrc(coverage_statistics),[tcltk_compute_coverage/1]).
688 get_operation_coverage_stats(list([list(['Info'])|LRes])) :-
689 tcltk_compute_coverage(list(Res)),
690 maplist(wrap_into_list,Res,LRes).
691 command_additional_info(operation_coverage_stats,group(coverage_info)).
692
693
694 command_description(show_typing,'Show Typing','Show types for variables and constants').
695 command_call(show_typing,[Result],[],tcltk_interface:tcltk_show_typing_of_variables_and_constants(Result)).
696 command_unavailable(show_typing,Txt) :- command_unavailable(b_mode,Txt).
697 command_arguments(show_typing,[table_result]). % also accepts expression_raw_ast
698 command_category(show_typing,table).
699 command_additional_info(show_typing,group(machine_info)).
700
701 command_description(variable_coverage,'Variable Coverage','Show number of distinct covered values for variables in current state space').
702 command_call(variable_coverage,[Result],[],state_space_reduction:tcltk_compute_nr_covered_values_for_all_variables(Result)).
703 command_unavailable(variable_coverage,Txt) :- command_unavailable(variables,Txt).
704 command_arguments(variable_coverage,[table_result]). % also accepts expression_raw_ast
705 command_category(variable_coverage,table).
706 command_additional_info(variable_coverage,group(coverage_info)).
707
708 command_description(constants_coverage,'Constant Coverage','Show number of distinct covered values for constants in current state space').
709 command_call(constants_coverage,[Result],[],state_space_reduction:tcltk_compute_nr_covered_values_for_all_constants(Result)).
710 command_unavailable(constants_coverage,Txt) :- command_unavailable(constants,Txt).
711 command_arguments(constants_coverage,[table_result]).
712 command_category(constants_coverage,table).
713 command_additional_info(constants_coverage,group(coverage_info)).
714
715 % analyze_constants
716 command_description(constants_analysis,'Constant Analysis','Show size (B and Prolog term size) and other infos about constants').
717 command_call(constants_analysis,[Result],[],coverage_statistics:tcltk_analyse_constants(Result)).
718 command_unavailable(constants_analysis,Txt) :- command_unavailable(constants,Txt).
719 command_arguments(constants_analysis,[table_result]).
720 command_category(constants_analysis,table).
721 command_additional_info(constants_analysis,group(debug_info)).
722
723 command_description(expression_coverage,'Expression Coverage...','Evaluate expression over current state space and compute distinct values and their number of occurence').
724 command_call(expression_coverage,[Expr,Result],[],meta_interface:expression_coverage(Expr,Result)).
725 command_unavailable(expression_coverage,Txt) :- command_unavailable(b_mode,Txt).
726 command_arguments(expression_coverage,[expression_atom,table_result]).
727 command_category(expression_coverage,table).
728 command_additional_info(expression_coverage,group(coverage_info)).
729
730 :- public expression_coverage/2.
731 :- use_module(dotsrc(state_space_reduction),[compute_covered_values_for_expression/4]).
732 expression_coverage(ExprToEvaluate,list(LRes)) :-
733 compute_covered_values_for_expression(ExprToEvaluate,_MaxTypeCard,_TotalNrOfValuesFound,list(Res)),
734 maplist(wrap_into_list,Res,LRes).
735
736 command_description(minmax_table,'Min/Max Values','Show minimum/maximum values for constants and variables in current state space; useful to analyse state explosion problems').
737 command_call(minmax_table,[Result],[],meta_interface:minmax_table(Result)).
738 command_unavailable(minmax_table,'only available when model successfully loaded') :- \+ spec_file_has_been_successfully_loaded.
739 command_arguments(minmax_table,[table_result]).
740 command_category(minmax_table,table).
741 command_additional_info(minmax_table,group(coverage_info)).
742 :- use_module(extrasrc(coverage_statistics),[tcltk_compute_min_max/1]).
743 :- public minmax_table/1.
744 minmax_table(R) :- tcltk_compute_min_max(R).
745
746 command_description(inv_coverage,'Invariant Analysis','Analyse the truth value of individual invariants in current state space').
747 command_call(inv_coverage,[Result],[],mcdc_coverage:tcltk_get_invariant_coverage(Result)).
748 command_unavailable(inv_coverage,Txt) :- command_unavailable(b_mode,Txt).
749 command_arguments(inv_coverage,[table_result]).
750 command_category(inv_coverage,table).
751 command_additional_info(inv_coverage,group(coverage_info)).
752
753 command_description(vacuous_invariants,'Vacuous Invariants','Show list of vacuous invariants (i.e., implications or disjunctions wich are useless, given current explicit state space)').
754 command_call(vacuous_invariants,[Result],[],meta_interface:vacuous_invariants(Result)).
755 command_unavailable(vacuous_invariants,Txt) :- command_unavailable(b_mode,Txt).
756 command_arguments(vacuous_invariants,[table_result]).
757 command_category(vacuous_invariants,table).
758 :- public vacuous_invariants/1.
759 vacuous_invariants(Res) :-
760 tcltk_interface:tcltk_get_vacuous_invariants_table(Res).
761 command_additional_info(vacuous_invariants,group(coverage_info)).
762
763 command_description(specialized_invariants,'Specialized Invariants','Show list of invariants (specialized using proof information for each operation; used by ProB for faster model checking)').
764 command_call(specialized_invariants,[Result],[],meta_interface:specialized_invariants(Result)).
765 command_unavailable(specialized_invariants,Txt) :- command_unavailable(b_mode,Txt).
766 command_arguments(specialized_invariants,[table_result]).
767 command_category(specialized_invariants,table).
768 command_additional_info(specialized_invariants,group(debug_info)).
769 :- public specialized_invariants/1.
770 specialized_invariants(list([list(['Operation','Unproven','Predicate'])|LRes])) :-
771 bmachine:tcltk_get_specialized_invariants_for_ops(list(Res)),
772 maplist(wrap_into_list,Res,LRes).
773
774 wrap_into_list(list(L),R) :- !, R=list(L).
775 wrap_into_list([],R) :- !, R=list([]).
776 wrap_into_list([H|T],R) :- !, R=list([H|T]).
777 wrap_into_list(X,list([X])).
778
779 command_description(vacuous_guards,'Vacuous Guards','Show list of vacuous Guards (i.e., guards which cannot be individually false and are thus useless, given current explicit state space)').
780 command_call(vacuous_guards,[Result],[],meta_interface:vacuous_guards(Result)).
781 command_unavailable(vacuous_guards,Txt) :- command_unavailable(operations_events,Txt).
782 command_arguments(vacuous_guards,[table_result]).
783 command_category(vacuous_guards,table).
784 command_additional_info(vacuous_guards,group(coverage_info)).
785 :- public vacuous_guards/1.
786 vacuous_guards(list([list(['Vacuous Guards'])|LRes])) :-
787 tcltk_interface:tcltk_get_vacuous_guards(list(Res)),
788 maplist(wrap_into_list,Res,LRes).
789
790 :- use_module(extrasrc(mcdc_coverage),[tcltk_get_invariant_coverage/1,
791 tcltk_compute_mcdc_operation_coverage/1,
792 tcltk_compute_mcdc_invariant_coverage/1]).
793
794
795
796
797 command_description(read_write_matrix,'Operation Read/Write Matrix','Show identifiers read and written by operations').
798 command_call(read_write_matrix,[Result],[],b_read_write_info:tcltk_read_write_matrix(Result)).
799 command_unavailable(read_write_matrix,Txt) :- command_unavailable(operations_events,Txt).
800 command_arguments(read_write_matrix,[table_result]).
801 command_category(read_write_matrix,table).
802 command_additional_info(read_write_matrix,group(machine_info)).
803
804 command_description(variable_read_write_matrix,'Variable Read/Write Matrix','Show for variables which operations read and write them').
805 command_call(variable_read_write_matrix,[Result],[],b_read_write_info:tcltk_variable_read_write_matrix(no_check,Result)).
806 command_unavailable(variable_read_write_matrix,Txt) :- command_unavailable(variables,Txt).
807 command_arguments(variable_read_write_matrix,[table_result]).
808 command_category(variable_read_write_matrix,table).
809 command_additional_info(variable_read_write_matrix,group(machine_info)).
810
811
812
813 command_description(wd_pos,'WD POs','Show Well-Definedness Proof Obligations').
814 command_call(wd_pos,[Result],[],well_def_analyser:tcltk_get_machine_wd_pos(only_goal,Result,_,_)).
815 command_unavailable(wd_pos,Txt) :- command_unavailable(b_mode,Txt).
816 command_arguments(wd_pos,[table_result]).
817 command_category(wd_pos,table).
818 command_preferences_category(wd_pos,wd_commands). % e.g., TABLE_COLUMN_LIMIT preference
819 command_additional_info(wd_pos,group(wd_info)).
820
821 command_description(wd_pos_and_hyps,'WD POs and Hyps','Show Well-Definedness Proof Obligations and Hypotheses necessary for successful proof (for discharged POs)').
822 command_call(wd_pos_and_hyps,[Result],[],well_def_analyser:tcltk_get_machine_wd_pos(goal_and_hyps,Result,_,_)).
823 command_unavailable(wd_pos_and_hyps,Txt) :- command_unavailable(b_mode,Txt).
824 command_arguments(wd_pos_and_hyps,[table_result]).
825 command_category(wd_pos_and_hyps,table).
826 command_preferences_category(wd_pos_and_hyps,wd_commands).
827 command_additional_info(wd_pos_and_hyps,group(wd_info)).
828
829 command_description(det_check_constants,'Compute Forced Constants','Analyse which values of CONSTANTS are forced and optionally compute an explanation (i.e., core of PROPERTIES/axioms which imply the value)').
830 command_call(det_check_constants,[Result],[],b_state_model_check:tcltk_cbc_constants_det_check(Result)).
831 command_unavailable(det_check_constants,Txt) :- command_unavailable(constants,Txt).
832 command_arguments(det_check_constants,[table_result]).
833 command_category(det_check_constants,table).
834 command_preferences_category(det_check_constants,cbc_commands).
835 command_additional_info(det_check_constants,group(debug_info)).
836
837 command_description(unsat_core_properties,Title,Desc) :-
838 get_specification_description(properties,P),
839 atom_concat('Unsat Core of ',P,Title),
840 atom_concat('Analyse a minimal unsatisfiable core of the ',P,Desc).
841 command_call(unsat_core_properties,[Result],[],unsat_cores:unsat_core_properties_table(Result)).
842 command_unavailable(unsat_core_properties,Txt) :- command_unavailable(b_mode,Txt).
843 command_unavailable(unsat_core_properties,'only available for models with CONSTANTS or PROPERTIES/Axioms') :-
844 b_or_z_mode, \+ (b_machine_has_constants_or_properties).
845 command_arguments(unsat_core_properties,[table_result]).
846 command_category(unsat_core_properties,table).
847 command_preferences_category(unsat_core_properties,table_commands).
848 command_additional_info(unsat_core_properties,group(debug_info)).
849
850 command_description(visb_attributes,'VisB Items','Show VisB items which set SVG attributes based on current state').
851 command_call(visb_attributes,[Result],[],visb_visualiser:tcltk_get_visb_items(Result)).
852 command_unavailable(visb_attributes,'only available after a VisB file was loaded') :-
853 \+ visb_visualiser:visb_file_is_loaded(_).
854 command_arguments(visb_attributes,[table_result]).
855 command_category(visb_attributes,table).
856 command_preferences_category(visb_attributes,table_commands).
857 command_additional_info(visb_attributes,group(visb_info)).
858
859 command_description(visb_events,'VisB Events','Show VisB click events that are available in current state').
860 command_call(visb_events,[Result],[],visb_visualiser:tcltk_get_visb_events(Result)).
861 command_unavailable(visb_events,'only available after a VisB file was loaded') :-
862 \+ visb_visualiser:visb_file_is_loaded(_).
863 command_arguments(visb_events,[table_result]).
864 command_category(visb_events,table).
865 command_preferences_category(visb_events,table_commands).
866 command_additional_info(visb_events,group(visb_info)).
867
868 command_description(visb_objects,'VisB Objects','Show VisB SVG objects which were created in addition to the SVG file').
869 command_call(visb_objects,[Result],[],visb_visualiser:tcltk_get_visb_objects(Result)).
870 command_unavailable(visb_objects,'only available after a VisB file was loaded') :-
871 \+ visb_visualiser:visb_file_is_loaded(_).
872 command_arguments(visb_objects,[table_result]).
873 command_category(visb_objects,table).
874 command_preferences_category(visb_objects,table_commands).
875 command_additional_info(visb_objects,group(visb_info)).
876
877 command_description(visb_hovers,'VisB Hovers','Show VisB hovers with enter and exit values').
878 command_call(visb_hovers,[Result],[],visb_visualiser:tcltk_get_visb_hovers(Result)).
879 command_unavailable(visb_hovers,'only available after a VisB file was loaded') :-
880 \+ visb_visualiser:visb_file_is_loaded(_).
881 command_arguments(visb_hovers,[table_result]).
882 command_category(visb_hovers,table).
883 command_preferences_category(visb_hovers,table_commands).
884 command_additional_info(visb_hovers,group(visb_info)).
885
886 command_description(find_exact_value,'Find Value (Exact)...','Find exact value inside variables and constants').
887 command_call(find_exact_value,[Expression,Result],[],
888 tcltk_interface:tcltk_find_value_as_table(Expression,[exact],Result)).
889 command_unavailable(find_exact_value,Txt) :- command_unavailable(b_mode,Txt).
890 command_arguments(find_exact_value,[expression_atom,table_result]). % also accepts expression_raw_ast
891 command_category(find_exact_value,table).
892 command_additional_info(find_exact_value,group(debug_info)).
893
894 command_description(find_value,'Find Value (Prefix)...','Find value or prefix of value inside variables and constants').
895 command_call(find_value,[Expression,Result],[],
896 tcltk_interface:tcltk_find_value_as_table(Expression,[prefix],Result)). % exact, prefix, infix, suffix, fuzzy
897 command_unavailable(find_value,Txt) :- command_unavailable(b_mode,Txt).
898 command_arguments(find_value,[expression_atom,table_result]). % also accepts expression_raw_ast
899 command_category(find_value,table).
900 command_additional_info(find_value,group(debug_info)).
901
902 command_description(find_fuzzy_value,'Find Value (Fuzzy)...','Look for fuzzy matches (ignoring case) of value inside variables and constants').
903 command_call(find_fuzzy_value,[Expression,Result],[],
904 tcltk_interface:tcltk_find_value_as_table(Expression,[fuzzy],Result)). % exact, prefix, infix, suffix, fuzzy
905 command_unavailable(find_fuzzy_value,Txt) :- command_unavailable(b_mode,Txt).
906 command_arguments(find_fuzzy_value,[expression_atom,table_result]). % also accepts expression_raw_ast
907 command_category(find_fuzzy_value,table).
908 command_additional_info(find_fuzzy_value,group(debug_info)).
909
910
911 command_description(id_value_formula_tree,'Value of Identifier as Formula Tree...','Show value of an identifier as a formula tree (mainly useful for symbolic values)').
912 command_call(id_value_formula_tree,[ID,File],[],tcltk_interface:tcltk_show_identifier_value_as_dot_tree(ID,File)).
913 command_unavailable(id_value_formula_tree,Txt) :- command_unavailable(b_mode,Txt).
914 command_arguments(id_value_formula_tree,[expression_atom,dotfile]). % is actually predicate_atom, also accepts expression_raw_ast
915 command_category(id_value_formula_tree,dot).
916 command_preferences_category(id_value_formula_tree,dot_formula_tree).
917 command_additional_info(id_value_formula_tree,group(formula_visualisation)).
918
919
920 command_description(mcdc_coverage,'MC/DC Operation Coverage','Show MC/DC operation coverage').
921 command_call(mcdc_coverage,[Result],[],mcdc_coverage:tcltk_compute_mcdc_operation_coverage(Result)).
922 command_unavailable(mcdc_coverage,Txt) :- command_unavailable(operations_events,Txt).
923 command_arguments(mcdc_coverage,[table_result]).
924 command_category(mcdc_coverage,table).
925 command_preferences_category(mcdc_coverage,mc_dc_commands).
926 command_additional_info(mcdc_coverage,group(coverage_info)).
927
928 command_description(mcdc_inv_coverage,'MC/DC Invariant Coverage','Show MC/DC invariant coverage').
929 command_call(mcdc_inv_coverage,[Result],[],mcdc_coverage:tcltk_compute_mcdc_invariant_coverage(Result)).
930 command_unavailable(mcdc_inv_coverage,Txt) :- command_unavailable(b_mode,Txt).
931 command_arguments(mcdc_inv_coverage,[table_result]).
932 command_category(mcdc_inv_coverage,table).
933 command_preferences_category(mcdc_inv_coverage,mc_dc_commands).
934 command_additional_info(mcdc_inv_coverage,group(coverage_info)).
935
936 :- use_module(probsrc(runtime_profiler),[runtime_profile_available/0, tcltk_get_profile_info/2,constants_profiling_on/0,
937 tcltk_get_operations_profile_info/1, tcltk_get_constants_profile_info/1]).
938 command_description(prob_profile_info,'ProB Profile Info',
939 'Show runtime information for operations/events and invariants (in ms)').
940 command_call(prob_profile_info,[Result],[],runtime_profiler:tcltk_get_operations_profile_info(Result)).
941 command_unavailable(prob_profile_info,'no profiling information available, set PROFILING_INFO preference to TRUE') :-
942 \+ runtime_profile_available,!. % and possibly remove -Dprob_profile=false flag
943 command_unavailable(prob_profile_info,Txt) :-
944 get_preference(prob_source_profiling_on,false), % with prob_source_profiling we also profile ProB2-UI calls
945 command_unavailable(b_mode,Txt).
946 command_arguments(prob_profile_info,[table_result]). % also accepts expression_raw_ast
947 command_category(prob_profile_info,table).
948 command_additional_info(prob_profile_info,group(debug_info)).
949
950 command_description(prob_constants_profile_info,'ProB Constants Profile Info',
951 'Show runtime information for calculation of constants by equations in PROPERTIES/axioms (in ms)').
952 command_call(prob_constants_profile_info,[Result],[],runtime_profiler:tcltk_get_constants_profile_info(Result)).
953 command_unavailable(prob_constants_profile_info,
954 'no profiling information available, set PROFILING_INFO and PERFORMANCE_INFO preference to TRUE') :-
955 \+ runtime_profile_available,!.
956 command_unavailable(prob_constants_profile_info,Txt) :- command_unavailable(b_mode,Txt).
957 command_arguments(prob_constants_profile_info,[table_result]).
958 command_category(prob_constants_profile_info,table).
959 command_additional_info(prob_constants_profile_info,group(debug_info)).
960
961 command_description(prob_external_fun_profile_info,
962 'ProB External Functions Profile Info','Show runtime information for external function calls (in ms)').
963 command_call(prob_external_fun_profile_info,[Result],[],runtime_profiler:tcltk_get_profile_info(external_functions,Result)).
964 command_unavailable(prob_external_fun_profile_info,
965 'no profiling information available, set PROFILING_INFO preference to TRUE') :-
966 \+ runtime_profile_available,!. % and possibly remove -Dprob_profile=false flag
967 command_unavailable(prob_external_fun_profile_info,Txt) :- command_unavailable(b_mode,Txt).
968 command_arguments(prob_external_fun_profile_info,[table_result]).
969 command_category(prob_external_fun_profile_info,table).
970 command_additional_info(prob_external_fun_profile_info,group(debug_info)).
971
972 command_description(prob_cache_info,'ProB Persistent Cache Profile Info',
973 'Show runtime information for on disk caching of constants and operation calls (in ms)').
974 command_call(prob_cache_info,[Result],[],
975 runtime_profiler:tcltk_get_multiple_profile_infos(cache,Result)).
976 command_unavailable(prob_cache_info,'persistent cache not activated; provide -cache DIRECTORY at startup') :-
977 \+ value_persistance:cache_is_activated,!.
978 command_unavailable(prob_cache_info,'no profiling information available, set PROFILING_INFO preference to TRUE') :-
979 \+ runtime_profile_available,!. % and possibly remove -Dprob_profile=false flag
980 command_unavailable(prob_cache_info,Txt) :- command_unavailable(b_mode,Txt).
981 command_arguments(prob_cache_info,[table_result]).
982 command_category(prob_cache_info,table).
983 command_additional_info(prob_cache_info,group(debug_info)).
984
985 :- use_module(disproversrc(disprover),[prover_result_stats_available/0, prover_result_stats_table/1]).
986 command_description(disprover_statistics,'Disprover Statistics',
987 'Show statistics about the provers used by the disprover (e.g. the WD prover and the constraint solver) and their results: number of calls and times in ms, for all calls and for the last one').
988 command_call(disprover_statistics,[Result],[],disprover:prover_result_stats_table(Result)).
989 command_unavailable(disprover_statistics,'the disprover has not been called yet') :-
990 \+ prover_result_stats_available,!.
991 command_arguments(disprover_statistics,[table_result]).
992 command_category(disprover_statistics,table).
993 command_additional_info(disprover_statistics,group(debug_info)).
994
995 :- use_module(extrasrc(b_operation_cache),[tcltk_op_cache_stats/1]).
996 command_description(prob_opcache_info,'ProB Operation Caching Info','Show information for in memory operation caching, useful for model checking (see OPERATION_REUSE preference)').
997 command_call(prob_opcache_info,[Result],[],b_operation_cache:tcltk_op_cache_stats(Result)).
998 command_unavailable(prob_opcache_info,'only available when OPERATION_REUSE is TRUE or full.') :-
999 get_preference(operation_reuse_setting,false).
1000 command_unavailable(prob_opcache_info,Txt) :- command_unavailable(b_mode,Txt).
1001 command_arguments(prob_opcache_info,[table_result]).
1002 command_category(prob_opcache_info,table).
1003 command_additional_info(prob_opcache_info,group(debug_info)).
1004
1005
1006 command_description(prob_memo_profile,'ProB Memoization Info','Show information for memoized constants').
1007 command_call(prob_memo_profile,[Result],[],memoization:tcltk_get_memo_profile_table(Result)).
1008 command_unavailable(prob_memo_profile,Txt) :- command_unavailable(b_mode,Txt).
1009 command_arguments(prob_memo_profile,[table_result]).
1010 command_category(prob_memo_profile,table).
1011 command_additional_info(prob_memo_profile,group(debug_info)).
1012
1013 :- use_module(probsrc(bmachine_static_checks),[find_constant_expressions_in_operations/1]).
1014 command_description(constant_expr_analysis,Msg,
1015 'Detect potentially expensive constant expressions in operations/events (and could be unnecessarily computed multiple times)') :- (eventb_mode -> Msg = 'Constant Expressions in Events' ; Msg = 'Constant Expressions in Operations').
1016 command_call(constant_expr_analysis,[Result],[],bmachine_static_checks:find_constant_expressions_in_operations(Result)).
1017 command_unavailable(constant_expr_analysis,Txt) :- command_unavailable(b_mode,Txt).
1018 command_arguments(constant_expr_analysis,[table_result]).
1019 command_category(constant_expr_analysis,table).
1020 command_additional_info(constant_expr_analysis,group(debug_info)).
1021
1022
1023 % a few typical reasons why commands are not available:
1024 command_unavailable(constants,Txt) :- command_unavailable(b_mode,Txt).
1025 command_unavailable(constants,'only available for models with CONSTANTS') :-
1026 b_or_z_mode, \+ (b_machine_has_constants).
1027 command_unavailable(variables,Txt) :- command_unavailable(b_mode,Txt).
1028 command_unavailable(variables,'only available for models with VARIABLES') :-
1029 b_or_z_mode, \+ (b_machine_has_variables).
1030 command_unavailable(operations_events,Txt) :- command_unavailable(b_mode,Txt).
1031 command_unavailable(operations_events,Msg) :-
1032 b_or_z_mode, \+ (b_machine_has_operations),
1033 (eventb_mode
1034 -> Msg = 'only available for machines with events' % not for contexts
1035 ; Msg = 'only available for models with OPERATIONS').
1036 command_unavailable(b_mode,'only available for B,Z or Event-B models') :- \+ b_or_z_mode.