| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S Y S T E M . V A L U E _ N -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 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 |
-- This package is used to compute the Value attribute for enumeration types |
| 33 |
-- other than those in packages Standard and System. See unit Exp_Imgv for |
| 34 |
-- details of the format of constructed image tables. |
| 35 |
|
| 36 |
generic |
| 37 |
|
| 38 |
type Index_Type is range <>; |
| 39 |
|
| 40 |
package System.Value_N is |
| 41 |
pragma Preelaborate; |
| 42 |
|
| 43 |
type Hash_Function_Ptr is access function (S : String) return Natural; |
| 44 |
|
| 45 |
function Value_Enumeration |
| 46 |
(Names : String; |
| 47 |
Indexes : System.Address; |
| 48 |
Hash : Hash_Function_Ptr; |
| 49 |
Num : Natural; |
| 50 |
Is_Wide : Boolean; |
| 51 |
Str : String) |
| 52 |
return Natural with Inline; |
| 53 |
-- Used to compute Enum'Value (Str) where Enum is some enumeration type |
| 54 |
-- other than those defined in package Standard. Names is a string with |
| 55 |
-- a lower bound of 1 containing the characters of all the enumeration |
| 56 |
-- literals concatenated together in sequence. Indexes is the address |
| 57 |
-- of an array of type array (0 .. N) of Index_Type, where N is the |
| 58 |
-- number of enumeration literals in the type. The Indexes values are |
| 59 |
-- the starting subscript of each enumeration literal, indexed by Pos |
| 60 |
-- values, with an extra entry at the end containing Names'Length + 1. |
| 61 |
-- The parameter Hash is a (perfect) hash function for Names and Indexes. |
| 62 |
-- The parameter Num is the value N - 1 (i.e. Enum'Pos (Enum'Last)). |
| 63 |
-- The reason that Indexes is passed by address is that the actual type |
| 64 |
-- is created on the fly by the expander. The parameter Is_Wide is True |
| 65 |
-- if the original attribute was [Wide_]Wide_Value. |
| 66 |
-- |
| 67 |
-- Str is the argument of the attribute function, and may have leading |
| 68 |
-- and trailing spaces, and letters can be upper or lower case or mixed. |
| 69 |
-- If the image is found in Names, then the corresponding Pos value is |
| 70 |
-- returned. If not, Constraint_Error is raised. |
| 71 |
|
| 72 |
function Valid_Value_Enumeration |
| 73 |
(Names : String; |
| 74 |
Indexes : System.Address; |
| 75 |
Hash : Hash_Function_Ptr; |
| 76 |
Num : Natural; |
| 77 |
Is_Wide : Boolean; |
| 78 |
Str : String) |
| 79 |
return Boolean with Inline; |
| 80 |
-- Returns True if Str is a valid Image of some enumeration literal, False |
| 81 |
-- otherwise. That is, returns False if and only if Value_Enumeration would |
| 82 |
-- raise Constraint_Error. The parameters have the same meaning as for |
| 83 |
-- Value_Enumeration. |
| 84 |
|
| 85 |
end System.Value_N; |