Commit eca3bce1 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Iterate on model transformations

parent cd279d58
......@@ -50,34 +50,44 @@ package body TASTE.Model_Transformations is
New_F : Taste_Terminal_Function :=
(Name => F.Name & "_" & PI.Name,
Language => US ("blackbox_device"),
-- Language_Device,
Context => F.Context,
Context => F.Name,
Required => F.Required, -- Inherit from RIs
others => <>);
New_F_PI : Taste_Interface := PI;
New_F_RI : Taste_Interface := PI;
Remote : constant Remote_Entity :=
(Function_Name => F.Name,
Interface_Name => PI.Name);
begin
New_F_PI.Parent_Function := New_F.Name;
New_F_RI.Parent_Function := New_F.Name;
-- Set the information about the function to which the new
-- RI is connected.
-- Set the name of the RI of the newly created function
-- (avoid keeping the same name as the PI)
New_F_RI.Name := (if PI.RCM = Cyclic_Operation
then "CYC_" & PI.Name
else "SPO_" & PI.Name);
-- Connect the new function's RI to the PI of the old function
New_F_RI.Remote_Interfaces.Clear;
New_F_RI.Remote_Interfaces.Append (Remote);
New_F_RI.Remote_Interfaces.Append
(Remote_Entity'(Function_Name => F.Name,
Interface_Name => PI.Name));
-- The Remote interface of the new PI are inherited from PI
-- Update the Remote interfaces of the callers of the PI to
-- make them point to the new function
-- TODO (need access to the model..)
-- we can probably do it after we return, since we will have
-- both the list of new funcxtions and the model
-- NOTE: The remote interfaces of the callers of the PI will be
-- updated after the creation of all new functions, at model
-- level.
-- Change the nature of the PI that triggered a new function
-- (Unprotected if the function only contained one active PI,
-- and possibly any number of other unprotected PIs)
PI.RCM := (if Count_Active_PI > 1
then Protected_Operation else Unprotected_Operation);
PI.RCM := (if Count_Active_PI > 1
then Protected_Operation
else Unprotected_Operation);
-- Replace the remotes of the PI with the new function
-- (They were copied to the PI of the new function)
PI.Remote_Interfaces.Clear;
PI.Remote_Interfaces.Append
(Remote_Entity'(Function_Name => New_F.Name,
Interface_Name => New_F_RI.Name));
-- Add the PI and RI to the new function
New_F.Provided.Insert (Key => To_String (PI.Name),
......@@ -85,6 +95,11 @@ package body TASTE.Model_Transformations is
New_F.Required.Insert (Key => To_String (New_F_RI.Name),
New_Item => New_F_RI);
-- Make sure the parent function of all RIs is set
for RI of New_F.Required loop
RI.Parent_Function := New_F.Name;
end loop;
-- Add to the list of newly created functions
New_Functions.Insert (Key => To_String (New_F.Name),
New_Item => New_F);
......@@ -112,8 +127,55 @@ package body TASTE.Model_Transformations is
end;
end loop;
-- Add all newly-created functions to the new model
-- Update the PI/RI connections of the existing functions:
-- For each PI and RI of newly-created function, look for all remote
-- functions, and check if the corresponding PI or RI already existed.
-- (1) If so, replace the old remote function with the new one
-- (2) If not, add corresponding PI or RI (not done yet TODO)
-- Then add all newly-created functions to the new model
-- NOTE: the following should be using the maps, not the nested
-- for loop/conditions...
for F of New_Functions loop
for PI of F.Provided loop
for Remote of PI.Remote_Interfaces loop
for Each of Result.Interface_View.Flat_Functions loop
if Each.Name = Remote.Function_Name then
for RI of Each.Required loop
if RI.Name = Remote.Interface_Name then
for RI_Remote of RI.Remote_Interfaces loop
if RI_Remote.Function_Name = F.Context then
-- Found it! Change the remote function name
RI_Remote.Function_Name := F.Name;
end if;
end loop;
end if;
end loop;
end if;
end loop;
end loop;
end loop;
-- for RI of F.Required loop
-- for Remote of RI.Remote_Interfaces loop
-- declare
-- Remote_Function : Function_Maps.Cursor :=
-- Result.Interface_View.Flat_Functions.Find
-- (To_String (Remote.Function_Name));
-- Corresponding_PI : Interfaces_Maps.Cursor :=
-- Function_Maps.Element (Remote_Function).Provided.Find
-- (To_String (Remote.Interface_Name));
-- begin
-- for PI_Remote of Interfaces_Maps.Element
-- (Corresponding_PI).Remote_Interfaces
-- loop
-- if PI_Remote.Function_Name = F.Context then
-- PI_Remote.Function_Name := F.Name;
-- end if;
-- end loop;
-- end;
-- end loop;
-- end loop;
Result.Interface_View.Flat_Functions.Insert
(Key => To_String (F.Name),
New_Item => F);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment