Skip to content

Commit

Permalink
Merge branch 'topic/lalrefactor_issue8' into 'master'
Browse files Browse the repository at this point in the history
Refactor Get_Insert_New_Dependency_Location function

See merge request eng/ide/libadalang-tools!138
  • Loading branch information
joaopsazevedo committed Sep 5, 2023
2 parents eafdd97 + 3f31474 commit bd1dde7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 60 deletions.
51 changes: 1 addition & 50 deletions src/laltools-common.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- --
-- Libadalang Tools --
-- --
-- Copyright (C) 2021-2022, AdaCore --
-- Copyright (C) 2021-2023, AdaCore --
-- --
-- Libadalang Tools is free software; you can redistribute it and/or modi- --
-- fy it under terms of the GNU General Public License as published by --
Expand Down Expand Up @@ -1520,55 +1520,6 @@ package body Laltools.Common is
end return;
end Get_Compilation_Units;

------------------------------
-- Get_Insert_With_Location --
------------------------------

function Get_Insert_With_Location
(Node : Compilation_Unit'Class;
Pack_Name : Text_Type;
Last : out Boolean)
return Source_Location
is
-- Cover the no with clause case
Res : Source_Location := Start_Sloc (Node.Sloc_Range);
Searching_Insert_Loc : Boolean := True;
begin
Last := False;
for N of Node.F_Prelude loop
if N.Kind in Ada_With_Clause_Range then
-- Handle list of packages: "with A, B, C;"
for P of N.As_With_Clause.F_Packages loop
if Pack_Name = P.Text then
-- We are already withed
return No_Source_Location;
elsif Searching_Insert_Loc
and then Pack_Name < P.Text
then
-- Assuming the with clauses are sorted alphabetically,
-- the insert location is before the first clause higher
-- than us. (Attention we must insert before N and not P)
Last := False;
Res := Start_Sloc (N.Sloc_Range);
Searching_Insert_Loc := False;
end if;
end loop;
end if;

if Searching_Insert_Loc
and then N.Kind in Ada_With_Clause_Range | Ada_Use_Package_Clause
then
-- If the highest alphabetically, insert it after the last
-- with clause. To not split a pair also keep track of the last
-- use clause.
Last := True;
Res := End_Sloc (N.Sloc_Range);
end if;
end loop;

return Res;
end Get_Insert_With_Location;

---------------------------
-- Find_Matching_Parents --
---------------------------
Expand Down
11 changes: 1 addition & 10 deletions src/laltools-common.ads
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- --
-- Libadalang Tools --
-- --
-- Copyright (C) 2021-2022, AdaCore --
-- Copyright (C) 2021-2023, AdaCore --
-- --
-- Libadalang Tools is free software; you can redistribute it and/or modi- --
-- fy it under terms of the GNU General Public License as published by --
Expand Down Expand Up @@ -494,15 +494,6 @@ package Laltools.Common is
return Compilation_Unit_Vector;
-- Returns a vector with all Compilation_Unit nodes of Analysis_Unit

function Get_Insert_With_Location
(Node : Compilation_Unit'Class;
Pack_Name : Text_Type;
Last : out Boolean)
return Source_Location;
-- Returns the Source_Location where to insert a with clause for Pack_Name
-- or No_Source_Location if Pack_Name is already withed.
-- Last indicates if the location is after the last with/use clause.

function Get_Decl_Block_Declarative_Part (Decl_B : Decl_Block)
return Declarative_Part;
-- Gets the Declarative_Part of a Decl_Block
Expand Down

0 comments on commit bd1dde7

Please sign in to comment.