libgpr2_24.0.0_eda3c693/src/lib/gpr2-source_info-parser-registry.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
--
--  Copyright (C) 2019-2023, AdaCore
--
--  SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--

with Ada.Containers.Indefinite_Ordered_Maps;

--  We must include here all the parser engine for them to be registered as
--  there is no other places where those are withed.

pragma Warnings (Off);
with GPR2.Source_Info.Parser.ALI;
with GPR2.Source_Info.Parser.Ada_Language;
with GPR2.Source_Info.Parser.D;
pragma Warnings (On);

package body GPR2.Source_Info.Parser.Registry is

   package Parser_Set is new Ada.Containers.Indefinite_Ordered_Maps
     (Name_Type, Object_Ref);

   Parser_Store : Parser_Set.Map;
   --  Record all parser for given language and kind

   function Key (Language : Language_Id; Kind : Backend) return Name_Type is
     (GPR2."&" (Name (Language), Name_Type ("@" & Backend'Image (Kind))));
   --  The key used in the parser store

   -----------------
   -- Clear_Cache --
   -----------------

   procedure Clear_Cache is
   begin
      for P of Parser_Store loop
         P.Clear_Cache;
      end loop;
   end Clear_Cache;

   ------------
   -- Exists --
   ------------

   function Exists (Language : Language_Id; Kind : Backend) return Boolean is
   begin
      if Kind = None then
         for K in Implemented_Backend loop
            if Parser_Store.Contains (Key (Language, K)) then
               return True;
            end if;
         end loop;

         return False;

      else
         return Parser_Store.Contains (Key (Language, Kind));
      end if;
   end Exists;

   ---------
   -- Get --
   ---------

   function Get
     (Language : Language_Id; Kind : Backend)
      return not null access Object'Class is
   begin
      return Parser_Store (Key (Language, Kind));
   end Get;

   --------------
   -- Register --
   --------------

   procedure Register (Parser : Object'Class) is
   begin
      Parser_Store.Insert
        (Key (Parser.Language, Parser.Kind), Parser.Self);
   end Register;

   ----------------
   -- Unregister --
   ----------------

   procedure Unregister (Parser : Object'Class) is
   begin
      Parser_Store.Delete (Key (Parser.Language, Parser.Kind));
   end Unregister;

end GPR2.Source_Info.Parser.Registry;