septum_0.0.8_6dbc8e6b/src/common/sp-contexts.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
-------------------------------------------------------------------------------
-- Copyright 2021, The Septum Developers (see AUTHORS file)

-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at

--     http://www.apache.org/licenses/LICENSE-2.0

-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-------------------------------------------------------------------------------

with Ada.Containers.Ordered_Sets;
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded;

with SP.Strings;

package SP.Contexts
    with Preelaborate
is

    package Line_Matches is new Ada.Containers.Ordered_Sets (Element_Type => Positive);

    type Context_Match is record
        File_Name        : Ada.Strings.Unbounded.Unbounded_String;
        Internal_Matches : Line_Matches.Set;
        Minimum          : Positive;
        Maximum          : Positive;
    end record;

    function From
        (File_Name : String; Line : Natural; Num_Lines : Natural; Context_Width : Natural) return Context_Match with
        Pre  => Line <= Num_Lines,
        Post => Is_Valid (From'Result);

    function Real_Min (C : Context_Match) return Positive with
        Pre  => Is_Valid (C),
        Post => C.Minimum <= Real_Min'Result and then Real_Min'Result <= C.Maximum;

    function Real_Max (C : Context_Match) return Positive with
        Pre  => Is_Valid (C),
        Post => C.Minimum <= Real_Max'Result and then Real_Max'Result <= C.Maximum;

    function Is_Valid (C : Context_Match) return Boolean;

    function Overlap (A, B : Context_Match) return Boolean with
        Pre => Is_Valid (A) and then Is_Valid (B);

    function Contains (A : Context_Match; Line_Num : Positive) return Boolean with
        Pre => Is_Valid (A);

    function Contains (A, B : Context_Match) return Boolean with
        Pre => Is_Valid (A) and then Is_Valid (B);

    function Merge (A, B : Context_Match) return Context_Match with
        Pre  => Is_Valid (A) and then Is_Valid (B),
        Post => Is_Valid (Merge'Result);

    function Image (A : Context_Match) return String with
        Pre => Is_Valid (A);

    overriding
    function "="(A, B : Context_Match) return Boolean with
        Pre => Is_Valid (A) and then Is_Valid (B);

    package Context_Vectors is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => Context_Match);

    function Files_In (V : Context_Vectors.Vector) return SP.Strings.String_Sets.Set;

end SP.Contexts;