---------------------------------------------------------- ---------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . A N N O T A T I O N S -- -- -- -- B o d y -- -- -- -- Copyright (C) 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 Locations; with Ocarina.Nodes; with Ocarina.Nutils; package body Ocarina.Annotations is use Locations; use Ocarina.Nodes; use Ocarina.Nutils; function Get_Annotation_Item (N : Node_Id; A : Node_Id) return Node_Id; function Get_Annotation_Item (N : Node_Id; A : Name_Id) return Node_Id; -- Return the annotation item identified by A from the annotation -- list of node N. Return No_Node if not found. ------------------------- -- Get_Annotation_Item -- ------------------------- function Get_Annotation_Item (N : Node_Id; A : Node_Id) return Node_Id is L : constant List_Id := Nodes.Annotations (N); I : Node_Id; begin if not Is_Empty (L) then I := First_Node (L); while Present (I) loop if Annotation_Node (I) = A then return I; end if; I := Next_Node (I); end loop; end if; return No_Node; end Get_Annotation_Item; ------------------------- -- Get_Annotation_Item -- ------------------------- function Get_Annotation_Item (N : Node_Id; A : Name_Id) return Node_Id is L : constant List_Id := Nodes.Annotations (N); I : Node_Id; begin if not Is_Empty (L) then I := First_Node (L); while Present (I) loop if Annotation_Name (I) = A then return I; end if; I := Next_Node (I); end loop; end if; return No_Node; end Get_Annotation_Item; -------------- -- Annotate -- -------------- procedure Annotate (N : Node_Id; A : Node_Id; I : Node_Id := No_Node) is AI : Node_Id := Get_Annotation_Item (N, A); begin if Present (AI) then Set_Annotation_Info (AI, I); else AI := Make_Annotation_Item (A, No_Name, I); if Nodes.Annotations (N) = No_List then Set_Annotations (N, New_List (K_List_Id, No_Location)); end if; Append_Node_To_List (AI, Nodes.Annotations (N)); end if; end Annotate; -------------- -- Annotate -- -------------- procedure Annotate (N : Node_Id; A : Name_Id; I : Node_Id := No_Node) is AI : Node_Id := Get_Annotation_Item (N, A); begin if Present (AI) then Set_Annotation_Info (AI, I); else AI := Make_Annotation_Item (No_Node, A, I); if Nodes.Annotations (N) = No_List then Set_Annotations (N, New_List (K_List_Id, No_Location)); end if; Append_Node_To_List (AI, Nodes.Annotations (N)); end if; end Annotate; ------------------------ -- Annotation_Present -- ------------------------ function Annotation_Present (N : Node_Id; A : Node_Id) return Boolean is begin return Present (Get_Annotation_Item (N, A)); end Annotation_Present; ------------------------ -- Annotation_Present -- ------------------------ function Annotation_Present (N : Node_Id; A : Name_Id) return Boolean is begin return Present (Get_Annotation_Item (N, A)); end Annotation_Present; -------------------- -- Get_Extra_Info -- -------------------- function Get_Extra_Info (N : Node_Id; A : Node_Id) return Node_Id is AI : constant Node_Id := Get_Annotation_Item (N, A); begin if No (AI) then raise Program_Error with "Annotation item not found"; end if; return Annotation_Info (AI); end Get_Extra_Info; -------------------- -- Get_Extra_Info -- -------------------- function Get_Extra_Info (N : Node_Id; A : Name_Id) return Node_Id is AI : constant Node_Id := Get_Annotation_Item (N, A); begin if No (AI) then raise Program_Error with "Annotation item not found"; end if; return Annotation_Info (AI); end Get_Extra_Info; ----------------------- -- Remove_Annotation -- ----------------------- procedure Remove_Annotation (N : Node_Id; A : Node_Id) is AI : constant Node_Id := Get_Annotation_Item (N, A); begin if Present (AI) then Remove_Node_From_List (AI, Nodes.Annotations (N)); end if; end Remove_Annotation; ----------------------- -- Remove_Annotation -- ----------------------- procedure Remove_Annotation (N : Node_Id; A : Name_Id) is AI : constant Node_Id := Get_Annotation_Item (N, A); begin if Present (AI) then Remove_Node_From_List (AI, Nodes.Annotations (N)); end if; end Remove_Annotation; ----------------------- -- Empty_Annotations -- ----------------------- procedure Empty_Annotations (N : Node_Id) is begin Set_Annotations (N, No_List); end Empty_Annotations; end Ocarina.Annotations;