Skip to content

Commit 00c51d8

Browse files
committed
Merge branch 'topic/backport/25.2/230-ada_2022' into '25.2'
TGen: Allow users to set Ada language version in the generated projects See merge request eng/ide/libadalang-tools!335
2 parents 573761d + a0623b3 commit 00c51d8

File tree

16 files changed

+172
-18
lines changed

16 files changed

+172
-18
lines changed

src/test-actions.adb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ package body Test.Actions is
217217

218218
Test.Common.Instrument := Arg (Cmd, Dump_Test_Inputs);
219219

220+
Test.Common.Lang_Version :=
221+
Utils.Command_Lines.Common.Ada_Version_Switches.Arg (Cmd);
222+
220223
if Arg (Cmd, Passed_Tests) /= null then
221224
if Arg (Cmd, Passed_Tests).all = "hide" then
222225
Test.Common.Show_Passed_Tests := False;
@@ -874,6 +877,15 @@ package body Test.Actions is
874877
& GNAT.OS_Lib.Directory_Separator & "tgen"
875878
& GNAT.OS_Lib.Directory_Separator & "templates"));
876879

880+
TGen.Libgen.Set_Minimum_Lang_Version
881+
(Test.Common.TGen_Libgen_Ctx,
882+
(case Test.Common.Lang_Version is
883+
when Ada_83 |
884+
Ada_95 |
885+
Ada_2005 |
886+
Ada_2012 => TGen.Libgen.Ada_12,
887+
when Ada_2022 => TGen.Libgen.Ada_22));
888+
877889
if Arg (Cmd, Gen_Test_Vectors) then
878890
Test.Common.Generate_Test_Vectors := True;
879891
Test.Common.Request_Lib_Support;

src/test-common.ads

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ with Langkit_Support.Slocs; use Langkit_Support.Slocs;
4343

4444
with TGen.Libgen;
4545

46+
with Utils.Command_Lines.Common; use Utils.Command_Lines.Common;
47+
4648
package Test.Common is
4749

4850
package String_Set is new
@@ -449,6 +451,10 @@ package Test.Common is
449451

450452
Instr_Suffix : constant String := "-gnattest-instr";
451453
-- Suffix for object subdirs containing instrumented sources
454+
455+
Lang_Version : Ada_Version_Type := Ada_2012;
456+
-- Language version to be inserted in the pragma in stub helper units.
457+
452458
private
453459

454460
Need_Lib_Support : Lib_Support_Status := Not_Needed;

src/test-generation.adb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ package body Test.Generation is
207207
if Debug_Flag_1 then
208208
Build_Args.Append ("-g");
209209
Build_Args.Append ("-O0");
210+
Build_Args.Append ("-bargs");
211+
Build_Args.Append ("-Es");
210212
end if;
211213
Run (Build_Args, "Build of the test generation harness");
212214

src/test-stub.adb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ with Ada.Strings; use Ada.Strings;
5151
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
5252
with Ada.Characters.Handling; use Ada.Characters.Handling;
5353

54-
with Utils.Command_Lines; use Utils.Command_Lines;
54+
with Utils.Command_Lines; use Utils.Command_Lines;
55+
with Utils.Command_Lines.Common;
5556
with Utils.Environment;
5657

5758
package body Test.Stub is
@@ -282,10 +283,13 @@ package body Test.Stub is
282283
-- Puts header of generated stub explaining where user code should be put
283284

284285
procedure Put_Import_Section
285-
(Markered_Data : in out Markered_Data_Maps.Map;
286-
Add_Import : Boolean := False;
287-
Add_Pragma_05 : Boolean := False);
286+
(Markered_Data : in out Markered_Data_Maps.Map;
287+
Add_Import : Boolean := False;
288+
Add_Language_Version : Boolean := False);
288289
-- Puts or regenerates markered section for with clauses
290+
--
291+
-- The included version is the one defined through the Ada_Version_Switch
292+
-- argument, if defined, or Ada_2012 otherwise.
289293

290294
procedure Put_Lines (MD : Markered_Data_Type; Comment_Out : Boolean);
291295

@@ -786,10 +790,11 @@ package body Test.Stub is
786790
------------------------
787791

