Rewrite (N,
Make_Integer_Literal (Loc, Enumeration_Rep (Entity (Expr))));
- -- If this is a renaming of a literal, recover the representation
- -- of the original. If it renames an expression there is nothing to
- -- fold.
-
- elsif Nkind (Expr) in N_Has_Entity
- and then Ekind (Entity (Expr)) = E_Constant
- and then Present (Renamed_Object (Entity (Expr)))
- and then Is_Entity_Name (Renamed_Object (Entity (Expr)))
- and then Ekind (Entity (Renamed_Object (Entity (Expr)))) =
- E_Enumeration_Literal
- then
- Rewrite (N,
- Make_Integer_Literal (Loc,
- Enumeration_Rep (Entity (Renamed_Object (Entity (Expr))))));
-
-- If not constant-folded above, Enum_Type'Enum_Rep (X) or
-- X'Enum_Rep expands to
-- Real to integer conversion
- else
+ elsif To_Be_Treated_As_Real (Source_Type) then
Result := UR_To_Uint (Expr_Value_R (Operand));
+
+ -- Enumeration to integer conversion, aka 'Enum_Rep
+
+ else
+ Result := Expr_Rep_Value (Operand);
end if;
-- If fixed-point type (Conversion_OK must be set), then the
if Is_Out_Of_Range (N, Etype (N), Assume_Valid => True) then
Out_Of_Range (N);
end if;
-
end Eval_Type_Conversion;
-------------------