| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S Y S T E M . V A L _ S P E C -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2023-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 |
-- Ghost code, loop invariants and assertions in this unit are meant for |
| 33 |
-- analysis only, not for run-time checking, as it would be too costly |
| 34 |
-- otherwise. This is enforced by setting the assertion policy to Ignore. |
| 35 |
|
| 36 |
pragma Assertion_Policy (Ghost => Ignore, |
| 37 |
Loop_Invariant => Ignore, |
| 38 |
Assert => Ignore); |
| 39 |
|
| 40 |
package body System.Val_Spec |
| 41 |
with SPARK_Mode |
| 42 |
is |
| 43 |
|
| 44 |
--------------------------- |
| 45 |
-- First_Non_Space_Ghost -- |
| 46 |
--------------------------- |
| 47 |
|
| 48 |
function First_Non_Space_Ghost |
| 49 |
(S : String; |
| 50 |
From, To : Integer) return Positive |
| 51 |
is |
| 52 |
begin |
| 53 |
for J in From .. To loop |
| 54 |
if S (J) /= ' ' then |
| 55 |
return J; |
| 56 |
end if; |
| 57 |
|
| 58 |
pragma Loop_Invariant (for all K in From .. J => S (K) = ' '); |
| 59 |
end loop; |
| 60 |
|
| 61 |
raise Program_Error; |
| 62 |
end First_Non_Space_Ghost; |
| 63 |
|
| 64 |
----------------------- |
| 65 |
-- Last_Number_Ghost -- |
| 66 |
----------------------- |
| 67 |
|
| 68 |
function Last_Number_Ghost (Str : String) return Positive is |
| 69 |
begin |
| 70 |
pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns", |
| 71 |
"occurs in ghost code, not executable"); |
| 72 |
|
| 73 |
for J in Str'Range loop |
| 74 |
if Str (J) not in '0' .. '9' | '_' then |
| 75 |
return J - 1; |
| 76 |
end if; |
| 77 |
|
| 78 |
pragma Loop_Invariant |
| 79 |
(for all K in Str'First .. J => Str (K) in '0' .. '9' | '_'); |
| 80 |
end loop; |
| 81 |
|
| 82 |
return Str'Last; |
| 83 |
|
| 84 |
pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns"); |
| 85 |
end Last_Number_Ghost; |
| 86 |
|
| 87 |
end System.Val_Spec; |