Skip to content

Commit

Permalink
extensions/nodes/ada_node/bodies: fix coding style
Browse files Browse the repository at this point in the history
no-tn-check
  • Loading branch information
pmderodat committed Jun 7, 2019
1 parent 9caa410 commit f4ebb5f
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions ada/extensions/nodes/ada_node/bodies
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ function P_Filter_Is_Imported_By
-- Decimal_IO, Enumeration_IO}
-- See `Actual_Target` to find out why these are considered special.

function Is_Special_Unit_Name
(Symbols : Internal_Symbol_Type_Array) return Boolean is
begin
-- Check that `Symbols` is of the form ("ada", "text_io", "xxx_io")
-- with xxx_io being the name of one of the special packages.
return Symbols'Length = 3 and then
Symbols (1 .. 2) = Ada_Text_IO_Symbol_Array and then
(for some Special_Package_Name of Ada_Text_IO_Special_Packages =>
Symbols (3) = Special_Package_Name);
end Is_Special_Unit_Name;

function Actual_Target return Internal_Unit;
-- There are special packages in the Ada runtime that are handled
-- in an ad-hoc way by GNAT: they are viewed as nested packages of
Expand All @@ -98,6 +87,30 @@ function P_Filter_Is_Imported_By
-- Ada.Text_IO instead, which allows the correct behavior of this whole
-- routine.

function Does_Import_Target (From : in Internal_Unit) return Boolean;
-- Predicate that returns True iff the given unit imports the target.
-- If Transitive is True, handle transitive imports.

--------------------------
-- Is_Special_Unit_Name --
--------------------------

function Is_Special_Unit_Name
(Symbols : Internal_Symbol_Type_Array) return Boolean is
begin
-- Check that `Symbols` is of the form ("ada", "text_io", "xxx_io")
-- with xxx_io being the name of one of the special packages.
return Symbols'Length = 3
and then Symbols (1 .. 2) = Ada_Text_IO_Symbol_Array
and then (for some Special_Package_Name
of Ada_Text_IO_Special_Packages =>
Symbols (3) = Special_Package_Name);
end Is_Special_Unit_Name;

-------------------
-- Actual_Target --
-------------------

function Actual_Target return Internal_Unit is
Target : constant Internal_Unit := Node.Unit;
T_Root : constant Bare_Ada_Node := Root (Target);
Expand All @@ -123,22 +136,24 @@ function P_Filter_Is_Imported_By
Target : constant Internal_Unit := Actual_Target;
Units_Import_Target : Analysis_Unit_Maps.Map;

function Does_Import_Target (From : in Internal_Unit) return Boolean;
-- Predicate that returns True iff the given unit imports the target.
-- If Transitive is True, handle transitive imports.
------------------------
-- Does_Import_Target --
------------------------

function Does_Import_Target (From : in Internal_Unit) return Boolean is
function Handle_Unit_Name
(Symbols : in Libadalang.Env_Hooks.Symbol_Type_Array)
return Boolean;
(Symbols : in Libadalang.Env_Hooks.Symbol_Type_Array) return Boolean;
-- Fetches the unit associated to the given name and returns whether
-- this unit IS the target unit. If Transitive is True, recursively look
-- if the target is one of the units imported by the given unit.

function Handle_Unit_Name
(Symbols : in Libadalang.Env_Hooks.Symbol_Type_Array)
return Boolean is
----------------------
-- Handle_Unit_Name --
----------------------

function Handle_Unit_Name
(Symbols : in Libadalang.Env_Hooks.Symbol_Type_Array) return Boolean
is
Unit : Internal_Unit := Libadalang.Env_Hooks.Fetch_Unit
(Node.Unit.Context, Symbols, Node.Unit,
Unit_Specification, True, False);
Expand Down Expand Up @@ -178,7 +193,7 @@ function P_Filter_Is_Imported_By
-- Add all explicit references by processing "with" clauses.

if Root_Node.Kind /= Ada_Compilation_Unit then
-- todo: handle list of compilation units.
-- TODO: handle list of compilation units.
raise Property_Error with
"Filter_Is_Imported_By: Unhandled type " & Root_Node.Kind'Image;
end if;
Expand All @@ -189,7 +204,7 @@ function P_Filter_Is_Imported_By
for I in 1 .. Prelude.Count loop
if Prelude.Item (I).Kind = Ada_With_Clause then
declare
Imported_Packages : Bare_Name_List :=
Imported_Packages : constant Bare_Name_List :=
Bare_With_Clause (Prelude.Item (I)).F_Packages;
begin
for J in 1 .. Imported_Packages.Count loop
Expand Down Expand Up @@ -221,8 +236,9 @@ function P_Filter_Is_Imported_By
(Unit_Name.Items'First .. Unit_Name.Items'Last - 1));
begin
if Parent_Symbols'Length > 0 then
if Handle_Unit_Name (Libadalang.Env_Hooks.Symbol_Type_Array
(Parent_Symbols)) then
if Handle_Unit_Name
(Libadalang.Env_Hooks.Symbol_Type_Array (Parent_Symbols))
then
Units_Import_Target.Replace (From, True);
return True;
end if;
Expand All @@ -243,8 +259,8 @@ begin

-- Create the result array from the vector.
declare
Result : Internal_Unit_Array_Access := Create_Internal_Unit_Array
(Natural (Result_Vector.Length));
Result : constant Internal_Unit_Array_Access :=
Create_Internal_Unit_Array (Natural (Result_Vector.Length));
N : Positive := Result.Items'First;
begin
for Unit of Result_Vector loop
Expand Down

0 comments on commit f4ebb5f

Please sign in to comment.