----------------------------------------------- --------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . E X P A N D E R . F I N D E R -- -- -- -- B o d y -- -- -- -- 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.Nodes; with Ocarina.Entities; with Ocarina.Expander.Components.Subprogram_Calls; package body Ocarina.Expander.Finder is use Ocarina.Nodes; use Ocarina.Expander.Components.Subprogram_Calls; use Ocarina.Entities; ------------------- -- Find_Instance -- ------------------- function Find_Instance (Instance_Root : node_id; Reference_Instance : node_id; Path : list_id) return node_id is pragma assert (Kind (Instance_Root) = k_architecture_instance); pragma assert (Present (Reference_Instance)); List_Node : node_id; Actual_List_Node : node_id; Pointed_Instance : node_id; begin -- Path may be the path of an entity reference; in this case it -- is a list of node_container that contain identifiers. Else -- it is a list of identifiers. if Path = No_List then Pointed_Instance := Reference_Instance; else Pointed_Instance := Reference_Instance; List_Node := First_Node (Path); while Present (List_Node) loop if Kind (List_Node) = k_node_container then Actual_List_Node := Item (List_Node); else Actual_List_Node := List_Node; end if; pragma assert (Kind (Actual_List_Node) = k_identifier); Pointed_Instance := Find_Local_Instance (Pointed_Instance, Actual_List_Node); if No (Pointed_Instance) then exit; elsif Kind (Pointed_Instance) = k_call_instance then Pointed_Instance := Duplicate_Subprogram_Call_Instance (Instance_Root, Pointed_Instance); Pointed_Instance := Corresponding_Instance (Pointed_Instance); elsif Kind (Pointed_Instance) = k_subcomponent_instance then Pointed_Instance := Corresponding_Instance (Pointed_Instance); end if; List_Node := Next_Node (List_Node); end loop; end if; return Pointed_Instance; end Find_Instance; ------------------------- -- Find_Local_Instance -- ------------------------- function Find_Local_Instance (Reference_Instance : node_id; Instance_Identifier : node_id) return node_id is pragma assert (Kind (Reference_Instance) = k_component_instance or else Kind (Reference_Instance) = k_connection_instance); pragma assert (Kind (Instance_Identifier) = k_identifier); List_Node : node_id; Sequence_List_Node : node_id; Instance_Name : constant name_id := Name (Instance_Identifier); Component_Instance : node_id; begin if Kind (Reference_Instance) = k_component_instance then Component_Instance := Reference_Instance; else Component_Instance := Parent_Component (Reference_Instance); end if; -- We compare lower case names. So, when we use -- Get_Name_Of_Entity, we set the Get_Display_Name flag to -- 'False'. if Ocarina.Nodes.Features (Component_Instance) /= No_List then List_Node := First_Node (Ocarina.Nodes.Features (Component_Instance)); while Present (List_Node) loop if Get_Name_Of_Entity (List_Node, False) = Instance_Name then return List_Node; end if; List_Node := Next_Node (List_Node); end loop; end if; if Ocarina.Nodes.Subcomponents (Component_Instance) /= No_List then List_Node := First_Node (Ocarina.Nodes.Subcomponents (Component_Instance)); while Present (List_Node) loop if Get_Name_Of_Entity (List_Node, False) = Instance_Name then return List_Node; end if; List_Node := Next_Node (List_Node); end loop; end if; if Ocarina.Nodes.Modes (Component_Instance) /= No_List then List_Node := First_Node (Ocarina.Nodes.Modes (Component_Instance)); while Present (List_Node) loop if Get_Name_Of_Entity (List_Node, False) = Instance_Name then return List_Node; end if; List_Node := Next_Node (List_Node); end loop; end if; if Ocarina.Nodes.Connections (Component_Instance) /= No_List then List_Node := First_Node (Ocarina.Nodes.Connections (Component_Instance)); while Present (List_Node) loop if Get_Name_Of_Entity (List_Node, False) = Instance_Name then return List_Node; end if; List_Node := Next_Node (List_Node); end loop; end if; if Ocarina.Nodes.Calls (Component_Instance) /= No_List then List_Node := First_Node (Ocarina.Nodes.Calls (Component_Instance)); while Present (List_Node) loop if Ocarina.Nodes.Subprogram_Calls (List_Node) /= No_List then Sequence_List_Node := First_Node (Ocarina.Nodes.Subprogram_Calls (List_Node)); while Present (Sequence_List_Node) loop if Get_Name_Of_Entity (Sequence_List_Node, False) = Instance_Name then return Sequence_List_Node; end if; Sequence_List_Node := Next_Node (Sequence_List_Node); end loop; List_Node := Next_Node (List_Node); end if; end loop; end if; if Ocarina.Nodes.Flows (Component_Instance) /= No_List then List_Node := First_Node (Ocarina.Nodes.Flows (Component_Instance)); while Present (List_Node) loop if Get_Name_Of_Entity (List_Node, False) = Instance_Name then return List_Node; end if; List_Node := Next_Node (List_Node); end loop; end if; return No_Node; end Find_Local_Instance; end Ocarina.Expander.Finder;