788792
procedure Put_Import_Section
789-
(Markered_Data : in out Markered_Data_Maps.Map;
790-
Add_Import : Boolean := False;
791-
Add_Pragma_05 : Boolean := False)
793+
(Markered_Data : in out Markered_Data_Maps.Map;
794+
Add_Import : Boolean := False;
795+
Add_Language_Version : Boolean := False)
792796
is
797+
use Utils.Command_Lines.Common;
793798
ID : constant Markered_Data_Id :=
794799
(Import_MD,
795800
new String'(""),
@@ -834,8 +839,17 @@ package body Test.Stub is
834839
S_Put (3, "with Ada.Real_Time;");
835840
New_Line_Count;
836841
end if;
837-
if Add_Pragma_05 then
838-
S_Put (0, "pragma Ada_2005;");
842+
if Add_Language_Version then
843+
S_Put
844+
(0,
845+
"pragma "
846+
& (case Test.Common.Lang_Version is
847+
when Ada_83 => "Ada_83",
848+
when Ada_95 => "Ada_95",
849+
when Ada_2005 => "Ada_2005",
850+
when Ada_2012 => "Ada_2012",
851+
when Ada_2022 => "Ada_2022")
852+
& ";");
839853
New_Line_Count;
840854
end if;
841855
end if;
@@ -3585,7 +3599,7 @@ package body Test.Stub is
35853599
Create (Tmp_File_Name);
35863600
Reset_Line_Counter;
35873601

3588-
Put_Import_Section (Markered_Subp_Data, Add_Pragma_05 => True);
3602+
Put_Import_Section (Markered_Subp_Data, Add_Language_Version => True);
35893603

35903604
S_Put
35913605
(0,

src/tgen/tgen-libgen.adb

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ package body TGen.Libgen is
113113
-- Include all the types in Source in the correct package key in Dest. All
114114
-- anonymous types are ignored.
115115

116+
function Lang_Version_To_Attr
117+
(Version : Ada_Language_Version) return String;
118+
-- Return the corresponding string to be added to the
119+
-- Compiler.Default_Switches attribute. This will return the empty string
120+
-- if Version is Unspecified.
121+
116122
----------------------
117123
-- Replace_Standard --
118124
----------------------
@@ -922,11 +928,19 @@ package body TGen.Libgen is
922928
Put_Line (Prj_File, " package Compiler is");
923929
Put_Line (Prj_File, " case Build_Mode is");
924930
Put_Line (Prj_File, " when ""dev"" =>");
925-
Put_Line (Prj_File, " for Default_Switches (""Ada"") use"
926-
& " (""-g"", ""-gnatg"", ""-gnatyN"", ""-gnatws"");");
931+
Put (Prj_File, " for Default_Switches (""Ada"") use"
932+
& " (""-g"", ""-gnatg"", ""-gnatyN"", ""-gnatws""");
933+
if Ctx.Lang_Version /= Unspecified then
934+
Put (Prj_File, ", " & Lang_Version_To_Attr (Ctx.Lang_Version));
935+
end if;
936+
Put_Line (Prj_File, ");");
927937
Put_Line (Prj_File, " when ""prod"" =>");
928938
Put_Line (Prj_File, " for Default_Switches (""Ada"") use"
929-
& " (""-gnatg"", ""-gnatyN"", ""-gnatws"");");
939+
& " (""-gnatg"", ""-gnatyN"", ""-gnatws""");
940+
if Ctx.Lang_Version /= Unspecified then
941+
Put (Prj_File, ", " & Lang_Version_To_Attr (Ctx.Lang_Version));
942+
end if;
943+
Put_Line (Prj_File, ");");
930944
Put_Line (Prj_File, " end case;");
931945
Put_Line (Prj_File, " end Compiler;");
932946
New_Line (Prj_File);
@@ -1320,6 +1334,11 @@ package body TGen.Libgen is
13201334
Put_Line (Prj_File, "project TGen_Generation_Harness is");
13211335
Put_Line (Prj_File, " for Main use (""generation_main.adb"");");
13221336
Put_Line (Prj_File, " for Object_Dir use ""obj"";");
1337+
Put_Line (Prj_File, "package Compiler is");
1338+
Put (Prj_File, " for Default_Switches (""Ada"") use (");
1339+
Put (Prj_File, Lang_Version_To_Attr (Ctx.Lang_Version) & ");");
1340+
Ada.Text_IO.Put_Line (Prj_File, "end Compiler;");
1341+
13231342
Put_Line (Prj_File, "end TGen_Generation_Harness;");
13241343
Close (Prj_File);
13251344

@@ -1371,4 +1390,25 @@ package body TGen.Libgen is
13711390
TGen.Marshalling.Set_Array_Size_Limit (Limit);
13721391
end Set_Array_Size_Limit;
13731392

1393+
------------------------------
1394+
-- Set_Minimum_Lang_Version --
1395+
------------------------------
1396+
1397+
procedure Set_Minimum_Lang_Version
1398+
(Ctx : in out Libgen_Context; Version : Ada_Language_Version) is
1399+
begin
1400+
Ctx.Lang_Version := Version;
1401+
end Set_Minimum_Lang_Version;
1402+
1403+
--------------------------
1404+
-- Lang_Version_To_Attr --
1405+
--------------------------
1406+
1407+
function Lang_Version_To_Attr
1408+
(Version : Ada_Language_Version) return String is
1409+
(case Version is
1410+
when Unspecified => "",
1411+
when Ada_12 => """-gnat2012""",
1412+
when Ada_22 => """-gnat2022""");
1413+
13741414
end TGen.Libgen;

src/tgen/tgen-libgen.ads

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ package TGen.Libgen is
5050
Test_Generation_Part => True,
5151
Wrappers_Part => True];
5252

