Skip to content

Commit

Permalink
Merge branch 'mr/pmderodat/gpr2-simplification' into 'master'
Browse files Browse the repository at this point in the history
Refactor to use the new GPR2.Build.Compilation_Unit.Unit_Part API

See merge request eng/libadalang/libadalang!1711
  • Loading branch information
pmderodat committed Jul 26, 2024
2 parents 670554d + 361cb01 commit 43b2168
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 74 deletions.
59 changes: 0 additions & 59 deletions extensions/src/libadalang-gpr_utils.adb
Original file line number Diff line number Diff line change
Expand Up @@ -745,63 +745,4 @@ package body Libadalang.GPR_Utils is
return Result;
end Closure;

-----------------------
-- Unit_Location_For --
-----------------------

function Unit_Location_For
(Self : GPR2.Project.View.Object;
Name : String;
Kind : Analysis_Unit_Kind)
return GPR2.Build.Compilation_Unit.Unit_Location
is
use type GPR2.Name_Type;

Req_Name : constant GPR2.Name_Type := GPR2.Name_Type (Name);
Unit : constant GPR2.Build.Compilation_Unit.Object :=
Self.Unit (Req_Name);
begin
if Unit.Is_Defined then

-- If we got a unit, but not the one we requested, we are likely
-- requesting a subunit: in that case, extract the subunit name and
-- request it separately.

if Req_Name = Unit.Name then
case Kind is
when Unit_Specification =>
if Unit.Has_Part (GPR2.S_Spec) then
return Unit.Spec;
end if;
when Unit_Body =>
if Unit.Has_Part (GPR2.S_Body) then
return Unit.Main_Body;
end if;
end case;

else
pragma Assert (Kind = Unit_Body);
declare
-- Requested unit name is "[ROOT].[SEP]", the name of the unit
-- we got is "[ROOT]": skip it plus the "dot" to extract only
-- the "[SEP]" part.

Prefix_Last : constant Positive :=
Req_Name'First + Unit.Name'Length;

pragma Assert
(Req_Name (Req_Name'First .. Prefix_Last)
= GPR2."&" (Unit.Name, "."));
Subunit_Name : constant GPR2.Name_Type :=
Req_Name (Prefix_Last + 1 .. Req_Name'Last);
begin
return
Unit.Get (GPR2.S_Separate, Subunit_Name);
end;
end if;
end if;

return GPR2.Build.Compilation_Unit.No_Unit;
end Unit_Location_For;

end Libadalang.GPR_Utils;
14 changes: 0 additions & 14 deletions extensions/src/libadalang-gpr_utils.ads
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ with Ada.Containers.Vectors;
with GNATCOLL.File_Paths; use GNATCOLL.File_Paths;
with GNATCOLL.Projects;
with GNATCOLL.Strings; use GNATCOLL.Strings;
with GPR2.Build.Compilation_Unit;
with GPR2.Project.Registry.Attribute;
with GPR2.Project.Tree;
with GPR2.Project.View;
with GPR2.Project.View.Vector;

with Libadalang.Common; use Libadalang.Common;

private package Libadalang.GPR_Utils is

package GPR1 renames GNATCOLL.Projects;
Expand Down Expand Up @@ -206,15 +203,4 @@ private package Libadalang.GPR_Utils is
(Self : GPR2.Project.View.Object) return GPR2.Project.View.Vector.Object;
-- Return the list of all views reachable from ``Self``, self included

function Unit_Location_For
(Self : GPR2.Project.View.Object;
Name : String;
Kind : Analysis_Unit_Kind)
return GPR2.Build.Compilation_Unit.Unit_Location;
-- Look in ``Self`` for the location of the ``Name``/``Kind`` unit and
-- return it. Return ``No_Unit`` if it is not found.
--
-- TODO??? (eng/gpr/gpr-issues#338) Remove this function once an equivalent
-- one is included in LibGPR2.

end Libadalang.GPR_Utils;
4 changes: 3 additions & 1 deletion extensions/src/libadalang-project_provider.adb
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,9 @@ package body Libadalang.Project_Provider is
use type GPR2.Unit_Index;

Unit : constant GPR2.Build.Compilation_Unit.Unit_Location :=
Unit_Location_For (View.GPR2_Value, Str_Name, Kind);
View.GPR2_Value.Unit_Part
(Name => GPR2.Name_Type (Str_Name),
Is_Spec => Kind = Unit_Specification);
begin
if Unit /= GPR2.Build.Compilation_Unit.No_Unit then

Expand Down

0 comments on commit 43b2168

Please sign in to comment.