1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . V A L U E _ D --
9 -- Copyright (C) 2020-2023, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This package contains the routines for supporting the Value attribute for
33 -- decimal fixed point types, and also for conversion operations required in
34 -- Text_IO.Decimal_IO for such types.
42 with procedure Scaled_Divide
47 package System
.Value_D
is
52 Ptr
: not null access Integer;
54 Scale
: Integer) return Int
;
55 -- This function scans the string starting at Str (Ptr.all) for a valid
56 -- real literal according to the syntax described in (RM 3.5(43)). The
57 -- substring scanned extends no further than Str (Max). There are three
58 -- cases for the return:
60 -- If a valid real literal is found after scanning past any initial spaces,
61 -- then Ptr.all is updated past the last character of the literal (but
62 -- trailing spaces are not scanned out). The value returned is the value
63 -- Int'Integer_Value (decimal-literal-value), using the given Scale to
64 -- determine this value.
66 -- If no valid real literal is found, then Ptr.all points either to an
67 -- initial non-digit character, or to Max + 1 if the field is all spaces
68 -- and the exception Constraint_Error is raised.
70 -- If a syntactically valid integer is scanned, but the value is out of
71 -- range, or, in the based case, the base value is out of range or there
72 -- is an out of range digit, then Ptr.all points past the integer, and
73 -- Constraint_Error is raised.
75 -- Note: these rules correspond to the requirements for leaving the
76 -- pointer positioned in Text_Io.Get
78 -- Note: if Str is null, i.e. if Max is less than Ptr, then this is a
79 -- special case of an all-blank string, and Ptr is unchanged, and hence
80 -- is greater than Max as required in this case.
82 function Value_Decimal
(Str
: String; Scale
: Integer) return Int
;
83 -- Used in computing X'Value (Str) where X is a decimal fixed-point type.
84 -- Str is the string argument of the attribute. Constraint_Error is raised
85 -- if the string is malformed or if the value is out of range of Int (not
86 -- the range of the fixed-point type, which must be done by the caller).
87 -- Otherwise the value returned is the value Int'Integer_Value
88 -- (decimal-literal-value), using Scale to determine this value.