File: load__data_files.pro

package info (click to toggle)
spark 2012.0.deb-9
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 29,260 kB
  • ctags: 3,098
  • sloc: ada: 186,243; cpp: 13,497; makefile: 685; yacc: 440; lex: 176; ansic: 119; sh: 16
file content (598 lines) | stat: -rw-r--r-- 23,215 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
% -----------------------------------------------------------------------------
%  (C) Altran Praxis Limited
% -----------------------------------------------------------------------------
% 
%  The SPARK toolset is free software; you can redistribute it and/or modify it
%  under terms of the GNU General Public License as published by the Free
%  Software Foundation; either version 3, or (at your option) any later
%  version. The SPARK toolset is distributed in the hope that it will be
%  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
%  Public License for more details. You should have received a copy of the GNU
%  General Public License distributed with the SPARK toolset; see file
%  COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy of
%  the license.
% 
% =============================================================================

%###############################################################################
% PURPOSE
%-------------------------------------------------------------------------------
% Establishes the names of all files for this session, based on the
% arguments provided on the command line and the parent directory.
%###############################################################################




%###############################################################################
% MODULE
%###############################################################################

:- module(load__data_files, [load_data_files/0]).

%###############################################################################
% DEPENDENCIES
%###############################################################################

:- use_module('librarypredicates.pro',
              [file_exists/1]).

:- use_module('data__switches.pro', [get_switch_deadpaths/1,
                                     get_switch_input_file/1,
                                     get_switch_log/1]).
:- use_module('data__data_files.pro', [get_datafiles_vcg/1,
                                       add_datafiles_vcg/1,
                                       get_datafiles_dpc/1,
                                       add_datafiles_dpc/1,
                                       get_datafiles_simplified_vcg/1,
                                       add_datafiles_simplified_vcg/1,
                                       get_datafiles_summary_dpc/1,
                                       add_datafiles_summary_dpc/1,
                                       get_datafiles_fdl/1,
                                       add_datafiles_fdl/1,
                                       get_datafiles_local_user_rule/1,
                                       add_datafiles_local_user_rule/1,
                                       get_datafiles_global_user_rule/1,
                                       add_datafiles_global_user_rule/1,
                                       get_datafiles_rule/1,
                                       add_datafiles_rule/1,
                                       get_datafiles_pfs/1,
                                       add_datafiles_pfs/1,
                                       get_datafiles_simplified_pfs/1,
                                       add_datafiles_simplified_pfs/1,
                                       get_datafiles_dec/1,
                                       add_datafiles_dec/1,
                                       get_datafiles_log/1,
                                       add_datafiles_log/1,
                                       add_datafiles_debug/2]).
:- use_module('ioutilities.pro',
              [show_error/2]).
:- use_module('newutilities.pro',
              [explode_separator_content_as_list/3,
               implode_separator_content_list/3]).

:- use_module('simplifier_ioutilities.pro',
              [retrieve_proof_file_kind/1]).

%###############################################################################
% TYPES
%###############################################################################

%###############################################################################
% DATA
%###############################################################################

%###############################################################################
% PREDICATES
%###############################################################################


:- set_prolog_flag(double_quotes, chars).

%===============================================================================
% load_data_files.
%-------------------------------------------------------------------------------
%Based on known information, determine and store the name of every file
%that may be used.
%===============================================================================

load_data_files:-

    % Establish all of the file names for this session.
    establish_static_files,
    establish_dynamic_files,
    !.

%===============================================================================
% establish_static_files.
%-------------------------------------------------------------------------------
% Calculate and store all of the hard-coded static files. It is expected
% that these files will only be used internally for debugging purposes.
%===============================================================================
establish_static_files:-

    %Add all debug files.
    establish_debug_file(data__prf),
    establish_debug_file(data__vcg),
    establish_debug_file(data__files),
    !.

%-------------------------------------------------------------------------------

%Adds a debug file in a consistent manner.
establish_debug_file(DebugFileKind):-
    implode_separator_content_list('',
                                   ['debug_', DebugFileKind, '.pro'],
                                   DebugFile_Atom),
    absolute_file_name(DebugFile_Atom, AbsoluteDebugFile_Atom),
    add_datafiles_debug(DebugFileKind, AbsoluteDebugFile_Atom),
    !.

%===============================================================================
% establish_dynamic_files.
%-------------------------------------------------------------------------------
% Calculate and store all of the files, whose location depends on
% changeable information.
%===============================================================================

% Input file has not been provided.
establish_dynamic_files:-
    \+ get_switch_input_file(_InputFile_Atom),
    show_error('Target file not provided on the command-line.', []).

