Skip to content

Commit 21051a1

Browse files
committed
Merge branch 'topic/machu/253-skip-class-wide-types' into 'master'
TGen: Handle class wide return type properly Closes #253 See merge request eng/ide/libadalang-tools!305
2 parents db0113a + c1a749a commit 21051a1

File tree

7 files changed

+47
-3
lines changed

7 files changed

+47
-3
lines changed

src/tgen/tgen-types-translation.adb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,6 +2950,8 @@ package body TGen.Types.Translation is
29502950
(Translate_Discriminant_Constraints
29512951
(N.As_Subtype_Indication.F_Constraint
29522952
.As_Composite_Constraint)),
2953+
Is_Class_Wide =>
2954+
not Type_Decl_Node.P_Classwide_Type.Is_Null,
29532955
others => <>));
29542956
end return;
29552957
when others =>
@@ -3042,7 +3044,7 @@ package body TGen.Types.Translation is
30423044
Comp_Unit_Idx : constant Positive :=
30433045
Comp_Unit_Decl.P_Fully_Qualified_Name_Array'Last;
30443046

3045-
FQN : constant Ada_Qualified_Name :=
3047+
FQN : Ada_Qualified_Name :=
30463048
(if not Type_Name.Is_Null
30473049
then Convert_Qualified_Name (Type_Name.P_Fully_Qualified_Name_Array)
30483050
else Ada_Identifier_Vectors.Empty);
@@ -3229,6 +3231,8 @@ package body TGen.Types.Translation is
32293231
Specialized_Res.Res.Get.Fully_Private := Decl_Is_Fully_Private (N);
32303232
Specialized_Res.Res.Get.Private_Extension :=
32313233
Basic_Decl'(N.P_All_Parts (1)).As_Base_Type_Decl.P_Is_Private;
3234+
Specialized_Res.Res.Get.Is_Class_Wide :=
3235+
not N.P_Classwide_Type.Is_Null;
32323236
end if;
32333237

32343238
return Specialized_Res;
@@ -3508,6 +3512,7 @@ package body TGen.Types.Translation is
35083512
if not Ret.Success then
35093513
return (False, Ret.Diagnostics);
35103514
end if;
3515+
35113516
F_Typ.Ret_Typ := Ret.Res;
35123517
end;
35133518
else

src/tgen/tgen_rts/tgen-types.adb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,24 @@ package body TGen.Types is
100100
(if Top_Level_Generic
101101
then Generic_Package_Instance_Name (Self.Name)
102102
else Self.Name);
103+
104+
function Append_Class_Wide_If_Needed (Type_Name : String) return String
105+
is ((if Self.Is_Class_Wide then
106+
Type_Name & "'Class"
107+
else Type_Name));
103108
begin
104109
if not No_Std
105110
or else not Ada.Strings.Equal_Case_Insensitive
106111
(+Unbounded_String (Name.First_Element),
107112
"standard")
108113
then
109-
return To_Ada (Name);
114+
return Append_Class_Wide_If_Needed (To_Ada (Name));
110115
end if;
111116
declare
112117
Stripped : Ada_Qualified_Name := Name;
113118
begin
114119
Stripped.Delete_First;
115-
return To_Ada (Stripped);
120+
return Append_Class_Wide_If_Needed (To_Ada (Stripped));
116121
end;
117122
end FQN;
118123

src/tgen/tgen_rts/tgen-types.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ package TGen.Types is
6666
Is_Generic : Boolean := False;
6767
-- If the type is the result of a generic package instantiation
6868

69+
Is_Class_Wide : Boolean := False;
70+
-- Whether the type is class wide (has `'Class` attribute)
71+
6972
end record
7073
with Dynamic_Predicate =>
7174
-- A top level generic instantion is a generic itself (Top_Level_Generic
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package body Pkg is
2+
function Create_Foo (Bar : Integer) return Foo'Class is
3+
begin
4+
return Foo'(Baz => Bar);
5+
end Create_Foo;
6+
end Pkg;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package Pkg is
2+
type Foo is tagged private;
3+
4+
private
5+
type Foo is tagged record
6+
Baz : Integer;
7+
end record;
8+
9+
function Create_Foo (Bar : Integer) return Foo'Class;
10+
end Pkg;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pkg.ads:9:4: info: corresponding test PASSED
2+
pkg.ads:9:4: info: corresponding test PASSED
3+
pkg.ads:9:4: info: corresponding test PASSED
4+
pkg.ads:9:4: info: corresponding test PASSED
5+
pkg.ads:9:4: info: corresponding test PASSED
6+
pkg.ads:9:4: error: corresponding test FAILED: Test not implemented. (pkg-test_data-tests.adb:61)
7+
6 tests run: 5 passed; 1 failed; 0 crashed.
8+
Test runner dumped 5 tests
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
description: |
2+
This test make sure that TGen ignores declaration with class wide return
3+
types. Class wide types (`'Class`) are not supported yet.
4+
5+
default-gpr: true
6+
7+
driver: gnattest_tgen

0 commit comments

Comments
 (0)