spat_1.3.0_4ad4ab14/src/core/spat-entity_location.adb

 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
------------------------------------------------------------------------------
--  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);

with Ada.Strings.Fixed;

package body SPAT.Entity_Location is

   ---------------------------------------------------------------------------
   --  "<"
   --
   --  Compares to locations and returns True for the one which comes first,
   --  either by file name, line number and then column number.
   ---------------------------------------------------------------------------
   not overriding
   function "<" (Left  : in T;
                 Right : in T) return Boolean is
   begin
      if Left.Source_File = Right.Source_File then
         if Left.Source_Line = Right.Source_Line then
            return Left.Column < Right.Column;
         end if;

         return Left.Source_Line < Right.Source_Line;
      end if;

      return Left.Source_File < Right.Source_File;
   end "<";

   ---------------------------------------------------------------------------
   --  Create
   ---------------------------------------------------------------------------
   overriding
   function Create (Object : in JSON_Value) return T is
     (Entity_Line.Create (Object => Object) with
        Column => Object.Get (Field => Field_Names.Column));

   ---------------------------------------------------------------------------
   --  Image
   ---------------------------------------------------------------------------
   overriding
   function Image (This : T) return String is
   begin
      return
        Entity_Line.T (This).Image & ":" &
        Ada.Strings.Fixed.Trim (Source => This.Column'Image,
                                Side   => Ada.Strings.Both);
   end Image;

end SPAT.Entity_Location;