public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1880] [Ada] Further adjustment and optimization of System.Value_N
@ 2021-06-29 14:25 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-06-29 14:25 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:1a9d13fff60c845a258d1e6607d42290db45e5e7
commit r12-1880-g1a9d13fff60c845a258d1e6607d42290db45e5e7
Author: Eric Botcazou <ebotcazou@adacore.com>
Date: Fri Apr 9 13:29:44 2021 +0200
[Ada] Further adjustment and optimization of System.Value_N
gcc/ada/
* rtsfind.ads (RE_Id): Change RE_Valid_Enumeration_Value_NN into
RE_Valid_Value_Enumeration_NN.
(RE_Unit_Table): Adjust to above renaming.
* exp_imgv.adb (Expand_Valid_Value_Attribute): Likewise.
* libgnat/s-valuen.ads (Invalid): Remove.
(Value_Enumeration_Pos): Move to...
* libgnat/s-valuen.adb (Value_Enumeration_Pos): ...here.
Return -1 instead of Invalid.
(Value_Enumeration): Compare against 0 instead of Invalid.
(Valid_Enumeration_Value): Likewise. Rename to...
(Valid_Value_Enumeration): ...this.
* libgnat/s-vaenu8.ads (Valid_Enumeration_Value_8): Rename into...
(Valid_Value_Enumeration_8): ...this.
* libgnat/s-vaen16.ads (Valid_Enumeration_Value_16): Rename into...
(Valid_Value_Enumeration_16): ...this.
* libgnat/s-vaen32.ads (Valid_Enumeration_Value_32): Rename into...
(Valid_Value_Enumeration_32): ...this.
Diff:
---
gcc/ada/exp_imgv.adb | 8 ++++----
gcc/ada/libgnat/s-vaen16.ads | 4 ++--
gcc/ada/libgnat/s-vaen32.ads | 4 ++--
gcc/ada/libgnat/s-vaenu8.ads | 4 ++--
gcc/ada/libgnat/s-valuen.adb | 49 ++++++++++++++++++++++++++++----------------
gcc/ada/libgnat/s-valuen.ads | 14 +------------
gcc/ada/rtsfind.ads | 12 +++++------
7 files changed, 48 insertions(+), 47 deletions(-)
diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
index 38ee11e5d66..6e17a5c452a 100644
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -1439,17 +1439,17 @@ package body Exp_Imgv is
begin
-- Generate:
- -- Valid_Enumeration_Value _NN
+ -- Valid_Value_Enumeration_NN
-- (typS, typN'Address, typH'Unrestricted_Access, Num, X)
Ttyp := Component_Type (Etype (Lit_Indexes (Rtyp)));
if Ttyp = Standard_Integer_8 then
- Func := RE_Valid_Enumeration_Value_8;
+ Func := RE_Valid_Value_Enumeration_8;
elsif Ttyp = Standard_Integer_16 then
- Func := RE_Valid_Enumeration_Value_16;
+ Func := RE_Valid_Value_Enumeration_16;
else
- Func := RE_Valid_Enumeration_Value_32;
+ Func := RE_Valid_Value_Enumeration_32;
end if;
Prepend_To (Args,
diff --git a/gcc/ada/libgnat/s-vaen16.ads b/gcc/ada/libgnat/s-vaen16.ads
index 86cdaa10fd1..6ea6071f8a8 100644
--- a/gcc/ada/libgnat/s-vaen16.ads
+++ b/gcc/ada/libgnat/s-vaen16.ads
@@ -49,13 +49,13 @@ package System.Val_Enum_16 is
return Natural
renames Impl.Value_Enumeration;
- function Valid_Enumeration_Value_16
+ function Valid_Value_Enumeration_16
(Names : String;
Indexes : System.Address;
Hash : Impl.Hash_Function_Ptr;
Num : Natural;
Str : String)
return Boolean
- renames Impl.Valid_Enumeration_Value;
+ renames Impl.Valid_Value_Enumeration;
end System.Val_Enum_16;
diff --git a/gcc/ada/libgnat/s-vaen32.ads b/gcc/ada/libgnat/s-vaen32.ads
index 0dead0704eb..e1a7644ec72 100644
--- a/gcc/ada/libgnat/s-vaen32.ads
+++ b/gcc/ada/libgnat/s-vaen32.ads
@@ -49,13 +49,13 @@ package System.Val_Enum_32 is
return Natural
renames Impl.Value_Enumeration;
- function Valid_Enumeration_Value_32
+ function Valid_Value_Enumeration_32
(Names : String;
Indexes : System.Address;
Hash : Impl.Hash_Function_Ptr;
Num : Natural;
Str : String)
return Boolean
- renames Impl.Valid_Enumeration_Value;
+ renames Impl.Valid_Value_Enumeration;
end System.Val_Enum_32;
diff --git a/gcc/ada/libgnat/s-vaenu8.ads b/gcc/ada/libgnat/s-vaenu8.ads
index db0b360d661..395a969db7b 100644
--- a/gcc/ada/libgnat/s-vaenu8.ads
+++ b/gcc/ada/libgnat/s-vaenu8.ads
@@ -49,13 +49,13 @@ package System.Val_Enum_8 is
return Natural
renames Impl.Value_Enumeration;
- function Valid_Enumeration_Value_8
+ function Valid_Value_Enumeration_8
(Names : String;
Indexes : System.Address;
Hash : Impl.Hash_Function_Ptr;
Num : Natural;
Str : String)
return Boolean
- renames Impl.Valid_Enumeration_Value;
+ renames Impl.Valid_Value_Enumeration;
end System.Val_Enum_8;
diff --git a/gcc/ada/libgnat/s-valuen.adb b/gcc/ada/libgnat/s-valuen.adb
index 7b72bc6ed06..ef613a28cf8 100644
--- a/gcc/ada/libgnat/s-valuen.adb
+++ b/gcc/ada/libgnat/s-valuen.adb
@@ -35,6 +35,16 @@ with System.Val_Util; use System.Val_Util;
package body System.Value_N is
+ function Value_Enumeration_Pos
+ (Names : String;
+ Indexes : System.Address;
+ Hash : Hash_Function_Ptr;
+ Num : Natural;
+ Str : String)
+ return Integer with Pure_Function;
+ -- Same as Value_Enumeration, except returns negative if Value_Enumeration
+ -- would raise Constraint_Error.
+
---------------------------
-- Value_Enumeration_Pos --
---------------------------
@@ -98,9 +108,25 @@ package body System.Value_N is
end if;
end;
- return Invalid;
+ return -1;
end Value_Enumeration_Pos;
+ -----------------------------
+ -- Valid_Value_Enumeration --
+ -----------------------------
+
+ function Valid_Value_Enumeration
+ (Names : String;
+ Indexes : System.Address;
+ Hash : Hash_Function_Ptr;
+ Num : Natural;
+ Str : String)
+ return Boolean
+ is
+ begin
+ return Value_Enumeration_Pos (Names, Indexes, Hash, Num, Str) >= 0;
+ end Valid_Value_Enumeration;
+
-----------------------
-- Value_Enumeration --
-----------------------
@@ -115,28 +141,15 @@ package body System.Value_N is
is
Result : constant Integer :=
Value_Enumeration_Pos (Names, Indexes, Hash, Num, Str);
+
begin
- if Result = Invalid then
+ -- The comparison eliminates the need for a range check on return
+
+ if Result < 0 then
Bad_Value (Str);
else
return Result;
end if;
end Value_Enumeration;
- -----------------------------
- -- Valid_Enumeration_Value --
- -----------------------------
-
- function Valid_Enumeration_Value
- (Names : String;
- Indexes : System.Address;
- Hash : Hash_Function_Ptr;
- Num : Natural;
- Str : String)
- return Boolean
- is
- begin
- return Value_Enumeration_Pos (Names, Indexes, Hash, Num, Str) /= Invalid;
- end Valid_Enumeration_Value;
-
end System.Value_N;
diff --git a/gcc/ada/libgnat/s-valuen.ads b/gcc/ada/libgnat/s-valuen.ads
index 7ef053914ac..db8ad1d0395 100644
--- a/gcc/ada/libgnat/s-valuen.ads
+++ b/gcc/ada/libgnat/s-valuen.ads
@@ -67,7 +67,7 @@ package System.Value_N is
-- If the image is found in Names, then the corresponding Pos value is
-- returned. If not, Constraint_Error is raised.
- function Valid_Enumeration_Value
+ function Valid_Value_Enumeration
(Names : String;
Indexes : System.Address;
Hash : Hash_Function_Ptr;
@@ -79,16 +79,4 @@ package System.Value_N is
-- raise Constraint_Error. The parameters have the same meaning as for
-- Value_Enumeration.
- Invalid : constant Integer := -1;
-
- function Value_Enumeration_Pos
- (Names : String;
- Indexes : System.Address;
- Hash : Hash_Function_Ptr;
- Num : Natural;
- Str : String)
- return Integer with Pure_Function;
- -- Same as Value_Enumeration, except returns Invalid if Value_Enumeration
- -- would raise Constraint_Error.
-
end System.Value_N;
diff --git a/gcc/ada/rtsfind.ads b/gcc/ada/rtsfind.ads
index df51477c139..ad84e9e761e 100644
--- a/gcc/ada/rtsfind.ads
+++ b/gcc/ada/rtsfind.ads
@@ -2040,9 +2040,9 @@ package Rtsfind is
RE_Value_Enumeration_16, -- System.Val_Enum_16
RE_Value_Enumeration_32, -- System.Val_Enum_32
- RE_Valid_Enumeration_Value_8, -- System.Val_Enum_8
- RE_Valid_Enumeration_Value_16, -- System.Val_Enum_16
- RE_Valid_Enumeration_Value_32, -- System.Val_Enum_32
+ RE_Valid_Value_Enumeration_8, -- System.Val_Enum_8
+ RE_Valid_Value_Enumeration_16, -- System.Val_Enum_16
+ RE_Valid_Value_Enumeration_32, -- System.Val_Enum_32
RE_Value_Fixed32, -- System_Val_Fixed_32
@@ -3731,11 +3731,11 @@ package Rtsfind is
RE_Value_Enumeration_32 => System_Val_Enum_32,
- RE_Valid_Enumeration_Value_8 => System_Val_Enum_8,
+ RE_Valid_Value_Enumeration_8 => System_Val_Enum_8,
- RE_Valid_Enumeration_Value_16 => System_Val_Enum_16,
+ RE_Valid_Value_Enumeration_16 => System_Val_Enum_16,
- RE_Valid_Enumeration_Value_32 => System_Val_Enum_32,
+ RE_Valid_Value_Enumeration_32 => System_Val_Enum_32,
RE_Value_Fixed32 => System_Val_Fixed_32,
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-06-29 14:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 14:25 [gcc r12-1880] [Ada] Further adjustment and optimization of System.Value_N Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).