Skip to content

Commit

Permalink
Merge branch 'machu/195-ada_2005-pragma-gets-added-in-a-loop' into 'm…
Browse files Browse the repository at this point in the history
…aster'

Emit `pragma Ada_2005` only once when generating stubs

Closes #195

See merge request eng/ide/libadalang-tools!245
  • Loading branch information
Volham22 committed Sep 27, 2024
2 parents 51b4e2a + 1c70fa5 commit f6785b4
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/test-stub.adb
Original file line number Diff line number Diff line change
Expand Up @@ -823,11 +823,6 @@ package body Test.Stub is

New_Line_Count;

if Add_Pragma_05 then
New_Line_Count;
S_Put (0, "pragma Ada_2005;");
end if;

if Markered_Data.Contains (ID) then
-- Extract importing MD
MD := Markered_Data.Element (ID);
Expand All @@ -839,6 +834,10 @@ package body Test.Stub is
S_Put (3, "with Ada.Real_Time;");
New_Line_Count;
end if;
if Add_Pragma_05 then
S_Put (0, "pragma Ada_2005;");
New_Line_Count;
end if;
end if;

S_Put (0, GT_Marker_Begin);
Expand Down
5 changes: 5 additions & 0 deletions testsuite/tests/test/195-repeated-pragmas/input.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project Input is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Source_Files use ("input.adb", "input.ads");
end Input;
8 changes: 8 additions & 0 deletions testsuite/tests/test/195-repeated-pragmas/ops.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
with "input";

project Ops is
for Source_Dirs use ("src");
for Object_Dir use "obj";

for Source_Files use ("square.adb", "square.ads");
end Ops;
10 changes: 10 additions & 0 deletions testsuite/tests/test/195-repeated-pragmas/src/input.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

with Text_IO;

package body Input is
function Read_Number return Integer is
S : String := Text_IO.Get_Line;
begin
return Integer'Value (S);
end Read_Number;
end Input;
3 changes: 3 additions & 0 deletions testsuite/tests/test/195-repeated-pragmas/src/input.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package Input is
function Read_Number return Integer;
end Input;
11 changes: 11 additions & 0 deletions testsuite/tests/test/195-repeated-pragmas/src/square.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
with Input;

package body Square is

function Square return Integer is
A : Integer := Input.Read_Number;
begin
return A * A;
end Square;

end Square;
4 changes: 4 additions & 0 deletions testsuite/tests/test/195-repeated-pragmas/src/square.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Square is
function Square return Integer;
-- Returns a square of a number
end Square;
56 changes: 56 additions & 0 deletions testsuite/tests/test/195-repeated-pragmas/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- begin read only
-- id:2.2/00/
--
-- This section can be used to add with clauses if necessary.
--
-- end read only

pragma Ada_2005;
-- begin read only
-- end read only

package Input.Stub_Data is

-- begin read only
-- id:2.2/04/a5520b8be5540073/b568d47f2e244743/0/Read_Number/
-- end read only
type Stub_Data_Type_Read_Number_a5520b_b568d4 is record
Read_Number_Result : Integer;

Stub_Counter : Natural := 0;
end record;
Stub_Data_Read_Number_a5520b_b568d4 : Stub_Data_Type_Read_Number_a5520b_b568d4;
procedure Set_Stub_Read_Number_a5520b_b568d4
(Read_Number_Result : Integer := Stub_Data_Read_Number_a5520b_b568d4.Read_Number_Result);
-- begin read only
-- end read only

end Input.Stub_Data;
-- begin read only
-- id:2.2/00/
--
-- This section can be used to add with clauses if necessary.
--
-- end read only

pragma Ada_2005;
-- begin read only
-- end read only

package Input.Stub_Data is

-- begin read only
-- id:2.2/04/a5520b8be5540073/b568d47f2e244743/0/Read_Number/
-- end read only
type Stub_Data_Type_Read_Number_a5520b_b568d4 is record
Read_Number_Result : Integer;

Stub_Counter : Natural := 0;
end record;
Stub_Data_Read_Number_a5520b_b568d4 : Stub_Data_Type_Read_Number_a5520b_b568d4;
procedure Set_Stub_Read_Number_a5520b_b568d4
(Read_Number_Result : Integer := Stub_Data_Read_Number_a5520b_b568d4.Read_Number_Result);
-- begin read only
-- end read only

end Input.Stub_Data;
10 changes: 10 additions & 0 deletions testsuite/tests/test/195-repeated-pragmas/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e

STUB_LOCATION='obj/gnattest_stub/stubs/Input/input-stub_data.ads'

gnattest --stub -P ops.gpr 2> /dev/null
cat $STUB_LOCATION
gnattest --stub -P ops.gpr 2> /dev/null
cat $STUB_LOCATION
4 changes: 4 additions & 0 deletions testsuite/tests/test/195-repeated-pragmas/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description:
gnattest test

driver: shell_script

0 comments on commit f6785b4

Please sign in to comment.