Skip to content

Commit

Permalink
* Remove code duplication
Browse files Browse the repository at this point in the history
        For #111
  • Loading branch information
yoogx committed Jan 3, 2018
1 parent ab0c47c commit c556cbc
Showing 1 changed file with 18 additions and 70 deletions.
88 changes: 18 additions & 70 deletions src/backends/mast/ocarina-backends-mast-main.adb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2010-2015 ESA & ISAE. --
-- Copyright (C) 2010-2018 ESA & ISAE. --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -40,6 +40,7 @@ with Ocarina.Backends.MAST_Tree.Nutils;
with Ocarina.Backends.MAST_Values;
with Ocarina.Backends.Properties;
with Ocarina.Backends.Utils;
with Ocarina.Backends.Helper;

package body Ocarina.Backends.MAST.Main is

Expand All @@ -50,6 +51,7 @@ package body Ocarina.Backends.MAST.Main is
use Ocarina.Backends.Utils;
use Ocarina.Backends.Properties;
use Ocarina.Backends.MAST_Values;
use Ocarina.Backends.Helper;

package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
Expand All @@ -66,6 +68,7 @@ package body Ocarina.Backends.MAST.Main is
procedure Visit_Data (E : Node_Id);
procedure Visit_Device (E : Node_Id);
procedure Visit_Virtual_Processor (E : Node_Id);
procedure Visit_Subcomponents_Of is new Visit_Subcomponents_Of_G (Visit);

function Map_Port_Operation_Name
(The_Thread : Node_Id;
Expand Down Expand Up @@ -441,7 +444,6 @@ package body Ocarina.Backends.MAST.Main is
------------------

procedure Visit_Device (E : Node_Id) is
S : Node_Id;
N : Node_Id;
begin
N := Make_Driver_Wrapper (E);
Expand All @@ -451,24 +453,14 @@ package body Ocarina.Backends.MAST.Main is
MTU.Append_Node_To_List (N, MTN.Declarations (MAST_File));
end if;

if not AINU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the component instance corresponding to the
-- subcomponent S.

Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
Visit_Subcomponents_Of (E);
end Visit_Device;

---------------------
-- Visit_Processor --
---------------------

procedure Visit_Processor (E : Node_Id) is
S : Node_Id;
N : Node_Id;
begin
N :=
Expand All @@ -489,43 +481,23 @@ package body Ocarina.Backends.MAST.Main is

MTU.Append_Node_To_List (N, MTN.Declarations (MAST_File));

if not AINU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the component instance corresponding to the
-- subcomponent S.

Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
Visit_Subcomponents_Of (E);
end Visit_Processor;

-------------------
-- Visit_Process --
-------------------

procedure Visit_Process (E : Node_Id) is
S : Node_Id;
begin
if not AINU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the component instance corresponding to the
-- subcomponent S.

Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
Visit_Subcomponents_Of (E);
end Visit_Process;

----------------
-- Visit_Data --
-------------------

procedure Visit_Data (E : Node_Id) is
S : Node_Id;
N : Node_Id;
CP : constant Supported_Concurrency_Control_Protocol :=
Get_Concurrency_Protocol (E);
Expand Down Expand Up @@ -564,24 +536,14 @@ package body Ocarina.Backends.MAST.Main is
Append_Node_To_List (N, MTN.Declarations (MAST_File));
end if;

if not AINU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the component instance corresponding to the
-- subcomponent S.

Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
Visit_Subcomponents_Of (E);
end Visit_Data;

------------------
-- Visit_Thread --
------------------

procedure Visit_Thread (E : Node_Id) is
S : Node_Id;
N : Node_Id;
Call : Node_Id;
Spg_Call : Node_Id;
Expand Down Expand Up @@ -840,16 +802,7 @@ package body Ocarina.Backends.MAST.Main is
end loop;
end if;

if not AINU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the component instance corresponding to the
-- subcomponent S.

Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
Visit_Subcomponents_Of (E);

if Has_Ports (E) then
The_Feature := First_Node (Features (E));
Expand Down Expand Up @@ -900,21 +853,16 @@ package body Ocarina.Backends.MAST.Main is
------------------

procedure Visit_System (E : Node_Id) is
S : Node_Id;
begin
if not AINU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the component instance corresponding to the
-- subcomponent S.
if Get_Category_Of_Component (Corresponding_Instance (S)) /=
CC_Device
then
Visit (Corresponding_Instance (S));
end if;
for S of Subcomponents_Of (E) loop
-- Visit the component instance corresponding to the
-- subcomponent S.
if Get_Category_Of_Component (Corresponding_Instance (S)) /=
CC_Device
then
Visit (Corresponding_Instance (S));
end if;

S := Next_Node (S);
end loop;
end if;
end loop;
end Visit_System;
end Ocarina.Backends.MAST.Main;

0 comments on commit c556cbc

Please sign in to comment.