% Input file has been provided.
establish_dynamic_files:-
    get_switch_input_file(InputFile_Atom),

    %The provided input file will use the syntax relevant for the current
    %platform. The input file provided may be relative to the current
    %directory, or rooted to some point in the filesystem. To treat the
    %platform specific relative or rooted file name consistently it is
    %always put into its absolute form, via a platform portable predicate.
    absolute_file_name(InputFile_Atom, AbsoluteInputFile_Atom),

    %Determine the proof file kind.
    proof_file_info(AbsoluteInputFile_Atom,
                    ProofFileKind,
                    AbsoluteDirectory_Atom,
                    BaseFile_Atom),

    establish_proof_file_dependent_files(ProofFileKind,
                                         AbsoluteDirectory_Atom,
                                         BaseFile_Atom),
    establish_common_files(AbsoluteDirectory_Atom,
                           BaseFile_Atom),
    !.

% None of the above is an error.
establish_dynamic_files:-
    show_error('Unexpected error in establishing input file details.', []).

%-------------------------------------------------------------------------------

%Set up files for verification conditions.
establish_proof_file_dependent_files(verification_conditions,
                                     AbsoluteDirectory_Atom,
                                     BaseFile_Atom):-

    %Mandatory input files.
    %----------------------

    %.vcg file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.vcg'],
                                   VcgFile_Atom),
    ensure_datafile_exists(VcgFile_Atom),
    add_datafiles_vcg(VcgFile_Atom),

    %.fdl file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.fdl'],
                                   FdlFile_Atom),
    ensure_datafile_exists(FdlFile_Atom),
    add_datafiles_fdl(FdlFile_Atom),

    %Optional input files.
    %---------------------

    % Although the current examiner always generates VCs with a supporting
    % rls file, this has not always been the case. Thus, the rls files are
    % optional.

    %.rls file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.rls'],
                                   RuleFile_Atom),
    potentially_add_datafiles_rule(RuleFile_Atom),

    %.rlu file (local)
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.rlu'],
                                   LocalUserRuleFile_Atom),
    potentially_add_datafiles_local_user_rule(LocalUserRuleFile_Atom),

    %.rlu file (global)
    retrieve_parent_directory(AbsoluteDirectory_Atom,
                              ParentDirectory_Atom),
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, ParentDirectory_Atom, '.rlu'],
                                   GlobalUserRuleFile_Atom),
    potentially_add_datafiles_global_user_rule(LocalUserRuleFile_Atom,
                                               GlobalUserRuleFile_Atom),

    %Mandatory output files.
    %-----------------------

    %.siv file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.siv'],
                                   SimplifiedVcgFile_Atom),
    add_datafiles_simplified_vcg(SimplifiedVcgFile_Atom),
    !.

% Set up files for dead path search.
establish_proof_file_dependent_files(zombie_scope,
                                     AbsoluteDirectory_Atom,
                                     BaseFile_Atom):-
    %Mandatory input files.
    %----------------------

    %.dpc file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.dpc'],
                                   DpcFile_Atom),
    ensure_datafile_exists(DpcFile_Atom),
    add_datafiles_dpc(DpcFile_Atom),

    %.fdl file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.fdl'],
                                   FdlFile_Atom),
    ensure_datafile_exists(FdlFile_Atom),
    add_datafiles_fdl(FdlFile_Atom),

    %Optional input files.
    %---------------------

    % Although the current examiner always generates VCs with a supporting
    % rls file, this has not always been the case. Thus, the rls files are
    % optional.

    %.rls file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.rls'],
                                   RuleFile_Atom),
    potentially_add_datafiles_rule(RuleFile_Atom),

    %Mandatory output files.
    %-----------------------

    %.sdp file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.sdp'],
                                   SummaryDpcFile_Atom),
    add_datafiles_summary_dpc(SummaryDpcFile_Atom),

    !.




%Set up files for path functions.
establish_proof_file_dependent_files(path_functions,
                                     AbsoluteDirectory_Atom,
                                     BaseFile_Atom):-

    %Mandatory input files.
    %----------------------

    %.pfs file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.pfs'],
                                   PfsFile_Atom),
    ensure_datafile_exists(PfsFile_Atom),
    add_datafiles_pfs(PfsFile_Atom),

    %.dec file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.dec'],
                                   DecFile_Atom),
    ensure_datafile_exists(DecFile_Atom),
    add_datafiles_dec(DecFile_Atom),

    %Mandatory output files.
    %-----------------------

    %.sip file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.sip'],
                                   SimplifiedPfsFile_Atom),
    add_datafiles_simplified_pfs(SimplifiedPfsFile_Atom),
    !.



