Skip to content

Commit 9b5f7e7

Browse files
committed
Add --spark-mode-off switch
For units that have "SPARK_Mode => On", allow top level stubs with "SPARK_Mode => Off".
1 parent a45a8ee commit 9b5f7e7

File tree

25 files changed

+177
-28
lines changed

25 files changed

+177
-28
lines changed

src/stub-actions.adb

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- --
33
-- Libadalang Tools --
44
-- --
5-
-- Copyright (C) 2021-2022, AdaCore --
5+
-- Copyright (C) 2021-2025, AdaCore --
66
-- --
77
-- Libadalang Tools is free software; you can redistribute it and/or modi- --
88
-- fy it under terms of the GNU General Public License as published by --
@@ -619,15 +619,15 @@ package body Stub.Actions is
619619
-- If we are processing a subunit, generate "separate (parent)".
620620

621621
procedure Generate_Subp_Body
622-
(Decl : Ada_Node; Name : W_Str; Ada_Stub : Boolean);
622+
(Decl : Ada_Node; Name : W_Str; Ada_Stub : Boolean; Level : Natural);
623623
-- Generate a subprogram body stub. If Ada_Stub is True, we generate
624624
-- "is separate"; otherwise the so-called "stub" is a proper body.
625625

626626
procedure Generate_Entry_Body (Decl : Ada_Node; Name : W_Str);
627627
-- Generate an entry body stub
628628

629629
procedure Generate_Subp_Or_Entry_Body
630-
(Decl : Ada_Node; Name : W_Str; Ada_Stub : Boolean);
630+
(Decl : Ada_Node; Name : W_Str; Ada_Stub : Boolean; Level : Natural);
631631

632632
procedure Generate_Stub_Begin_End (Name, Stub_Kind : W_Str);
633633
-- Generate the text from "begin" to "end" of the generated code for a
@@ -743,7 +743,7 @@ package body Stub.Actions is
743743
end Generate_Subunit_Start;
744744

745745
procedure Generate_Subp_Body
746-
(Decl : Ada_Node; Name : W_Str; Ada_Stub : Boolean)
746+
(Decl : Ada_Node; Name : W_Str; Ada_Stub : Boolean; Level : Natural)
747747
is
748748
Empty_Vec, Pp_Out_Vec : Char_Vector;
749749
Spec : constant Subp_Spec := Get_Subp_Spec (Decl);
@@ -761,10 +761,20 @@ package body Stub.Actions is
761761
Output => Pp_Out_Vec,
762762
Messages => Tool.Ignored_Messages);
763763
pragma Assert (Is_Empty (Tool.Ignored_Messages));
764-
Put
765-
(" \1\2 is",
766-
Overriding_String (Overrides),
767-
From_UTF8 (Elems (Pp_Out_Vec) (1 .. Last_Index (Pp_Out_Vec))));
764+
if Arg (Cmd, Spark_Mode_Off)
765+
and then Level = 0
766+
and then Decl.P_Has_Spark_Mode_On
767+
then
768+
Put
769+
(" \1\2 with SPARK_Mode => Off is",
770+
Overriding_String (Overrides),
771+
From_UTF8 (Elems (Pp_Out_Vec) (1 .. Last_Index (Pp_Out_Vec))));
772+
else
773+
Put
774+
(" \1\2 is",
775+
Overriding_String (Overrides),
776+
From_UTF8 (Elems (Pp_Out_Vec) (1 .. Last_Index (Pp_Out_Vec))));
777+
end if;
768778
if Ada_Stub then
769779
Put (" separate;\n");
770780
else
@@ -805,11 +815,11 @@ package body Stub.Actions is
805815
end Generate_Entry_Body;
806816

807817
procedure Generate_Subp_Or_Entry_Body
808-
(Decl : Ada_Node; Name : W_Str; Ada_Stub : Boolean) is
818+
(Decl : Ada_Node; Name : W_Str; Ada_Stub : Boolean; Level : Natural) is
809819
begin
810820
case Decl.Kind is
811821
when Ada_Subp_Decl | Ada_Generic_Subp_Decl =>
812-
Generate_Subp_Body (Decl, Name, Ada_Stub);
822+
Generate_Subp_Body (Decl, Name, Ada_Stub, Level);
813823

814824
when Ada_Entry_Decl =>
815825
Generate_Entry_Body (Decl, Name);
@@ -921,28 +931,52 @@ package body Stub.Actions is
921931
=>
922932
Generate_Local_Header (Name, Level);
923933
Generate_Subunit_Start (Level);
924-
Put ("package body \1 is\n", Name);
934+
if Arg (Cmd, Spark_Mode_Off)
935+
and then Level = 0
936+
and then Decl.P_Has_Spark_Mode_On
937+
then
938+
Put ("package body \1 with Spark_Mode => Off is\n", Name);
939+
else
940+
Put ("package body \1 is\n", Name);
941+
end if;
925942

926943
when Ada_Single_Protected_Decl
927944
| Ada_Protected_Type_Decl
928945
| Ada_Protected_Body_Stub
929946
=>
930947
Generate_Local_Header (Name, Level);
931948
Generate_Subunit_Start (Level);
932-
Put ("protected body \1 is\n", Name);
949+
if Arg (Cmd, Spark_Mode_Off)
950+
and then Level = 0
951+
and then Decl.P_Has_Spark_Mode_On
952+
then
953+
Put ("protected body \1 with SPARK_Mode => Off is\n", Name);
954+
else
955+
Put ("protected body \1 is\n", Name);
956+
end if;
933957

