Skip to content

Commit c2c7abb

Browse files
committed
Fix Other_File for separates of subprograms without spec
Fix Other_File for the case when it is called on a separate, whose body stub is defined in a library subprogram body that does not have a separate spec. Improve its comment to clarify situation with separates. Add test. Change-Id: I55afa476b646370cda0a106a21d62cde66c12217 TN: U805-042
1 parent a917894 commit c2c7abb

File tree

12 files changed

+128
-2
lines changed

12 files changed

+128
-2
lines changed

src/gnatcoll-projects.adb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2887,7 +2887,29 @@ package body GNATCOLL.Projects is
28872887
if Unit (J) = '.' then
28882888
declare
28892889
Base : constant Filesystem_String := File_From_Unit
2890-
(Project (Info), Unit (Unit'First .. J - 1), Part,
2890+
(Project (Info), Unit (Unit'First .. J - 1), Unit_Spec,
2891+
Language => Info.Language);
2892+
begin
2893+
if Base'Length > 0 then
2894+
return Self.Create (Base, Use_Object_Path => False);
2895+
end if;
2896+
end;
2897+
end if;
2898+
end loop;
2899+
end if;
2900+
2901+
-- Second special case for separate units. When no parent spec has
2902+
-- been found, there still exists a scenario when separate is from
2903+
-- a body unit that does not have a spec. We need an extra loop
2904+
-- to not wrongly pick up the case when there is a chain of separates
2905+
-- one declared in another.
2906+
2907+
if Info.Part = Unit_Separate then
2908+
for J in reverse Unit'Range loop
2909+
if Unit (J) = '.' then
2910+
declare
2911+
Base : constant Filesystem_String := File_From_Unit
2912+
(Project (Info), Unit (Unit'First .. J - 1), Unit_Body,
28912913
Language => Info.Language);
28922914
begin
28932915
if Base'Length > 0 then

src/gnatcoll-projects.ads

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,12 @@ package GNATCOLL.Projects is
669669
function Other_File
670670
(Self : Project_Tree;
671671
File : GNATCOLL.VFS.Virtual_File) return GNATCOLL.VFS.Virtual_File;
672-
-- If Info is a spec, returns the body of the same unit. If Info is a
672+
-- If File is a spec, returns the body of the same unit. If File is a
673673
-- body, returns its spec.
674+
-- If File is a separate, returns parent (possibly indirect, looping
675+
-- through the chain of separates) unit spec. In case when a body stub
676+
-- is defined in a library subprogram body that does not have a separate
677+
-- spec, returns subprogram body file.
674678
-- If there is no "other file" in the project, but we could compute the
675679
-- name it should have, that name is returned (the file is created in the
676680
-- same directory as File).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
separate (Main)
2+
procedure Separate_Of_Body is
3+
begin
4+
null;
5+
end Separate_Of_Body;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
with Pkg_0;
2+
procedure Main is
3+
procedure Separate_Of_Body is separate;
4+
begin
5+
null;
6+
end Main;
7+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
separate (Pkg_0)
2+
procedure P_Separate_Common is
3+
begin
4+
null;
5+
end P_Separate_Common;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
separate (Pkg_0.Pack)
2+
procedure P_Separate_Of_Separate is
3+
begin
4+
null;
5+
end P_Separate_Of_Separate;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
separate (Pkg_0)
2+
package body Pack is
3+
procedure P_Separate_Of_Separate is separate;
4+
end Pack;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package body Pkg_0 is
2+
procedure P_Separate_Common is separate;
3+
4+
package body Pack is separate;
5+
end Pkg_0;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package Pkg_0 is
2+
procedure P_Separate_Common;
3+
package Pack is
4+
procedure P_Separate_Of_Separate;
5+
end Pack;
6+
end Pkg_0;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project Prj is
2+
for Main use ("main.adb");
3+
end Prj;
4+

0 commit comments

Comments
 (0)