Commit 6f1e23f2 authored by julien.delange's avatar julien.delange

* begin to implementation traceability matrix for functional part

   of the system



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@2321 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 04192a21
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- OCARINA.BACKENDS.FUNCTIONS_MATRIX.MAIN --
-- --
-- B o d y --
-- --
-- Copyright (C) 2011, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.Properties;
with Ocarina.Backends.Messages;
with Ocarina.Backends.XML_Tree.Nodes;
with Ocarina.Backends.XML_Tree.Nutils;
with Namet; use Namet;
package body Ocarina.Backends.Functions_Matrix.Main is
use Ocarina.ME_AADL;
use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.ME_AADL.AADL_Instances.Entities;
use Ocarina.Backends.Messages;
use Ocarina.Backends.Properties;
use Ocarina.Backends.XML_Tree.Nutils;
package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
package XTN renames Ocarina.Backends.XML_Tree.Nodes;
procedure Visit_Architecture_Instance (E : Node_Id);
procedure Visit_Component_Instance (E : Node_Id);
procedure Visit_System_Instance (E : Node_Id);
Current_Parent_Node : Node_Id;
My_Root : Node_Id;
-----------
-- Visit --
-----------
procedure Visit (E : Node_Id) is
begin
case Kind (E) is
when K_Architecture_Instance =>
Visit_Architecture_Instance (E);
when K_Component_Instance =>
Visit_Component_Instance (E);
when others =>
null;
end case;
end Visit;
---------------------------------
-- Visit_Architecture_Instance --
---------------------------------
procedure Visit_Architecture_Instance (E : Node_Id) is
N : constant Node_Id := New_Node (XTN.K_HI_Node);
D : constant Node_Id := New_Node (XTN.K_HI_Distributed_Application);
U : Node_Id;
T : Node_Id;
P : Node_Id;
Q : Node_Id;
Tmp : Node_Id;
H1 : Node_Id;
Title : Node_Id;
begin
My_Root := Root_System (E);
XML_Root := D;
Get_Name_String (To_XML_Name (AIN.Name (AIN.Identifier (My_Root))));
XTN.Set_Name (D, Name_Find);
XTN.Set_Units (D, New_List (XTN.K_List_Id));
XTN.Set_HI_Nodes (D, New_List (XTN.K_List_Id));
Push_Entity (D);
Set_Str_To_Name_Buffer ("general");
XTN.Set_Name (N, Name_Find);
XTN.Set_Units (N, New_List (XTN.K_List_Id));
-- Append the partition N to the node list
Append_Node_To_List (N, XTN.HI_Nodes (Current_Entity));
XTN.Set_Distributed_Application (N, Current_Entity);
Push_Entity (N);
U := New_Node (XTN.K_HI_Unit, AIN.Identifier (My_Root));
Get_Name_String
(To_XML_Name (Display_Name (Identifier (My_Root))));
Add_Str_To_Name_Buffer ("_functions_matrix");
T := Make_Defining_Identifier (Name_Find);
P := Make_XML_File (T);
-- This is a special XML file, we specify .html extension
XTN.Set_Is_HTML (P, True);
XTN.Set_Distributed_Application_Unit (P, U);
XTN.Set_XML_File (U, P);
-- Make the main <html> node in the XML file.
XTN.Set_Root_Node (P, Make_XML_Node ("html"));
Append_Node_To_List (U, XTN.Units (Current_Entity));
XTN.Set_Entity (U, Current_Entity);
Push_Entity (U);
Current_Parent_Node := XTN.Root_Node
(XTN.XML_File (U));
-- Make the <head> node of the HTML file.
Tmp := Make_XML_Node ("head");
Append_Node_To_List (Tmp, XTN.Subitems (Current_Parent_Node));
-- Add a title in the <head> section node
Title := Make_XML_Node ("title");
Set_Str_To_Name_Buffer ("Traceability of functions " &
"implementation for System ");
Get_Name_String_And_Append (Display_Name (Identifier (My_Root)));
XTN.Set_Node_Value (Title, Make_Defining_Identifier (Name_Find));
Append_Node_To_List (Title, XTN.Subitems (Tmp));
-- Make the <body>...</body> node of the HTML file.
Tmp := Make_XML_Node ("body");
Append_Node_To_List (Tmp, XTN.Subitems (Current_Parent_Node));
Current_Parent_Node := Tmp;
-- Title of the document, using a <h1>...</h1> node
Tmp := Make_XML_Node ("h1");
Append_Node_To_List (Tmp, XTN.Subitems (Current_Parent_Node));
-- Style of the <h1> node
Set_Str_To_Name_Buffer
("font-family: Arial;" &
"text-align: center; font-weight: bold; font-size: 1.2em");
P := Make_Defining_Identifier (Name_Find);
Set_Str_To_Name_Buffer ("style");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, P), XTN.Items (Tmp));
-- Title of the document
Set_Str_To_Name_Buffer ("Traceability of functions implementation "&
"for System ");
Get_Name_String_And_Append (Display_Name (Identifier (My_Root)));
H1 := Make_Defining_Identifier (Name_Find);
XTN.Set_Node_Value (Tmp, H1);
Visit (My_Root);
Pop_Entity;
Pop_Entity;
Pop_Entity;
end Visit_Architecture_Instance;
------------------------------
-- Visit_Component_Instance --
------------------------------
procedure Visit_Component_Instance (E : Node_Id) is
Category : constant Component_Category
:= Get_Category_Of_Component (E);
begin
case Category is
when CC_System =>
Visit_System_Instance (E);
when others =>
null;
end case;
end Visit_Component_Instance;
---------------------------
-- Visit_System_Instance --
---------------------------
procedure Visit_System_Instance (E : Node_Id) is
S : Node_Id;
N : Node_Id;
T : Node_Id;
TR : Node_Id;
TD : Node_Id;
Table : Node_Id;
P : Node_Id;
Q : Node_Id;
Impl_System : Node_Id := No_Node;
Functional_System : Node_Id := No_Node;
begin
-- Declare the table node that will contain the connectivity matrix.
Table := Make_XML_Node ("table");
-- Some CSS style to apply on the table.
Set_Str_To_Name_Buffer ("border-style: solid; border-width: 1px;");
P := Make_Defining_Identifier (Name_Find);
Set_Str_To_Name_Buffer ("style");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, P), XTN.Items (Table));
if not AINU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
if Get_Category_Of_Component (S) = CC_System and then
Display_Name (Identifier (S)) =
Get_String_Name ("Functional") then
Functional_System := Corresponding_Instance (S);
end if;
if Get_Category_Of_Component (S) = CC_System and then
Display_Name (Identifier (S)) =
Get_String_Name ("Impl") then
Impl_System := Corresponding_Instance (S);
end if;
S := Next_Node (S);
end loop;
end if;
if Impl_System = No_Node then
Display_Error
("Implementation system not found", Fatal => True);
end if;
if Functional_System = No_Node then
Display_Error
("Functional system not found", Fatal => True);
end if;
if not AINU.Is_Empty (Subcomponents (Functional_System)) then
-- Add a <tr> node that represent a line.
TR := Make_XML_Node ("tr");
-- Add a <td> node that represent a colon in the line.
TD := Make_XML_Node ("td");
Append_Node_To_List (TD,
XTN.Subitems (TR));
S := First_Node (Subcomponents (Functional_System));
-- In the following loop, we build a complete line
-- that contains the name of all system subcomponents.
while Present (S) loop
TD := Make_XML_Node ("td");
Set_Str_To_Name_Buffer
("font-family: Arial; background-color: #0a97ac;" &
"text-align: center; font-weight: bold; font-size: 0.8em");
P := Make_Defining_Identifier (Name_Find);
Set_Str_To_Name_Buffer ("style");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, P), XTN.Items (TD));
Get_Name_String (Display_Name (Identifier (S)));
N := Make_Defining_Identifier (Name_Find);
XTN.Set_Node_Value (TD, N);
Append_Node_To_List (TD,
XTN.Subitems (TR));
S := Next_Node (S);
end loop;
Append_Node_To_List (TR,
XTN.Subitems (Table));
end if;
if not AINU.Is_Empty (Subcomponents (Impl_System)) then
S := First_Node (Subcomponents (Impl_System));
-- In the following loop, we iterate on each subcomponents
-- and analyzes which one is connected.
while Present (S) loop
if Get_Category_Of_Component (S) /= CC_Bus then
-- Create a new line (<tr> node).
TR := Make_XML_Node ("tr");
-- Create a new colon that contain the name of the
-- sub-component being analyzed.
TD := Make_XML_Node ("td");
Set_Str_To_Name_Buffer
("font-family: Arial; background-color: #0a97ac;" &
"text-align: center; font-weight: bold; font-size: 0.8em");
P := Make_Defining_Identifier (Name_Find);
Set_Str_To_Name_Buffer ("style");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, P), XTN.Items (TD));
Get_Name_String (Display_Name (Identifier (S)));
N := Make_Defining_Identifier (Name_Find);
XTN.Set_Node_Value (TD, N);
Append_Node_To_List (TD,
XTN.Subitems (TR));
T := First_Node (Subcomponents (Functional_System));
-- Here, we iterate again on all system sub-components
-- and try to see which one is connected to the component
-- actually analyzed (S).
while Present (T) loop
TD := Make_XML_Node ("td");
if Get_Bound_Function
(Corresponding_Instance (S)) /= No_Node and then
Get_Bound_Function
(Corresponding_Instance (S)) = T then
Set_Str_To_Name_Buffer ("X");
else
Set_Str_To_Name_Buffer ("O");
end if;
N := Make_Defining_Identifier (Name_Find);
if N /= No_Node then
XTN.Set_Node_Value (TD, N);
end if;
Append_Node_To_List (TD,
XTN.Subitems (TR));
T := Next_Node (T);
end loop;
Append_Node_To_List (TR,
XTN.Subitems (Table));
end if;
S := Next_Node (S);
end loop;
end if;
-- Add the table to the main HTML node (<body/>).
Append_Node_To_List (Table,
XTN.Subitems (Current_Parent_Node));
end Visit_System_Instance;
end Ocarina.Backends.Functions_Matrix.Main;
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- OCARINA.BACKENDS.FUNCTIONS_MATRIX.MAIN --
-- --
-- S p e c --
-- --
-- Copyright (C) 2011, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
package Ocarina.Backends.Functions_Matrix.Main is
Functions_Matrix_Root_Node : Node_Id;
procedure Visit (E : Node_Id);
end Ocarina.Backends.Functions_Matrix.Main;
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- O C A R I N A . B A C K E N D S . F U N C T I O N S _ M A T R I X --
-- --
-- B o d y --
-- --
-- Copyright (C) 2011, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
with Ocarina.Instances;
with Ocarina.Backends.Messages;
with Ocarina.Backends.Expander;
with Ocarina.Backends.XML_Tree.Generator;
with Ocarina.Backends.Utils;
with Ocarina.Backends.Functions_Matrix.Main;
with GNAT.Command_Line; use GNAT.Command_Line;
with Namet; use Namet;
package body Ocarina.Backends.Functions_Matrix is
use Ocarina.Instances;
use Ocarina.Backends.Expander;
use Ocarina.Backends.Messages;
use Ocarina.Backends.XML_Tree.Generator;
use Ocarina.Backends.Utils;
Remove_Generated_Sources : Boolean := False;
Generated_Sources_Directory : Name_Id := No_Name;
procedure Visit_Architecture_Instance (E : Node_Id);
-- Most top level visitor routine. E is the root of the AADL
-- instance tree. The procedure does a traversal for each
-- compilation unit to be generated.
--------------
-- Generate --
--------------
procedure Generate (AADL_Root : Node_Id) is
Instance_Root : Node_Id;
begin
Instance_Root := Instantiate_Model (AADL_Root);
Expand (Instance_Root);
Visit_Architecture_Instance (Instance_Root);
-- Abort if the construction of the tree failed
if No (XML_Root) then
Display_Error
("Functional traceability matrix " &
"generation failed", Fatal => True);
end if;
-- At this point, we have a valid tree, we can begin the XML
-- file generation.
-- Enter the output directory
Enter_Directory (Generated_Sources_Directory);
if not Remove_Generated_Sources then
-- Create the source files
XML_Tree.Generator.Generate (XML_Root);
end if;
-- Leave the output directory
Leave_Directory;
end Generate;
----------
-- Init --
----------
procedure Init is
begin
Generated_Sources_Directory := Get_String_Name (".");
Initialize_Option_Scan;
loop
case Getopt ("* b z o:") is
when ASCII.NUL =>
exit;
when 'z' =>
Remove_Generated_Sources := True;
when 'o' =>
declare
D : constant String := Parameter;
begin
if D'Length /= 0 then
Generated_Sources_Directory := Get_String_Name (D);
end if;
end;
when others =>
null;
end case;
end loop;
Register_Backend
("Function_Matrix",
Generate'Access,
Functions_Matrix_Analysis);
end Init;
-----------
-- Reset --
-----------
procedure Reset is
begin
null;
end Reset;
---------------------------------
-- Visit_Architecture_Instance --
---------------------------------
procedure Visit_Architecture_Instance (E : Node_Id) is
begin
Main.Visit (E);
end Visit_Architecture_Instance;
end Ocarina.Backends.Functions_Matrix;
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- O C A R I N A . B A C K E N D S . F U N C T I O N S _ M A T R I X --
-- --
-- S p e c --
-- --
-- Copyright (C) 2011, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
package Ocarina.Backends.Functions_Matrix is
procedure Generate (AADL_Root : Node_Id);
-- The main entry point of the generator
procedure Init;
-- Fills the corresponding location in the generator table by the
-- information on this generator and execute some initialization
-- routines necessary for its work.
procedure Reset;
private
XML_Root : Node_Id;
-- The root of the XML trees to generate HTML file.