53+
type Ada_Language_Version is (Unspecified, Ada_12, Ada_22);
54+
-- Ada language versions
55+
5356
type Libgen_Context is private;
5457

5558
function Create
@@ -160,6 +163,16 @@ package TGen.Libgen is
160163
-- Supported_Subprogram to ensure consistency of the array limit used in
161164
-- all the marshallers, otherwise Constraint_Error is raised.
162165

166+
procedure Set_Minimum_Lang_Version
167+
(Ctx : in out Libgen_Context; Version : Ada_Language_Version);
168+
-- Set the desired language version to be used in project compilation
169+
-- switches. Note that if not set, no languages version switches will be
170+
-- added to the generated project files.
171+
--
172+
-- TGen also requires at least an Ada_2012 compiler to be available, so
173+
-- setting a version lower than that will result in -gnat12 being used in
174+
-- the compiler switches, instead of the specified language version.
175+
163176
private
164177
use TGen.Strings;
165178
use TGen.Context;
@@ -226,6 +239,10 @@ private
226239
Array_Index_Types : Typ_Set;
227240
-- Set of types used to instantiate array index constraints
228241

242+
Lang_Version : Ada_Language_Version := Unspecified;
243+
-- Language version to be used in the compilation switches of the
244+
-- generated projects. If Unspecified, no language version switch will
245+
-- be added to the projects.
229246
end record;
230247

231248
end TGen.Libgen;

src/utils-command_lines-common.ads

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ package Utils.Command_Lines.Common is
7878
Common_Boolean_Switches.Set_Shorthands
7979
([Syntax_Only => +"-so"]);
8080

81-
type Ada_Version_Type is (Ada_83, Ada_95, Ada_2005, Ada_2012);
81+
type Ada_Version_Type is (Ada_83, Ada_95, Ada_2005, Ada_2012, Ada_2022);
8282

8383
package Ada_Version_Switches is new Enum_Switches
8484
(Common_Descriptor, Ada_Version_Type,
85-
Default => Ada_Version_Type'Last);
85+
Default => Ada_2012);
8686
-- These switches are ignored. The tools are tolerant of using newer
8787
-- reserved words, such as "interface", as identifiers, so we don't need to
8888
-- know the version.
@@ -91,7 +91,8 @@ package Utils.Command_Lines.Common is
9191
([Ada_83 => +"-gnat83",
9292
Ada_95 => +"-gnat95",
9393
Ada_2005 => +"-gnat2005",
94-
Ada_2012 => +"-gnat2012"]);
94+
Ada_2012 => +"-gnat2012",
95+
Ada_2022 => +"-gnat2022"]);
9596

9697
package Ada_Version_Shorthands_2 is new Ada_Version_Switches.Set_Shorthands
9798
([Ada_2005 => +"-gnat05",

testsuite/tests/test/195-repeated-pragmas/test.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
--
66
-- end read only
77

8-
pragma Ada_2005;
8+
pragma Ada_2012;
99
-- begin read only
1010
-- end read only
1111

@@ -33,7 +33,7 @@ end Input.Stub_Data;
3333
--
3434
-- end read only
3535

36-
pragma Ada_2005;
36+
pragma Ada_2012;
3737
-- begin read only
3838
-- end read only
3939

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package body Dep is
2+
3+
function Get_Acc (X : aliased Integer) return Int_Acc is
4+
(X'Unrestricted_Access);
5+
6+
end Dep;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package Dep is
2+
3+
type Int_Acc is access all Integer;
4+
5+
function Get_Acc (X : aliased Integer) return Int_Acc;
6+
7+
end Dep;

0 commit comments

Comments
 (0)