%None of the above is unexpected.
establish_proof_file_dependent_files(ProofFileKind,
                                     _AbsoluteDirectory_Atom,
                                     _BaseFile_Atom):-
    show_error('Unexpected proof file kind: ~p.', [ProofFileKind]).


%-------------------------------------------------------------------------------

ensure_datafile_exists(File_Atom):-
    file_exists(File_Atom),
    !.

ensure_datafile_exists(File_Atom):-
    show_error('Required input file does not exist: ~a.', [File_Atom]).

%-------------------------------------------------------------------------------

potentially_add_datafiles_rule(RuleFile_Atom):-
    file_exists(RuleFile_Atom),
    add_datafiles_rule(RuleFile_Atom),
    !.

% From above, file does not exist, so do not add.
potentially_add_datafiles_rule(_RuleFile_Atom):-
    !.

%-------------------------------------------------------------------------------

potentially_add_datafiles_local_user_rule(LocalUserRuleFile_Atom):-
    file_exists(LocalUserRuleFile_Atom),
    add_datafiles_local_user_rule(LocalUserRuleFile_Atom),
    !.

% From above, file does not exist, so do not add.
potentially_add_datafiles_local_user_rule(_LocalUserRuleFile_Atom):-
    !.

%-------------------------------------------------------------------------------

potentially_add_datafiles_global_user_rule(LocalUserRuleFile_Atom,
                                           GlobalUserRuleFile_Atom):-

    % While unusual, it is possible for the optional user rule input files
    % to be exactly the same. In this case the global usr rule file is not
    % added. (For example, the examiner may generate false VCs following a
    % semantic error.  It is a semantic error in SPARK for a package to
    % have a subprogram with the same name. In this case the examiner
    % generates false VCs for the subprogram, using the same name as its
    % package, creating potential duplicate same name for the local and
    % global user rule files).
    %







    \+ (LocalUserRuleFile_Atom = GlobalUserRuleFile_Atom),
    file_exists(GlobalUserRuleFile_Atom),
    add_datafiles_global_user_rule(GlobalUserRuleFile_Atom),
    !.

% From above, file does not exist, so do not add.
potentially_add_datafiles_global_user_rule(_LocalUserRuleFile_Atom,
                                           _GlobalUserRuleFile_Atom):-
    !.

%-------------------------------------------------------------------------------

establish_common_files(AbsoluteDirectory_Atom,
                       BaseFile_Atom):-
    establish_log_file(AbsoluteDirectory_Atom,
                       BaseFile_Atom),
    !.

%-------------------------------------------------------------------------------

% Log file requested. Use default name.
% Log file is slg when Simplifier is discharging VCs and zlg when Simplifier
% is searching for dead paths,

establish_log_file(AbsoluteDirectory_Atom,
                   BaseFile_Atom):-
    get_switch_deadpaths(off),
    get_switch_log(yes_log_file),

    %.slg file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.slg'],
                                   LogFile_Atom),
    add_datafiles_log(LogFile_Atom),
    !.

establish_log_file(AbsoluteDirectory_Atom,
                   BaseFile_Atom):-
    get_switch_deadpaths(on),
    get_switch_log(yes_log_file),

    %.zlg file
    implode_separator_content_list('',
                                   [AbsoluteDirectory_Atom, BaseFile_Atom, '.zlg'],
                                   LogFile_Atom),
    add_datafiles_log(LogFile_Atom),
    !.

% Log file requested, with specific name.
establish_log_file(_AbsoluteDirectory_Atom,
                   _BaseFile_Atom):-
    get_switch_log(provided_log_file(LogFile_Atom)),

    % To treat the platform specific relative or rooted file name
    % consistently it is always put into its absolute form, via a platform
    % portable predicate.
    absolute_file_name(LogFile_Atom, AbsoluteLogFile_Atom),
    add_datafiles_log(AbsoluteLogFile_Atom),
    !.

% User has specified that no log be used.
establish_log_file(_AbsoluteDirectory_Atom,
                   _BaseFile_Atom):-
    get_switch_log(no_log_file),
    !.

% None of the above is an error.
establish_log_file(_AbsoluteDirectory_Atom,
                   _BaseFile_Atom):-
    show_error('Unable to determine correct logging behaviour.',
                []).

