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,
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;
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;
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;
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 --
---------------------------
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 --
-----------------------
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;
-- 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;
-- 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;
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
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,