Debian Codegraph @

gcc/ada/libgnat/s-imagen.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . I M A G E _ N --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2021-2025, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 with Ada.Unchecked_Conversion;
33
34 package body System.Image_N is
35
36 -----------------------
37 -- Image_Enumeration --
38 -----------------------
39
40 procedure Image_Enumeration
41 (Pos : Natural;
42 S : in out String;
43 P : out Natural;
44 Names : String;
45 Indexes : System.Address)
46 is
47 pragma Assert (S'First = 1);
48
49 subtype Names_Index is
50 Index_Type range Index_Type (Names'First)
51 .. Index_Type (Names'Last) + 1;
52 subtype Index is Natural range Natural'First .. Names'Length;
53 type Index_Table is array (Index) of Names_Index;
54 type Index_Table_Ptr is access Index_Table;
55
56 function To_Index_Table_Ptr is
57 new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr);
58
59 IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes);
60
61 pragma Assert (Pos in IndexesT'Range);
62 pragma Assert (Pos + 1 in IndexesT'Range);
63
64 Start : constant Natural := Natural (IndexesT (Pos));
65 Next : constant Natural := Natural (IndexesT (Pos + 1));
66
67 pragma Assert (Next - 1 >= Start);
68 pragma Assert (Start >= Names'First);
69 pragma Assert (Next - 1 <= Names'Last);
70
71 pragma Assert (Next - Start <= S'Last);
72 -- The caller should guarantee that S is large enough to contain the
73 -- enumeration image.
74 begin
75 S (1 .. Next - Start) := Names (Start .. Next - 1);
76 P := Next - Start;
77 end Image_Enumeration;
78
79 end System.Image_N;