]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/libgnat/s-valboo.ads
ada: Refactor the proof of the Value and Image runtime units
[thirdparty/gcc.git] / gcc / ada / libgnat / s-valboo.ads
CommitLineData
cacbc350
RK
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- S Y S T E M . V A L _ B O O L --
6-- --
7-- S p e c --
8-- --
cccef051 9-- Copyright (C) 1992-2023, 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
6df3ec0e
YM
32-- Preconditions in this unit are meant for analysis only, not for run-time
33-- checking, so that the expected exceptions are raised. This is enforced by
34-- setting the corresponding assertion policy to Ignore. Postconditions and
35-- contract cases should not be executed at runtime as well, in order not to
36-- slow down the execution of these functions.
37
38pragma Assertion_Policy (Pre => Ignore,
39 Post => Ignore,
40 Contract_Cases => Ignore,
41 Ghost => Ignore);
42
70bcf5c4 43with System.Val_Spec;
6df3ec0e
YM
44
45package System.Val_Bool
46 with SPARK_Mode
47is
ca305a84 48 pragma Preelaborate;
cacbc350 49
6df3ec0e 50 function Is_Boolean_Image_Ghost (Str : String) return Boolean is
70bcf5c4 51 (not System.Val_Spec.Only_Space_Ghost (Str, Str'First, Str'Last)
6df3ec0e
YM
52 and then
53 (declare
70bcf5c4 54 F : constant Positive := System.Val_Spec.First_Non_Space_Ghost
649b3efa 55 (Str, Str'First, Str'Last);
6df3ec0e
YM
56 begin
57 (F <= Str'Last - 3
58 and then Str (F) in 't' | 'T'
59 and then Str (F + 1) in 'r' | 'R'
60 and then Str (F + 2) in 'u' | 'U'
61 and then Str (F + 3) in 'e' | 'E'
62 and then
63 (if F + 3 < Str'Last then
70bcf5c4 64 System.Val_Spec.Only_Space_Ghost (Str, F + 4, Str'Last)))
6df3ec0e
YM
65 or else
66 (F <= Str'Last - 4
67 and then Str (F) in 'f' | 'F'
68 and then Str (F + 1) in 'a' | 'A'
69 and then Str (F + 2) in 'l' | 'L'
70 and then Str (F + 3) in 's' | 'S'
71 and then Str (F + 4) in 'e' | 'E'
72 and then
73 (if F + 4 < Str'Last then
70bcf5c4 74 System.Val_Spec.Only_Space_Ghost (Str, F + 5, Str'Last)))))
6df3ec0e
YM
75 with
76 Ghost;
77 -- Ghost function that returns True iff Str is the image of a boolean, that
78 -- is "true" or "false" in any capitalization, possibly surounded by space
79 -- characters.
80
81 function Value_Boolean (Str : String) return Boolean
82 with
83 Pre => Is_Boolean_Image_Ghost (Str),
84 Post =>
40b18099 85 Value_Boolean'Result =
70bcf5c4 86 (Str (System.Val_Spec.First_Non_Space_Ghost
649b3efa 87 (Str, Str'First, Str'Last)) in 't' | 'T');
9de61fcb 88 -- Computes Boolean'Value (Str)
cacbc350
RK
89
90end System.Val_Bool;