langkit_support_25.0.0_7c5f4981/testsuite/tests/ada_api/generic_api/hash.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
with Ada.Containers.Hashed_Maps;
with Ada.Text_IO; use Ada.Text_IO;

with Langkit_Support.Generic_API; use Langkit_Support.Generic_API;
with Langkit_Support.Generic_API.Analysis;
use Langkit_Support.Generic_API.Analysis;

with Libfoolang.Generic_API;

procedure Hash is
   Id : Language_Id renames Libfoolang.Generic_API.Foo_Lang_Id;

   package Context_Maps is new Ada.Containers.Hashed_Maps
     (Lk_Context, Integer, Hash, "=");
   package Unit_Maps is new Ada.Containers.Hashed_Maps
     (Lk_Unit, Integer, Hash, "=");
   package Node_Maps is new Ada.Containers.Hashed_Maps
     (Lk_Node, Integer, Hash, "=");
   package Token_Maps is new Ada.Containers.Hashed_Maps
     (Lk_Token, Integer, Hash, "=");

   Ctx  : constant Lk_Context := Create_Context (Id);
   Ctx2 : constant Lk_Context := Create_Context (Id);
   U    : constant Lk_Unit := Ctx.Get_From_File ("example.txt");
   U2   : constant Lk_Unit := Ctx2.Get_From_File ("example2.txt");
   N    : constant Lk_Node := U.Root;
   N2   : constant Lk_Node := U2.Root;
   T    : constant Lk_Token := N.Token_Start;
   T2   : constant Lk_Token := N2.Token_Start;

   Context_Map : Context_Maps.Map;
   Unit_Map    : Unit_Maps.Map;
   Node_Map    : Node_Maps.Map;
   Token_Map   : Token_Maps.Map;
begin
   Context_Map.Insert (Ctx, 1);
   Context_Map.Insert (Ctx2, 2);
   if Context_Map.Element (Ctx) /= 1 then
      raise Program_Error;
   end if;
   if Context_Map.Element (U2.Context) /= 2 then
      raise Program_Error;
   end if;

   Unit_Map.Insert (U, 1);
   Unit_Map.Insert (U2, 2);
   if Unit_Map.Element (U) /= 1 then
      raise Program_Error;
   end if;
   if Unit_Map.Element (N2.Unit) /= 2 then
      raise Program_Error;
   end if;

   Node_Map.Insert (N, 1);
   Node_Map.Insert (N2, 2);
   if Node_Map.Element (N) /= 1 then
      raise Program_Error;
   end if;
   if Node_Map.Element (U2.Root) /= 2 then
      raise Program_Error;
   end if;

   Token_Map.Insert (T, 1);
   Token_Map.Insert (T2, 2);
   if Token_Map.Element (T) /= 1 then
      raise Program_Error;
   end if;
   if Token_Map.Element (N2.Token_Start) /= 2 then
      raise Program_Error;
   end if;

   Put_Line ("hash.adb: no error");
   New_Line;
end Hash;