Commit 13ce1261 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Cleanup code

parent 2671e391
...@@ -96,14 +96,14 @@ package body TASTE.Backend.Code_Generators is ...@@ -96,14 +96,14 @@ package body TASTE.Backend.Code_Generators is
end Generate_Global_Makefile; end Generate_Global_Makefile;
-- Render a set (Tag) of interfaces by applying a template -- Render a set (Tag) of interfaces by applying a template
function Process_Interfaces (Interfaces : Interface_Vectors.Vector; function Process_Interfaces (Interfaces : ST_Interfaces.Vector;
Path : String) return Tag Path : String) return Tag
is is
Result : Tag; Result : Tag;
Tmplt_Sign : constant String := Path & "interface.tmplt"; Tmplt_Sign : constant String := Path & "interface.tmplt";
begin begin
for Each of Interfaces loop for Each of Interfaces loop
Result := Result & String'(Parse (Tmplt_Sign, Each.Header)); Result := Result & String'(Parse (Tmplt_Sign, Each));
end loop; end loop;
return Result; return Result;
end Process_Interfaces; end Process_Interfaces;
...@@ -398,38 +398,10 @@ package body TASTE.Backend.Code_Generators is ...@@ -398,38 +398,10 @@ package body TASTE.Backend.Code_Generators is
& Assoc ("Instance_Of", & Assoc ("Instance_Of",
F.Instance_Of.Value_Or (US ("")))); F.Instance_Of.Value_Or (US (""))));
function Interface_Template (TI : Taste_Interface)
return Interface_As_Template
is
-- use Template_Vectors;
Result : Interface_As_Template;
Param_Names : Vector_Tag;
Param_Types : Vector_Tag;
Param_Directions : Vector_Tag;
Param_Encodings : Vector_Tag;
begin
Result.Header := +Assoc ("Name", TI.Name)
& Assoc ("Kind", TI.RCM'Img)
& Assoc ("Parent_Function", TI.Parent_Function);
for Each of TI.Params loop
-- Result.Params := Result.Params & Parameter_Template (Each, TI);
Param_Names := Param_Names & Each.Name;
Param_Types := Param_Types & Each.Sort;
Param_Directions := Param_Directions & Each.Direction'Img;
Param_Encodings := Param_Encodings & Each.Encoding'Img;
end loop;
Result.Header := Result.Header
& Assoc ("Param_Names", Param_Names)
& Assoc ("Param_Types", Param_Types)
& Assoc ("Param_Encodings", Param_Encodings)
& Assoc ("Param_Directions", Param_Directions);
return Result;
end Interface_Template;
function Func_Template (F : Taste_Terminal_Function) return Func_As_Template function Func_Template (F : Taste_Terminal_Function) return Func_As_Template
is is
use Interface_Vectors;
use Ctxt_Params; use Ctxt_Params;
use ST_Interfaces;
Result : Func_As_Template; Result : Func_As_Template;
List_Of_PIs : Tag; List_Of_PIs : Tag;
List_Of_RIs : Tag; List_Of_RIs : Tag;
...@@ -444,7 +416,7 @@ package body TASTE.Backend.Code_Generators is ...@@ -444,7 +416,7 @@ package body TASTE.Backend.Code_Generators is
Property_Values : Vector_Tag; Property_Values : Vector_Tag;
CP_Names : Vector_Tag; -- For Context Parameters CP_Names : Vector_Tag; -- For Context Parameters
CP_Types : Vector_Tag; -- For Context Parameters CP_Types : Vector_Tag; -- For Context Parameters
Interface_Tmplt : Interface_As_Template; Interface_Tmplt : Translate_Set;
begin begin
Result.Header := +Assoc ("Name", F.Name) Result.Header := +Assoc ("Name", F.Name)
& Assoc ("Language", Language_Spelling (F)) & Assoc ("Language", Language_Spelling (F))
...@@ -456,7 +428,7 @@ package body TASTE.Backend.Code_Generators is ...@@ -456,7 +428,7 @@ package body TASTE.Backend.Code_Generators is
CP_Types := CP_Types & Each.Sort; CP_Types := CP_Types & Each.Sort;
end loop; end loop;
-- Add all user-defined properties -- Add all function user-defined properties
for Each of F.User_Properties loop for Each of F.User_Properties loop
Property_Names := Property_Names & Each.Name; Property_Names := Property_Names & Each.Name;
Property_Values := Property_Values & Each.Value; Property_Values := Property_Values & Each.Value;
...@@ -464,12 +436,16 @@ package body TASTE.Backend.Code_Generators is ...@@ -464,12 +436,16 @@ package body TASTE.Backend.Code_Generators is
-- Add list of all PI names (both synchronous and asynchronous) -- Add list of all PI names (both synchronous and asynchronous)
for Each of F.Provided loop for Each of F.Provided loop
Interface_Tmplt := Interface_Template (Each); -- Note: some backends need to have access to the function
Interface_Tmplt.Header := Interface_Tmplt.Header -- user defined properties, and implementation language
& Assoc ("Direction", "PI") -- They are added here. At the moment the user-defined properties
& Assoc ("Property_Names", Property_Names) -- of the interfaces themselves are not part of the template
& Assoc ("Property_Values", Property_Values) -- This could be be added later if needed.
& Assoc ("Language", Language_Spelling (F)); Interface_Tmplt := Each.To_Template
& Assoc ("Direction", "PI")
& Assoc ("Property_Names", Property_Names)
& Assoc ("Property_Values", Property_Values)
& Assoc ("Language", Language_Spelling (F));
Result.Provided := Result.Provided & Interface_Tmplt; Result.Provided := Result.Provided & Interface_Tmplt;
List_Of_PIs := List_Of_PIs & Each.Name; List_Of_PIs := List_Of_PIs & Each.Name;
case Each.RCM is case Each.RCM is
...@@ -482,12 +458,11 @@ package body TASTE.Backend.Code_Generators is ...@@ -482,12 +458,11 @@ package body TASTE.Backend.Code_Generators is
-- Add list of all RI names (both synchronous and asynchronous) -- Add list of all RI names (both synchronous and asynchronous)
for Each of F.Required loop for Each of F.Required loop
Interface_Tmplt := Interface_Template (Each); Interface_Tmplt := Each.To_Template
Interface_Tmplt.Header := Interface_Tmplt.Header & Assoc ("Direction", "RI")
& Assoc ("Direction", "RI") & Assoc ("Property_Names", Property_Names)
& Assoc ("Property_Names", Property_Names) & Assoc ("Property_Values", Property_Values)
& Assoc ("Property_Values", Property_Values) & Assoc ("Language", Language_Spelling (F));
& Assoc ("Language", Language_Spelling (F));
Result.Required := Result.Required & Interface_Tmplt; Result.Required := Result.Required & Interface_Tmplt;
List_Of_RIs := List_Of_RIs & Each.Name; List_Of_RIs := List_Of_RIs & Each.Name;
case Each.RCM is case Each.RCM is
......
...@@ -13,20 +13,13 @@ package TASTE.Backend.Code_Generators is ...@@ -13,20 +13,13 @@ package TASTE.Backend.Code_Generators is
private private
package Template_Vectors is new Indefinite_Vectors (Natural, Translate_Set); package Template_Vectors is new Indefinite_Vectors (Natural, Translate_Set);
type Interface_As_Template is package ST_Interfaces is new Indefinite_Vectors (Natural, Translate_Set);
record
Header : Translate_Set;
-- Params : Template_Vectors.Vector;
end record;
package Interface_Vectors is new Indefinite_Vectors (Natural,
Interface_As_Template);
type Func_As_Template is type Func_As_Template is
record record
Header : Translate_set; Header : Translate_set;
Provided : Interface_Vectors.Vector; Provided : ST_Interfaces.Vector;
Required : Interface_Vectors.Vector; Required : ST_Interfaces.Vector;
end record; end record;
package Func_Maps is new Indefinite_Ordered_Maps (String, Func_As_Template); package Func_Maps is new Indefinite_Ordered_Maps (String, Func_As_Template);
...@@ -37,8 +30,6 @@ private ...@@ -37,8 +30,6 @@ private
end record; end record;
-- Set of functions translating the AST into Templates_Parser mappings -- Set of functions translating the AST into Templates_Parser mappings
function Interface_Template (TI : Taste_Interface)
return Interface_As_Template;
function Func_Template (F : Taste_Terminal_Function) function Func_Template (F : Taste_Terminal_Function)
return Func_As_Template; return Func_As_Template;
function CP_Template (F : Taste_Terminal_Function) return Translate_Set; function CP_Template (F : Taste_Terminal_Function) return Translate_Set;
......
...@@ -42,7 +42,7 @@ package body TASTE.Concurrency_View is ...@@ -42,7 +42,7 @@ package body TASTE.Concurrency_View is
end Debug_Dump; end Debug_Dump;
-- This function translates a protected block into a template -- This function translates a protected block into a template
function Pro_To_ST (B : Protected_Block) return Translate_Set is function To_Template (B : Protected_Block) return Translate_Set is
Calling_Threads : Tag; Calling_Threads : Tag;
-- TODO: Provided and Required -- TODO: Provided and Required
begin begin
...@@ -55,10 +55,10 @@ package body TASTE.Concurrency_View is ...@@ -55,10 +55,10 @@ package body TASTE.Concurrency_View is
& Assoc ("Calling_Threads", Calling_Threads) & Assoc ("Calling_Threads", Calling_Threads)
& Assoc ("Node_Name", To_String (B.Node.Value_Or & Assoc ("Node_Name", To_String (B.Node.Value_Or
(Taste_Node'(Name => US (""), others => <>)).Name))); (Taste_Node'(Name => US (""), others => <>)).Name)));
end Pro_To_ST; end To_Template;
-- This function translates a thread definition into a template -- This function translates a thread definition into a template
function Thread_To_ST (T : AADL_Thread) return Translate_Set is function To_Template (T : AADL_Thread) return Translate_Set is
Remote_Thread : Vector_Tag; Remote_Thread : Vector_Tag;
Remote_PI : Vector_Tag; Remote_PI : Vector_Tag;
Ports_Matrix : Matrix_Tag; Ports_Matrix : Matrix_Tag;
...@@ -77,7 +77,7 @@ package body TASTE.Concurrency_View is ...@@ -77,7 +77,7 @@ package body TASTE.Concurrency_View is
& Assoc ("Node_Name", To_String (T.Node.Value_Or & Assoc ("Node_Name", To_String (T.Node.Value_Or
(Taste_Node'(Name => US (""), others => <>)).Name)) (Taste_Node'(Name => US (""), others => <>)).Name))
& Assoc ("Out_Ports", Ports_Matrix)); & Assoc ("Out_Ports", Ports_Matrix));
end Thread_To_ST; end To_Template;
function Concurrency_View_Template (CV : Taste_Concurrency_View) function Concurrency_View_Template (CV : Taste_Concurrency_View)
return CV_As_Template return CV_As_Template
...@@ -85,10 +85,10 @@ package body TASTE.Concurrency_View is ...@@ -85,10 +85,10 @@ package body TASTE.Concurrency_View is
Result : CV_As_Template; Result : CV_As_Template;
begin begin
for Thread of CV.Threads loop for Thread of CV.Threads loop
Result.Threads.Append (Thread_To_ST (Thread)); Result.Threads.Append (Thread.To_Template);
end loop; end loop;
for Pro of CV.Blocks loop for Pro of CV.Blocks loop
Result.Blocks.Append (Pro_To_ST (Pro)); Result.Blocks.Append (Pro.To_Template);
end loop; end loop;
return Result; return Result;
end Concurrency_View_Template; end Concurrency_View_Template;
......
...@@ -35,7 +35,7 @@ package TASTE.Concurrency_View is ...@@ -35,7 +35,7 @@ package TASTE.Concurrency_View is
package Protected_Block_PIs is new Indefinite_Ordered_Maps package Protected_Block_PIs is new Indefinite_Ordered_Maps
(String, Protected_Block_PI); (String, Protected_Block_PI);
type Protected_Block is type Protected_Block is tagged
record record
Name : Unbounded_String; Name : Unbounded_String;
Provided : Protected_Block_PIs.Map; Provided : Protected_Block_PIs.Map;
...@@ -44,6 +44,8 @@ package TASTE.Concurrency_View is ...@@ -44,6 +44,8 @@ package TASTE.Concurrency_View is
Node : Option_Node.Option; Node : Option_Node.Option;
end record; end record;
function To_Template (B : Protected_Block) return Translate_Set;
package Protected_Blocks is new Indefinite_Ordered_Maps package Protected_Blocks is new Indefinite_Ordered_Maps
(String, Protected_Block); (String, Protected_Block);
...@@ -55,7 +57,7 @@ package TASTE.Concurrency_View is ...@@ -55,7 +57,7 @@ package TASTE.Concurrency_View is
package Ports is new Indefinite_Ordered_Maps (String, Port); package Ports is new Indefinite_Ordered_Maps (String, Port);
type AADL_Thread is type AADL_Thread is tagged
record record
Name : Unbounded_String; Name : Unbounded_String;
Entry_Port_Name : Unbounded_String; Entry_Port_Name : Unbounded_String;
...@@ -64,6 +66,8 @@ package TASTE.Concurrency_View is ...@@ -64,6 +66,8 @@ package TASTE.Concurrency_View is
Node : Option_Node.Option; Node : Option_Node.Option;
end record; end record;
function To_Template (T : AADL_Thread) return Translate_Set;
package AADL_Threads is new Indefinite_Ordered_Maps (String, AADL_Thread); package AADL_Threads is new Indefinite_Ordered_Maps (String, AADL_Thread);
type Taste_Concurrency_View is tagged type Taste_Concurrency_View is tagged
......
...@@ -958,4 +958,29 @@ package body TASTE.Interface_View is ...@@ -958,4 +958,29 @@ package body TASTE.Interface_View is
New_Line (Output); New_Line (Output);
end loop; end loop;
end Debug_Dump; end Debug_Dump;
-- Create a Templates_Parser translate set for an interface (PI or RI)
function To_Template (TI : Taste_Interface) return Translate_Set is
Result : Translate_Set;
Param_Names : Vector_Tag;
Param_Types : Vector_Tag;
Param_Directions : Vector_Tag;
Param_Encodings : Vector_Tag;
begin
Result := +Assoc ("Name", TI.Name)
& Assoc ("Kind", TI.RCM'Img)
& Assoc ("Parent_Function", TI.Parent_Function);
for Each of TI.Params loop
Param_Names := Param_Names & Each.Name;
Param_Types := Param_Types & Each.Sort;
Param_Directions := Param_Directions & Each.Direction'Img;
Param_Encodings := Param_Encodings & Each.Encoding'Img;
end loop;
Result := Result & Assoc ("Param_Names", Param_Names)
& Assoc ("Param_Types", Param_Types)
& Assoc ("Param_Encodings", Param_Encodings)
& Assoc ("Param_Directions", Param_Directions);
return Result;
end To_Template;
end TASTE.Interface_View; end TASTE.Interface_View;
...@@ -10,6 +10,7 @@ with Ada.Containers.Indefinite_Ordered_Maps, ...@@ -10,6 +10,7 @@ with Ada.Containers.Indefinite_Ordered_Maps,
Ada.Strings.Equal_Case_Insensitive, Ada.Strings.Equal_Case_Insensitive,
Ada.Strings.Less_Case_Insensitive, Ada.Strings.Less_Case_Insensitive,
Text_IO, Text_IO,
Templates_Parser,
Ocarina, Ocarina,
Ocarina.Types, Ocarina.Types,
Option_Type, Option_Type,
...@@ -18,6 +19,7 @@ with Ada.Containers.Indefinite_Ordered_Maps, ...@@ -18,6 +19,7 @@ with Ada.Containers.Indefinite_Ordered_Maps,
use Ada.Containers, use Ada.Containers,
Ada.Strings.Unbounded, Ada.Strings.Unbounded,
Text_IO, Text_IO,
Templates_Parser,
Ocarina, Ocarina,
Ocarina.Types, Ocarina.Types,
TASTE.Parser_Utils; TASTE.Parser_Utils;
...@@ -99,7 +101,7 @@ package TASTE.Interface_View is ...@@ -99,7 +101,7 @@ package TASTE.Interface_View is
package Remote_Entities is new Indefinite_Vectors (Natural, Remote_Entity); package Remote_Entities is new Indefinite_Vectors (Natural, Remote_Entity);
type Taste_Interface is type Taste_Interface is tagged
record record
Name : Unbounded_String; Name : Unbounded_String;
Parent_Function : Unbounded_String; Parent_Function : Unbounded_String;
...@@ -112,6 +114,8 @@ package TASTE.Interface_View is ...@@ -112,6 +114,8 @@ package TASTE.Interface_View is
User_Properties : Property_Maps.Map; User_Properties : Property_Maps.Map;
end record; end record;
function To_Template (TI : Taste_Interface) return Translate_Set;
package Interfaces_Maps is new Indefinite_Ordered_Maps (String, package Interfaces_Maps is new Indefinite_Ordered_Maps (String,
Taste_Interface); Taste_Interface);
...@@ -129,7 +133,7 @@ package TASTE.Interface_View is ...@@ -129,7 +133,7 @@ package TASTE.Interface_View is
type Taste_Terminal_Function is type Taste_Terminal_Function is
record record
Name : Unbounded_String; Name : Unbounded_String;
Context : Unbounded_String := Null_Unbounded_String; Context : Unbounded_String := Null_Unbounded_String;
Full_Prefix : Option_UString.Option := Option_UString.Nothing; Full_Prefix : Option_UString.Option := Option_UString.Nothing;
-- Language : Supported_Source_Language; -- Language : Supported_Source_Language;
Language : Unbounded_String; Language : Unbounded_String;
...@@ -151,8 +155,7 @@ package TASTE.Interface_View is ...@@ -151,8 +155,7 @@ package TASTE.Interface_View is
function "<"(Left, Right : Case_Insensitive_String) return Boolean function "<"(Left, Right : Case_Insensitive_String) return Boolean
renames Ada.Strings.Less_Case_Insensitive; renames Ada.Strings.Less_Case_Insensitive;
package Function_Maps is new Indefinite_Ordered_Maps package Function_Maps is new Indefinite_Ordered_Maps
(Case_Insensitive_String, (Case_Insensitive_String, Taste_Terminal_Function);
Taste_Terminal_Function);
type Connection is type Connection is
record record
......
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