spat_1.3.0_4ad4ab14/src/util/spat-spark_files.ads

 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
------------------------------------------------------------------------------
--  Copyright (C) 2020 by Heisenbug Ltd. (gh+spat@heisenbug.eu)
--
--  This work is free. You can redistribute it and/or modify it under the
--  terms of the Do What The Fuck You Want To Public License, Version 2,
--  as published by Sam Hocevar. See the LICENSE file for more details.
------------------------------------------------------------------------------
pragma License (Unrestricted);

------------------------------------------------------------------------------
--
--  SPARK Proof Analysis Tool
--
--  S.P.A.T. - Read .spark files
--
--  Collect file contents.
--
--  Please note that Read is parallelized and uses background threads, hence
--  you need to call Shutdown once you're done, otherwise the application will
--  hang.
--
------------------------------------------------------------------------------

limited with Ada.Containers.Hashed_Maps;
limited with SPAT.Strings;

package SPAT.Spark_Files is

   --  .spark files are stored in a Hash map with the file name as key and the
   --  JSON reading result as value.
   package File_Maps is new Ada.Containers.Hashed_Maps
     (Key_Type        => SPARK_File_Name,
      Element_Type    => GNATCOLL.JSON.Read_Result,
      Hash            => Hash,
      Equivalent_Keys => "=",
      "="             => GNATCOLL.JSON."=");

   --
   --  Some renames for commonly used File_Maps.Cursor operations.
   --
   No_Element : File_Maps.Cursor renames File_Maps.No_Element;
   subtype Cursor is File_Maps.Cursor;

   ---------------------------------------------------------------------------
   --  Key
   ---------------------------------------------------------------------------
   function Key (C : in Cursor) return SPARK_File_Name renames File_Maps.Key;

   --
   --  Data collection and operations defined on it.
   --

   type T is new File_Maps.Map with private;
   --  Stores all data collected from SPARK files for analysis.

   ---------------------------------------------------------------------------
   --  Read
   ---------------------------------------------------------------------------
   not overriding
   procedure Read (This  : in out T;
                   Names : in     Strings.SPARK_File_Names);
   --  Reads the list of files, and parses and stores their content in This.

   ---------------------------------------------------------------------------
   --  Num_Workers
   --
   --  Report the number of tasks used for parallel file reads.
   ---------------------------------------------------------------------------
   function Num_Workers return Positive;

   ---------------------------------------------------------------------------
   --  Shutdown
   --
   --  Terminates all worker tasks.
   ---------------------------------------------------------------------------
   procedure Shutdown;

private

   type T is new File_Maps.Map with null record;

end SPAT.Spark_Files;