libgpr2_24.0.0_eda3c693/src/lib/gpr2-project-attribute_index.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
56
--
--  Copyright (C) 2019-2023, AdaCore
--
--  SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--

with Ada.Strings.Equal_Case_Insensitive;

package body GPR2.Project.Attribute_Index is

   use Ada.Strings;

   ---------
   -- "=" --
   ---------

   overriding function "=" (Left, Right : Object) return Boolean is
      Is_Others : constant Boolean :=
                    Left.Is_Others = Right.Is_Others;
      L_Text    : constant String :=
                    (if Source_Reference.Value.Object (Left).Is_Defined
                     then Left.Text
                     else "");
      R_Text    : constant String :=
                    (if Source_Reference.Value.Object (Right).Is_Defined
                     then Right.Text
                     else "");
   begin
      if L_Text = "" and then R_Text = "" then
         --  Empty index should be different from undefined index

         return Source_Reference.Value.Object (Left).Is_Defined
           = Source_Reference.Value.Object (Right).Is_Defined;
      end if;

      if Left.Case_Sensitive then
         return Is_Others and then L_Text = R_Text;

      else
         return Is_Others
           and then Equal_Case_Insensitive (L_Text, R_Text);
      end if;
   end "=";

   --------------
   -- Set_Case --
   --------------

   procedure Set_Case
     (Self              : in out Object;
      Is_Case_Sensitive : Boolean) is
   begin
      Self.Case_Sensitive := Is_Case_Sensitive;
   end Set_Case;

end GPR2.Project.Attribute_Index;