File: gnatcoll-any_types.ads

package info (click to toggle)
libgnatcoll 18-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 5,068 kB
  • sloc: ada: 40,393; python: 354; ansic: 310; makefile: 245; sh: 31
file content (77 lines) | stat: -rw-r--r-- 3,222 bytes parent folder | download | duplicates (2)
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
------------------------------------------------------------------------------
--                             G N A T C O L L                              --
--                                                                          --
--                     Copyright (C) 2009-2017, AdaCore                     --
--                                                                          --
-- This library is free software;  you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software  Foundation;  either version 3,  or (at your  option) any later --
-- version. This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
------------------------------------------------------------------------------

--  This package provides a few utilities to manipulate types that can have
--  multiple forms. In particular this is used to provide a convenient way
--  of manipulating Python objects, without having the need to manipulate
--  PyObject in the Ada code.
--  See GNATCOLL.Any_Types.Python.

with Ada.Unchecked_Deallocation;
with Interfaces.C;

package GNATCOLL.Any_Types is

   --------------
   -- Any_Type --
   --------------

   --  This type provides an Ada encapsulation of certain types

   type Types is (No_Type,
                  Integer_Type,
                  String_Type,
                  Tuple_Type,
                  List_Type);

   type Any_Type;
   type Any_Type_Access is access Any_Type;

   type Any_Type_Array is array (Natural range <>) of Any_Type_Access;

   type Any_Type (T : Types; Length : Natural) is record
      case T is
         when No_Type =>
            null;
         when Integer_Type =>
            Int : Interfaces.C.long;
         when String_Type =>
            Str : String (1 .. Length);
         when Tuple_Type =>
            Tuple : Any_Type_Array (1 .. Length);
         when List_Type =>
            List  : Any_Type_Array (1 .. Length);
      end case;
   end record;

   procedure Free (X : in out Any_Type);
   --  Free memory associated to X

   Empty_Any_Type : constant Any_Type := (No_Type, 0);

private

   procedure Unchecked_Free is new Ada.Unchecked_Deallocation
     (Any_Type, Any_Type_Access);

end GNATCOLL.Any_Types;