Skip to content

Commit

Permalink
Use P_Designated_Type_Decl instead of our own in house helper
Browse files Browse the repository at this point in the history
The LAL properties often account for more edge cases, and laltools
will also benefit from bug fixes reported by other teams this way.
  • Loading branch information
leocreuse committed Mar 7, 2024
1 parent af8109b commit e46c754
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/test-stub.adb
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,6 @@ package body Test.Stub is
function Requires_Body (N : Ada_Node) return Boolean;
-- Checks if a body sample should be created for an element

function Get_Declaration
(Elem : Subtype_Indication)
return Base_Type_Decl
is
(Elem.F_Name.P_Relative_Name.As_Name.P_Referenced_Decl.As_Base_Type_Decl);
-- Returns declaration of corresponding parameter type

-------------------------------
-- Setter package generation --
-------------------------------
Expand Down Expand Up @@ -2336,7 +2329,7 @@ package body Test.Stub is
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;

Type_Decl := Get_Declaration (Subtype_Ind);
Type_Decl := Subtype_Ind.P_Designated_Type_Decl;

if Type_Decl.Kind in Ada_Generic_Formal then
return False;
Expand Down Expand Up @@ -2387,7 +2380,7 @@ package body Test.Stub is
--------------------------

function Get_Access_Type_Name (Elem : Subtype_Indication) return String is
Decl : constant Base_Type_Decl := Get_Declaration (Elem);
Decl : constant Base_Type_Decl := Elem.P_Designated_Type_Decl;
Attr_Suff : constant String :=
(if Elem.F_Name.Kind = Ada_Attribute_Ref then
"_" & Node_Image (Elem.F_Name.As_Attribute_Ref.F_Attribute)
Expand All @@ -2410,7 +2403,7 @@ package body Test.Stub is
declare
S : String :=
Encode
(Decl.As_Basic_Decl.P_Fully_Qualified_Name,
(Decl.P_Defining_Name.P_Fully_Qualified_Name,
Decl.Unit.Get_Charset)
& Attr_Suff & "_Access";
begin
Expand Down Expand Up @@ -2458,7 +2451,7 @@ package body Test.Stub is
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;

Decl := Get_Declaration (Subtype_Ind);
Decl := Subtype_Ind.P_Designated_Type_Decl;

if To_Lower (Get_Nesting (Decl)) = "standard" then
return Overall_Image;
Expand Down Expand Up @@ -2547,7 +2540,7 @@ package body Test.Stub is
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;

Type_Decl := Get_Declaration (Subtype_Ind);
Type_Decl := Subtype_Ind.P_Designated_Type_Decl;

if Type_Decl.Kind in Ada_Generic_Formal then
return False;
Expand Down Expand Up @@ -2631,14 +2624,13 @@ package body Test.Stub is
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;

Type_Decl := Get_Declaration (Subtype_Ind).P_Canonical_Type;
Type_Decl := Subtype_Ind.P_Designated_Type_Decl.P_Canonical_Type;
if Type_Decl.Kind = Ada_Classwide_Type_Decl
and then Get_Declaration (Subtype_Ind).Kind = Ada_Subtype_Decl
and then Subtype_Ind.P_Designated_Type_Decl.Kind = Ada_Subtype_Decl
then
Type_Decl :=
Get_Declaration
(Subtype_Ind).As_Subtype_Decl.F_Subtype.F_Name.P_Relative_Name.
P_Referenced_Decl.As_Base_Type_Decl;
Subtype_Ind.P_Designated_Type_Decl.As_Subtype_Decl.F_Subtype
.P_Designated_Type_Decl;
end if;

while not Type_Decl.Is_Null loop
Expand Down Expand Up @@ -2698,7 +2690,7 @@ package body Test.Stub is
Subtype_Ind := Param_Type.As_Subtype_Indication;
end if;

Type_Decl := Get_Declaration (Subtype_Ind);
Type_Decl := Subtype_Ind.P_Designated_Type_Decl;

declare
Insts : constant Generic_Instantiation_Array :=
Expand Down Expand Up @@ -3129,7 +3121,7 @@ package body Test.Stub is

procedure Add_Unconstrained_Type_To_Dictionary (Elem : Subtype_Indication)
is
Encl : Ada_Node := Get_Declaration (Elem).As_Ada_Node;
Encl : Ada_Node := Elem.P_Designated_Type_Decl.As_Ada_Node;
Dict_Elem : Access_Dictionary_Entry;

D_Cur : Access_Dictionaries.Cursor;
Expand All @@ -3143,7 +3135,7 @@ package body Test.Stub is
Encl := Encl.Parent;
end loop;

Dict_Elem.Type_Decl := Get_Declaration (Elem).As_Ada_Node;
Dict_Elem.Type_Decl := Elem.P_Designated_Type_Decl.As_Ada_Node;

D_Cur := Dictionary.First;
while D_Cur /= Access_Dictionaries.No_Element loop
Expand Down

0 comments on commit e46c754

Please sign in to comment.