934958
when Ada_Single_Task_Decl | Ada_Task_Type_Decl | Ada_Task_Body_Stub
935959
=>
936960
Generate_Local_Header (Name, Level);
937961
Generate_Subunit_Start (Level);
938-
Put ("task body \1 is\n", Name);
962+
if Arg (Cmd, Spark_Mode_Off)
963+
and then Level = 0
964+
and then Decl.P_Has_Spark_Mode_On
965+
then
966+
Put ("task body \1 with SPARK_Mode => Off is\n", Name);
967+
else
968+
Put ("task body \1 is\n", Name);
969+
end if;
939970
Generate_Stub_Begin_End (Name, "task");
940971

941972
when Ada_Subp_Decl | Ada_Generic_Subp_Decl | Ada_Subp_Body_Stub =>
942973
Generate_Local_Header (Name, Level);
943974
Generate_Subunit_Start (Level);
944975
Generate_Subp_Body
945-
(Decl, Name, Ada_Stub => Generating_Ada_Stubs);
976+
(Decl,
977+
Name,
978+
Ada_Stub => Generating_Ada_Stubs,
979+
Level => Level);
946980

947981
when Ada_Entry_Decl =>
948982
Generate_Local_Header (Name, Level);
@@ -1187,19 +1221,25 @@ package body Stub.Actions is
11871221
(if Root_Node.Kind in Ada_Body_Stub then Unit_Separate
11881222
else Unit_Body);
11891223
begin
1190-
pragma
1191-
Assert
1192-
(Extending_Project (Project (Arg_File_Info)) = No_Project);
1193-
-- We don't want to modify extended projects
1224+
if Project (Arg_File_Info) /= No_Project then
1225+
pragma
1226+
Assert
1227+
(Extending_Project (Project (Arg_File_Info)) = No_Project);
1228+
-- We don't want to modify extended projects
1229+
1230+
end if;
11941231

11951232
return
11961233
Result : constant String :=
1197-
+GNATCOLL.Projects.File_From_Unit
1198-
(Project => Project (Arg_File_Info),
1199-
Unit_Name => Unit_Name,
1200-
Part => Part,
1201-
Language => "Ada",
1202-
File_Must_Exist => False)
1234+
(if Project (Arg_File_Info) /= No_Project
1235+
then
1236+
+GNATCOLL.Projects.File_From_Unit
1237+
(Project => Project (Arg_File_Info),
1238+
Unit_Name => Unit_Name,
1239+
Part => Part,
1240+
Language => "Ada",
1241+
File_Must_Exist => False)
1242+
else Simple_Name (Default_Name))
12031243
do
12041244
null;
12051245
end return;
@@ -1531,7 +1571,10 @@ package body Stub.Actions is
15311571
Generate_Local_Header (Name, Level);
15321572
Generate_Subunit_Start (Level);
15331573
Generate_Subp_Or_Entry_Body
1534-
(Subp_Decl, Name, Ada_Stub => Arg (Cmd, Subunits));
1574+
(Decl => Subp_Decl,
1575+
Name => Name,
1576+
Ada_Stub => Arg (Cmd, Subunits),
1577+
Level => Level);
15351578
Set_Arg (Pp_Cmd, Initial_Indentation, 0);
15361579

15371580
declare

src/stub-command_lines.ads

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- --
33
-- Libadalang Tools --
44
-- --
5-
-- Copyright (C) 2021-2022, AdaCore --
5+
-- Copyright (C) 2021-2025, AdaCore --
66
-- --
77
-- Libadalang Tools is free software; you can redistribute it and/or modi- --
88
-- fy it under terms of the GNU General Public License as published by --
@@ -48,7 +48,8 @@ package Stub.Command_Lines is
4848
No_Exception,
4949
No_Local_Header,
5050
Ignored_Reuse_Tree_File,
51-
Ignored_Overwrite_Tree_File);
51+
Ignored_Overwrite_Tree_File,
52+
Spark_Mode_Off);
5253
-- Above "Ignored_" switches are legacy switches from the ASIS-based
5354
-- version.
5455

@@ -65,7 +66,8 @@ package Stub.Command_Lines is
6566
No_Exception => null,
6667
No_Local_Header => null,
6768
Ignored_Reuse_Tree_File => +"-r",
68-
Ignored_Overwrite_Tree_File => +"-t"]);
69+
Ignored_Overwrite_Tree_File => +"-t",
70+
Spark_Mode_Off => null]);
6971

7072
type Stub_Strings is (Header_File, Output);
7173

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package My_Package_1 with SPARK_Mode => On is
2+
procedure My_Procedure with SPARK_Mode => On;
3+
end My_Package_1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package My_Package_2 is
2+
procedure My_Procedure;
3+
end My_Package_2;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project My_Project is
2+
end My_Project;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
my_package_2.adb:11:10: warning: My_Procedure unimplemented [enabled by default]
2+
my_package_1.adb:13:10: warning: My_Procedure unimplemented [enabled by default]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gnatstub -q -P my_project.gpr --spark-mode-off
2+
gprbuild -q
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
description: gnatstub test
2+
driver: shell_script
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package My_Package_1 with SPARK_Mode => On is
2+
procedure My_Procedure with SPARK_Mode => On;
3+
end My_Package_1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package My_Package_2 is
2+
procedure My_Procedure;
3+
end My_Package_2;

0 commit comments

Comments
 (0)