protobuf_1.0.0_43962766/source/compiler/compiler-context.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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--  MIT License
--
--  Copyright (c) 2020 Max Reznik
--
--  Permission is hereby granted, free of charge, to any person obtaining a
--  copy of this software and associated documentation files (the "Software"),
--  to deal in the Software without restriction, including without limitation
--  the rights to use, copy, modify, merge, publish, distribute, sublicense,
--  and/or sell copies of the Software, and to permit persons to whom the
--  Software is furnished to do so, subject to the following conditions:
--
--  The above copyright notice and this permission notice shall be included in
--  all copies or substantial portions of the Software.
--
--  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
--  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
--  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
--  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
--  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
--  DEALINGS IN THE SOFTWARE.

with Ada.Containers.Hashed_Maps;
with Ada.Containers.Ordered_Sets;

with Ada_Pretty;

with League.Strings;
with League.Strings.Hash;

with Google.Protobuf.Descriptor;
with Google.Protobuf.Compiler.Plugin;

package Compiler.Context is

   Is_Proto_2 : Boolean := True;
   --  Proto version of current file

   Factory : aliased Ada_Pretty.Factory;
   --  Node factory for pretty printing generated sources

   package String_Sets is new Ada.Containers.Ordered_Sets
     (League.Strings.Universal_String,
      "<" => League.Strings."<",
      "=" => League.Strings."=");
   --  Set of strings

   Fake : String_Sets.Set;
   --  Set of id for each field that breaks circular usage.

   type Ada_Type_Name is record
      Package_Name : League.Strings.Universal_String;
      Type_Name    : League.Strings.Universal_String;
   end record;

   function "+" (Self : Ada_Type_Name) return League.Strings.Universal_String;
   --  Join package name (if any) and type name into selected name.

   function Relative_Name
     (Full_Name : League.Strings.Universal_String;
      Current_Package : League.Strings.Universal_String)
      return League.Strings.Universal_String;
   --  Try to avoid wrong interpretation of selected Full_Name when it's
   --  used from Current_Package. Example:
   --  Full_Name => Conformance.Conformance.Type_Name
   --  Current_Package => Conformance.Conformance
   --  Result => Conformance.Type_Name

   type Enumeration_Information is record
      Min, Max : Integer;  --  Minimum and maximum representation value
      Default  : League.Strings.Universal_String;  --  Default value
   end record;

   type Named_Type (Is_Enumeration : Boolean := False) is record
      Ada_Type : Ada_Type_Name;

      case Is_Enumeration is
         when True =>
            Enum : Enumeration_Information;
         when False =>
            null;
            --  Message : Google.Protobuf.Descriptor_Proto;
      end case;
   end record;

   package Named_Type_Maps is new Ada.Containers.Hashed_Maps
     (League.Strings.Universal_String,
      Named_Type,
      League.Strings.Hash,
      League.Strings."=");

   Named_Types : Named_Type_Maps.Map;

   procedure Populate_Named_Types
     (Request : Google.Protobuf.Compiler.Plugin.Code_Generator_Request;
      Map     : in out Compiler.Context.Named_Type_Maps.Map);
   --  Fill Map with type information found in Request

   function Get_File
     (Request : Google.Protobuf.Compiler.Plugin.Code_Generator_Request;
      Name    : League.Strings.Universal_String)
      return Google.Protobuf.Descriptor.File_Descriptor_Proto;
   --  Find file by Name in the Request

   function To_Ada_Name
     (Text : League.Strings.Universal_String)
      return League.Strings.Universal_String;
   --  Convert text to look like an Ada Name

   function To_Selected_Ada_Name
     (Text : League.Strings.Universal_String)
      return League.Strings.Universal_String;
   --  Convert text to look like a selected Ada Name

end Compiler.Context;