]>
Commit | Line | Data |
---|---|---|
cacbc350 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3084fecd | 3 | -- GNAT RUN-TIME COMPONENTS -- |
cacbc350 RK |
4 | -- -- |
5 | -- S Y S T E M . W I D _ E N U M -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
4b490c1e | 9 | -- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- |
cacbc350 RK |
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- -- | |
748086b7 | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
cacbc350 RK |
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 -- | |
748086b7 JJ |
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/>. -- | |
cacbc350 RK |
26 | -- -- |
27 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
cacbc350 RK |
29 | -- -- |
30 | ------------------------------------------------------------------------------ | |
31 | ||
cecaf88a | 32 | with Ada.Unchecked_Conversion; |
cacbc350 RK |
33 | |
34 | package body System.Wid_Enum is | |
35 | ||
36 | ------------------------- | |
37 | -- Width_Enumeration_8 -- | |
38 | ------------------------- | |
39 | ||
40 | function Width_Enumeration_8 | |
41 | (Names : String; | |
42 | Indexes : System.Address; | |
43 | Lo, Hi : Natural) | |
44 | return Natural | |
45 | is | |
07fc65c4 GB |
46 | pragma Warnings (Off, Names); |
47 | ||
cacbc350 RK |
48 | W : Natural; |
49 | ||
50 | type Natural_8 is range 0 .. 2 ** 7 - 1; | |
51 | type Index_Table is array (Natural) of Natural_8; | |
52 | type Index_Table_Ptr is access Index_Table; | |
53 | ||
54 | function To_Index_Table_Ptr is | |
cecaf88a | 55 | new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr); |
cacbc350 RK |
56 | |
57 | IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes); | |
58 | ||
59 | begin | |
60 | W := 0; | |
61 | ||
62 | for J in Lo .. Hi loop | |
63 | W := Natural'Max (W, Natural (IndexesT (J + 1) - IndexesT (J))); | |
64 | end loop; | |
65 | ||
66 | return W; | |
67 | end Width_Enumeration_8; | |
68 | ||
69 | -------------------------- | |
70 | -- Width_Enumeration_16 -- | |
71 | -------------------------- | |
72 | ||
73 | function Width_Enumeration_16 | |
74 | (Names : String; | |
75 | Indexes : System.Address; | |
76 | Lo, Hi : Natural) | |
77 | return Natural | |
78 | is | |
07fc65c4 GB |
79 | pragma Warnings (Off, Names); |
80 | ||
cacbc350 RK |
81 | W : Natural; |
82 | ||
83 | type Natural_16 is range 0 .. 2 ** 15 - 1; | |
84 | type Index_Table is array (Natural) of Natural_16; | |
85 | type Index_Table_Ptr is access Index_Table; | |
86 | ||
87 | function To_Index_Table_Ptr is | |
cecaf88a | 88 | new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr); |
cacbc350 RK |
89 | |
90 | IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes); | |
91 | ||
92 | begin | |
93 | W := 0; | |
94 | ||
95 | for J in Lo .. Hi loop | |
96 | W := Natural'Max (W, Natural (IndexesT (J + 1) - IndexesT (J))); | |
97 | end loop; | |
98 | ||
99 | return W; | |
100 | end Width_Enumeration_16; | |
101 | ||
102 | -------------------------- | |
103 | -- Width_Enumeration_32 -- | |
104 | -------------------------- | |
105 | ||
106 | function Width_Enumeration_32 | |
107 | (Names : String; | |
108 | Indexes : System.Address; | |
109 | Lo, Hi : Natural) | |
110 | return Natural | |
111 | is | |
07fc65c4 GB |
112 | pragma Warnings (Off, Names); |
113 | ||
cacbc350 RK |
114 | W : Natural; |
115 | ||
116 | type Natural_32 is range 0 .. 2 ** 31 - 1; | |
117 | type Index_Table is array (Natural) of Natural_32; | |
118 | type Index_Table_Ptr is access Index_Table; | |
119 | ||
120 | function To_Index_Table_Ptr is | |
cecaf88a | 121 | new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr); |
cacbc350 RK |
122 | |
123 | IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes); | |
124 | ||
125 | begin | |
126 | W := 0; | |
127 | ||
128 | for J in Lo .. Hi loop | |
129 | W := Natural'Max (W, Natural (IndexesT (J + 1) - IndexesT (J))); | |
130 | end loop; | |
131 | ||
132 | return W; | |
133 | end Width_Enumeration_32; | |
134 | ||
135 | end System.Wid_Enum; |