| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S Y S T E M . V A L U E _ F -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2020-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 contains the routines for supporting the Value attribute for |
| 33 |
-- ordinary fixed point types whose Small is the ratio of two Int values, and |
| 34 |
-- also for conversion operations required in Text_IO.Fixed_IO for such types. |
| 35 |
|
| 36 |
generic |
| 37 |
|
| 38 |
type Int is range <>; |
| 39 |
|
| 40 |
type Uns is mod <>; |
| 41 |
|
| 42 |
with procedure Scaled_Divide |
| 43 |
(X, Y, Z : Int; |
| 44 |
Q, R : out Int; |
| 45 |
Round : Boolean); |
| 46 |
|
| 47 |
package System.Value_F is |
| 48 |
pragma Preelaborate; |
| 49 |
|
| 50 |
function Scan_Fixed |
| 51 |
(Str : String; |
| 52 |
Ptr : not null access Integer; |
| 53 |
Max : Integer; |
| 54 |
Num : Int; |
| 55 |
Den : Int) return Int; |
| 56 |
-- This function scans the string starting at Str (Ptr.all) for a valid |
| 57 |
-- real literal according to the syntax described in (RM 3.5(43)). The |
| 58 |
-- substring scanned extends no further than Str (Max). There are three |
| 59 |
-- cases for the return: |
| 60 |
-- |
| 61 |
-- If a valid real literal is found after scanning past any initial spaces, |
| 62 |
-- then Ptr.all is updated past the last character of the literal (but |
| 63 |
-- trailing spaces are not scanned out). The value returned is the value |
| 64 |
-- Int'Integer_Value (decimal-literal-value), using the given Num/Den to |
| 65 |
-- determine this value. |
| 66 |
-- |
| 67 |
-- If no valid real literal is found, then Ptr.all points either to an |
| 68 |
-- initial non-digit character, or to Max + 1 if the field is all spaces |
| 69 |
-- and the exception Constraint_Error is raised. |
| 70 |
-- |
| 71 |
-- If a syntactically valid integer is scanned, but the value is out of |
| 72 |
-- range, or, in the based case, the base value is out of range or there |
| 73 |
-- is an out of range digit, then Ptr.all points past the integer, and |
| 74 |
-- Constraint_Error is raised. |
| 75 |
-- |
| 76 |
-- Note: these rules correspond to the requirements for leaving the |
| 77 |
-- pointer positioned in Text_Io.Get |
| 78 |
-- |
| 79 |
-- Note: if Str is null, i.e. if Max is less than Ptr, then this is a |
| 80 |
-- special case of an all-blank string, and Ptr is unchanged, and hence |
| 81 |
-- is greater than Max as required in this case. |
| 82 |
|
| 83 |
function Value_Fixed |
| 84 |
(Str : String; |
| 85 |
Num : Int; |
| 86 |
Den : Int) return Int; |
| 87 |
-- Used in computing X'Value (Str) where X is an ordinary fixed-point type. |
| 88 |
-- Str is the string argument of the attribute. Constraint_Error is raised |
| 89 |
-- if the string is malformed or if the value is out of range of Int (not |
| 90 |
-- the range of the fixed-point type, which must be done by the caller). |
| 91 |
-- Otherwise the value returned is the value Int'Integer_Value |
| 92 |
-- (decimal-literal-value), using Small Num/Den to determine this value. |
| 93 |
|
| 94 |
end System.Value_F; |