procedure Put_C_Type_And_Subtypes
(S : in out Sink; Root : Root_Type) is
+ Cur_Pos : Root_Nat := 0;
+ -- 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
-- for T in Node_Kind and Entity_Kind (i.e. concrete types).
+ -- This looks like "#define 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.
procedure Put_Kind_Subtype (T : Node_Or_Entity_Type);
-- Print out the SUBTYPE macro call corresponding to an abstract
procedure Put_Enum_Lit (T : Node_Or_Entity_Type) is
begin
if T in Concrete_Type then
- Put (S, "#define " & Image (T) & " " & Image (Pos (T)) & "" & LF);
+ Put (S, "#define " & Image (T) & " " & Image (Cur_Pos) & LF);
+ Cur_Pos := Cur_Pos + 1;
end if;
end Put_Enum_Lit;
Iterate_Types (Root, Pre => Put_Enum_Lit'Access);
Put (S, "#define Number_" & Node_Or_Entity (Root) & "_Kinds " &
- Image (Pos (Last_Concrete (Root)) + 1) & "" & LF & LF);
+ Image (Cur_Pos) & "" & LF & LF);
Iterate_Types (Root, Pre => Put_Kind_Subtype'Access);
Put (S, "-- End type hierarchy for " & N_Or_E & LF & LF);
end Put_Type_Hierarchy;
- ---------
- -- Pos --
- ---------
-
- function Pos (T : Concrete_Type) return Root_Nat is
- First : constant Concrete_Type :=
- (if T in Concrete_Node then Concrete_Node'First
- else Concrete_Entity'First);
- begin
- return Type_Enum'Pos (T) - Type_Enum'Pos (First);
- end Pos;
-
end Gen_IL.Internals;
Nil'Access);
-- Iterate top-down on the type hierarchy. Call Pre and Post before and
-- after walking child types. Note that this ignores union types, because
- -- they are nonhierarchical.
+ -- they are nonhierarchical. The order in which concrete types are visited
+ -- matches the order of the generated enumeration types Node_Kind and
+ -- Entity_Kind, which is not the same as the order of the Type_Enum
+ -- type in Gen_IL.Types.
function Is_Descendant (Ancestor, Descendant : Node_Or_Entity_Type)
return Boolean;
procedure Put_Type_Hierarchy (S : in out Sink; Root : Root_Type);
- function Pos (T : Concrete_Type) return Root_Nat;
- -- Return Node_Kind'Pos (T) or Entity_Kind'Pos (T)
-
----------------
type Field_Desc is record