%===============================================================================
% proof_file_info(+AbsoluteInputFile_Atom,
%                 -ProofFileKind,
%                 -AbsoluteDirectory_Atom,
%                 -BaseFile_Atom).
%-------------------------------------------------------------------------------
% Given an input file (AbsoluteInputFile_Atom) determine its proof file
% kind (ProofFileKind) and its absolute directory (with trailing '/') and
% its base file name (BaseFile_Atom). Note that if the proof file kind can
% not be determined from the file name, it is assumed that the extension
% '.vcg' is missing and corrects aspects accordingly. Note that sicstus
% uses '/' as the directory separator, regardless of whatever the platform
% uses.
%
% For example:
% AbsoluteInputFile_Atom=U:/one/two/three/four.vcg
% ProofFileKind=verification_conditions
% AbsoluteDirectory_Atom=U:/one/two/three/
% BaseFile_Atom=four
%
% For example:
% AbsoluteInputFile_Atom=U:/one/two/three/six
% ProofFileKind=verification_conditions
% AbsoluteDirectory_Atom=U:/one/two/three/
% BaseFile_Atom=six
%===============================================================================

proof_file_info(AbsoluteInputFile_Atom,
                ProofFileKind,
                AbsoluteDirectory_Atom,
                BaseFile_Atom):-

    %Retrieve the directory parts and file part.
    explode_separator_content_as_list('/',
                                      AbsoluteInputFile_Atom,
                                      Item_AtomList),

    %The last part is the file part.
    append(Directory_AtomList, [File_Atom], Item_AtomList),
    determine_proof_file_kind_and_base_file(File_Atom,
                                            ProofFileKind,
                                            BaseFile_Atom),

    %Reassemble the directory part.
    implode_separator_content_list('/',
                                   Directory_AtomList,
                                   AbsoluteDirectoryLessTrailing_Atom),

    %Add the trailing '/'.
    atom_concat(AbsoluteDirectoryLessTrailing_Atom,
                '/',
                AbsoluteDirectory_Atom),
    !.

%-------------------------------------------------------------------------------

determine_proof_file_kind_and_base_file(File_Atom,
                                        ProofFileKind,
                                        BaseFile_Atom):-
    atom_chars(File_Atom, File_CharList),
    determine_proof_file_kind_and_base_file_x(File_CharList,
                                              ProofFileKind,
                                              BaseFile__CharList),
    atom_chars(BaseFile_Atom, BaseFile__CharList),
    !.

%-------------------------------------------------------------------------------

% If deadpath switch is off.

% Without extension, verification_conditions is the default.
determine_proof_file_kind_and_base_file_x(File__BaseFile__CharList,
                                          verification_conditions,
                                          File__BaseFile__CharList):-
    get_switch_deadpaths(off),
    \+ member('.', File__BaseFile__CharList),
    !.

% With explicit vcg extension is verification_conditions.
determine_proof_file_kind_and_base_file_x(File_CharList,
                                          verification_conditions,
                                          BaseFile_CharList):-
    get_switch_deadpaths(off),
    append(BaseFile_CharList, ".vcg", File_CharList),
    !.

% If dead path switch is on

% Without extension deadpath_search.
determine_proof_file_kind_and_base_file_x(File__BaseFile__CharList,
                                          zombie_scope,
                                          File__BaseFile__CharList):-
    get_switch_deadpaths(on),
    \+ member('.', File__BaseFile__CharList),
    !.

% With explicit dpc extension
determine_proof_file_kind_and_base_file_x(File_CharList,
                                          zombie_scope,
                                          BaseFile_CharList):-
    get_switch_deadpaths(on),
    append(BaseFile_CharList, ".dpc", File_CharList),
    !.



% With explicit pfs extension is path_functions.
determine_proof_file_kind_and_base_file_x(File_CharList,
                                          path_functions,
                                          BaseFile_CharList):-
    append(BaseFile_CharList, ".pfs", File_CharList),
    !.



% Any other extension is treated as an error.
determine_proof_file_kind_and_base_file_x(File_CharList,
                                          _ProofFileKind,
                                          _BaseFile_CharList):-
    atom_chars(File_Atom, File_CharList),
    show_error('Provided input file ~a should have no extension or have a .vcg or .pfs extension.',
               [File_Atom]).

%===============================================================================
% retrieve_parent_directory(+AbsoluteDirectory_Atom,
%                           -ParentDirectory_Atom).
%-------------------------------------------------------------------------------
% Given an absolute directory (with trailing '/') determine the parent
% directory name.
%
% For example:
% AbsoluteDirectory_Atom=U:/one/two/three/
% ParentDirectory_Atom=three
%===============================================================================

retrieve_parent_directory(AbsoluteDirectory_Atom,
                          ParentDirectory_Atom):-

    %Retrieve the directory parts and file part.
    explode_separator_content_as_list('/',
                                      AbsoluteDirectory_Atom,
                                      Item_AtomList),
    append(_LeadingItem_AtomList,
           [ParentDirectory_Atom, _TopDirectory_Atom],
           Item_AtomList),
    !.


:- set_prolog_flag(double_quotes, codes).

%###############################################################################
% END-OF-FILE