-- type of the object.
-- Lit_Hash [root type only]
--- Defined in enumeration types and subtypes. Non-empty only for the
--- case of an enumeration root type, where it contains the entity for
+-- Defined in enumeration types and subtypes. Contains the entity for
-- the generated hash function. See unit Exp_Imgv for full details of
-- the nature and use of this entity for implementing the Value
-- attribute for the enumeration type in question.
--- Lit_Indexes
--- Defined in enumeration types and subtypes. Non-empty only for the
--- case of an enumeration root type, where it contains the entity for
+-- Lit_Indexes [root type only]
+-- Defined in enumeration types and subtypes. Contains the entity for
-- the generated indexes entity. See unit Exp_Imgv for full details of
-- the nature and use of this entity for implementing the Image and
-- Value attributes for the enumeration type in question.
--- Lit_Strings
--- Defined in enumeration types and subtypes. Non-empty only for the
--- case of an enumeration root type, where it contains the entity for
+-- Lit_Strings [root type only]
+-- Defined in enumeration types and subtypes. Contains the entity for
-- the literals string entity. See unit Exp_Imgv for full details of
-- the nature and use of this entity for implementing the Image and
-- Value attributes for the enumeration type in question.
-- E_Enumeration_Subtype
-- First_Entity $$$ type
-- Renamed_Object $$$
- -- Lit_Strings (root type only)
-- First_Literal
+ -- Lit_Hash (root type only)
-- Lit_Indexes (root type only)
+ -- Lit_Strings (root type only)
-- Default_Aspect_Value (base type only)
-- Scalar_Range
- -- Lit_Hash (root type only)
-- Enum_Pos_To_Rep (type only)
-- Static_Discrete_Predicate
-- Has_Biased_Representation
-- Ada 2022 allows 'Image on private types, so fetch the underlying
-- type to obtain the structure of the type. We use the base type,
- -- not the root type for discrete types, to handle properly derived
- -- types, but we use the root type for enumeration types, because the
- -- literal map is attached to the root. Should be inherited ???
+ -- not the root type, for discrete types in order to handle derived
+ -- types, except for character types for which this is not needed.
- if Is_Real_Type (Ptyp) or else Is_Enumeration_Type (Ptyp) then
+ if Is_Real_Type (Ptyp) or else Is_Character_Type (Ptyp) then
Rtyp := Underlying_Type (Root_Type (Ptyp));
else
Rtyp := Underlying_Type (Base_Type (Ptyp));
Enum_Case := False;
- if Rtyp = Standard_Boolean then
+ if Is_Boolean_Type (Rtyp) then
-- Use inline expansion if the -gnatd_x switch is not passed to the
-- compiler. Otherwise expand into a call to the runtime.
(Sm (First_Literal, Node_Id),
Sm (Has_Enumeration_Rep_Clause, Flag),
Sm (Has_Pragma_Ordered, Flag, Impl_Base_Type_Only),
- Sm (Lit_Indexes, Node_Id),
- Sm (Lit_Strings, Node_Id),
+ Sm (Lit_Hash, Node_Id, Root_Type_Only),
+ Sm (Lit_Indexes, Node_Id, Root_Type_Only),
+ Sm (Lit_Strings, Node_Id, Root_Type_Only),
Sm (Nonzero_Is_True, Flag, Base_Type_Only,
- Pre => "Root_Type (N) = Standard_Boolean"),
- Sm (Lit_Hash, Node_Id, Root_Type_Only)));
+ Pre => "Root_Type (N) = Standard_Boolean")));
Cc (E_Enumeration_Type, Enumeration_Kind,
-- Enumeration types, created by an enumeration type declaration
--- /dev/null
+-- { dg-do run }
+
+procedure Enum6 is
+
+ type Base_Enum is (Ten, Twenty);
+
+ type Derived_Enum is new Base_Enum;
+ for Derived_Enum use (Ten => 10, Twenty => 20);
+
+ type Rep_Enum is (Ten, Twenty);
+ for Rep_Enum use (Ten => 10, Twenty => 20);
+
+ OK : Boolean := True;
+
+begin
+ for E in Base_Enum loop
+ if (E = Ten and then Base_Enum'Image(E) /= "TEN")
+ or else (E = Twenty and then Base_Enum'Image(E) /= "TWENTY")
+ then
+ OK := False;
+ end if;
+ end loop;
+
+ for E in Derived_Enum loop
+ if (E = Ten and then Derived_Enum'Image(E) /= "TEN")
+ or else (E = Twenty and then Derived_Enum'Image(E) /= "TWENTY")
+ then
+ OK := False;
+ end if;
+ end loop;
+
+ for E in Rep_Enum loop
+ if (E = Ten and then Rep_Enum'Image(E) /= "TEN")
+ or else (E = Twenty and then Rep_Enum'Image(E) /= "TWENTY")
+ then
+ OK := False;
+ end if;
+ end loop;
+
+ if not OK then
+ raise Program_Error;
+ end if;
+end;