------------------------------------- ------------------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . G E N E R A T O R S . U T I L S -- -- -- -- S p e c -- -- -- -- Copyright (C) 2005-2007, GET-Telecom Paris. -- -- -- -- 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.Generators.Properties; use Ocarina.Generators.Properties; package Ocarina.Generators.Utils is -------------------------- -- Directory Operations -- -------------------------- procedure Create_Directory (Dir_Full_Name : name_id); -- Trys to create a directory and handle some creation errors procedure Enter_Directory (Dirname : name_id); -- Change the current directory to Dirname, and saves the -- old current_directory value procedure Leave_Directory; -- Leave the latest entered directory and change to la latest -- left directory function Add_Directory_Separator (Path : name_id) return name_id; -- If there is no directory separator at the end of the path, -- then add it and return the result. Else, return the same -- string. function Remove_Directory_Separator (Path : name_id) return name_id; -- If there is a directory separator at the end of the path, then -- remove it and retirn the result. Else, return the same string. ---------------------- -- Names Operations -- ---------------------- function Get_String_Name (The_String : String) return name_id; -- Enters 'The_String' in the name table and returns the -- corresponding name id -- FIXME : To be moved to Namet ---------- -- Misc -- ---------- function Normalize_Name (Name : name_id) return name_id; -- Rewrite Name so that it only contains characters that are legal -- in most languages: a-z, 0-9, _ ----------------------------------------------------- -- Routines that are common to the code generators -- ----------------------------------------------------- -- The routines below are used to chek the cathegory of a -- component or subcomponent instance. function Is_Data (C : node_id) return Boolean; function Is_Subprogram (C : node_id) return Boolean; function Is_Process (C : node_id) return Boolean; function Is_Thread (C : node_id) return Boolean; function Is_System (C : node_id) return Boolean; function Is_Processor (C : node_id) return Boolean; function Is_Bus (C : node_id) return Boolean; function Is_Namespace (N : node_id) return Boolean; -- Return True if the node N corresponds to a namespace instance -- node. function Has_In_Parameters (E : node_id) return Boolean; -- Return True IFF the subprogram instance E contains at least one -- IN or IN OUT parameter. function Has_Out_Parameters (E : node_id) return Boolean; -- Return True IFF the subprogram instance E contains at least one -- OUT or IN OUT parameter. function Has_In_Ports (E : node_id) return Boolean; -- Return True IFF the component instance E contains at least one -- IN or IN OUT port. function Has_Out_Ports (E : node_id) return Boolean; -- Return True IFF the component instance E contains at least one -- OUT or IN OUT port. function Has_Ports (E : node_id) return Boolean; -- Return True IFF the component instance E contains at least one -- port. function Has_Modes (E : node_id) return Boolean; -- Return True IFF the entity instance E has AADL operational -- modes. function Get_Source_Ports (P : node_id) return list_id; -- Return a node container list of all the THREAD OUT ports that are -- endpoint sources of the IN port P. function Get_Destination_Ports (P : node_id) return list_id; -- Return a node container list of all the THREAD IN ports that are -- endpoint sources of the OUT port P. function Get_Actual_Owner (Spg_Call : node_id) return node_id; -- Return the data *subcomponent* whose corresponding component -- has the corresponding subprogram of Spg_Call as a -- feature. No_Node is returned id Spg_Call is not a method call -- or if its not connected to the data access provider. function Get_Container_Process (E : node_id) return node_id; -- Return the process subcomponent instance that contains the -- subprogram call or thread instance E. function Get_Container_Thread (E : node_id) return node_id; -- Return the thread subcomponent instance that contains the -- subprogram call E. type comparison_kind is (by_name, by_node); -- When we want to "handle" a node only once, the "once" criterion -- may be the name of the node (in which case two different nodes -- having the same name will be seen as the same node) or by node -- in which case two different nodes are seen as two different -- nodes. type handling_kind is (h_add_enumerator_internals_spec, h_ada_marshallers_spec, h_ada_marshallers_body, h_ada_subprogram_spec, h_ada_subprogram_body, h_ada_type_body, h_ada_type_spec, h_ada_type_default_value, h_add_case_alternative_internals_spec, h_add_case_alternative_ssra_body, h_ada_namespaces_spec, h_ada_namespaces_body, h_ada_helpers_spec, h_ada_helpers_body, h_c_type_spec, h_c_type_body, h_c_type_default_value, h_c_stub_spec, h_c_stub_body, h_c_subprogram_spec, h_c_subprogram_body, h_c_unmarshall_spec, h_c_unmarshall_body, h_c_marshall_spec, h_c_marshall_body); -- These are tags to precise the meaning of "handle" procedure Set_Handling (E : node_id; Comparison : comparison_kind; Handling : handling_kind; A : node_id); -- Set the AADL node E as 'Handling'-handled by 'Comparison' and -- the handling result being the Ada node 'A'. function Get_Handling (E : node_id; Comparison : comparison_kind; Handling : handling_kind) return node_id; -- If the AADL node E has been already 'Handling'-handled by -- 'Comparison', then return the Ada node which is the handling -- result. Otherwise, return No_Node. procedure Start_Recording_Handlings; -- After a call to this procedure. All the new registered handling -- will be appended to the internal handling repository. -- IMPORTANT NOTE: No consecutive calls to Start_Recording are -- allowed. procedure Stop_Recording_Handlings; -- No more Handlings will be added to the internal handling -- repository afetr the call to this procedure. procedure Reset_Handlings; -- All the handlings present in the internal handling repository -- are reset. The internal handling repository is DEALLOCATED then -- REINITIALIZED at the end of the call. function Bind_Two_Nodes (N_1 : node_id; N_2 : node_id) return node_id; -- Bind the couple of given nodes to a newly creted node. The -- firts call of this function to a couple of nodes will crete a -- new binding node. The furthser calls will return the node -- creted at the first call. procedure Bind_Transport_API (P : node_id; T : supported_transport_apis); -- Create a link between the process instance P and the transport layer T function Fetch_Transport_API (P : node_id) return supported_transport_apis; -- Fetch a transport layer bound using 'Bind_Transport_API' function Map_Ada_Subprogram_Spec (S : node_id) return node_id; -- Create an Ada subprogram specification from the AADL subprogram -- instance S. function Map_Ada_Subprogram_Body (S : node_id) return node_id; -- Create an Ada subprogram body from the AADL subprogram instance -- S. function Map_Ada_Call_Seq_Subprogram_Spec (Spg : node_id; Seq : node_id) return node_id; -- Create the spec of the subprogram generated for a call sequence -- of a hybprod subprogram. function Map_Ada_Call_Seq_Subprogram_Body (Spg : node_id; Seq : node_id) return node_id; -- Create the body of the subprogram generated for a call sequence -- of a hybprod subprogram. function Map_Ada_Call_Seq_Access (S : node_id) return node_id; -- Map an access type declaration for a subprogram mapped from a -- call sequence of the hybrid subprogram S. function Map_Ada_Subprogram_Status (S : node_id) return node_id; -- Create an Ada record definition corresponding to the status of -- a hybrid AADL subprogram instance. function Map_Ada_Data_Type_Designator (E : node_id) return node_id; -- Fetch the Ada type corresponding to the data component instance -- E. procedure Handle_Call_Sequence (Caller : node_id; Call_Seq : node_id; Declarations : list_id; Statements : list_id); -- This procedure generate the Ada code correspodning to a call -- sequence of a thread or a subprogram. All local variable -- declarations will be generated in the Declarations list and all -- the subprogram calls will be generated in the Statements -- list. These two lists have to be initialized before the call to -- this subprogram. function Get_Ada_Default_Value (D : node_id) return node_id; -- Return an Ada "default value" for the Ada type mapped from the -- data component instance D. function Map_Ada_Full_Parameter_Name (Spg : node_id; P : node_id; Suffix : Character := ASCII.NUL) return name_id; -- Maps a name by concatening the subprogram instance full Spg -- name to the parameter instance P name (separated by '_') and -- verifying that the resulting name is an Ada-valid identifier -- name. function Map_Ada_Full_Feature_Name (E : node_id; Suffix : Character := ASCII.NUL) return name_id; -- Maps a name by concatening the full name of the feature -- instance E and to Suffix (separated by '_') and verifying that -- the resulting name is an Ada-valid identifier name. Any root -- system name will be troncated. function Map_Ada_Enumerator_Name (E : node_id; Server : Boolean := False) return name_id; -- Maps an Ada-valid enumerator name from the component or -- subcomponent instance E. If Server is True, appends the _Server -- suffix to the enumerator identifier. function Map_Ada_Defining_Identifier (A : node_id; Suffix : Character := ASCII.NUL) return node_id; -- Maps an Ada-valid defining identifier form the name of the -- given AADL entity. If suffix is not nul, concat it to the -- obtained name and separate them by a '_'. function Map_Ada_Component_Name (F : node_id) return name_id; -- Map a name corresponding to a component corresponding to an -- [event] data port in a thread interface. function Map_Ada_Protected_Aggregate_Identifier (S : node_id; A : node_id) return node_id; -- Maps an identifier correspodning to the subcomponent A of the -- required data S. function Map_Ada_Default_Value_Identifier (D : node_id) return node_id; -- Maps an identifier for the default value variable corresponding -- to the AADL data component instance D. function Map_Ada_Subprogram_Identifier (E : node_id) return node_id; -- Return a node that designate the implementation subprogram -- corresponding to the entity instance E. E is either a thread, -- subprogram or a port instance. If a 'with' clause is necessary, -- this subprogram add it. function Map_Ada_Namespace_Defining_Identifier (N : node_id; Prefix : String := "") return node_id; -- Creates an Ada defining identifier corresponding to the -- namespace instance E. The parent unit names of the Identifier -- are correctly laced depending on the namespace hierarchey. If -- 'Prefix' is specified, then all the full name is prefixed by it. function Map_Ada_Size (S : size_type) return unsigned_long_long; -- Converts the given size S into bytes and return it. If the size -- cannot be converted into byte, then return 0. procedure Check_Connection_Consistency (C : node_id); -- Perform some legality rules check on the connection instance S -- and raises an error if one of these rules is broken. See the -- comments in the body for more detail on the checked rules. procedure Check_Thread_Consistency (T : node_id); -- Check the thread consistency and raises an error if something -- is wrong (Unknown implementation kind). function Get_Subcomponent_Access_Source (S : node_id) return node_id; -- Return the source subcomponent of the required subprogram -- access S. Raises an error if S is not connected to any source. end Ocarina.Generators.Utils;