aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gen_il-gen.adb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-06-30 09:31:40 -0600
committerMarc Poulhiès <poulhies@adacore.com>2023-07-28 09:28:13 +0200
commit5d8fc02062b36e58c9d0bd39e7c9bb286335d870 (patch)
treee4dbc0452ae0bb0f82ff9dfbc824ba30257981c5 /gcc/ada/gen_il-gen.adb
parent7e448f3c3dfb53a0d9e0b67c2fef566a56942596 (diff)
downloadgcc-5d8fc02062b36e58c9d0bd39e7c9bb286335d870.zip
gcc-5d8fc02062b36e58c9d0bd39e7c9bb286335d870.tar.gz
gcc-5d8fc02062b36e58c9d0bd39e7c9bb286335d870.tar.bz2
ada: Emit enums rather than defines for various constants
This patch changes xsnamest and gen_il-gen to emit various constants as enums rather than a sequence of preprocessor defines. This enables better debugging and somewhat better type safety. gcc/ada/ * fe.h (Convention): Now inline function. * gen_il-gen.adb (Put_C_Type_And_Subtypes.Put_Enum_Lit) (Put_C_Type_And_Subtypes.Put_Kind_Subtype, Put_C_Getter): Emit enum. * snames.h-tmpl (Name_Id, Name_, Attribute_Id, Attribute_) (Convention_Id, Convention_, Pragma_Id, Pragma_): Now enum. (Get_Attribute_Id, Get_Pragma_Id): Now inline functions. * types.h (Node_Kind, Entity_Kind, Convention_Id, Name_Id): Now enum. * xsnamest.adb (Output_Header_Line, Make_Value): Emit enum.
Diffstat (limited to 'gcc/ada/gen_il-gen.adb')
-rw-r--r--gcc/ada/gen_il-gen.adb11
1 files changed, 7 insertions, 4 deletions
diff --git a/gcc/ada/gen_il-gen.adb b/gcc/ada/gen_il-gen.adb
index bf760f3..1cee17c 100644
--- a/gcc/ada/gen_il-gen.adb
+++ b/gcc/ada/gen_il-gen.adb
@@ -2957,9 +2957,9 @@ package body Gen_IL.Gen is
-- Current Node_Kind'Pos or Entity_Kind'Pos to be printed
procedure Put_Enum_Lit (T : Node_Or_Entity_Type);
- -- Print out the #define corresponding to the Ada enumeration literal
+ -- Print out the enumerator corresponding to the Ada enumeration literal
-- for T in Node_Kind and Entity_Kind (i.e. concrete types).
- -- This looks like "#define Some_Kind <pos>", where Some_Kind
+ -- This looks like "Some_Kind = <pos>", where Some_Kind
-- is the Node_Kind or Entity_Kind enumeration literal, and
-- <pos> is Node_Kind'Pos or Entity_Kind'Pos of that literal.
@@ -2970,7 +2970,7 @@ package body Gen_IL.Gen is
procedure Put_Enum_Lit (T : Node_Or_Entity_Type) is
begin
if T in Concrete_Type then
- Put (S, "#define " & Image (T) & " " & Image (Cur_Pos) & LF);
+ Put (S, " " & Image (T) & " = " & Image (Cur_Pos) & "," & LF);
Cur_Pos := Cur_Pos + 1;
end if;
end Put_Enum_Lit;
@@ -2990,7 +2990,9 @@ package body Gen_IL.Gen is
begin
Put_Union_Membership (S, Root, Only_Prototypes => True);
+ Put (S, "enum " & Node_Or_Entity (Root) & "_Kind : unsigned int {" & LF);
Iterate_Types (Root, Pre => Put_Enum_Lit'Access);
+ Put (S, "};" & LF);
Put (S, "#define Number_" & Node_Or_Entity (Root) & "_Kinds " &
Image (Cur_Pos) & "" & LF & LF);
@@ -3046,7 +3048,8 @@ package body Gen_IL.Gen is
Put (S, "unsigned int Raw = slot;" & LF);
end if;
- Put (S, Get_Set_Id_Image (Rec.Field_Type) & " val = ");
+ Put (S, Get_Set_Id_Image (Rec.Field_Type) & " val = (" &
+ Get_Set_Id_Image (Rec.Field_Type) & ") ");
if Field_Has_Special_Default (Rec.Field_Type) then
Increase_Indent (S, 2);