Skip to content

Commit

Permalink
Merge branch '13-w130-003-multiple-refactoring_suppress_separate-regr…
Browse files Browse the repository at this point in the history
…essions' into 'master'

Resolve "W130-003 multiple refactoring_suppress_separate regressions"

Closes #13

See merge request eng/ide/libadalang-tools!31
  • Loading branch information
joaopsazevedo committed Jan 30, 2023
2 parents dbe418d + 617e562 commit b64afac
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 115 deletions.
54 changes: 48 additions & 6 deletions src/laltools-common.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2370,13 +2370,8 @@ package body Laltools.Common is

function Get_Used_Units
(Node : Compilation_Unit'Class)
return Compilation_Unit_Array
return Compilation_Unit_Array
is
package Compilation_Unit_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural,
Element_Type => Compilation_Unit,
"=" => "=");

Used_Units : Compilation_Unit_Vectors.Vector;

begin
Expand Down Expand Up @@ -2416,6 +2411,53 @@ package body Laltools.Common is
end return;
end Get_Used_Units;

----------------------
-- Get_Withed_Units --
----------------------

function Get_Withed_Units
(Node : Compilation_Unit'Class)
return Compilation_Unit_Array
is
Used_Units : Compilation_Unit_Vectors.Vector;

begin
if Node.Is_Null then
return [];
end if;

for Clause of Node.F_Prelude loop
if Clause.Kind in Ada_With_Clause_Range then
for Use_Clause of Clause.As_With_Clause.F_Packages loop
declare
C_Unit : constant Compilation_Unit :=
Get_Compilation_Unit (Use_Clause.P_Referenced_Decl);
begin
if not C_Unit.Is_Null then
Used_Units.Append (C_Unit);
end if;
end;
end loop;
end if;
end loop;

-- Copy the Used_Units elements to an array

return R : Compilation_Unit_Array
(1 .. Integer (Used_Units.Length))
do
declare
Idx : Positive := 1;

begin
for U of Used_Units loop
R (Idx) := U;
Idx := Idx + 1;
end loop;
end;
end return;
end Get_Withed_Units;

------------
-- Insert --
------------
Expand Down
26 changes: 19 additions & 7 deletions src/laltools-common.ads
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ package Laltools.Common is
(Element_Type => Defining_Name,
"=" => "=");

package Compilation_Unit_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural,
Element_Type => Compilation_Unit,
"=" => "=");

subtype Compilation_Unit_Vector is Compilation_Unit_Vectors.Vector;

package Declarative_Part_Vectors is new Ada.Containers.Indefinite_Vectors
(Index_Type => Natural,
Element_Type => Declarative_Part'Class,
Expand Down Expand Up @@ -474,13 +481,6 @@ package Laltools.Common is
return Compilation_Unit;
-- Returns the Compilation_Unit associated to Node

package Compilation_Unit_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural,
Element_Type => Compilation_Unit,
"=" => "=");

subtype Compilation_Unit_Vector is Compilation_Unit_Vectors.Vector;

function Get_Compilation_Units
(Analysis_Unit : Libadalang.Analysis.Analysis_Unit)
return Compilation_Unit_Vector;
Expand Down Expand Up @@ -722,6 +722,18 @@ package Laltools.Common is
return Declarative_Part_Vectors.Vector;
-- Gets all public Declarative_Parts of the units used by Node's unit

function Get_Withed_Units
(Node : Compilation_Unit'Class)
return Compilation_Unit_Array;
-- Returns a Compilation_Unit_Array with all the Compilation_Unit
-- whose Node has a with clause for. If Node is null, then returns an empty
-- Compilation_Unit_Array. The return array does not contain null
-- Compilation_Units. This function differs from P_Withed_Units since
-- the latter will also return the parent packages of the withed
-- package. As an example, for 'with Ada.Assertions;', this function will
-- return only 'Ada.Assertions' while P_Withed_Units will return 'Ada' and
-- 'Ada.Assertions'.

function Get_Used_Units
(Node : Compilation_Unit'Class)
return Compilation_Unit_Array;
Expand Down
10 changes: 5 additions & 5 deletions src/laltools-refactor-suppress_separate.adb
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,19 @@ package body Laltools.Refactor.Suppress_Separate is
else Separate_Decl.P_Parent_Basic_Decl.As_Package_Decl);

Pkg_Spec_Withed_Units : constant Compilation_Unit_Array :=
Pkg_Spec.Unit.Root.As_Compilation_Unit.P_Withed_Units;
Get_Withed_Units (Pkg_Spec.Unit.Root.As_Compilation_Unit);
Pkg_Spec_Used_Units : constant Compilation_Unit_Array :=
Get_Used_Units (Pkg_Spec.Unit.Root.As_Compilation_Unit);

-- Package Body
Pkg_Body_Withed_Units : constant Compilation_Unit_Array :=
Separate_Stub.Unit.Root.As_Compilation_Unit.P_Withed_Units;
Get_Withed_Units (Separate_Stub.Unit.Root.As_Compilation_Unit);
Pkg_Body_Used_Units : constant Compilation_Unit_Array :=
Get_Used_Units (Separate_Stub.Unit.Root.As_Compilation_Unit);

-- Subunit
Subunit_Withed_Units : constant Compilation_Unit_Array :=
Separate_Body.Unit.Root.As_Compilation_Unit.P_Withed_Units;
Get_Withed_Units (Separate_Body.Unit.Root.As_Compilation_Unit);
Subunit_Used_Units : constant Compilation_Unit_Array :=
Get_Used_Units (Separate_Body.Unit.Root.As_Compilation_Unit);

Expand All @@ -274,12 +274,12 @@ package body Laltools.Refactor.Suppress_Separate is
Missing_With_Clauses :=
(As_Compilation_Unit_Set (Subunit_Withed_Units)
- (As_Compilation_Unit_Set (Pkg_Spec_Withed_Units)
or As_Compilation_Unit_Set (Pkg_Body_Withed_Units)));
or As_Compilation_Unit_Set (Pkg_Body_Withed_Units)));

Missing_Used_Clauses :=
(As_Compilation_Unit_Set (Subunit_Used_Units)
- (As_Compilation_Unit_Set (Pkg_Spec_Used_Units)
or As_Compilation_Unit_Set (Pkg_Body_Used_Units)));
or As_Compilation_Unit_Set (Pkg_Body_Used_Units)));
end;

-- Compute the necessary edits for the prelude ('with' and 'use'
Expand Down

This file was deleted.

0 comments on commit b64afac

Please sign in to comment.